I'm wondering what the easiest way to create a custom widget where I can select one or more parcels and pass the parcel_id attribute to another service.
I would like to use the draw toolbar to draw a geometry and select the parcels that intersect, similar to this example: Feature layer with selection | ArcGIS API for JavaScript
first step: How do I define/cast the parcel layer in my webmap as a FeatureLayer (esri/layers/FeatureLayer)?
Solved! Go to Solution.
Adam,
See if this works for you:
LayerInfos.getInstance(map, map.itemInfo).then(lang.hitch(function(operLayerInfos) { operLayerInfos.getLayerInfoArray().forEach(function(layerInfo) { if (layerInfo.title == 'MC Taxlot') { taxlotLayerId = layerInfo.id; taxlotLayerInfo = layerInfosObject.getLayerInfoById(layerInfo.id) taxlotLayerInfo.disablePopup(); } }); }));
Adam,
I would begin my looking at how other widgets do it. If you look in the OTB esri widgets they use the
'jimu/LayerInfos/LayerInfos' Require and LayerInfos parameter and then code like this:
LayerInfos.getInstance(this.map, this.map.itemInfo) .then(lang.hitch(this, function(operLayerInfos) { //Now the operLayerInfos is an array of layerInfos that have the layers of the map. }));
Thank you Robert,
I was able to get the reference to the LayerInfo object in my map using the following:
LayerInfos.getInstance(map, map.itemInfo).then(function(layerInfosObject) { layerInfosObject.getLayerInfoArray().forEach(function(layerInfo) { if (layerInfo.title == 'MC Taxlot') { taxlotLayerInfo = layerInfosObject.getLayerInfoById(layerInfo.id) } }); });
I'd like to be able to do two things with the taxlot layer:
1. disable the popup
2. use something similar to the following so the user can click on the map and build a list of taxlots (field = "TAXLOT"), to be passed to another service:
featureLayer.on('click', function(e){ var taxlotString = esriLang.substitute(e.graphic.attributes, "${TAXLOT}"); var highlightGraphic = new Graphic(e.graphic.geometry, highlightSymbol); map.graphics.add(highlightGraphic); taxlotList.push(taxlotString); }); });
Any suggestions, or help pointing me in the right direction would be much appreciated. Adam
I'm now able to select parcels and build a list of taxlots using the following code:
postCreate: function() { console.log('ParcelSoils::postCreate'); this.inherited(arguments); }, startup: function() { console.log('ParcelSoils::startup'); var map = this.map; var taxlotLayerId, taxlotLayer, taxlotList; var highlightSymbol = new SimpleFillSymbol( SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol( SimpleLineSymbol.STYLE_SOLID, new Color([255,0,0]), 3 ), new Color([125,125,125,0.35]) ); LayerInfos.getInstance(map, map.itemInfo).then(lang.hitch(function(operLayerInfos) { operLayerInfos.getLayerInfoArray().forEach(function(layerInfo) { if (layerInfo.title == 'MC Taxlot') { taxlotLayerId = layerInfo.id; console.log('Taxlot layer ID = ', taxlotLayerId) } }); })); taxlotLayer = map.getLayer(taxlotLayerId); taxlotList = []; this.own(on(taxlotLayer, 'click', function(e) { var taxlotString = esriLang.substitute(e.graphic.attributes, "${TAXLOT}"); var highlightGraphic = new Graphic(e.graphic.geometry, highlightSymbol); map.graphics.add(highlightGraphic); taxlotList.push(taxlotString); console.log('Selection = ' + taxlotList); }));
Now I need to figure out how to temporarily disable the Pop-up for the Taxlot layer...
Looking through the OTB widget code for that, but it is anything but self-explanatory.
Adam,
See if this works for you:
LayerInfos.getInstance(map, map.itemInfo).then(lang.hitch(function(operLayerInfos) { operLayerInfos.getLayerInfoArray().forEach(function(layerInfo) { if (layerInfo.title == 'MC Taxlot') { taxlotLayerId = layerInfo.id; taxlotLayerInfo = layerInfosObject.getLayerInfoById(layerInfo.id) taxlotLayerInfo.disablePopup(); } }); }));
Robert,
That worked! I'm wondering how though... is the .disablePopup() method defined inside the WAB app folder structure? I can't find that method in the API reference for the LayerInfo object.
Thank you for your help!
Adam,
The LayerInfo objects is loosely documented. Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.