Ticket #3549 (closed defect: fixed)

Opened 3 years ago

Last modified 16 months ago

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) (diff)

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

Changed 3 years ago by dmorissette

  • cc jmckenna added

Changed 3 years ago by dmorissette

  • description modified (diff)

Changed 3 years ago by sdlime

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

Changed 3 years ago by nhermann

  • cc nhermann added

Changed 3 years ago by dmorissette

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.

Changed 3 years ago by sdlime

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

Changed 3 years ago by dmorissette

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)

Changed 3 years ago by dmorissette

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.

Changed 3 years ago by aboudreault

  • component changed from MapServer CGI to MapServer Documentation

Committed in r10704.

Changed 3 years ago by aboudreault

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

Changed 3 years ago by aboudreault

  • status changed from new to closed
  • resolution set to fixed

Closing this ticket.

Changed 18 months ago by havatv

  • cc havatv added
  • status changed from closed to reopened
  • resolution fixed deleted

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

Changed 16 months ago by dmiddlecamp

  • status changed from reopened to closed
  • resolution set to fixed

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.