Select to view content in your preferred language

Using Javascript to link a user directly to a map feature

846
2
07-22-2014 01:47 PM
RyanLaird
Deactivated User

.     Hi everyone,

I'm currently trying to work out issues with my script in the following thread and it was suggested I make a new one.

https://community.esri.com/message/389731#389731

The end goal is to be able to send a link to a user, this link would than automatically select and zoom to the feature referenced by the link. This has already been done so we based the script off of a public Esri sample found here: Parcel Locator

We just wanted to get it to work with our data but it seems like we've hit every problem in the book. Now everything's working except the script still will not pull the "OBJECTID" from the URL and use it to select the feature. I suspect the error is within lines 147-164. The script also updates the URL whenever a feature is selected by clicking, this coding can be found within lines 92-106.

0 Kudos
2 Replies
OwenEarley
Frequent Contributor

The main issue with your code is in the getParcelFromUrl() function. You are attempting to access a query property called 'parcelid' when the URL does not contain this query string parameter. Your code sets the window history to include an 'objectid' parameter.    

Modify your getParcelFromUrl() function to access the objectid parameter:

     //extract the parcel id from the url - new version using objectid

     function getParcelFromUrl(url) {

          var urlObject = urlUtils.urlToObject(url);

          if (urlObject.query && urlObject.query.objectid) {

               return urlObject.query.objectid;

          } else {

               return null;

          }

     }

Also, note that this appears to be case sensitive so you will need to update the following line (101) from:

window.history.pushState(null, null, "?OBJECTID=" + selection[0].attributes.OBJECTID);

To (note the lowercase objectid parameter key):

window.history.pushState(null, null, "?objectid=" + selection[0].attributes.OBJECTID);

A working example is available here.

RyanLaird
Deactivated User

Hey there, sorry we actually figured out the problem was that (on the same line you referenced) OBJECTID and to be changed to parcelid, sorry about that, but thanks for the help!

0 Kudos