Cannot view WMSLayer nwhen basemap set

6995
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
JeffPace
MVP Alum
most likely adding the basemap is slowing down map creation, so you are trying to add the wms layers prior to the map being ready

try

map.on('load', lang.hitch(function(){
addNorway(WMSLayer,WMSLayerInfo,Extent);
addBGS(WMSLayer,WMSLayerInfo,Extent);
}))
0 Kudos
DanielNwankwo
New Contributor II
Hello Jeff,
I tried your suggestion but it did not work.

The load event seems to be triggered before the basemap is displayed so im thinking maybe there is another event that could be set instead, assuming that this is the right track.

Thanks, more ideas pls.
0 Kudos
JeffPace
MVP Alum
try

1.create the map without the basemap
2. manually add the basemap
3. basemap.on('load', <add wms>)
0 Kudos
DanielNwankwo
New Contributor II
try

1.create the map without the basemap
2. manually add the basemap
3. basemap.on('load', <add wms>)



Hey Jeff,
Tried but to no avail, also set a timeout (5secs) before creating the WMSLayer just to be sure but no joy also, strange problem
Theres a chocolate bar waiting if this one is solved!!!

Thanks
0 Kudos
JeffPace
MVP Alum
ok,
i would alert(map.layerIds) after the wms load.  That way you can see if they are there and not drawing, or if they are not being added

Side note .. oh wait


Your wms services are 102100 (3857) right? They HAVE to be if you want to add them to a tiled basemap
0 Kudos
DanielNwankwo
New Contributor II
Hi Jeff
Not too certain how the coordinate system is used so may have to do some reading before I can answer.
0 Kudos
JeffPace
MVP Alum
i can tell by your extent that they are not (wkid 4326).  that is wgs 84 (lat long).  You need to be in web mercator auxiliary sphere
0 Kudos
DanielNwankwo
New Contributor II
i can tell by your extent that they are not (wkid 4326).  that is wgs 84 (lat long).  You need to be in web mercator auxiliary sphere


HI, I've was away for a few days. I am not the publisher of the WMS service. Also it seems I can only view the layers if
spatialReference set to wgs84(4326), in this setting I cannot display a world map from ESRI.

This being the case, I have two questions:


  1. Can I convert a wgs84 service to 3857/102100 in the javascript side, or via the url parameters?

  2. Is my only other option to use a proxy



Thanks for the help so far!
Daniel
0 Kudos
JeffPace
MVP Alum
1. you cannot convert tiled services to a different coordinate system
2. proxy will not help

Basically if you need to use that WMS service, you cannot use ESRI basemaps.

You only option appears to be to find a wkid 4326 basemap.  I am not aware of any
0 Kudos