Skip to content

Commit

Permalink
Show map popup for the smallest feature at the clicked point
Browse files Browse the repository at this point in the history
  • Loading branch information
symbioquine authored and mstenta committed Mar 9, 2023
1 parent a1babd8 commit 7a3cd9b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/core/map/js/farmOS.map.behaviors.popup.js
Expand Up @@ -17,7 +17,15 @@
// Create a popup and add it to the instance for future reference.
instance.popup = instance.addPopup(function (event) {
var content = '';
var feature = instance.map.forEachFeatureAtPixel(event.pixel, function(feature, layer) { return feature; });

// Get all features at the point that was clicked and sort them by area from smallest to largest.
// @todo GeometryCollections have an area of 0, which can cause some undesirable behavior.
var clickedFeatures = instance.map.getFeaturesAtPixel(event.pixel);
const sortValue = feature => typeof feature.getGeometry().getArea === 'function' ? feature.getGeometry().getArea() : 0;
clickedFeatures.sort((a,b) => sortValue(a) - sortValue(b))

// Get the first clicked feature.
var feature = clickedFeatures[0];
if (feature) {

// If the feature is a cluster, then create a list of names and add it
Expand Down

0 comments on commit 7a3cd9b

Please sign in to comment.