Select to view content in your preferred language

Getting error while instantiation of CreateDriveTimeAreas

948
5
11-01-2017 04:20 AM
WilliamHynes
New Contributor

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 have a small area FeatureLayer on ArcGIS online from which I am creating an activeFeatureLayer programmatically and is as well the active layer on the visible map.
  • I also have a mapLayer that is created as an overlay on the current active layers on the map. This layer holds information regarding the drop point on the map with/without buffer distance.

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");

  1. The code breaks when the instantiation of the CreateDriveTimesAreas is called.
  2. I am not sure whether is pertaining to portalUrl.

Can anyone please tell me what I am doing wrong here?

Thank you.

0 Kudos
5 Replies
MattNicol
Regular Contributor

I posted this here too:

https://community.esri.com/message/678700-getting-a-stringsubstitute-could-not-find-key-layername-in...

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.

0 Kudos
GaneshSubbiah
Esri Contributor

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

0 Kudos
GaneshSubbiah
Esri Contributor

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

0 Kudos
MattNicol
Regular Contributor

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.

                var fl = new FeatureLayer(myFeatureLayer.url, { opacity: 0.5 });
                fl.name = "My Layer";
          
                var cdtaOpts = {
                    inputLayer: fl, ,
                    inputLayers: [fl],
                    inputType: "point",
                    map: myMap,
                    portalUrl: "https://myurl.maps.arcgis.com",
                    showCredits: true,
                    showSelectAnalysisLayer: true,
                    showReadyToUseLayers: false,
                    showChooseExtent: false
                };
                var cdta = new CreateDriveTimeAreas(cdtaOpts, "createDriveTimeContainer");
                cdta.startup();
0 Kudos
GaneshSubbiah
Esri Contributor

Hi Matt, 

Did you check this codepen CreateDriveTimeAreas  , this sample works, you need not pass `fl.name`. let me know if this is working. 

0 Kudos