[OpenLayers-Users] Classic GIS Info tool

Bill Thoen bthoen at gisnet.com
Mon Mar 23 15:56:55 EDT 2009


I just got this going for a project I'm working on. You'll need modules 
WMSGetFeatrueInfo.js  and FeatureInfo.js which are not in the 2.7 OL 
release, but you can get them from Bart's sandbox at:
http://dev.openlayers.org/sandbox/bartvde/wmsgetfeatureinfo/openlayers/lib/OpenLayers/Control/FeatureInfo.js
And here's a working example:
http://dev.openlayers.org/sandbox/bartvde/wmsgetfeatureinfo/openlayers/examples/featureinfo-control.html

You can see my demo scrapplication at 
http://206.168.217.244/gallery/InfoTool.html and grab anything you want 
to from that page. You have to set your browser to allow popup windows 
for this one. Just click on the blue question mark button and then click 
anywhere in the map over some visible layers. This should display a 
small popup window in the traditional spot for the info window listing 
all the layer info. It works in FireFox, but I don't know about IE. 
Sometimes it doesn't seem to "take" on the first click.
The version I made opens up a separate window and lists all the 
attributes you specify of all the WMS layers found under where you 
click. I'm using MapServer to produce the WMS layers and for those you 
want to be queryable, you've got to add some attributes in the mapfile. 
Specifically in the WEB object, you need at least the last two lines of 
metadata seen here (with your own content of course):
   WEB
      IMAGEPATH "/var/www/html/tmp/"
      IMAGEURL "/tmp/"
      METADATA
         "wms_title" "VFM Data Layers"
         "wms_onlineresource" 
"http://***.***.***.***/cgi-bin/mapserv?map=/var/www/html/vfm/ms.map&"
         "wms_srs" "epsg:900913 epsg:4326"
      END
   END

and for each layer you need at least the gml_include_items metadata and 
the parameters DUMP TRUE and TEMPLATE (anything, but it doesn't have to 
be a real template.) Looks like this:
   LAYER
      NAME "counties"
      METADATA
         "wms_title" "County Boundaries"
         "gml_include_items" "NAME,STATE,COUNTY"
      END
      TYPE POLYGON
      STATUS ON
      DATA ../maps/data/County_tiger_2007_region
      DUMP TRUE
      TEMPLATE counties
    ...
You can also use "gml_include_items" "all" if you want all layer 
attributes displayed.

Then in OpenLayers for each layer you want to be queryable, you need to 
add the queryable:true parameter to the options object when you load 
each WMS layer.

Since this uses AJAX , you may also need to set up a proxy script. 
Anyway, if you do all that, you can then use this tool just like 
MapInfo's Info tool. It's pretty fast too, and it can be made to respond 
to a hover event if you like.

- Bill Thoen

jegou at univ-tlse2.fr wrote:
> Hello all,
>
> I'm using OpenLayers to build a geodata exploring map : several layers  
> of polygons and points, with attributes data.
>
> To show those attributes to the visitor, i'd like to offer an Info  
> tool, the classic "I" icon tool on our desktop GIS.
>
> I've tested the SelectFeature control, but it's only returning one  
> feature at a time.
>
> I've seen the GetFeatureInfo control, but it's reserved to WFS  
> datasources (i may be wrong), and i'm using a KML source (generated  
> from PostGIS tables).
>
> I've also seen the GetFeature control from the trunk version docs :
> http://dev.openlayers.org/docs/files/OpenLayers/Control/GetFeature-js.html
>
> But i'm lost at testing it. Anyone has an example of it's use ?
>
> Another solution could be generating the on click features list by  
> postgis, but it seems slow and counter-intuitive (the features are  
> already client side).
>
> Thanks for any help,
>
> Laurent Jégou
> Dept. of Geography / Univ. Toulouse-2
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>   




More information about the Users mailing list