I am trying to create drive time areas for a point. When I call the routine I get the following error.
Uncaught Error: string.substitute could not find key "layername" in template
at js.arcgis.com/3.21/init.js:376
at String.replace (<anonymous>)
at Object.r.substitute (js.arcgis.com/3.21/init.js:376)
at Object._updateAnalysisLayerUI (js.arcgis.com/3.21/esri/dijit/analysis/CreateDriveTimeAreas.js:22)
at Object._buildUI (js.arcgis.com/3.21/esri/dijit/analysis/CreateDriveTimeAreas.js:20)
at Object.postCreate (js.arcgis.com/3.21/esri/dijit/analysis/CreateDriveTimeAreas.js:8)
at Object.create (js.arcgis.com/3.21/init.js:350)
at Object.postscript (js.arcgis.com/3.21/init.js:349)
at Object.advice (js.arcgis.com/3.21/init.js:119)
at Object.c [as postscript] (js.arcgis.com/3.21/init.js:119)
Background -
I am following the javascript jsapi 3 documentation(https://developers.arcgis.com/javascript/3/jsapi/createdrivetimeareas-amd.html#createdrivetimeareas1) for this. This is what I am doing -
var activeFeatureLayer = new FeatureLayer("https://services5.arcgis.com/<auth_id>/arcgis/rest/services/<layer_id>/FeatureServer/0");
var createDriveTimeAreas = new CreateDriveTimeAreas({
inputLayer: activeFeatureLayer,
inputType: "point",
map: this.map,
showReadyToUseLayers: false, // to disable an option to the UI that allows users to choose ready to use analysis layers from the Living Atlas Analysis Layers
portalUrl: "https://<server>.maps.arcgis.com"
}, "analysis-tool");
Can anyone please tell me what I am doing wrong here?
Thank you.
I posted this here too:
If you add a "name" property to your input layer, you'll work around there. In the CreateDriveTimeAreas code, "layername" is set to your inputLayer.name. Layers from ArcGIS Online have this. Layers created from instantiating your own FeatureLayer do not.
Basically, add:
activeFeatureLayer.name = "Some name";
Unfortunately, in my own case, I still could not get CreateDriveTimeAreas to work, but the step above did get rid of that "layername" error message for me.
Hi Matt,
We will fix this issue in coming release of JSAPI. you can use the current workaround you suggested above.
> Unfortunately, in my own case, I still could not get CreateDriveTimeAreas to work
Can you share your sample code here so we can take a look at it.
Thanks and Regards
Ganesh Subbiah | Software Developer | JSAPI/ArcGIS Online Team
The errors above is more due to a configuration setting that was needed in the above code shared.
Here is a working sample :
All Analysis Widgets support 2 UX styles , to allow the input layer to be changed via dropdown (default) or not.
CreateDriveTimeAreas | ShowSelectAnalysisLayer
ShowSelectAnalysisLayer : Default is true
1. Create Drive Time Areas with Fixed Input Layer : https://codepen.io/subgan82/pen/jZajyP/?editors=1000 : This was based on the code above, by setting ShowSelectAnalysisLayer to false, the Widget Works
2. Create Drive Time Areas with changeable Input Layers ( step 1)https://codepen.io/subgan82/pen/MQOMmj/?editors=1000
When ShowSelectAnalysisLayer is true, Widget requires to set this property. We will add this in documentation.
inputLayers: [array of possible inputlayers]
Thanks
Ganesh Subbiah | Software Developer | JSAPI/ArcGIS Online Team
Ganesh,
It's a little tricky to post my code here without posting some sensitive data, but basically, I do get the Create Drive Time Areas widget to render with no visible errors. However, when I click "Show Credits" or "Run Analysis," the container the widget is housed in scrolls up instead of running. I'm assuming it's trying to highlight some sort of client validation error, but nothing is shown.
I can give you more details privately if needed, but a snippet of my code to initialize the widget is below. I am using the 3.23 version of the API that's configured automatically through a downloaded WebApp Builder application that I'm writing my own custom widget for.
Hi Matt,
Did you check this codepen CreateDriveTimeAreas , this sample works, you need not pass `fl.name`. let me know if this is working.