Using Vaadin Maps 24.9.9 I’ve found that I can control which icons are “on top” by adding these MarkerFeatures to the map in a deterministic order, adding the topmost icons last.
However, I’ve found an odd case where if I zoom in so a feature is outside the frame, remove it, and then zoom out and re-add it, then it insists on being “on top” regardless of the order I add it in. (It’s a bit hard to explain - see the attached video.)
Here is the code I use to achieve this; basically on each checkbox change I remove all features from the map and the re-add them in a certain order, adding the pin at the middle (defaultFeature in my code) as the last step so it should always be on top.
// Maps each layer to a group of features.
final protected Map<String, List<Feature>> featureLayers = new LinkedHashMap<>();
// Maps each layer to a checkbox which controls its visibility.
final protected Map<String, Checkbox> featureLayersCheckboxes = new LinkedHashMap<>();
...
final Checkbox layerCheckbox = vaadinUtil.makeCheckbox(label);
layerCheckbox.addValueChangeListener(event -> {
final FeatureLayer featureLayer = map.getFeatureLayer();
featureLayer.removeAllFeatures();
for (String featureKey : featureLayers.keySet()) {
if (featureLayersCheckboxes.get(featureKey).getValue()) {
featureLayers.get(featureKey).forEach(markerFeature -> featureLayer.addFeature(markerFeature));
}
}
// Remove and re-add the default feature so that it is always on top
featureLayer.addFeature(defaultFeature);
});