4 Replies Latest reply on May 4, 2012 10:01 AM by ytang-esristaff

    Displaying WMS layer from ArcGIS 10 in OpenLayers v2.11

    c_r_b
      I'm trying to add an AGS v10 layer to an OL map but it only seems to work if:
      - map.projection = WGS84
      - map.displayProjection = WGS84
      - isBaseLayer = true

      My end goal is to use Bing or ESRI cloud-based maps in EPSG:900913 as the base maps, so my map.projection will be EPSG:900913 and my map.displayProjection will be EPSG:4326.  But the only way I can get AGS v10 REST and WMS services to display in an OL map is to set the map.projection, map.displayProjection and layer.projection to EPSG:4326. I'm using OL v2.11.

      I have AGS v10 services published as both REST and WMS.  The CRS of the REST service is '102100 (3857)'. EPSG doesn't recognize 102100 which I believe is ESRI's own designation, so I experimented using 3857. If I view the service in an ESRI client (ArcMap, ArcCatalog) then it displays with the correct projection.  But the only way I can display the layer at all in an OL map, whether using a OpenLayers.Layer.ArcGIS93Rest or a OpenLayers.Layer.WMS layer, is to use 4326 for both map.projection and map.displayProjection, which of course will not overlay on top of the Bing/ESRI base layers in EPSG:90013.

      While I'd prefer to be able to use WMS, any workaround would be acceptable.  I wasn't able to get WFS to display at all, but that may be because I don't have all the OL layer params that are required.  I tried:

      var layer = new OpenLayers.Layer.WFS( 
                  "Counties", 
                  "http://myserver/arcgis/services/county_wm/MapServer/WFSServer?", 
                              { layers: "0" } 
      );
      


      I found this information as well and tried that solution using a map.projection of 3857 for map.projection, map.displayProjection and layer.projection, e.g.:

      var options =
      {
          'units': 'm'
      };
      
      var map = new OpenLayers.Map('gxmap', options);
      
      mapprj = new OpenLayers.Projection("EPSG:3857");
      dspprj = new OpenLayers.Projection("EPSG:3857");
      
      map.projection = mapprj;
      map.displayProjection = dspprj;
      
      var layer = new OpenLayers.Layer.WMS(
          "Counties",
          "http://myserver/arcgis/services/county_wm/MapServer/WMSServer?",
          {
              layers: "0",
              format: 'image/png',
              srs: 'EPSG:3857'
          },
          {
              opacity: 0.5,
              singleTile: false,
              projection: 'EPSG:3857'
          } 
      );
      


      but still no go.  My WMS capabilities file for this layer looks thus:

      <Layer queryable="1">
          <Name>0</Name>
          <Title>
              <![CDATA[ county_webmerc ]]>
          </Title>
          <Abstract>
              <![CDATA[ county_webmerc ]]>
          </Abstract>
          <CRS>CRS:84</CRS>
          <CRS>EPSG:4326</CRS>
          <CRS>EPSG:3857</CRS>
          <EX_GeographicBoundingBox>
              <westBoundLongitude>-90.4182892958519</westBoundLongitude>
              <eastBoundLongitude>-82.4134778047652</eastBoundLongitude>
              <southBoundLatitude>41.6961255799368</southBoundLatitude>
              <northBoundLatitude>48.262692384982</northBoundLatitude>
          </EX_GeographicBoundingBox>
          <BoundingBox CRS="CRS:84" minx="-90.4182892958519" miny="41.6961255799368" maxx="-82.4134778047652" maxy="48.262692384982"/>
          <BoundingBox CRS="EPSG:4326" minx="-90.4182892958519" miny="41.6961255799368" maxx="-82.4134778047652" maxy="48.262692384982"/>
          <BoundingBox CRS="EPSG:3857" minx="-10065317.9228131" miny="5115568.65804322" maxx="-9174226.38372922" maxy="6150669.28758651"/>
          <Style>
              <Name>default</Name>
              <Title>0</Title>
              <LegendURL width="32" height="16">
                  <Format>image/png</Format>
              <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gis4/arcgis/services/MI/county_wm/MapServer/WMSServer?request=GetLegendGraphic%26version=1.3.0%26format=image/png%26layer=0" xlink:type="simple"/>
              </LegendURL>
          </Style>
      </Layer>
      


      Have also tried using 'crs' for layer instead of 'srs' per this thread, but still no go.

      Also worried that the 'isBaseLayer=true' will be required even if I do figure out the projection issue, since I need to display these as overlays.

      Has anyone been able to get a non-WGS84 ArcGIS v10 layer -- either REST or WMS -- to display in an OL map?
        • Re: Displaying WMS layer from ArcGIS 10 in OpenLayers v2.11
          c_r_b
          Figured this out, thanks to James Fee, his 2009 Dev Summit presentation, and the spherical mercator example at mkgeomatics. Basically just had to publish an AGS service in WGS84 and in OL use a map.projection of EPSG:102113.

          Also found some cool stuff for using AGS json in OL (and important potato cooking safety tips) at mapbutcher in the process...
          • Re: Displaying WMS layer from ArcGIS 10 in OpenLayers v2.11
            ytang-esristaff
            Hi, I am using following code sample and I am able to overlay an ArcGIS Server WMS on top of MapQuest OSM which is the same projection as Google Maps.

            var map = null;
            
            function init() {         
                 
             OpenLayers.ProxyHost= function(url) {
              return "/openlayers-trunk/ApacheProxyServlet?url=" + url;
                };
                
                // set MapBox customized theme
                OpenLayers.ImgPath = "http://js.mapbox.com/theme/dark/";
            
                // San Francisco
                //var lon = -122.391667;
             //var lat = 37.760628;
                //var zoom = 5;
            
                // Portland
                //var lon = -122.838493; 
             //var lat = 45.432976;
             //var zoom = 4;
                
                // Haiti, Port au Prince
                var lon = -72.3386; 
             var lat = 18.5425;
             var zoom = 8;
                    
             var options =  {
              //panMethod: null, // set 'panMethod' to null to disable animated panning
              controls: [         
                  new OpenLayers.Control.LayerSwitcher(),
                  new OpenLayers.Control.PanZoomBar(),
                     new OpenLayers.Control.Navigation(),         
                     new OpenLayers.Control.MousePosition()
                    ],
                    projection: "EPSG:900913",
                    units: "m",
                    maxResolution: 156543.0339,
                    numZoomLevels: 20, // default allowed zoom levels is 16 so change it to 20
                    maxExtent: new OpenLayers.Bounds(-20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789)        
                };
                 
             map = new OpenLayers.Map('map', options); 
             
             // MapQuest OSM tiles as base layer  
             OpenLayers.Layer.MapQuestOSM = OpenLayers.Class(OpenLayers.Layer.XYZ, {
                    name: "MapQuestOSM",
                    //attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
                    sphericalMercator: true,
                    url: ' http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
                    clone: function(obj) {
                        if (obj == null) {
                            obj = new OpenLayers.Layer.OSM(
                                this.name, this.url, this.getOptions());
                        }
                        obj = OpenLayers.Layer.XYZ.prototype.clone.apply(this, [obj]);
                        return obj;
                    },
                    CLASS_NAME: "OpenLayers.Layer.MapQuestOSM"
                });    
                var base_layer = new OpenLayers.Layer.MapQuestOSM(); 
             
                var wms_3857_layer = new OpenLayers.Layer.WMS(
                    "ArcGIS Server WMS EPSG:3857",
                    "http://gouf:6080/arcgis/services/playground/haiti_3857/MapServer/WMSServer?",
                    {
                     layers: 'provinces',
                     styles: '',         
                     version: '1.3.0',
                     crs: 'EPSG:3857',
                     transparent: true
                    },
                    {
                     singleTile: true, 
                     transparent: true,
                     isBaseLayer: false,
                     projection: 'EPSG:3857'
                    }
                );   
                wms_3857_layer.setOpacity(0.72);
                
                map.addLayers([base_layer, wms_3857_layer]);
             
             // transform lon/lat to coordinate in EPSG:900913
             map.setCenter(
              new OpenLayers.LonLat(lon, lat).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
              ), 
              zoom
             );
                
             
            }


            Figured this out, thanks to James Fee, his 2009 Dev Summit presentation, and the spherical mercator example at mkgeomatics. Basically just had to publish an AGS service in WGS84 and in OL use a map.projection of EPSG:102113.

            Also found some cool stuff for using AGS json in OL (and important potato cooking safety tips) at mapbutcher in the process...
            • Re: Displaying WMS layer from ArcGIS 10 in OpenLayers v2.11
              c_r_b
              Hi, I am using following code sample and I am able to overlay an ArcGIS Server WMS on top of MapQuest OSM which is the same projection as Google Maps...



              Thanks Yingqi.

              Out of curiosity, did you do anything special to publish the ArcGIS WMS layer?  I see you used CRS 3857 and a WMS version of 1.3.0.  Anything else you had to do to get this to work?

              Thanks,

              crb
              • Re: Displaying WMS layer from ArcGIS 10 in OpenLayers v2.11
                ytang-esristaff
                Hi Chris,

                Nothing special, just publish the service using Web Mercator projection, and EPSG:3857 (use to be EPSG:102113 or EPSG:102100) is the standard wkid for that projection. And also you can switch to use 1.1.1 too with some parameter change (CRS-->SRS etc.)

                Thanks.