Adding WMS layer from a non-Esri WMS server

7912
5
12-19-2012 05:10 AM
BetsySchenck-Gardner
Occasional Contributor
Has anyone had any success adding a layer from a non-esri wms server?  I have no trouble adding a wms layers via the WMSLayer command if the WMS server being accessed is an ArcGIS server.  For example, I can add the rivers layer from http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServe... by doing the following:
  var layer1 = new esri.layers.WMSLayerInfo({name:"1",title:"Rivers"});
  var resourceInfo = { extent: new esri.geometry.Extent(-126.40869140625,31.025390625,-109.66552734375,41.5283203125,{wkid: 4326}), layerInfos: [layer1] };
  var lyr = new esri.layers.WMSLayer("http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServe...",{resourceInfo:resourceInfo, visibleLayers: ["1"]});
  map.addLayer(lyr);

But if I try to add a layer from non-esri WMS server, I get nothing.  For example, I tried adding a layer from a USGS WMS server - (http://mrdata.usgs.gov/services/porcu?request=getCapabilities&service=wms):
  var layer1 = new esri.layers.WMSLayerInfo({name:"porcu",title:"porcu"});
  var resourceInfo = { extent: new esri.geometry.Extent(-179,-89,179,89,{wkid: 4326}), layerInfos: [layer1] };
  var lyr = new esri.layers.WMSLayer("http://mrdata.usgs.gov/services/porcu",{resourceInfo:resourceInfo, visibleLayers: ["porcu"] });
  map.addLayer(lyr);

Has anyone else had this issue?
5 Replies
JeffPace
MVP Alum
are you using a proxy to access the cross domain resource?
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
No. That is why I'm using the resourceInfo object.  According to documentation, this bypasses the getCapabilities file which is what you need for the proxy.  This approach worked for a WMS server hosted on ArcGIS Server.
0 Kudos
BigNate
New Contributor
Any update on this?
0 Kudos
DanielNwankwo
New Contributor II
I have found that if your 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 if you know how to get round this please drop a line.

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


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
JeffPace
MVP Alum
moved to your other thread
0 Kudos