Skip to content

Commit

Permalink
Optionally add graphic layers to LayerControl widget and remove them …
Browse files Browse the repository at this point in the history
…when all features are cleared or the graphic layers removed. from map.
  • Loading branch information
tmcgee committed Jun 4, 2017
1 parent 860eee2 commit 8258907
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions widgets/AttributesTable/_GraphicsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ define([
spatialReference: null,
pointExtentSize: null,

addToLayerControl: true,

symbolOptions: {},

// Default symbology for features
Expand Down Expand Up @@ -306,6 +308,10 @@ define([

this.map.addLayer(this.selectedGraphics);

if (this.addToLayerControl) {
this.addLayerToLayerControl();
}

},

/*******************************
Expand Down Expand Up @@ -662,6 +668,9 @@ define([
clearFeatureGraphics: function (specificFeatures) {
this.clearGraphicsLayer(this.featureGraphics, specificFeatures);
this.hideInfoWindow();
if (this.addToLayerControl && (this.featureGraphics.graphics.length === 0)) {
this.removeLayerFromLayerControl();
}
},

clearSelectedGraphics: function () {
Expand Down Expand Up @@ -718,6 +727,10 @@ define([
*******************************/

removeGraphicLayers: function () {
if (this.addToLayerControl) {
this.removeLayerFromLayerControl();
}

this.map.removeLayer(this.featureGraphics);
this.featureGraphics = null;

Expand All @@ -729,6 +742,43 @@ define([

this.map.removeLayer(this.bufferGraphics);
this.bufferGraphics = null;
},

/*******************************
* Add/Remove layer from Layer Control widget
*******************************/

addLayerToLayerControl: function () {
var layerControlInfo = {
controlOptions: {
expanded: false,
noLegend: true,
metadataUrl: false,
swipe: false
},
layer: this.featureGraphics,
title: 'Search Results - ' + this.title,
type: 'feature'
};
topic.publish('layerControl/addLayerControls', [layerControlInfo]);

this.layerControlToggleTopic = topic.subscribe('layerControl/layerToggle', lang.hitch(this, function (r) {
if (r.id === this.featureGraphics.id) {
var viz = this.featureGraphics.visible;
this.sourceGraphics.setVisibility(viz);
this.bufferGraphics.setVisibility(viz);
this.featureGraphics.setVisibility(viz);
this.selectedGraphics.setVisibility(viz);
}
}));
},

removeLayerFromLayerControl: function () {
topic.publish('layerControl/removeLayerControls', [this.featureGraphics]);
if (this.layerControlToggleTopic) {
this.layerControlToggleTopic.remove();
this.layerControlToggleTopic = null;
}
}
});
});

0 comments on commit 8258907

Please sign in to comment.