[OpenLayers-Users] Display Map from MapServer with OpenLayers

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Fri May 11 07:11:06 EDT 2007


I've done that using PHP/Mapscript already.

HTML code:

<div id="scaleContainer">
  <img id="scaleIndicationBar" alt="Schaal indicatie">
</div>

javascript code:

        function scalebarinit(){
          if (map) { 
            map.events.register( 'moveend', this, updateScale);
            var image = document.getElementById('scaleIndicationBar');
            // make sure it is reloaded when it fails loading
            OpenLayers.Event.observe(image, "load",
OpenLayers.Util.onImageLoad.bindAsEventListener(image));
            updateScale();
          }
        }
        function updateScale(){
            if (!map) { return false; }
            document.getElementById('scaleIndicationBar').src =
"widgets/OpenLayersScalebar/drawScalebar.php?width="+map.size.w+"&height="+map.size.h+"&minx="+map.getExtent().left+"&miny="+map.getExtent().bottom+"&maxx="+map.getExtent().right+"&maxy="+map.getExtent().top;
        }

PHP code:
<?php

// parameters:
$width = '';
if (isset($_REQUEST['width'])) { $width = $_REQUEST['width']; }
$height = '';
if (isset($_REQUEST['height'])) { $height = $_REQUEST['height']; }
$minx = '';
if (isset($_REQUEST['minx'])) { $minx = $_REQUEST['minx']; }
$miny = '';
if (isset($_REQUEST['miny'])) { $miny = $_REQUEST['miny']; }
$maxx = '';
if (isset($_REQUEST['maxx'])) { $maxx = $_REQUEST['maxx']; }
$maxy = '';
if (isset($_REQUEST['maxy'])) { $maxy = $_REQUEST['maxy']; }

$oMap = ms_newMapObj(dirname(__FILE__).'/../../../map/scalebar.map');

if ($width != '') { $oMap->set("width", $width); }
if ($height != '') { $oMap->set("height", $height); }

if (($minx != '') && ($miny != '') && ($maxx != '') && ($maxy != ''))
{
  $oMap->setExtent($minx, $miny, $maxx, $maxy);
}

if ($oMap->scale < 100000)
{
  $oMap->scalebar->set("units", MS_METERS);
}

$oImage = $oMap->drawScaleBar();

$oMap->selectOutputFormat('GIF');

header("Content-type: image/gif");

// output scalebar to stdout
$url = $oImage->saveImage("");

?>

Good luck.

Best regards,
Bart

--
Bart van den Eijnden
OSGIS, Open Source GIS
http://www.osgis.nl


--------- Oorspronkelijk bericht --------
Van: Barend Köbben <kobben at itc.nl>
Naar: Pfirter Lukas <lp at rpag.ch>, openlayer <users at openlayers.org>
Onderwerp: Re: [OpenLayers-Users] Display Map from MapServer with OpenLayers
Datum: 11/05/07 08:20

> &gt; Your solutions sounds interesting. But I think this is for legends
(as
> &gt; explanations of different objects) only. Or else a Javascript would
have to
> &gt; reload that scalebar-image with every OL-Zoom-Change and tell it, how
deep OL
> &gt; is zoomed in/out. Well I didn't get this to work anyways but don't
want to
> &gt; invest further into it as it is only a test project to see what you
can do
> &gt; with OL. 
> 
> It's for the legend only, because the WMS spec has no interface for
> scalebars. 
> 
> It should be trivial however to script the scalebar in OL, maybe even
> somebody has already done that (if not, maybe it's a nice student project
> ;-).
> 
> &gt; - just doesn't show the bar. Do I have to change anything ion the
mapfile
> &gt; (currently: &quot;STATUS EMBED&quot;)?
> Not that I am aware of...
>  
> Barend
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 






More information about the Users mailing list