[GIS] OpenLayers WMS disappears when including OpenStreetMap

geoserveropenlayers-2openstreetmapoverlay

Setup:

  • ArcSDE 9.3.2
  • Oracle 11g
  • GeoServer 2.1.4
  • OpenLayers (latest build)
  • OpenStreetMap
  • InternetExplorer 7.0/ Google Chrome

EDIT: I have updated information just below the screen shots

Problem:

I am trying to take some feature classes from our arcsde and overlay them with OSM, originally i was trying to keep them in their native projection of BC_Albers (EPSG:42102) but i couldn't get them to overlay properly. So i consigned my self to having to do a reprojection of my data from 42102 to 4326.

I did the reprojection this morning and then modified my openlayers test page to view the data. I can view my featureset by itself just fine, I can view the OSM layer by itself just fine but when I try and combine the two all I get is OSM.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="/openlayers/OpenLayers.js"></script>
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function ()
    {

        var bounds = new OpenLayers.Bounds(
                -127.998497751, 49.138495421,
                -114.19842900799999, 60.000008341
            );
        var options = {
            maxExtents:bounds,
            projection: "EPSG:4326",
            units: 'degrees'
        };
        var map = new OpenLayers.Map('map', options);


        var copi = new OpenLayers.Layer.WMS(
        "Div 51 COPI", "http://wldev1.canfor.ca:8080/geoserver/WIM/wms",
        {
            layers: 'WIM:FOREST_WIM.WEB_COPI_TRAPPER',
            format: 'image/gif',
            transparent: 'true'
        }
        );
        map.addLayer(new OpenLayers.Layer.OSM());
        map.addLayer(copi);
        map.addControl(new OpenLayers.Control.LayerSwitcher({ 'ascending': false }));
        map.addControl(new OpenLayers.Control.Navigation());
        map.zoomToMaxExtent();//bounds, true);

    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="map" style="clear:both;width:800px;height:400px;border:2px solid green;"></div>
</div>
        <div id="wrapper">
        <div id="location">location</div>
        <div id="scale">
        </div>
    </div>
</form>
</body>
</html>

Layers In ArcMap
Overlay Layer without OSM
Overlay Layer with OSM

it appears it may have something to do with the way that openlayers is changing the EPSG:

without OSM on map:
http://wldev1.canfor.ca:8080/geoserver/WIM/wms?LAYERS=WIM%3AFOREST_WIM.WEB_COPI_TRAPPER&FORMAT=image%2Fgif&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&BBOX=-180,-90,0,90&WIDTH=256&HEIGHT=256

WITH OSM on map:
http://wldev1.canfor.ca:8080/geoserver/WIM/wms?LAYERS=WIM%3AFOREST_WIM.WEB_COPI_TRAPPER&FORMAT=image%2Fgif&TRANSPARENT=true&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A900913&BBOX=-180,-90,10018574.17,10018664.17&WIDTH=256&HEIGHT=256

Best Answer

As @drnextgis states the displayProjection property of the map is only really about the system in which coordinate values are displayed to users (behind the scenes I think OpenLayers is doing a transform).

When you add an OSM layer to the map it becomes the base layer, it is the base layer that then informs the projection of the map. So, since OpenStreetMap is EPSG:900913 all WMS layer requests will default to that value if one is not set on the layer itself. If one is set then the data is requested using that one instead, in your case EPSG:4326. Since your source data is being served by GeoServer it is capable of doing the transformation itself so you don't need to worry about it on the client.

Remove the projection: "EPSG:4326" property from your map options object and let OpenLayers handle it based on the base OSM layer.