From 782386bad45a870dc1cee9593f578e1f9116d763 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 6 Mar 2025 17:25:40 +0100 Subject: [PATCH] feat: display a target on hover on search results Co-authored-by: David Larlet --- umap/static/umap/img/target.svg | 1 + umap/static/umap/js/umap.controls.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 umap/static/umap/img/target.svg diff --git a/umap/static/umap/img/target.svg b/umap/static/umap/img/target.svg new file mode 100644 index 00000000..d7b58538 --- /dev/null +++ b/umap/static/umap/img/target.svg @@ -0,0 +1 @@ + diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 7a35cde6..3aee1cf2 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -468,6 +468,20 @@ U.Search = L.PhotonSearch.extend({ }) el.appendChild(tools) this._formatResult(feature, el) + const path = U.SCHEMA.iconUrl.default.replace('marker.svg', 'target.svg') + const icon = L.icon({ + iconUrl: path, + iconSize: [24, 24], + iconAnchor: [12, 12], + }) + const coords = feature.geometry.coordinates + const target = L.marker([coords[1], coords[0]], { icon }) + el.addEventListener('mouseover', (event) => { + target.addTo(this.map) + }) + el.addEventListener('mouseout', (event) => { + target.removeFrom(this.map) + }) }, setChoice: function (choice) {