I have a use case where an external WMS server can serve maps in the Web Mercator projection using EPSG code 900913, but won't recognize ESRI's 102100 code.
My question is: can I force all WMS requests to use EPSG code 900913?
To illustrate, I have a simple map page:
Test
Where test.js creates a simple map and adds a WMSLayer to it:
var wmsAddress = "http://some.server.com/wms";
var map, srs, extent;
require(["esri/map",
"esri/layers/WMSLayer",
"esri/layers/WMSLayerInfo",
"esri/geometry/Extent",
"esri/geometry/Point",
"esri/SpatialReference",
"dojo/domReady!"],
function (Map, WMSLayer, WMSLayerInfo, Extent, Point, SpatialReference) {
srs = new SpatialReference({wkid:900913});
extent = new Extent(
1362550.0288221193, 7616458.979152972,
2281987.5791366613, 9525359.127428867,
srs);
map = new Map("mapDiv", {
center: new Point(1800000, 7900000, srs),
extent: extent
});
var wmsService = new WMSLayer(wmsAddress, {
resourceInfo: {
extent: extent,
layerInfos: [new WMSLayerInfo({name:"layerName",title:"TestMap"})]
},
visibleLayers: ["layerName"]
});
map.addLayers([wmsService]);
});
When loading the application, the request that is sent to the WMS server looks like this (viewed in a browser console):
http//some.server.com/wms?SERVICE=WMS&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=TRUE&STYLES=&VERSION=1.3.0&LAYERS=layerName&WIDTH=1904&HEIGHT=400&CRS=EPSG:102100&BBOX=-2743182.35289663,6945549.925862053,6343182.35289663,8854450.074137948
Which results in this response from the server:
Error occurred decoding the espg code urn:x-ogc:def:crs:EPSG:102100 No code "EPSG:102100" from authority "European Petroleum Survey Group" found for object of type "IdentifiedObject".
Answer
I'm not sure if this is the right way to do it, but there is a spatialreferences
attribute of the WMSLayer
object that contains a list of numbers that represent what to request from the backing server.
If you insert 900913
as the first element:
var wmsService = new WMSLayer(wmsAddress, {
resourceInfo: {
extent: extent,
layerInfos: [new WMSLayerInfo({name:"layerName",title:"TestMap"})]
},
visibleLayers: ["layerName"]
});
wmsService.spatialReferences[0] = 900913;
map.addLayers([wmsService]);
Then the javascript API will use 900913 when requesting the map. For an example, see this jsfiddle.
The spatialReferences
object does not appear in the documentation, but it also is not prefixed with an underscore so I presume it's OK to manipulate like this.
No comments:
Post a Comment