private void renderWay(Way way) { this.drawingLayers = this.ways[getValidLayer(way.Layer)]; // TODO what about the label position? GeoPointList2 GeoPoints = way.GeoPoints; this.coordinates = new MapPoint[GeoPoints.Count][]; for (int i = 0; i < this.coordinates.Length; ++i) { this.coordinates[i] = new MapPoint[GeoPoints[i].Count]; for (int j = 0; j < this.coordinates[i].Length; ++j) { this.coordinates[i][j] = scaleGeoPoint(GeoPoints[i][j]); } } this.shapeContainer = new WayContainer(this.coordinates); if (GeometryUtils.isClosedWay(this.coordinates[0])) { this.renderTheme.matchClosedWay(this, way.Tags, this.currentTile.ZoomFactor); } else { this.renderTheme.matchLinearWay(this, way.Tags, this.currentTile.ZoomFactor); } }
private GeoPointList2 processWayDataBlock(bool doubleDeltaEncoding) { // get and check the number of way coordinate blocks (VBE-U) int numberOfWayCoordinateBlocks = this.readBuffer.ReadUnsignedInt(); if (numberOfWayCoordinateBlocks < 1 || numberOfWayCoordinateBlocks > short.MaxValue) { System.Diagnostics.Debug.WriteLine("invalid number of way coordinate blocks: " + numberOfWayCoordinateBlocks); return(null); } // create the array which will store the different way coordinate blocks GeoPointList2 wayCoordinates = new GeoPointList2(numberOfWayCoordinateBlocks); // read the way coordinate blocks for (int coordinateBlock = 0; coordinateBlock < numberOfWayCoordinateBlocks; coordinateBlock++) { // get and check the number of way nodes (VBE-U) int numberOfWayNodes = this.readBuffer.ReadUnsignedInt(); if (numberOfWayNodes < 2 || numberOfWayNodes > MAXIMUM_WAY_NODES_SEQUENCE_LENGTH) { System.Diagnostics.Debug.WriteLine("invalid number of way nodes: " + numberOfWayNodes); return(null); } // create the array which will store the current way segment GeoPointList waySegment; if (doubleDeltaEncoding) { waySegment = decodeWayNodesDoubleDelta(numberOfWayNodes); } else { waySegment = DecodeWayNodesSingleDelta(numberOfWayNodes); } wayCoordinates.Add(waySegment); } return(wayCoordinates); }
private List <Way> processWays(QueryParameters queryParameters, int numberOfWays) { List <Way> ways = new List <Way>(); Tag[] wayTags = this.mapFileHeader.MapFileInfo.WayTags; for (int elementCounter = numberOfWays; elementCounter != 0; --elementCounter) { if (this.mapFileHeader.MapFileInfo.DebugFile) { // get and check the way signature this.signatureWay = this.readBuffer.ReadUTF8Encodedstring(SIGNATURE_LENGTH_WAY); if (!this.signatureWay.StartsWith("---WayStart")) { System.Diagnostics.Debug.WriteLine("invalid way signature: " + this.signatureWay); System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_BLOCK + this.signatureBlock); return(null); } } // get the size of the way (VBE-U) int wayDataSize = this.readBuffer.ReadUnsignedInt(); if (wayDataSize < 0) { System.Diagnostics.Debug.WriteLine("invalid way data size: " + wayDataSize); if (this.mapFileHeader.MapFileInfo.DebugFile) { System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_BLOCK + this.signatureBlock); } return(null); } if (queryParameters.useTileBitmask) { // get the way tile bitmask (2 bytes) int tileBitmask = this.readBuffer.Readshort(); // check if the way is inside the requested tile if ((queryParameters.queryTileBitmask & tileBitmask) == 0) { // skip the rest of the way and continue with the next way this.readBuffer.SkipBytes(wayDataSize - 2); continue; } } else { // ignore the way tile bitmask (2 bytes) this.readBuffer.SkipBytes(2); } // get the special byte which encodes multiple flags byte specialbyte = (byte)this.readBuffer.ReadByte(); // bit 1-4 represent the layer byte layer = (byte)((specialbyte & WAY_LAYER_BITMASK) >> WAY_LAYER_SHIFT); // bit 5-8 represent the number of tag IDs byte numberOfTags = (byte)(specialbyte & WAY_NUMBER_OF_TAGS_BITMASK); List <Tag> tags = new List <Tag>(); for (byte tagIndex = numberOfTags; tagIndex != 0; --tagIndex) { int tagId = this.readBuffer.ReadUnsignedInt(); if (tagId < 0 || tagId >= wayTags.Length) { System.Diagnostics.Debug.WriteLine("invalid way tag ID: " + tagId); return(null); } tags.Add(wayTags[tagId]); } // get the feature bitmask (1 byte) byte featurebyte = (byte)this.readBuffer.ReadByte(); // bit 1-6 enable optional features bool featureName = (featurebyte & WAY_FEATURE_NAME) != 0; bool featureHouseNumber = (featurebyte & WAY_FEATURE_HOUSE_NUMBER) != 0; bool featureRef = (featurebyte & WAY_FEATURE_REF) != 0; bool featureLabelPosition = (featurebyte & WAY_FEATURE_LABEL_POSITION) != 0; bool featureWayDataBlocksbyte = (featurebyte & WAY_FEATURE_DATA_BLOCKS_byte) != 0; bool featureWayDoubleDeltaEncoding = (featurebyte & WAY_FEATURE_DOUBLE_DELTA_ENCODING) != 0; // check if the way has a name if (featureName) { tags.Add(new Tag(TAG_KEY_NAME, this.readBuffer.ReadUTF8Encodedstring())); } // check if the way has a house number if (featureHouseNumber) { tags.Add(new Tag(TAG_KEY_HOUSE_NUMBER, this.readBuffer.ReadUTF8Encodedstring())); } // check if the way has a reference if (featureRef) { tags.Add(new Tag(TAG_KEY_REF, this.readBuffer.ReadUTF8Encodedstring())); } GeoPoint labelPosition = readOptionalLabelPosition(featureLabelPosition); int wayDataBlocks = readOptionalWayDataBlocksbyte(featureWayDataBlocksbyte); if (wayDataBlocks < 1) { System.Diagnostics.Debug.WriteLine("invalid number of way data blocks: " + wayDataBlocks); return(null); } for (int wayDataBlock = 0; wayDataBlock < wayDataBlocks; ++wayDataBlock) { GeoPointList2 wayNodes = processWayDataBlock(featureWayDoubleDeltaEncoding); if (wayNodes == null) { return(null); } ways.Add(new Way(layer, tags, wayNodes, labelPosition)); } } return(ways); }