Map: Geometry cannot be converted

14738
12
01-24-2013 03:03 AM
JonasEngedal
New Contributor
When using WMTSLayer in v3.3 I can't set the initial extent. Using the "center" option gives the same result.

I am getting this really weird log entry in the console:

[HTML]Map: Geometry (wkid: 4326) cannot be converted to spatial reference of the map (wkid: 4326)[/HTML]

Here is my code:

var map;
require(["esri/map", "esri/layers/wmts", "dojo/parser", "dijit/layout/BorderContainer",
         "dijit/layout/ContentPane", "dojo/domReady!"], function (myMap, wmts, parser) {

    parser.parse();
    esri.config.defaults.io.proxyUrl = "proxy/proxy.ashx";

    map = new esri.Map("map", {
            extent: new esri.geometry.Extent(-166.27, -95.74, 166.67, 5.54, new esri.SpatialReference({ "wkid": 4326 }))
    });
    var layerInfo = new esri.layers.WMTSLayerInfo({
          identifier: "world",
          tileMatrixSet: "EPSG:4326",
          format: "gif"
    });
    var options = {
          serviceMode: "KVP",
          layerInfo: layerInfo
    };
    var wmtsLayer = new esri.layers.WMTSLayer("http://v2.suite.opengeo.org/geoserver/gwc/service/wmts",options);
    map.addLayer(wmtsLayer);
});


I guess this must be a bug. The problem is not present in v2.8, which I am currently updating from.
0 Kudos
12 Replies
ChristophHoesli
New Contributor II
I had the same issue when I was using wkid as string instead of number, coming from a JSON configuration file.

After changing wkid to number, the extent for the tile service was loaded correctly.

Instead of:
new SpatialReference({wkid: "2056"})

use this:
new SpatialReference({wkid: 2056})


map.spatialReference is not available before map loading is complete.
TimCollyer
Occasional Contributor

For anyone still having this issue (I was in 3.18), this appears to be the fix. It's not a "bug" per se, just that the wkid you pass to the SpatialReference constructor must be a number, not a string. If you are getting your wkid from a configuration file, consider using dojo/number.parse() to convert it to a number.

0 Kudos
GregYetman
Occasional Contributor

I happened upon the post below, which worked for me as a way to do this with a non-WMTS layer that was in a different projection:

Map options: issues with non-mercator spatial reference

0 Kudos