user1173933
user1173933

Reputation: 23

openlayers - wms - map not loading

I've created a simple site with a map where I'm connecting to a wms-server. The problem is now, that the map isn't shown, just a view small pictures. Here is the site i've created: http://dl.dropbox.com/u/2418858/index.html

Here is the code i've been using:

<script type="text/javascript">
        var map;
        var wms;
        var map_controls = [new OpenLayers.Control.LayerSwitcher(),
                             new OpenLayers.Control.PanZoomBar(), 
                             new OpenLayers.Control.MouseToolbar(), 
                             new OpenLayers.Control.KeyboardDefaults()];

        function init() {
            map = new OpenLayers.Map("map", {
                controls : map_controls
            });
            wms = new OpenLayers.Layer.WMS("Satellitenbild_30m", "http://gis.lebensministerium.at/wmsgw/", {
                layers : 'Satellitenbild_30m',
                key : '6ae2a41178c77ccee1db7248c9f92b04',
            }, {
                projection : new OpenLayers.Projection('EPSG:32632'),
                singleTile : true,
                buffer : 0,
                ratio : 1
            });

            map.addLayer(wms);

            map.zoomToMaxExtent();

        }
    </script>
</head>
<body onload=init()>
    <div id="map" style="width: 1000px; height: 1000px"></div>
    </div>
</body>

When I'm using Spatial commander (a GIS-desktop-program) I'm seeing the map and can zoom-in and out, but when I'm using Openlayers I don't see a map.

So what I've done is intercepting the request vom Spatial Commander with a proxy to see how this request differs from mine sent from my website.

The only difference I've found was the BBOX parameter which in SC looked like this:

BBOX=495149.712089618,4954209.6147000715,1173065.9355847104,5633477.615310807

and the parameter in a request sent from my webpage looked like this:

BBOX=-351.5625,-351.5625,351.5625,351.5625

So I changed the BBOX parameter sent through my webpage manually and get this: manual request So there was the map!

Now my actual questions:

Thanks!

Upvotes: 2

Views: 7856

Answers (3)

igorti
igorti

Reputation: 3856

The problem is that you don't set projection on OpenLayers map object. In this case OpenLayers sets default projection which is "EPSG:4326". Then you can also set maxExtent property so that OpenLayers knows for which area it should send image requests. In init method do this:

map = new OpenLayers.Map("map", {
  controls : map_controls,
  projection: "EPSG:32632",
  maxExtent: new OepnLayers.Bounds(495149.712089618,4954209.6147000715,1173065.9355847104,5633477.615310807)                 
});

Upvotes: 0

Chau
Chau

Reputation: 5570

Try setting the property maxResolution on the map object:

map = new OpenLayers.Map("map", {
    controls : map_controls,
    maxResolution: 1000
}); 

Upvotes: 2

geographika
geographika

Reputation: 6528

OpenLayers only handles a couple of projections (Web Mercator and WGS84) itself. For other projections you need to include the Proj4js library available at - http://proj4js.org/

OpenLayers integrates automatically with this library if it is available (i.e. added to your web page).

Next add in the projection parameters for your projection (before it is used in your code). In this case EPSG:32632

You can get nearly all projection details from http://spatialreference.org (when the site is up) in the Proj4js format:

Proj4js.defs["EPSG:32632"] = "+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";

http://spatialreference.org/ref/epsg/32632/proj4js/

However looking at the capabilities of your WMS service - it can be requested in Web Mercator projection as well - so there is no need for reprojections:

Finally, the demo link you sent is displaying a map - in FireFox at least. Are you sure you don't have JavaScript errors? You have an extra comma in this line:

key : '6ae2a41178c77ccee1db7248c9f92b04',

This often causes Internet Explorer to stop showing the map.

Upvotes: 1

Related Questions