DMS2

Zoom to full extent & 'Geometry cannot be converted to spatial ref of map' message

Discussion created by DMS2 on Jan 12, 2014
Latest reply on Jan 15, 2014 by DMS2
I'm having some issues with 3.7 version of the API.
Now it is with zooming to full extent. It doesn't work and I get this log in the console:
[HTML]"Map: Geometry (wkid: 4326) cannot be converted to spatial reference of the map (wkid: 25831)"[/HTML]

I'm afraid this is the main reason I'm having some other issues but I better focuse on just one and see how to fix it.
I added a function to check the map's spatial reference as I was having issues with that too.
This is some sample code based on my actual code with the zooming to full extent not working. It worked with version 2.1 of the API. Didn't I define the spatial reference of the map properly?

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css"/>
    <style>
      html, body, #mapDiv{
        padding: 0;
        margin: 0;
        height: 100%;
      }
    </style>
    <script src="http://js.arcgis.com/3.7/"></script>
    <script>
      var mySpatialRef;
      var initialExtent;
      var map;
      var urlWMSBase="http://mapcache.icc.cat/map/bases/service?";
      var wmsLayer;
      var navToolbar;

      dojo.require("esri.map");
      dojo.require("esri.layers.agsdynamic");
      dojo.require("esri.layers.ImageParameters");
      dojo.require("esri.geometry.Extent");
      dojo.require("esri.layers.wms");
      dojo.require("esri.toolbars.navigation");
      
      dojo.ready(function() {
       esriConfig.defaults.io.proxyUrl = "http://FLOPEZV:8080/proxy/proxy.jsp"; 
       init();
      });

      function init(){
        mySpatialRef = new esri.SpatialReference({"wkid":25831});
        initialExtent = new esri.geometry.Extent(258000,4485000,536000,4766600,mySpatialRef);
        map = new esri.Map("mapDiv", {
          extent: initialExtent,
          spatialReference: mySpatialRef //unnecessary?
        });
        navToolbar = new esri.toolbars.Navigation(map);
        addWMSLayer();
        map.on("load",showSR);
      }
      function showSR(){
        alert(map.loaded);
        alert(map.spatialReference.wkid);
      }
      function addWMSLayer(){
        wmsLayer = new esri.layers.WMSLayer(urlWMSBase);
        wmsLayer.setVisibleLayers(["orto"]); 
        wmsLayer.spatialReference = mySpatialRef; //map.spatialReference;<-- should this work?
        wmsLayer.setImageFormat("png");
        wmsLayer.version = "1.1.3";
        map.addLayer(wmsLayer);
      }   
    </script>
  </head>
  <body>
    <div id="mapDiv"></div>
    <div id="rightPane" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'">
      <button id="btn_fullExtent" data-dojo-type="dijit.form.Button" style="margin-right:10px;" type="button" onClick="navToolbar.zoomToFullExtent();">Full extent</button>
    </div>
  </body>
</html>

Outcomes