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

815
6
01-12-2014 11:13 PM
AleydisG__Pere
Regular Contributor
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>
0 Kudos
6 Replies
JohnathanBarclay
Regular Contributor
The map takes on the spatial reference of the first layer added to it, so it is unnecessary to assign a spatial reference to the map.
0 Kudos
AleydisG__Pere
Regular Contributor
As I'm only loading a single layer I can't do this then:
wmsLayer.spatialReference = map.spatialReference;

Ok. That has sense.
But if I do this,
wmsLayer.spatialReference = mySpatialRef;

I shouldn't have an issue when zooming to full extent.
Press the 'Full extent' button in my app and see the message in the web browser console.
The spatial reference of my wms layer is 25831 and my map is taking it correctly. But then for some reason when zooming to full extent it considers the spatial reference of my wms layer is 4326. Is it a bug?
0 Kudos
JohnathanBarclay
Regular Contributor
The navigation.zoomToFullExtent() method is trying to zoom to the full extent of the basemap.

A better way for you may be to use the following:

map.setExtent(initialExtent);
0 Kudos
AleydisG__Pere
Regular Contributor
I'm not loading any basemap. Maybe the navigation.zoomToFullExtent() method uses the default spatial reference of the map class (i.e. 4326).
I think it should zoom to the extent of the first layer added if you are not loading a basemap to your map. That would have some more sense.

I'm also getting this error when zooming to selected features of layers with a spatial reference different than that of my map (25831).

The newer versions of the API aren't working as I expected. Everything works if you use spatial reference 4326 but when working with other spatial references you get this error.

As a workaround I'm using the map.setExtent(initialExtent); you suggested and replacing every map.spatialReference with the mySpatialRef object I defined.
0 Kudos
JonathanUihlein
Esri Regular Contributor
Is there a specific technical reason you need to use a spatial reference of 25831 for your application (E.G. not 4326 or 102100)?
0 Kudos
AleydisG__Pere
Regular Contributor
It's ETRS89, the official datum in my country (and the 'officialy accepted' common spatial reference for Europe).
All my data is in that spatial reference and its use is a requirement for my web app.
0 Kudos