2

declutter does not working as it should be for point geometry, it should avoid overlapping labels and not styling format or geometry. when I set it true for points, points are starting disappear when map is zoomed out.

I used the example from OpenLayers then I set declutter to true for point (line 190) and also for line (line 168), for line is working and it avoid labels to overlap and it allows line geometry overlapping each other with the custom styling, but the whole point will be disappear when the map is zoomed out.

Did I miss any configuration or this is a bug from OL. (Tested with OL 6.1.1 and 6.2.1) at the end the question is why the points geometry disappear with enabled declutter?

Code Snippet: https://codesandbox.io/s/vector-labels-s7oeu

3

See the documentation https://openlayers.org/en/latest/apidoc/module-ol_layer_Vector-VectorLayer.html "Declutter images and text". CircleStyle is an image:

function pointStyleFunction(feature, resolution) {
  return new Style({
    image: new CircleStyle({
      radius: 10,
      fill: new Fill({ color: "rgba(255, 0, 0, 0.1)" }),
      stroke: new Stroke({ color: "red", width: 1 })
    }),
    text: createTextStyle(feature, resolution, myDom.points)
  });
}

To avoid decluttering you could style the points as Circle geometry:

function pointStyleFunction(feature, resolution) {
  return new Style({
    geometry: new Circle(feature.getGeometry().getCoordinates(), 10 * resolution),
    fill: new Fill({ color: "rgba(255, 0, 0, 0.1)" }),
    stroke: new Stroke({ color: "red", width: 1 }),
    text: createTextStyle(feature, resolution, myDom.points)
  });
}

https://codesandbox.io/s/vector-labels-5dlub

3
  • so it means default stayling for point is also 'image', right? because when I remove the styling (commented out line 190) with enabled declutter, point disappears again. (codesandbox.io/s/vector-labels-wco36)
    – MK83
    Feb 18 '20 at 14:36
  • 1
    Yes, point geometry can only be styled by image and text The default image is the blue circle openlayers.org/en/latest/apidoc/…
    – Mike
    Feb 18 '20 at 14:48
  • Is there any option to enable declutter just for Text and not images? I use symbols (image) for points.Is there any option to enable declutter just for Text and not images? I use symbols (image) for points. reason is my point has both image as symbol and text as label with enabled declutter, but declutter makes both disppear which make sens from OL implementation but is it possible to make it configurable, to make enable for images and not text?
    – MK83
    Mar 27 '20 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.