Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show map popup for the smallest feature at the clicked point #652

Merged
merged 1 commit into from Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- [Attempt to update the map size until it is rendered #576](https://github.com/farmOS/farmOS/issues/576)
- [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