[mapserver-users] Openayers - Map zoomed in to much

Andy Colson andy at squeakycode.net
Wed Jul 22 09:47:39 EDT 2009


Paul Curran wrote:
> Hi,
> I am having trouble viewing my map correctly via open layers, the map is 
> zoomed in very close I cannot zoom out anymore.
> I have tried different zoom extents however it is the same. Can anyone 
> tell me where I am going wrong is it the epsg code? If I enter a 
> different epsg code I just see the background colour of my map file.
> Andy help greatly appreciated
> My map and openlayers files are below
> Thanks
>  
>  
> MAP
> 
> NAME UK1
> PROJECTION
> "init=epsg:4326"
> END
> SIZE 1600 1200
> IMAGECOLOR 153 204 255
> IMAGETYPE JPEG
> SHAPEPATH "http://localhost/openlayers/data/"
> EXTENT -8883850.321101 -310000.000000 15483850.321101 12710000.000000
> UNITS METERS
> 
> 
> WEB
> TEMPLATE "http://localhost/openlayers/examples/test.html"
> LOG "\ms4w\tmp\ms_tmp\log.txt"
> IMAGEPATH "\ms4w\tmp\ms_tmp\"
> IMAGEURL "/ms_tmp/"
> METADATA
> 'wms_title' "wms demo"
> 'wcs_onlineresource' 
> "http://127.0.0.1./cgi-bin/mapserv?map=/ms4w/apps/openlayers-2.5/data/uk1.map&"
> 'wms_srs' "epsg:4326 epsg:4269"
> END
> END
> LAYER
> 
> NAME "UK"
> METADATA
> 'wms_title' "wms_demo"
> END
> STATUS DEFAULT
> TYPE raster
> TILEINDEX "map"
> TILEITEM "Location"
> PROJECTION
> "init=epsg:4326"
> END
> CLASS
> STYLE
> COLOR 0 0 0
> END
> LABEL
> COLOR 0 0 0
> SIZE SMALL
> END
> 
> END
> 
> END
> END
>  
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>MAPPING TEST
> <style type="text/css">
> #map {
> width: 90%;
> height: 90%;
> border: 8px solid black;
> }
> </style>
> <script src="../lib/OpenLayers.js"></script>
> <script type="text/javascript">
> var zoom = 1;
> var bounds = new OpenLayers.Bounds(-888385.321101, -31000.000000, 
> 1548385.321101, 1271000.000000);
> var map, layer;
> 
> function init(){
> map = new OpenLayers.Map('map', { maxExtent: bounds });
> map.addControl(new OpenLayers.Control.PanZoomBar());
> map.addControl(new OpenLayers.Control.OverviewMap());
> map.addControl(new OpenLayers.Control.MousePosition());
> layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
> "http://127.0.0.1/cgi-bin/mapserv.exe?", { layers: 'uk', map: 
> '/ms4w/apps/openlayers-2.5/data/uk1.map'},
> { gutter: 15 });
> map.addLayer(layer);
> map.zoomToExtent(bounds);
> map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
> 
> }
> </script>
> </head>
> <body onload="init()">
> <div id="map"></div>
> </body>
> </html>
> 


In the javascript, I set the zoom between 17 (all the way out) and 5 
(zoomed in), you have zoom set to 1 so that would be way way in.

Also, in the constructer add numZoomLevels, like:

map = new OpenLayers.Map('map', { maxExtent: bounds, numZoomLevels: 10 });

That'll give you 10 levels to hit the + / - to zoom in/out.

-Andy


More information about the mapserver-users mailing list