API 3.3 Measurement widget and wkid

1526
4
Jump to solution
01-15-2013 06:34 AM
MattLane
Occasional Contributor II
I've updated an app to vs 3.3 and am getting the following error with the measurement widget:
Uncaught TypeError: Cannot read property 'wkid' of undefined Measurement.js:19

I'm guessing the issue may lie with the basemap and all layers not being in web mercator, so I made a jsfiddle from the "Set custom extent and spatial reference" sample merged with the Measurement widget sample and got the same error.

http://jsfiddle.net/efx8L/

It sounds like the issue from a past version of the api might be back
http://forums.arcgis.com/threads/30762-implement-measurement-widget-(version-2.3)-to-a-different-wki...
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
Hi Matt,

In the code I provided earlier I also moved the logic to create the measurement widget until after the map loads. Here's a revised fiddle showing this:

http://jsfiddle.net/efx8L/5/



Thanks for the reply, Kelly.

I copied your code to an updated fiddle and I still get the same error. I also made a page on my dev machine just to make sure that jsfiddle isn't the problem

http://jsfiddle.net/efx8L/3/

View solution in original post

0 Kudos
4 Replies
KellyHutchins
Esri Frequent Contributor
Matt,

I ran a quick test using your code and the measurement widget worked for me. I did have to add a geometry service so that the measurement widget could use it to project. Here's the revised code:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Dynamic Map Service Layer with Custom Projection and Extent</title>

    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
    
    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
    <script>
      dojo.require("esri.map");
      dojo.require("esri.dijit.Measurement");

      function init() {
        esri.config.defaults.geometryService = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
        var customExtentAndSR = new esri.geometry.Extent(-20037506,-9823074,20037506,10214431,new esri.SpatialReference({"wkid":54052}));
        //create map with new custom spatial reference and extent.  The map will be in the Goode Homolosine Land projection
        var map = new esri.Map("map", { extent: customExtentAndSR });
        
        dojo.connect(map, "onLoad", function(){
          var measurement = new esri.dijit.Measurement({
            map: map
          }, dojo.byId('measurementDiv'));
          measurement.startup();        
        });
        
        //map service layer has a default spatial reference of 4326.
        var mapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");
        map.addLayer(mapServiceLayer);

      }

      dojo.ready(init);
    </script>

  </head>
  <body class="tundra">
    <div id="map" class="claro" style="position:relative; width:1024px; height:512px; border:2px solid #000;background-color:#99CCFF;"></div>
    <div id="measurementDiv"></div>
  </body>
</html>

0 Kudos
MattLane
Occasional Contributor II
Thanks for the reply, Kelly.

I copied your code to an updated fiddle and I still get the same error. I also made a page on my dev machine just to make sure that jsfiddle isn't the problem

http://jsfiddle.net/efx8L/3/
0 Kudos
KellyHutchins
Esri Frequent Contributor
Hi Matt,

In the code I provided earlier I also moved the logic to create the measurement widget until after the map loads. Here's a revised fiddle showing this:

http://jsfiddle.net/efx8L/5/



Thanks for the reply, Kelly.

I copied your code to an updated fiddle and I still get the same error. I also made a page on my dev machine just to make sure that jsfiddle isn't the problem

http://jsfiddle.net/efx8L/3/
0 Kudos
MattLane
Occasional Contributor II
Ah, I see. My 3.2 site didn't wait till the map was loaded and I never had an error. I made that change and it works now.

Thanks for the quick replies.

Matt
0 Kudos