Cannot view WMSLayer nwhen basemap set

6987
12
05-22-2014 06:42 AM
DanielNwankwo
New Contributor II
I have found that if my map object has a basemap property set then the WMSLayer does not display when retrieving by resourceInfo method. When I do not set the basemap property then the WMSLayer is displayed.

This is not very useful as I need to see the basemap. I dont know if this is a bug or me, I have no solution at the moment so any help greatly appreciated.

Here is the url 'http://npdwms.npd.no/NPD_FactMap.asp' and layer is 'Quadrants'

I tried setting the visibility to no avail.

I do not have this problem when retrieving by proxy method but I would rather use the resourceInfo method

Here is my code


<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples
       on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Map with WMS</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">
    <style>
        html, body, #map {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }
        body {
            background-color: #FFF;
            overflow: hidden;
            font-family: "Trebuchet MS";
        }
    </style>
    <script src="http://js.arcgis.com/3.9/"></script>

    <script>
        var map;

        require(["esri/map", "esri/layers/WMSLayer", "esri/config","esri/layers/WMSLayerInfo","esri/geometry/Extent","esri/layers/FeatureLayer"],
                function(Map, WMSLayer, esriConfig, WMSLayerInfo,Extent,FeatureLayer,parser) {

                    map = new Map("map", {
                      extent: new Extent({xmin:-8.64846,ymin:49.8638,xmax:1.76767,ymax:60.8612,spatialReference:{wkid:4326}}),
                        zoom: 2,
                        // basemap: "streets"
                    });

                    addNorway(WMSLayer,WMSLayerInfo,Extent);
                    addBGS(WMSLayer,WMSLayerInfo,Extent);
                });



        function addBGS(WMSLayer,WMSLayerInfo,Extent){
            var layer20 = new WMSLayerInfo({name:"GBR_BGS_625k_BLS",title:"GBR BGS 1:625k Bedrock Lithology"});

            var resourceInfo20 = {
                extent: new Extent(-8.64846,49.8638,1.76767,60.8612,{wkid: 4326}),
                layerInfos: []
            };
            var wmsLayer20 = new WMSLayer("http://ogc.bgs.ac.uk/cgi-bin/BGS_Bedrock_and_Superficial_Geology/wms",
                    {
                        resourceInfo: resourceInfo20,
                        visibleLayers: ["GBR_BGS_625k_BLS"]
                    }
            );
            map.addLayers([wmsLayer20]);
            wmsLayer20.setVisibility(true);

        }

        function addNorway(WMSLayer,WMSLayerInfo,Extent){
            var layer10 = new WMSLayerInfo({name:"Quadrants",title:"NO Quads"});

            var resourceInfo10 = {
                extent: new Extent(-10.0,50.0,20.0,65.0,{wkid: 4326}),
                layerInfos: [layer10],
                version:"1.1.1"
            };
            var wmsLayer10 = new WMSLayer("http://npdwms.npd.no/NPD_FactMap.asp",
                    {resourceInfo: resourceInfo10,
                        visibleLayers: ["Quadrants","pl_all","Fields","Exploration","Development"]
                    }
            );

            map.addLayers([wmsLayer10]);
 
        }


    </script>
</head>

<body>
<div id="map">
</div>
</body>
</html>
0 Kudos
12 Replies
DanielNwankwo
New Contributor II
My colleague miraculously has found a workaround for displaying this WMS with the basemaps. Just before the WMSLayer object is added as a layer to the map, you overwrite the spatialReferences array in the WMSLayer object setting the CRS to 3857

wmsLayer.spatialReferences[0] = 3857


after this is done now add the layer to the map and hey presto the WMS layer appears.
In the background this forces a change to one of the attributes that is set on the WMS url from

&CRS=EPSG:102100

TO
&CRS=EPSG:3857


Here is the bit of code in full

function addBGS(WMSLayer,WMSLayerInfo,Extent,lang){
            var layerInfo = new WMSLayerInfo({name:"GBR_BGS_625k_BLS",title:"GBR BGS 1:625k Bedrock Lithology"});

            var resourceInfo = {
                extent: new Extent(-8.64846,49.8638,1.76767,60.8612,{wkid: 4326}),
                layerInfos: [layerInfo]
            };
            var wmsLayer = new WMSLayer("http://ogc.bgs.ac.uk/cgi-bin/BGS_Bedrock_and_Superficial_Geology/wms",
                    {
                        resourceInfo: resourceInfo,
                        visibleLayers: ["GBR_BGS_625k_BLS"]
                    }
            );

           wmsLayer.spatialReferences[0] = 3857;
            map.addLayer(wmsLayer);
        }


If we do not set the spatialReferences array as above, we get the response error message below

HTTP/1.1 200 OK
Date: Thu, 29 May 2014 13:02:01 GMT
Server: Apache
Access-Control-Allow-Origin: *
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/xml

278
<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
<ServiceException code="InvalidSRS">
msWMSLoadGetMapParams(): WMS server error. Invalid CRS given : CRS must be valid for all requested layers.
msProcessProjection(): Projection library error. proj error &quot;no options found in 'init' file&quot; for &quot;init=epsg:102100&quot;
</ServiceException>
</ServiceExceptionReport>

0


Anyway that's where I am at the moment, hope this helps someone and thanks Jeff.

Regards
Daniel
PavelVeselský1
New Contributor III

I know it's late, but can you mark this as the correct answer? This helped several people already (one of them linked me here) and can help even more if available without scrolling through whole discussion.

Thanks!

Pavel

0 Kudos
JeffPace
MVP Alum
3857 and 102100 should the same.

If this makes your WMS work, then the WMS is set up with 3857 but not 102100.  This is just a config issue with the data provider.
0 Kudos