Opened 14 years ago

Closed 12 years ago

#3549 closed defect (fixed)

Add built-in OpenLayers map viewer

Reported by: dmorissette Owned by: aboudreault
Priority: normal Milestone: 6.0 release
Component: Documentation - MapServer Version: unspecified
Severity: normal Keywords:
Cc: sdlime, msmitherdc, assefa, jmckenna, nhermann, havatv

Description (last modified by dmorissette)

Every once in a while we get requests for a simple way to test a mapfile. One way to handle this could be to do as GeoServer does and provide a built-in OpenLayers based map viewer. In the GeoServer case, this viewer is returned when one issues a WMS GetMap request with format=application/openlayers in it.

I propose that we provide a similar functionality in MapServer, which would be triggered in one of two ways:

1- Using mapserv?map=/path/to/my.map&mode=openlayers ... in this case the viewer would be initialized based on the mapfile defaults, and some of the traditional mapserv CGI params may also work (such as map size, layer selection, etc.)

2- Using format=application/openlayers in a WMS GetMap request as GeoServer does. Note that in this case the rest of the GetMap parameters would be used to configure the map to view (BBOX, WIDTH, HEIGHT, LAYERS, etc.)

Both cases would call the same function internally to produce a simple OpenLayers viewer with one singletile layer for the whole map with the selected layers.

Change History (13)

comment:1 by dmorissette, 14 years ago

Cc: jmckenna added

comment:2 by dmorissette, 14 years ago

Description: modified (diff)

comment:3 by sdlime, 14 years ago

The downside is that we automatically generate an interface that could be used to pound a server. Granted, that can be done now but it takes effort. Should there be a mechanism to not enable this?

Steve

comment:4 by nhermann, 14 years ago

Cc: nhermann added

comment:5 by dmorissette, 14 years ago

To test whether this could be implemented using regular templates, I produced the following generic MapServer template which works with MapServer 5.6 (or trunk) if you set the WEB.TEMPLATE in your mapfile to point to it and then call a URL with map=...mode=browse&layers=...

<!-- MapServer Template -->
<html>
<head>
  <title>MapServer Simple Viewer</title>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    </head>
    <body>
      <div style="width:[mapwidth]; height:[mapheight]" id="map"></div>
      <script defer="defer" type="text/javascript">
        var map = new OpenLayers.Map('map', 
                                     {maxExtent: new OpenLayers.Bounds([minx],[miny],[maxx],[maxy]), 
                                      maxResolution: [cellsize]} );

        var mslayer = new OpenLayers.Layer.MapServer( "MapServer Layer",
            "http://[host]/cgi-bin/mapserv?map=[map]", 
             {layers: '[layers]'},
             {singleTile: "true", ratio:1} );
        map.addLayer(mslayer);
        map.zoomToMaxExtent();
      </script>
</body>
</html>

The main thing missing in MapServer 5.6 for this to work is the reference to the mapserv CGI for which there is currently no template keyword (notice that in the template above part of the URL is hardcoded). We would need to add a [mapserv_url] template tag that uses a mechanism similar to msOWSGetOnlineResource (mapows.c) to determine the complete URL of the CGI and set it in the template output.

comment:6 by sdlime, 14 years ago

Are you thinking we might be able to extract the executable from CGI environment vars set by the web server? That is "/cgi-bin/mapserv" from http://maps.dnr.state.mn.us/cgi-bin/mapserv?

It would be much nicer to compute that value rather than have users code it someplace.

Steve

comment:7 by dmorissette, 14 years ago

Yes, that's what msOWSGetOnlineResource() does (in mapows.c), I have created ticket #3552 about adding a [mapserv_url] template tag for this (better name welcome, see #3552 for the details)

comment:8 by dmorissette, 14 years ago

An important comment that was made on the -dev list while discussing this was that relying on http://openlayers.org/api/OpenLayers.js may cause problems if/when the version of OpenLayers.js changes in the future.

Two options were proposed:

1- Point to a specific version of OpenLayers.js, e.g. http://openlayers.org/api/2.10/OpenLayers.js

2- Host our own stripped down version of OpenLayers.js on www.mapserver.org, with just the stuff we need for WMS and a couple of basic controls. In this case the URL that we use should still take versioning into account.

comment:9 by aboudreault, 13 years ago

Component: MapServer CGIMapServer Documentation

Committed in r10704.

comment:10 by aboudreault, 13 years ago

I just committed a small fix to support WMS version 1.3.0 in r10707.

comment:11 by aboudreault, 13 years ago

Resolution: fixed
Status: newclosed

Closing this ticket.

comment:12 by havatv, 12 years ago

Cc: havatv added
Resolution: fixed
Status: closedreopened

I can't find this documented anywhere (I searched for "openlayers").

comment:13 by dmiddlecamp, 12 years ago

Resolution: fixed
Status: reopenedclosed

I added a basic document for this in /docs/en/cgi/openlayers.txt This just has some basic examples for the moment, but could probably be expanded.

Note: See TracTickets for help on using tickets.