1

I'm trying to add WMS layer from remote ArcGIS server to my GWT web app. I'm using gwt-openlayers library.

My code:

    MapOptions defaultMapOptions = new MapOptions();

    mapWidget = new MapWidget("100%", "100%", defaultMapOptions);   

    Map map = mapWidget.getMap();


    //gNormal = new GoogleV3("Google Normal", gOptions);
    //map.addLayer(gNormal);   


    WMSParams wmsParams = new WMSParams();
    wmsParams.setFormat("image/png");
    wmsParams.setLayers("1");
    wmsParams.setStyles("");

    WMSOptions wmsLayerParams = new WMSOptions(); 
    wmsLayerParams.setUntiled();
    wmsLayerParams.setProjection("EPSG:3857"); // is it correct setting for WMS layer?
   //  wmsLayerParams.setProjection("EPSG:102113");
   // wmsLayerParams.setProjection("EPSG:4326");
    wmsLayerParams.setTransitionEffect(TransitionEffect.RESIZE);


    String wmsUrl = "sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer";
    arcGis = new WMS("ArcGis", wmsUrl, wmsParams);
    map.addLayer(arcGis);
    map.setBaseLayer(arcGis);


   LonLat lonLat = new LonLat(-84.1,36.4); //USA

   lonLat.transform("EPSG:4326", map.getProjection()); 
    //System.out.println("map projection "+map.getProjection());
   map.setCenter(lonLat, 3); 

   add(mapWidget);

I read many articles and SO questions but I still can't solve the problem. My problem is rendering pink tiles on the map instead of normal image. I copied image url as many stackoverflow answers suggested and saw the following:

http://localhost:8084/sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?FORMAT=image%2Fpng&LAYERS=1&STYLES=&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG%3A4326&BBOX=-135,45,-90,90&WIDTH=256&HEIGHT=256

Without localhost:8084 prefix url works fine and shows me small piece of map.

Questions:

1) How get rid from localhost prefix in WMS url? In my code wmsUrl look like sampleserver1... so it's correct. It seems my application adds it's root path to remote url.

2) I read that WMS layers should have the following projection - "EPSG:3857". Is it true? As i mentioned above when I manually put in the browser correct url without "localhost" prefix I saw some image but I'm not sure it's correct. Probably image is shifted.

3) My final goal is adding 2 layers to the map - Google Map layer and WMS layer. Google Map uses "EPSG:900913" as default projection. Could somebody give common tips to place google layer and WMS layer in one map. May be there are some tricks, common mistakes related to projections an so on.

1 Answer 1

0

In the wmsUrl variable, you are missing the "http://", that may help. Pink tiles generally mean that the data source was not found, so this is where you should look for the problem. Try checking the wms URL you are supplying in a wms viewer (e.g. ArcGIS Explorer ).

To your questions: 1)try just adding the http:// to your url, without the localhost

2)A WMS layer can have any projection, it depends solely on the projection in which it was published. Information about a specific WMS's projection should be found in metadata.

3)If the two layers have the same projection, you do not need to do anything. If you want to use two layers in different projections in one map, one of the layers must be reprojected. In pure OpenLayers, this is done by specifying the projection parameter for each layer and then specifying the displayProjection parameter for the map. The layers will automatically be reprojected. However, reprojection takes some time and it increases the load time VERY significantly. It is better to avoid reprojection on-the-fly, if possible. You can either reproject the source data of one of the layers and use reprojected data. Of course, this is not possible for a WMS, so you should consider using a different data source. If you want a background map, you can donwload OpenStreetMap data, reproject them to your desired projection, and then use them with the other WMS you want to use.

Hope at least some of this helps :-)

4
  • Could you share a little bit more about rendering 2 layers simultaneously with gwt openlayers? I read somewhere that it's possible to create Vector object from WFS service. Problems with FeatureType and FeatureNamespace - where I can find values? GetCapabilities request returns empty featureTypeList. Also I read about creating WFS from WMS, but all my efforts was unsuccessful.
    – user2104560
    Sep 3, 2013 at 3:47
  • As far as I know, it is not possible to create WFS from WMS. At least nor "proper" - it would still behave in the same way as the original WMS. The same goes for Vector objects. WMS always provides raster data - the server processes its own, sometimes vector, data based on the client request and provides a geocoded map image - a raster. See opengeospatial.org/standards/wms .
    – Kenny806
    Sep 3, 2013 at 6:14
  • To your first question: I have no experience with gwt-OpenLayers, I have only worked with javascript OpenLayers (see openlayers.org ). But rendering two or more layers simultaneously should not require more than creating a layer object and than adding it to a map, like this: wms1 = new WMS("wms1",wms1URL,wms1Options); wms2 = new WMS("wms2",wms2URL,wms2Options); map.addLayers([wms1,wms2]); map.setBaseLayer(wms1);
    – Kenny806
    Sep 3, 2013 at 6:16
  • Thanks, I managed to draw 2 layers - it turns out, simple addition of many layers works fine. My problem was in ignoring transparent property. When I set transparent=true I saw WMS overlay on google map.
    – user2104560
    Sep 3, 2013 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.