You are here: Using REST > v2006.1 services > Tutorials and samples > Obtaining the cmr value from a REST v2006.1 map

S A M P L E S

Obtaining the cmr value from a REST v2006.1 map

When a REST Map request is sent with the ocs parameter, projection mode is turned on and a string representing the Current Map Reference (cmr) is returned in the response with the projected map. The cmr value can be used in subsequent requests in conjunction with the dc parameter to pan this projected map. See the dc and cmr parameters for details. Note that you do not have to parse the contents of cmr to send it in subsequent requests.

There are several ways to obtain the cmr value for a REST map depending on the map image format:

NOTE:  See Samples—terms and conditions for usage permissions.

Obtaining the cmr value for SWF format

This sample demonstrates how to obtain the cmr value from a projected REST map in SWF format using Flash. In Flash, the cmr value is set by the method setCurrentMapReference().

Software requirement

How to obtain the cmr value using Flash

See REST mapping parameters for details on the parameters mentioned below.

  1. Obtain a token using the getToken method.
  2. Make a map request using getMap.
  3. To retrieve the cmr value from the map generated in step 2, use ActionScript to load a map. The map itself calls the parent.SetCurrentMapReference(String), so it is required that the developer implement this method to retrieve the cmr value:
  4. var cmr:String;

    var mclListener:Object

    var image_mc:MovieClip;

    var url:String; //REST URL to call

    System.security.allowDomain("www.arcwebservices.com");

    //create the MovieClip to load the map onto

    image_mc = this.createEmptyMovieClip("image_mc",this.getNextHighestDepth());

    //create a listener

    mclListener = new Object();

    //create the MovieClipLoader

    var image_mcc:MovieClipLoader = new MovieClipLoader();

    //set the listener to this loader

    image_mcc.addListener(mclListener);

    //load the rest url into image_mc

    image_mcc.loadClip(url, image_mc);

    mclListener.onLoadComplete = function(target_mc:MovieClip):Void{

    trace( "onLoadComplete");

    };

    //Once onLoadComplete is fired, the map will call this function

    function setCurrentMapReference(sys:String){

    cmr=sys;

    trace(cmr);

    }

  5. Click on the map to create a dc parameter for panning the map. The dx|dy value is the difference (in pixels) between where the user clicks and the center of the map.
  6. Make a second getMap request using the cmr value from step 3 and the dc parameter from step 4. The c parameter from the first map is no longer needed, because the center latitude and longitude are computed from the combination of cmr and dc.
  7. Repeat steps 3–5 for more maps.

Obtaining the cmr value from within the SVG environment

This sample demonstrates how to obtain the cmr value from a projected REST map in SVG format from within the SVG environment and parse the response to obtain the cmr parameter value.

In the code for this sample, the getURL() method makes a call to restproxyservlet, and upon receipt of the data, the function specified in the getURL is called. In this example, MapLoaded is the callback function.

The MapLoaded function parses the SVG response from the ArcWeb server and displays cmr in a Web browser. The cmr along with dc parameter can then be used in subsequent requests for panning the map.

Software requirements

How to obtain the cmr value from within the SVG environment

  1. Send a valid REST request to generate a map in SVG format using the ProxyServlet method.
  2. View Source for the map created in step 1. The cmr value is in the <desc> tag located immediately after the <svg> tag.
  3. For example:

    <?xml version="1.0" standalone="no"?>

    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">

    <svg width="400px " height="400px" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink">

    <desc>

    -117.0|34.0|0.0|0.0|50000.0|0.0|3

    </desc>

    In this example, the cmr value is:

    -117.0|34.0|0.0|0.0|50000.0|0.0|3

  4. Download the sample code (1getcmr.zip) and unzip the getcmr.svg file to the restproxyservlet folder.
  5. NOTE: The SVG document needs to be hosted on the same server where the REST map is created—in this case it is the server hosting the restproxyservlet—otherwise, a security violation error will occur.

  6. Open the getcmr.svg file in a text editor and, in the following line, replace <myhostname> and [:port] with the server name and port number where the restproxyservlet and getcmr.svg files are hosted:
  7. "http://<myhostname>[:port]/restproxyservlet/restProxy?sf=50000&ds=bam&c=-117|34&actn=getMap&fmt=svg&ocs=0";

  8. Type the following in a Web browser to initiate getcmr.svg:
  9. http://<localhost>[:port]/restproxyservlet/getcmr.svg

    For example: http://myhostname:8080/restproxyservlet/getcmr.svg

    The above request displays the cmr contained in the SVG response of the REST request specified in the getcmr.svg document.

Using Java to read the cmr value from the HTTP header

This sample demonstrates how to obtain the cmr value from the HTTP header of a projected REST map using Java. This method can be used for maps in JPG, PNG, SVG, or SWF format.

Software requirement

How to obtain and use the cmr value using Java

  1. Download the sample code (1cmrHTTPHeader.zip) and unzip the cmrHTTPHeader.jsp file.
  2. Open cmrHTTPHeader.jsp in a text editor and replace ArcWeb username and ArcWeb password in the cmrHTTPHeader.jsp file with your ArcWeb Services user name and password:
  3. username: ArcWeb Username

    password: ArcWeb Password

  4. Save the file.
  5. Place cmrHTTPHeader.jsp in your Web server where it is accessible via HTTP/HTTPS.
  6. Make a request to cmrHTTPHeader.jsp by typing the following in a Web browser:
  7. http://<localhost>:<port number>/<path to cmrHTTPHeader.jsp>/getcmrHTTPHeader.jsp

    The map and the HTTP header display on the HTML page.

  8. Make a new request to pan the map using the cmr value and the dc parameter; for example, dc=50|100 pans the map 50 pixels to the west and 100 pixels to the south.

Code overview

The following lines of code in cmrHTTPHeader.jsp create a URL REST request with a valid ArcWeb REST token:

String restURL= "https://www.arcwebservices.com/services/v2006_1/restmap?" +

"actn=getMap&tkn=" +  getToken(username,password, ipAddress) + "&ds=bam&sf=500000&c=-117|34&ocs=0";

  URL urlCMR = new URL(restURL);

This line of code opens a URL connection:

URLConnection connectionCMR = urlCMR.openConnection();

Use this code to prevent cached data from being used in the response:

connectionCMR.setUseCaches(false);

This line of code reads the cmr value from the HTTP header:

cmrhdr = connectionCMR.getHeaderField("Cmr");

Using a network capturing tool to obtain the cmr value

This sample demonstrates how to obtain the cmr value from a projected REST map using a network capturing tool such as Ethereal.

Software requirement

How to obtain the cmr value using a network capturing tool

  1. Obtain a token using the getToken method.
  2. Make a map request using getMap.
  3. Capture the REST HTTP request and response using a network capturing tool, such as Ethereal.
  4. Find the "Cmr" HTTP header.
  5. Make a second getMap request using the cmr value from step 4, and choose a dc parameter to pan the map, for example, dc=50|100 pans the map 50 pixels to the west and 100 pixels to the south. The c parameter from the first map is no longer needed, because the center latitude and longitude are computed from the combination of cmr and dc.
  6. Repeat steps 3–5 for more maps.

See also


Visit the Feedback page to give comments or suggestions about the ArcWeb Developer's Guide.

ArcWeb site | ArcWeb support | support.esri.com

Copyright © ESRI