maplibre / maplibre-gl-js

MapLibre GL JS - Interactive vector tile maps in the browser
https://maplibre.org/maplibre-gl-js/docs/
Other
6.74k stars 726 forks source link

Symbol for polygon not placed at center. #5048

Open exotfboy opened 2 weeks ago

exotfboy commented 2 weeks ago

Hi:

When adding symbols to polygons with symbol-placement set to point, it is expected that the symbol will be placed at the center of the polygon.

However, in some situations, this is not the case. Live Example.

As shown in the example, the symbol for A is correctly centered, while the symbol for B is not.

What's going on?

HarelM commented 1 week ago

I would consider this as an issue with the limitation of accuracy for geojson source. Geojson source only build tiles to zoom 15 or something similar, so the accuracy at zoom 21 is very low, which I would assume what's causing this calculation issues. But you are more than welcome to check my theory. You can also try out making vector tiles with higher resolution to see if it helps.

exotfboy commented 1 week ago

1 I will have a try if possible.

2 Any fallback instead of vector tiles at the moment?

HarelM commented 1 week ago

Maybe addProtocol where you could return the relevant tiles you create "on the fly", just maybe...

exotfboy commented 1 week ago

@HarelM

Since I do not have the environment to create vector tiles from the server side. So I tried to generate vector tiles on the fly as you said, it does not change anything. Have a look at this.

HarelM commented 1 week ago

Thanks! But this still users geijson-vt which I think is where the bug is. Try to use vt-pbf or something that can serialize a geojson object to a vector tile. No sure it will help but world be interesting to see if it changes anything...

exotfboy commented 1 week ago

Indeed the vt-pbf is used:

  const tile = tileIndex.getTile(z, x, y); //use geojson-vt create vector tile with json format
  if (tile == null) return { data: null };
  const buff = vtpbf.fromGeojsonVt({ json: tile }); //use vt-pbf to generate pbf format.
HarelM commented 1 week ago

I would advise to try and create a tile using a different method and then try to read it and see if you still have a problem.

exotfboy commented 1 week ago

Finally I tried to upload my data to mapbox studio to generate vector tiles. And things does not change.

HarelM commented 1 week ago

Ok, thanks for taking the time to try this out, this rules that the problem is with the geojson conversation to MVT, and leaves text location precision I guess...

exotfboy commented 1 week ago

I also tried to publish the geojson to vector tiles with geoserver locally, and got the same result. Also I do not notice any precision lose for the geometry. So I guess if this is caused by the symbol algorithm.

HarelM commented 1 week ago

This is my gut feeling as well. Feel free to drive into it...