Reputation: 3
I am trying to highlight a feature on a map using Mapbox Android SDK. First, the map is loaded in the app using custom styles from a vector tiles server.
To highlight the feature, the data is received from a server with the coordinates and feature data stored in the database. The android app receives a GeoJSON like this:
{
…
"geometry":{
[enter image description here][1]"type":"LineString",
"coordinates":[
[-6.280378997325897,36.52107960787673],[-6.280381679534912,36.52104619723205],
[-6.280373632907867,36.52102787525949]
]
},
"mapboxId":487
…
}
I use the geometry type to know the type of object and then create a feature of the same type from the geometry itself.
when (current.getGeometryType()) {
POINT -> …
LINE_STRING -> marker.geometry = LineString.fromJson(current.getGeometry())
…
}
Then I add the Source and Layer with some properties.
style.apply {
addSource(
GeoJsonSource(
SOURCE_ID3_RED_BORDER,
FeatureCollection.fromFeatures(marker)
)
)
addLayer(
LineLayer(
LAYER_ID3_RED_BORDER,
SOURCE_ID3_RED_BORDER
)
.withProperties(
PropertyFactory.lineGapWidth(5f),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineWidth(2f),
PropertyFactory.lineColor(Color.RED)
)
)
}
But my LineString does not exactly fit with the LineString data received from the server, probably due to generalization of the vector tiles, since we receive
The result is not what I expected, I would like the red line to fit exactly with the green one. I don’t know why the lines don’t fit.
Is there a way to achieve this? It seems to be similar to the "Select Building" example (https://docs.mapbox.com/android/maps/examples/select-a-building/) but the feature to be highlighted is not driven by the selection of the user, but from a know feature data coming from a server when loading the map view.
Upvotes: 0
Views: 847
Reputation: 1790
For some parts of it, like the curve, you do not have enough coordinates to represent the curve. For the straight parts, there appears to be the same problem. When you look at the part below the yellow region, the red lines are perfectly aligned with the green.
In this parts you have sufficient coordinates. In the rest you do not.
Upvotes: 0