Set layer definition on Webmap through URL?

606
5
Jump to solution
02-01-2013 11:05 AM
RobertWinterbottom
Occasional Contributor
My question is that is it possible to set a layer definition on a Webmap through the URL? 

What I am essentially trying to do is I am building an app that has a profile page with a link to an AGOL webmap.  When the user clicks the link I would not only like to be able to take them to a webmap but also set a layer definition on the layer in the webmap. Each profile page is for a specific district and there are tons of districts over the whole country, can I link them to the webmap and pass in a definition expression, say something like 'DistrictId = 240042' and have that set on the map on load.
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor
you can definitely dig into the layers in the web map in an application written with our API.  this sample loops through the webmap layers to add them to a legend.

it sounds however like you are currently sharing a link to open the original web map (perhaps in the standard arcgis.com viewer?).  in order to build out the functionality you describe you would need to be linking to a configurable web application (that loads a web map based on its id) and similarly pulls additional information out of the Url to write a definition query on the fly.

View solution in original post

0 Kudos
5 Replies
JohnGravois
Frequent Contributor
have you seen Sonia's code sample in this forum post?  it allows her to fire a spatial query by appending X and Y coordinates to the Url of her app.  perhaps you could modify it to use similar information to create a definition query on your layer.
0 Kudos
RobertWinterbottom
Occasional Contributor
Thanks for the response, How would I get access to the layer though to apply the layer definition?  If it were for the map in my app I think this would be very easy but because it is a webmap on an AGOL account I don't have access to the layer(atleast not that I know of).  I am just giving my user an <a> tag with the link to the webmap to open it in a new page.  I was hoping to be able to have it open with a particular definition set on it.
0 Kudos
JohnGravois
Frequent Contributor
you can definitely dig into the layers in the web map in an application written with our API.  this sample loops through the webmap layers to add them to a legend.

it sounds however like you are currently sharing a link to open the original web map (perhaps in the standard arcgis.com viewer?).  in order to build out the functionality you describe you would need to be linking to a configurable web application (that loads a web map based on its id) and similarly pulls additional information out of the Url to write a definition query on the fly.
0 Kudos
RobertWinterbottom
Occasional Contributor
you can definitely dig into the layers in the web map in an application written with our API.  this sample loops through the webmap layers to add them to a legend.


Thanks I have done this a few times, the API makes it pretty simple.

it sounds however like you are currently sharing a link to open the original web map (perhaps in the standard arcgis.com viewer?).  in order to build out the functionality you describe you would need to be linking to a configurable web application (that loads a web map based on its id) and similarly pulls additional information out of the Url to write a definition query on the fly.


But this is exactly what I was going for.  The webmap is currently living on the standard viewer.  I think my project manager would prefer I do this through the standard AGOL viewer but it sounds like at this time that is not possible. I will suggest this as an alternative to her as this would be fairly simple to build and see if it's something we can do.  Thanks a lot, I appreciate the response.
0 Kudos
JohnGravois
Frequent Contributor
no problem at all.  i see people share links to open web maps directly in the arcgis.com viewer quite a bit.  my perception is that it adds quite a bit of unnecessary background noise for a lot of end users. 

a clean, simple web mapping application is a much better way to present the web map.  and if it adds some logic to build a definition query on the fly, all the better 🙂
0 Kudos