1

I want to display a MapServer raster image with OpenLayers 2. My problem is that I cannot zoom into the image although the resolution should allow it.

This is what I have so far: http://geocre.net/mapservertest/

A detail of the original image:

HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title>OpenLayers MapServer Test</title>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/theme/default/style.css" media="all" />
<style>
html { width:100%; height:100%; margin:0; }
body { width:100%; height:100%; margin:0; font-family:sans-serif; }
#map { width:100%; height:100%; margin:0; }
</style>
</head>
<body>
<div id="map"></div>

<script src="//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js"></script>
<script>
// set projection:
var projData = new OpenLayers.Projection("EPSG:4326");
var projDisplay = new OpenLayers.Projection("EPSG:900913");

// initialize map:
var map = new OpenLayers.Map('map', { projection:projDisplay, controls:[new OpenLayers.Control.Zoom(), new OpenLayers.Control.Navigation({'zoomWheelEnabled':true}), new OpenLayers.Control.ScaleLine()] } );

// set basemap:
var rasterLayer = new OpenLayers.Layer.MapServer("Tamale (wet season)", "http://78.47.251.2/cgi-bin/mapserv", {map:'/mapserver/tamale_ws.map'});
map.addLayer(rasterLayer);

// set map center:
map.setCenter(new OpenLayers.LonLat( -0.83945,9.3833).transform(projData, projDisplay), 15);

</script>
</body>
</html>

MapServer map file:

MAP
  IMAGETYPE      JPEG
  EXTENT         -94018 1048833 -92362 1049470
  SIZE           1000 400

  WEB
    METADATA
      "wms_title" "mymap"
      "wms_srs" "epsg:900913"
    END
  END

  LAYER

    METADATA
      "wms_title" "mymap"
      "wms_srs" "epsg:900913"
      "wms_enable_request" "*"
    END

    NAME         myraster
    DATA         /mapserver/data/tamale_wet_season.tif
    STATUS       DEFAULT
    TYPE         RASTER
    PROCESSING   "BANDS=1,2,3"
    OFFSITE      0 0 0
  END 
END
4
  • If you don't show the code you have so far you probably won't get any answers.
    – user30184
    Commented Nov 5, 2014 at 9:35
  • I linked HTML file.
    – Mark
    Commented Nov 5, 2014 at 9:43
  • There is something odd with the MapServer configuration. It can't respond to WMS requests. Do you have the line "wms_enable_request" "GetMap GetCapabilities" in the METADATA section of your mapfile? Commented Nov 5, 2014 at 10:29
  • I just added it, here is my map file: geocre.net/mapservertest/tamale_ws.map
    – Mark
    Commented Nov 5, 2014 at 10:52

1 Answer 1

2

With the fixed mapfile, it become clear to me, this is a client side problem. There is nothing wrong with the MapServer setup, the resolution limit has been set in the OpenLayers map object automatically. To override this limit, include a maxResolution parameter in your OpenLayers.Map constructor.

var map = new OpenLayers.Map('map', { 
    projection:projDisplay, 
    controls:[
        new OpenLayers.Control.Zoom(), 
        new OpenLayers.Control.Navigation({'zoomWheelEnabled':true}), 
        new OpenLayers.Control.ScaleLine()
    ], 
    maxResolution: 500 
});

Adjust the default zoom level corresponding with the new resolutions.

map.setCenter(new OpenLayers.LonLat( -0.83945,9.3833).transform(projData, projDisplay), 8);

JSFiddle example: http://jsfiddle.net/GFarkas/ank15g68/1/

Note: the 500 px maxResolution value is just an estimate. Take your time to play with it, until it fully satisfies your needs.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.