[GIS] Change output spatial reference for ArcGISTiledMapService

arcgis-javascript-apiarcgis-server

I'm using the New Zealand Topo50 maps for my basemaps from an ArcGIS map server at http://services.arcgisonline.co.nz/ArcGIS/rest/services/LINZ/geotiffs/MapServer. However, this service has a spatial reference of EPSG:2193 and the tiles are being projected over Europe instead of New Zealand.

I've noticed that vector feature layers, e.g. FeatureLayer and ArcGISDynamicMapServiceLayer, automatically add an output spatial reference to the request so that the returned features are in EPSG:3857 (Web Mercator). Raster layers don't seem to work the same though.

What can I do to have the basemap projected correctly?

My code:

var map = new Map("map", {
  basemap: "topo"
});

var topo50Layer = new ArcGISDynamicMapServiceLayer(
  "http://services.arcgisonline.co.nz/arcgis/rest/services/LINZ/geotiffs/MapServer"
);

map.addLayer(topo50Layer);

Best Answer

There is an option to specify the SpatialReference when creating the map using the extent option. The dynamic map service layer should automatically project onto the map's spatial reference. It would look something like this

var map = new Map("map", {
  extent: new Extent({
    xmin: <xmin value>,
    ymin: <ymin value>,
    xmax: <xmax value>,
    ymax: <ymax value>,
    spatialReference:{ wkid: 2193 }
  })
});

A working sample of this is provided on the documentation page. For more information on how to create an Extent, take a look at the API documentation for extent.

Related Question