Zoom to location by name or other parameter using cgi mapserv

Richard Greenwood richard.greenwood at GMAIL.COM
Fri Dec 21 06:02:48 PST 2007


On Dec 21, 2007 6:18 AM, Ben Madin <ben at remoteinformation.com.au> wrote:
>  Thanks for your help Richard, I think I am closer, but I haven't got it yet
> to the point I can write it up!
>
> After struggling to work out the validation thing, I can run the script, but
> as soon as I use mode=itemquery I return a list of locations, and a
> querymap, beautifully shrunk down to show only the polygon I am interested
> in.
>
> However, I was hoping to be able to use this function in the main window -
> as an example say I was looking for roadside stops by name, it could then
> "zoom" me to the one I wanted, and I could continue panning or zooming.
>
>
> http://remote.local/cgi-bin/mapserv?layer=coastline&layer=roads&layer=location
> &layer=stops&mode=itemquery&qlayer=stops&qstring=gid=342
> &map=%2FLibrary%2FWebServer%2FDocuments%2Froads%2Froads.map&mapext=shapes&iw=650&ih=550
>
> but if I use mode=browse, I just get my normal interface, with a quarter of
> Australia to zoom in from!
>
> I'm guessing the better option may just be to make the select list with the
> extents of each object, queried from the database, so when the form is
> submitted that is the mapext value.

The trick to getting the query result into your main map is to make
the TEMPLATE for the query layer be the main map. So in your map file
the template for 'stops' should be whatever your main map html file
is.

A couple more tricks. Sometimes you will need to have two versions of
your 'stops' layer with different templates. The first "stops" layer
would have a template for displaying attribute data and the style of
that layer would be the regular default style. Then the second layer,
we'll call "stops_spatial" has the main map defined as the template,
it has a FILTER %gid% so that it only shows the selected object(s) and
the style ewould be something bright and bold to show the object.

Another trick. If you want to display more than selected object in one
map (as opposed to several maps each just showing one object) then
instead of putting the main map html in the template, put it in the
HEADER for your "stops" or "stops_spatial" layer, and define an empty
html file for the template.

You can see an example of this at: http://www2.tetonwyo.org/mapserver/
Select the "Property Search" link near the bottom of the page. In the
"Search by Owner" "Last Name" enter 'Smith'. This will give you a
list, click the "Map It" link.

HTH,
Rich

-- 
Richard Greenwood
richard.greenwood at gmail.com
www.greenwoodmap.com



More information about the MapServer-users mailing list