Skip to content

Commit

Permalink
Show map popup for the smallest feature at the clicked point farmOS#652
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 5453ce5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Fix map ui being unreadable on dark mode #642](https://github.com/farmOS/farmOS/pull/642)
- Patch Drupal core to fix [Issue #3266341: Views pagers do math on disparate data types, resulting in type errors in PHP 8](https://www.drupal.org/project/drupal/issues/3266341)
- [Implement FarmBreadcrumbBuilder::applies() to only affect desired routes](https://github.com/farmOS/farmOS/pull/644)
- [Show map popup for the smallest feature at the clicked point #652](https://github.com/farmOS/farmOS/pull/652)

## [2.0.1] 2023-02-08

Expand Down
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 5453ce5

Please sign in to comment.