[mapserver-dev] Proposal to add built-in OpenLayers map viewer

Daniel Morissette dmorissette at mapgears.com
Mon Sep 27 17:16:27 EDT 2010


Dan Little wrote:
> I sorta like the idea of "mode=browse" and then "template=[template]"
> 
> Then have a "$prefix/share" directory that contains the "openlayers.html" 
> template. So, "mapserv?..stuff..&mode=browse&template=openlayers", would then 
> read form the share directory and regurgitate openlayers.html with any parsing 
> freebies we could pore into it.
> 

For security reasons I'm not sure it would be smart to support reading
arbitrary templates from $prefix/share out of the box without an
explicit mechanism to enable this feature (and having it turned off by
default).

However, I would be supportive of adding something like a TEMPLATEPATH
setting in the mapfile which could be used to point (associate) a
specific mapfile with a directory of templates, and then using
template=openlayers as you suggest could automatically load
openlayers.html from the TEMPLATEPATH directory.


Back to my initial proposal, to test whether this kind of generic
templates could be implemented using regular templates, I produced the
following generic MapServer/OpenLayers 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.


Now, what I am proposing is that we embed a template such as this one
directly in the executable and tie it to mode=openlayers, or
mode=browse&template=openlayers to make it easier to use (i.e. without
requiring any external dependency or mapfile modification)

Daniel
-- 
Daniel Morissette
http://www.mapgears.com/


More information about the mapserver-dev mailing list