Querying a Layer using an ArcGIS Online Map

ArcGIS-OnlineWhile exploring the possibilities of ArcGIS API for JavaScript, I was wondering how to query a web map that has been created through ArcGIS Online.

I spent quite a lot of time trying to figure out how to pass my Web Map created through ArcGIS Online as a URL. Especially for “var MapServiceToDisplay” and “var MapServiceToSearch”.

So here is the answer:

The first thing you have to do is create an account in ArcGIS Online. After catering for profile photos and other general settings, create a map.

create-map-arcgis_online

Next you have to Share this new map

share-arcgis-online_map

After that, add an item to your map, preferably from your computer

arcgisonline-add-item

Remember also to Publish this file as a feature layer

arcgisonline-feature-layer

Next: Share this Feature Layer

arcgisonline-share-feature-layer

Next step is to Add Feature Layer to Map, Save your map after adding your layer.

arcgisonline-add-layer-to-map

Now, as soon as you do that, if you click on the Map that this new layer resides, you will get the following link for the Map Contents:

arcgisonline-link

You can now use this link for var MapServiceToDisplay and var MapServiceToSearch whenever you want to refer to this map as follows:

var MapServiceToDisplay = “http://services5.arcgis.com/3a3dkCUNh3aCnKgy/ArcGIS/rest/services/kalyvia_egsa/FeatureServer/”;
var MapServiceToSearch = “http://services5.arcgis.com/3a3dkCUNh3aCnKgy/ArcGIS/rest/services/kalyvia_egsa/FeatureServer/0”;

0 in the line above implies the layer you want to query.

Express Yourself

*