Select to view content in your preferred language

Map: Geometry cannot be converted

15135
12
01-24-2013 03:03 AM
JonasEngedal
Deactivated User
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
JohnGravois
Deactivated User
i can confirm your results and i would agree that it looks like a bug.  i will do some more testing and let you know what i find.
0 Kudos
JohnGravois
Deactivated User
i have logged the following bug related to this issue.  thank you for bringing the item to our attention!

[NIM088460: It is not possible to control the map extent when a WMTS layer is present in JS API 3.3. Error (Map: Geometry (wkid: "x") cannot be converted to spatial reference of the map (wkid: "x") )]
0 Kudos
ChristopheDAMOUR
Deactivated User
Hi,

Any news or workaround for that bug ?

--
Christophe
0 Kudos
ChristopheDAMOUR
Deactivated User
This bug seems to still be present in V3.4.
I am still trying to find a workaround.

Thanks for any help.

--
Christophe
0 Kudos
AdamSkoog
Deactivated User
Seems that this bug is still preset in 3.5 as well, would be nice if we could get an idea of a work around or when this will be fixed.
0 Kudos
AdamSkoog
Deactivated User
Here is my work around to fix this issue. Basically just need to use the geometry service to do a projection. Hopefully this helps someone out, I'm guess this is something they are not going to fix as it says in the documentation of setExtent that it needs to be in the same spatial reference.

var extent = <populate extent>;

var projectParams = new esri.tasks.ProjectParameters();
projectParams.geometries = [extent];
projectParams.outSR = map.spatialReference;

var defer = esri.config.defaults.geometryService.project(projectParams);
dojo.when(defer, function (projectedGeometry) {
    if (projectedGeometry.length > 0) {
        map.setExtent(projectedGeometry[0]);
    }
});
0 Kudos
GarthTissington
Emerging Contributor
I know this won;t be the fix for everyone but for me it was a simple mater of just using the Spatial reference already defined.

So, instead of

new esri.SpatialReference({ "wkid": 4326 })


use this

map.spatialReference


of course if you are create a geometry that is not the same SR as the map then you will need to follow the example already given by AMxtremezx2



Not sure why using the same wkid doesn't make the same SR but that fixed it for me... and really make more sense than creating a new one anyway.
0 Kudos
KjetilPettersson
Emerging Contributor
I get the same issue in 3.6.
0 Kudos
AzharIbrahim
Occasional Contributor
I'm using 3.7. My WMTS is not in ESPG:4326. When I use the service in ArcMap, the projection shows up correctly. When using the Javascript API, if you check the spatial reference for the layer it appears as 4326. After adding the layer to the map, the map's spatial reference is correct, but I still get this error. Could it be that the spatial reference isn't interpreted properly when creating the layer?

Geometry (wkid: 32617) cannot be converted to spatial reference of the map (wkid: 32617)
0 Kudos