Map options: issues with non-mercator spatial reference

5087
2
Jump to solution
06-05-2013 08:47 AM
ReneRubalcava
Frequent Contributor
I've been having trouble trying to load a map in a spatial reference wkid of 26915.
I've tried a couple of different ways.
I load a map without any basemaps and then add an ImageService that has a wkid of 26915.
    require([       'esri/map',       'esri/layers/ArcGISImageServiceLayer'       ], function(Map, ArcGISImageServiceLayer) {       var map = new Map('map', {             autoResize: true,             center: [762120.3983057996, 4286928.371310163],             scale: 2888.131627324678            }),       imgurl = 'http://moimagery.missouri.edu/arcgis/rest/services/LGov/EWGateway2012_6inch/ImageServer';       map.addLayers([new ArcGISImageServiceLayer(imgurl)]);       map.on('click', function() {         console.debug('MAP CENTER: ', map.extent.getCenter());         console.debug('MAP SCALE: ', map.getScale());       });     });

I get a console message like so:
Map: Geometry (wkid: 4326) cannot be converted to spatial reference of the map (wkid: 26915) 

But my map is not where it should be.
If you open the debug console of your browser and click on the map, you can see the center and scale are not as expected.

I even tried explicitly defining the spatial reference of the map in the map options.
    require([       'esri/map',       'esri/layers/ArcGISImageServiceLayer',       'esri/SpatialReference'       ], function(Map, ArcGISImageServiceLayer, SR) {       var map = new Map('map', {             autoResize: true,             spatialReference: new SR({wkid:26915}),             center: [762120.3983057996, 4286928.371310163],             scale: 2888.131627324678            }),       imgurl = 'http://moimagery.missouri.edu/arcgis/rest/services/LGov/EWGateway2012_6inch/ImageServer';       map.addLayers([new ArcGISImageServiceLayer(imgurl)]);       map.on('click', function() {         console.debug('MAP CENTER: ', map.extent.getCenter());         console.debug('MAP SCALE: ', map.getScale());       });     });


You can run a sample of this here;
http://plnkr.co/edit/lUXpEIfdpMToCYGzMK4R

Again, checking the console, these numbers don't match.

If I don't set the scale, it will just default to the full extent of the service.

This does work if I explicitly define an extent like this:
    require([       'esri/map',       'esri/layers/ArcGISImageServiceLayer',       'esri/SpatialReference',       'esri/geometry/Extent'       ], function(Map, ArcGISImageServiceLayer, SpatialReference, Extent) {       var ext = new Extent(689690.1735286616, 4231176.807089917, 739306.7413302765, 4256822.370572377, new SpatialReference({wkid: 26915})),            map = new Map('map', {             autoResize: true,             extent: ext           }),       imgurl = 'http://moimagery.missouri.edu/arcgis/rest/services/LGov/EWGateway2012_6inch/ImageServer';       map.addLayers([new ArcGISImageServiceLayer(imgurl)]);     });

http://plnkr.co/edit/LqpDulsrKhGYEH3QRS3H?p=preview

So the map is using the SpatialReference of the extent to set itself up properly, but doesn't seem to like having a SpatialReference set and use the center option like I was trying to do above.

Am I missing something? The map reference for the center option doesn't say it has to be in wkid: 4326.
http://developers.arcgis.com/en/javascript/jsapi/map-amd.html#map1

edit, because it does say array containing longitude and latitude in the docs, so yeah, that implies I can only use the center option if using a web mercator map that it could convert the lat/longs from. That kinda blows, I'll just have to go with extents in this case.
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor
when your map is being drawn with a spatialReference other than web mercator, you need to create a point object (with the same spatialReference) and pass the point as the center in the map constructor.

var renesPoint = new esri.geometry.Point(762120, 4286928, new esri.SpatialReference({ wkid: 26915 })); ... center: renesPoint

View solution in original post

2 Replies
JohnGravois
Frequent Contributor
when your map is being drawn with a spatialReference other than web mercator, you need to create a point object (with the same spatialReference) and pass the point as the center in the map constructor.

var renesPoint = new esri.geometry.Point(762120, 4286928, new esri.SpatialReference({ wkid: 26915 })); ... center: renesPoint
ReneRubalcava
Frequent Contributor
Well, that makes sense I suppose. I'll just need to rewrite my config loader to check for that.

Thanks.
0 Kudos