Hi all,
I'm trying to get a URL to open up from a link in an attribute field when the feature is clicked on. I have added the following sample code taken from another post to MapManager.js and have gotten it to work with the sample links that came with it.
I don't want to create a new feature layer, I would like to use an existing layer - how do I alter the code to do this? Also, will this work on a point feature as well as a polygon? Because right now it doesn't work on point features.
I'm inexperienced with ArcGIS API for JavaScript but I'm trying to use online resources to find a solution so any help would be appreciated as I've spent a long time trying to get this to work!
Try to get your existing feature layer with the following logic (let is just another forma of declaring a variable which I personally prefer, you can as well use var). And don't get confused of (e) => { //code } it means the same as function (e) { //code }
let myFeatureLayerTitle = 'TitleOfYourExistingFeatureLayer';
let myFeatureLayer = webmap.allLayers.find((layer) => {
return layer.title === myFeatureLayerTitle;
});
If you don't know the title of your layer you can also use the ID property or something else which identifies the layer. Additionally you can put the var view variable into the global scope (put it before the API require statement require([ ... ] ..... ) so you can use it in your browser dev tools and access your layers with view.map.allLayers.items