Search code examples
openlayers

Openlayers popup do not follow selected feature on zoom out


I created popup for my openlayers map as discribed in openlayers website example

Along with openlayers I am using ol-ext (openlayers extension), and I am using animated cluster feature from it. So I have a cluster and features inside, when I click on cluster, the map is zooming in to features and I can click on each feature and popup with info will be displayed.

When I zoom out, feature is still selected and popup is shown and on place. But when I zoom out to cluster level the feature is moved to cluster, but popup is not and leave on the same place.

Feature is inside the cluster and it's automatically moves, but popup know nothing about that and do not follow the feature. I need my popup to follow the selected feature even if it moves to cluster. How that can be achieved? By the way I do not use any select interaction functionality provided by openlayers, maybe that cause the issue?


Solution

  • A popup isn't related to the feature in any way, you simply used the features coordinates at the time of clicking to position it. To make it follow clusters you would need to search the clusters whenever they are updated to see if they contain the original feature, then reposition the overlay to the cluster's coordinate. See https://codesandbox.io/s/thirsty-shaw-qi1tb where you can only click on a single feature (shows 1) but after that the popup will move as you zoom out and the feature gets included in clusters.