URL parameters

Initializing the Viewer using URL parameters

The ArcGIS Viewer for Silverlight allows the specification of certain initialization parameters in the query string of a deployed Viewer application's URL. These parameters enable setting the initial extent, scale, center, scale level, web map, and place search of a Viewer without altering that Viewer's configuration. Each parameter is set by including a certain key-value pair in the query string. The effect and syntax of each parameter is described below.

Web map

The webmap parameter causes the Viewer to show the web map specified. To use this parameter, specify a key-value pair of webmap=id in the query string, where id is the unique identifier of the web map. Note that, if a web map is specified that is not shared publicly, a log-in prompt will be shown when the Viewer loads. A Viewer URL with this parameter specified would appear as follows:

// Load the Esri Atlas Geology web map
http://www.example.com/apps/myviewer/index.htm?webmap=74a8f6645ab44c4f82d537f1aa0e375d

Place search

The search parameter causes the Viewer's Search tool to execute a place search as soon as the Viewer application loads. To use this parameter, specify a key-value pair of search=place in the query string, where place describes the place to be searched for, such as an address, city, landmark, or business name. The following URLs illustrate how this parameter can used:

// Search for Redlands, CA
http://www.example.com/apps/myviewer/index.htm?search=Redlands,California,United States

// Search for the Eiffel Tower
http://www.example.com/apps/myviewer/index.htm?search=Eiffel Tower

// Search for ESRI
http://www.example.com/apps/myviewer/index.htm?search=ESRI

Extent

The extent parameter causes the Viewer's map to load at the extent indicated. To use this parameter, specify a key-value pair of extent=xmin,ymin,xmax,ymax,wkid in the query string, where xmin is the extent's left coordinate, ymin is the extent's bottom coordinate, xmax is the extent's right coordinate, ymax is the extent's top coordinate, and wkid is the well-known identifier of the extent's spatial reference. If the coordinates are in the same spatial reference as the Viewer's map, then wkid can be omitted. Examples of Viewer URLs with this parameter specified are:

// Set map extent to Greater Copenhagen area, assuming the map is in the same spatial 
// reference as the coordinates
http://www.example.com/apps/myviewer/index.htm?extent=1220000,7364000,1632000,7632000

// Set map extent to Greater Copenhagen area using coordinates in WGS 84 (WKID 4326)
http://www.example.com/apps/myviewer/index.htm?extent=14.70,51.76,12.66,59.37,4326

Scale

The scale parameter causes the Viewer's map to load at the scale indicated. To use this parameter, specify a key-value pair of scale=<scale> in the query string, where <scale> is the denominator of the desired scale. For instance, if the desired scale is 1/24000, then <scale> should be set to 24000. This parameter can be specified as shown below:

// Set map scale to 1/100,000
http://www.example.com/apps/myviewer/index.htm?scale=100000

Scale Level

The level parameter causes the Viewer's map to load at a level of detail defined in the tiled map service being used as the map's basemap. To use this parameter, specify a key-value pair of level=levelid in the query string, where levelid is the ID of the desired level of detail as defined in the tiled map service. A URL with this parameter included would appear as follows:

// Initialize the map to the level of detail with an ID of 10
http://www.example.com/apps/myviewer/index.htm?level=10

Combining URL parameters

Many of the URL parameters supported by the Viewer can be combined. For example, it may be desirable to specify a scale in conjunction with a center point. To combine parameters, simply separate the key-value pairs defining each parameter with an ampersand (&). An example is shown here:

// Center on Singapore at a map scale of 1/300,000
http://www.example.com/apps/myviewer/index.htm?center=11563270,144180&scale=300000
1/26/2015