diff --git a/umap/static/umap/js/modules/browser.js b/umap/static/umap/js/modules/browser.js index 2c7cfdec..36fb306e 100644 --- a/umap/static/umap/js/modules/browser.js +++ b/umap/static/umap/js/modules/browser.js @@ -45,7 +45,7 @@ export default class Browser { Icon.setContrast(icon, colorBox, symbol, bgcolor) } const viewFeature = (e) => { - feature.zoomTo({ ...e, callback: feature.view }) + feature.zoomTo({ ...e, callback: () => feature.view() }) } DomEvent.on(zoom_to, 'click', viewFeature) DomEvent.on(title, 'click', viewFeature) diff --git a/umap/static/umap/js/modules/data/features.js b/umap/static/umap/js/modules/data/features.js index 8432f2fd..4d16d2d8 100644 --- a/umap/static/umap/js/modules/data/features.js +++ b/umap/static/umap/js/modules/data/features.js @@ -439,7 +439,7 @@ class Feature { zoomTo({ easing, latlng, callback } = {}) { if (easing === undefined) easing = this.map.getOption('easing') - if (callback) this.map.once('moveend', callback.call(this)) + if (callback) this.map.once('moveend', callback.bind(this)) if (easing) { this.map.flyTo(this.center, this.getBestZoom()) } else { @@ -663,9 +663,9 @@ export class Point extends Feature { } zoomTo(event) { - if (this.datalayer.isClustered() && !this._icon) { + if (this.datalayer.isClustered() && !this.ui._icon) { // callback is mandatory for zoomToShowLayer - this.datalayer.layer.zoomToShowLayer(this, event.callback || (() => {})) + this.datalayer.layer.zoomToShowLayer(this.ui, event.callback || (() => {})) } else { super.zoomTo(event) } diff --git a/umap/tests/integration/test_cluster.py b/umap/tests/integration/test_cluster.py new file mode 100644 index 00000000..14d20af6 --- /dev/null +++ b/umap/tests/integration/test_cluster.py @@ -0,0 +1,53 @@ +import pytest +from playwright.sync_api import expect + +from ..base import DataLayerFactory + +pytestmark = pytest.mark.django_db + + +DATALAYER_DATA = { + "type": "FeatureCollection", + "_umap_options": { + "name": "Calque 1", + "type": "Cluster", + "cluster": {}, + "browsable": True, + "inCaption": True, + "displayOnLoad": True, + }, + "features": [ + { + "type": "Feature", + "properties": {"name": "one point in france"}, + "geometry": {"type": "Point", "coordinates": [3.339844, 46.920255]}, + }, + { + "type": "Feature", + "properties": { + "name": "one another point in france in same position", + "description": "can you see me ?", + }, + "geometry": {"type": "Point", "coordinates": [3.339844, 46.920255]}, + }, + { + "type": "Feature", + "properties": { + "name": "again one another point", + "description": "and me ?", + }, + "geometry": {"type": "Point", "coordinates": [3.34, 46.1]}, + }, + ], +} + + +def test_can_open_feature_on_browser_click(live_server, page, map): + map.settings["properties"]["onLoadPanel"] = "databrowser" + map.save() + DataLayerFactory(map=map, data=DATALAYER_DATA) + page.goto(f"{live_server.url}{map.get_absolute_url()}#7/46.920/3.340") + page.get_by_text("one another point in france in same position").click() + expect(page.get_by_text("can you see me ?")).to_be_visible() + page.get_by_text("again one another point").click() + expect(page.get_by_text("and me ?")).to_be_visible()