Skip to content

Commit bb1f0a9

Browse files
committed
Restore ability to set click action on layer
- Re-add feature added in #2488. - Add map method to prevent (and re-enable) all click actions on features. Use these methods in the DownloadPanelView when draw mode is enabled. - Remove some dev code Issue #1889
1 parent 6ef83c3 commit bb1f0a9

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

src/js/models/connectors/GeoPoints-Cesium.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ define([
108108
connect: function () {
109109
try {
110110
this.disconnect();
111+
111112
// Listen for changes to the points collection and update the layer
112113
const geoPoints = this.get("geoPoints");
113114
const events = ["update", "reset"];

src/js/models/connectors/GeoPoints-CesiumPoints.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ define(["cesium", "models/connectors/GeoPoints-Cesium"], function (
4949
*/
5050
handleCollectionChange(eventName, collection, options) {
5151
try {
52-
// alert("Point change");
5352
// For merges and resets, just remove all points and re-add them
5453
if (!options?.add && !options?.remove) {
5554
this.resetLayerPoints();

src/js/models/maps/MapInteraction.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,20 @@ define([
176176
// Clone the models in hovered features and set them as clicked features
177177
const hoveredFeatures = this.get("hoveredFeatures").models;
178178
this.setClickedFeatures(hoveredFeatures);
179-
const clickAction = this.get("mapModel")?.get("clickFeatureAction");
179+
180+
// First check if there is specific action set for the layer.
181+
let clickAction = this.get("hoveredFeatures")
182+
?.at(0)
183+
?.get("mapAsset")
184+
?.get("clickFeatureAction");
185+
// Default to the mapModel action otherwise.
186+
if (clickAction == null) {
187+
clickAction = this.get("mapModel")?.get("clickFeatureAction");
188+
}
189+
190+
if (this.get("preventClickAction")) {
191+
clickAction = false;
192+
}
180193

181194
if (clickAction === "showDetails") {
182195
this.selectFeatures(hoveredFeatures);
@@ -191,6 +204,16 @@ define([
191204
this.setClickedPositionFromMousePosition();
192205
},
193206

207+
/** Prevent any action from happening when the user clicks a feature */
208+
preventClickAction() {
209+
this.set("preventClickAction", true);
210+
},
211+
212+
/** Enable click actions on features if previous prevented */
213+
enableClickAction() {
214+
this.set("preventClickAction", false);
215+
},
216+
194217
/**
195218
* Sets the clicked position to the current mouse position.
196219
*/
@@ -339,8 +362,6 @@ define([
339362
return;
340363
}
341364

342-
// alert("This is where the error is happening....");
343-
344365
// Ignore if new features are identical to the current features
345366
const currentFeatures = model.get(type);
346367
if (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="toolbar__content-header">Layers</div>
22
<div class="<%= classNames.search %>"></div>
3-
<div class="<%= classNames.layers %>"></div>
3+
<div class="<%= classNames.layers %>"></div>

src/js/templates/maps/toolbar.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
<div class="toolbar__all-content"></div>
2-
<div class="toolbar__links"></div>
3-
2+
<div class="toolbar__links"></div>

src/js/views/maps/CesiumWidgetView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ define([
174174
if (!MetacatUI.appModel.get("enableCesium")) {
175175
return;
176176
}
177+
177178
// Save a reference to this view
178179
const view = this;
179180

@@ -607,7 +608,6 @@ define([
607608
if (now - lastCall < delay) return;
608609
this.setHoveredFeaturesLastCall = now;
609610
const pickedFeature = view.scene.pick(position);
610-
611611
view.interactions.setHoveredFeatures([pickedFeature]);
612612
},
613613

src/js/views/maps/DownloadPanelView.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,14 @@ define([
315315
initialize(options) {
316316
this.mapModel = options.model || new Map();
317317
this.objectServiceUrl = MetacatUI.appModel.get("objectServiceUrl");
318-
// Add models & collections and add interactions, layer, connector,
319-
// points, and originalAction properties to this view
318+
// Add models & collections, interactions, layer, connector, points
320319
this.setUpMapModel();
321320
this.setUpLayer();
322321
this.setUpConnectors();
323322
},
324323

325-
/**
326-
* Sets up the map model and adds the interactions and originalAction
327-
* properties to this view.
328-
*/
324+
/** Adds reference to interaction model to view */
329325
setUpMapModel() {
330-
this.originalAction = this.mapModel.get("clickFeatureAction");
331326
this.interactions =
332327
this.mapModel.get("interactions") ||
333328
this.mapModel.setUpInteractions();
@@ -569,13 +564,12 @@ define([
569564
*/
570565
removeClickListeners() {
571566
const handler = this.clickHandler;
572-
const { originalAction } = this;
573567
if (handler) {
574568
handler.stopListening();
575569
handler.clear();
576570
this.clickHandler = null;
577571
}
578-
this.mapModel.set("clickFeatureAction", originalAction);
572+
this.interactions.enableClickAction();
579573
this.listeningForClicks = false;
580574
},
581575

@@ -592,7 +586,7 @@ define([
592586
this.clickHandler = handler;
593587
const { interactions } = this;
594588
const clickedPosition = interactions.get("clickedPosition");
595-
this.mapModel.set("clickFeatureAction", null);
589+
this.interactions.preventClickAction();
596590
handler.listenTo(
597591
clickedPosition,
598592
"change:latitude change:longitude",

0 commit comments

Comments
 (0)