Skip to content
Permalink
Browse files

Read & render polygon label/symbol position, fix #1064

  • Loading branch information...
devemux86 committed May 17, 2018
1 parent 2845cf2 commit 12dffae7a168d6efe43cd6b7bc9ec8df456d573b
@@ -3,8 +3,9 @@
## New since 0.9.1

- Mapsforge maps **v5 beta**: custom tag keys [#1041](https://github.com/mapsforge/mapsforge/issues/1041)
- Read & render polygon label/symbol position [#1064](https://github.com/mapsforge/mapsforge/issues/1064)
- POI: offline address search [#1063](https://github.com/mapsforge/mapsforge/issues/1063)
- POI: tag keys as categories [#1062](https://github.com/mapsforge/mapsforge/pull/1062)
- POI writer: tag keys as categories [#1062](https://github.com/mapsforge/mapsforge/pull/1062)
- MyLocationOverlay implementation [#1035](https://github.com/mapsforge/mapsforge/issues/1035)
- Polyline / Polygon rendering optimizations [#1057](https://github.com/mapsforge/mapsforge/issues/1057)
- Tile sources with api keys [#1028](https://github.com/mapsforge/mapsforge/issues/1028)
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014-2015 Ludwig M Brinckmann
* Copyright 2014-2017 devemux86
* Copyright 2014-2018 devemux86
* Copyright 2015-2016 lincomatic
* Copyright 2016 bvgastel
* Copyright 2017 linuskr
@@ -796,7 +796,10 @@ private MapReadResult processBlocks(QueryParameters queryParameters, SubFilePara
tags.add(new Tag(TAG_KEY_REF, readBuffer.readUTF8EncodedString()));
}

LatLong labelPosition = readOptionalLabelPosition(tileLatitude, tileLongitude, featureLabelPosition, readBuffer);
int[] labelPosition = null;
if (featureLabelPosition) {
labelPosition = readOptionalLabelPosition(readBuffer);
}

int wayDataBlocks = readOptionalWayDataBlocksByte(featureWayDataBlocksByte, readBuffer);
if (wayDataBlocks < 1) {
@@ -811,7 +814,12 @@ private MapReadResult processBlocks(QueryParameters queryParameters, SubFilePara
continue;
}
if (Selector.ALL == selector || featureName || featureHouseNumber || featureRef || wayAsLabelTagFilter(tags)) {
ways.add(new Way(layer, tags, wayNodes, labelPosition));
LatLong labelLatLong = null;
if (labelPosition != null) {
labelLatLong = new LatLong(wayNodes[0][0].latitude + LatLongUtils.microdegreesToDegrees(labelPosition[1]),
wayNodes[0][0].longitude + LatLongUtils.microdegreesToDegrees(labelPosition[0]));
}
ways.add(new Way(layer, tags, wayNodes, labelLatLong));
}
}
}
@@ -899,18 +907,16 @@ private MapReadResult readMapData(Tile upperLeft, Tile lowerRight, Selector sele
}
}

private LatLong readOptionalLabelPosition(double tileLatitude, double tileLongitude, boolean featureLabelPosition, ReadBuffer readBuffer) {
if (featureLabelPosition) {
// get the label position latitude offset (VBE-S)
double latitude = tileLatitude + LatLongUtils.microdegreesToDegrees(readBuffer.readSignedInt());
private int[] readOptionalLabelPosition(ReadBuffer readBuffer) {
int[] labelPosition = new int[2];

// get the label position longitude offset (VBE-S)
double longitude = tileLongitude + LatLongUtils.microdegreesToDegrees(readBuffer.readSignedInt());
// get the label position latitude offset (VBE-S)
labelPosition[1] = readBuffer.readSignedInt();

return new LatLong(latitude, longitude);
}
// get the label position longitude offset (VBE-S)
labelPosition[0] = readBuffer.readSignedInt();

return null;
return labelPosition;
}

private int readOptionalWayDataBlocksByte(boolean featureWayDataBlocksByte, ReadBuffer readBuffer) {
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2015 devemux86
* Copyright 2015-2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -52,9 +52,12 @@ public PolylineContainer(Way way, Tile upperLeft, Tile lowerRight) {
this.tags = way.tags;
this.upperLeft = upperLeft;
this.lowerRight = lowerRight;
layer = way.layer;
this.layer = way.layer;
this.way = way;
this.isClosedWay = LatLongUtils.isClosedWay(way.latLongs[0]);
if (this.way.labelPosition != null) {
this.center = MercatorProjection.getPixelAbsolute(this.way.labelPosition, this.upperLeft.mapSize);
}
}

public PolylineContainer(Point[] coordinates, final Tile upperLeft, final Tile lowerRight, List<Tag> tags) {
@@ -70,7 +73,7 @@ public PolylineContainer(Point[] coordinates, final Tile upperLeft, final Tile l
}

public Point getCenterAbsolute() {
if (null == center) {
if (this.center == null) {
this.center = GeometryUtils.calculateCenterOfBoundingBox(getCoordinatesAbsolute()[0]);
}
return this.center;

0 comments on commit 12dffae

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.