Web App Builder Click on Feature to open URL

1406
6
05-23-2018 11:04 AM
JohnDye2
Occasional Contributor

We have an app that we built with Web App Builder along with some custom LayerList and Swipe widgets. One of the requirements we got this morning is that instead of showing a popup with a Hyperlinked URL when a user clicks on a feature in the web map, the customer just wants to skip the popup behavior altogether and click on features to open the URL.

I found a GeoNet Post by jai siva which gives me some good starting code:

    

  1. var map;  
  2.   
  3.       require(["esri/map",  
  4.                 "esri/layers/FeatureLayer",  
  5.                 "esri/InfoTemplate",  
  6.                 "dojo/on",  
  7.                 "dojo/domReady!"],   
  8.   function(Map,FeatureLayer,InfoTemplate,on) {  
  9.           map = new Map("map", {  
  10.           basemap: "topo",  //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd  
  11.           center: [00// longitude, latitude          
  12.         });  
  13.   
  14.   var featureLayer = new FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3");  
  15.   map.addLayer(featureLayer);  
  16.   
  17.   //Code for the specific URL to open in a new window  
  18.   featureLayer.on('click',function(e){   
  19.     var specific = e.graphic.attributes['SpecificAttribute']   
  20.     window.open("http://YourUrl.com/"+specific);  
  21.   });  
  22.       });  

However, since this is going to be in a custom Web App Builder App, I'm having trouble finding the best place to drop the code. I've tried at init.js, simpleLoader.js and jimu.js/MapManager.js but haven't had any luck. Any ideas on the best place and/or way to accomplish this?

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

   The MapManager.js would be the likely place to put this. In the _show2DWebMap function and inside the mapDeferred.then  function handler.

0 Kudos
JohnDye2
Occasional Contributor

sorry, which part should go where?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

  Do you really need to add the FeatureLayer manually or is it already part of your web map?

0 Kudos
JohnDye2
Occasional Contributor

It's not currently, but can already be part of the map. I just need to suppress the popup and instead create a functionality where when a user clicks on a feature, it grabs the url from the 'url' column in the attribute table for that feature, then opens a browser window to that url.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

So just add lines 14 - 21 to the _show2DWebMap function and inside the mapDeferred.then  function handler. Also you will need to add "esri/layers/FeatureLayer", to the define array.

0 Kudos
Keagan1
New Contributor

Hi John,

Did you end up resolving this? I'm currently trying to do the same thing - any advice?

0 Kudos