[mapserver-users] Fwd: Zoom to something and display in one shot from MapServer CGI.

Andy Colson andy at squeakycode.net
Tue Jul 11 14:30:27 PDT 2017


On 7/11/2017 1:43 PM, Basques, Bob (CI-StPaul) wrote:
> Steve,
> 
> Yeah, my poison is Perl.  Was just trying to make it simpler is all.
> 
> I have a few services already in place like this.
> 
> A separate service it is then . . .
> 
> bobb

You want something like this:
http://maps.camavision.com/map/jasperia?pin=08.34.204.012


I use perl with mapscript, the request looks like:

my $xpin = $req->param('pin');
# pin can only contain letters and numbers
($xpin) = $xpin =~ /(\w+)/;

my $map = new mapscript::mapObj($filename);

$q = $db->prepare(
	"select * from $schema.getpoint where pin = \$1",
	{pg_server_prepare => 0}
);

getPoint returns box2d(st_expand(the_geom, 100)) for a single pin.

Then we generate some javascript:

if ($zoom =~ /BOX\(([-0-9\.]+)\s+([-0-9\.]+),([-0-9\.]+)\s+([-0-9\.]+)\)/)
{
	$zoom = "zoomToBound($1, $2, $3, $4);\n";
}

That variable is included in the html, and I have a javascript library 
function:

function zoomToBound(x1, y1, x2, y2) {
	var bb = new OpenLayers.Bounds.fromArray([x1, y1, x2, y2]);
	map.zoomToExtent(bb, true);
}


-Andy


More information about the mapserver-users mailing list