[OpenLayers-Users] Get Feature Info in pop up working example

Robert Sanson SansonR at asurequality.com
Sun Mar 21 16:20:33 EDT 2010


Hi
 
In my OpenLayers code I register a click event on the map. This captures the x,y of the click point, then computes a bounding box which is then used to create WMS GetFeatureInfo request. The return from that request can then be parsed, with values put into a div on the page or put into a pop-up window.
 
//Here is the click event code:
map.events.register('click', map, function (e) {
                  var xys = map.getLonLatFromViewPortPx(e.xy);
                  easting = xys.lon;
                  northing = xys.lat;
                  OpenLayers.Util.getElement('coords').innerHTML = "<strong>x:</strong>" + parseInt(easting) + " <strong>y:</strong>" + parseInt(northing);
                  if (mode == "qry") {
                    var bbox1 = easting - 10;
                    var bbox2 = northing - 10;
                    var bbox3 = easting + 10;
                    var bbox4 = northing + 10;
                    OpenLayers.Util.getElement('comments').innerHTML = "Looking for parcel details... please wait...";
                    var regc = "http://ws-esrimt/arcgis/services/mapservice_asurequality_prod/MapServer/WMSServer?service=WMS&version=1.1.1&request=GetFeatureInfo&QUERY_LAYERS=2&INFO_FORMAT=text/plain&SRS=EPSG:2193&BBOX=" + bbox1 + "," + bbox2 + "," + bbox3 + "," + bbox4 + "&WIDTH=20&HEIGHT=20&X=10&Y=10";
                    OpenLayers.loadURL(regc, '', this, setHTML2); 
                  }
                  Event.stop(e);
                });
 
//Here is the function to get the response:
            function setHTML2(response2) {
              var ta = "";
              var rc = "";
              if (response2.responseText.indexOf('no results') != -1) {
                ta="Outside NZ";
              }
              else {
                var lines = response2.responseText.split('\n');
                var vals = lines[1].replace(/^"/,'').replace(/\s$/,'').replace(/"$/,'').split('" "');
                ta = vals[5];
                rc = vals[7];
              }
              OpenLayers.Util.getElement('region').innerHTML = "<small>" + ta + " : " + rc + "</small>";
            }
 
regards,
 
Robert Sanson

>>> sunny74 <sb.ray at hotmail.com> 22/03/2010 7:33 a.m. >>>

Dear Friends,

Does anybody have a working example of Get Feature Info in POP up where the
map file is pointing to and getting attribute data from the shape files?


If so pls give a step by step description of what you have done along with
the code.Also the mapfile changes that you have done to get it working.

Pls reply soon.

Thanks for your attention and efforts.



-- 
View this message in context: http://n2.nabble.com/Get-Feature-Info-in-pop-up-working-example-tp4773944p4773944.html 
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at openlayers.org 
http://openlayers.org/mailman/listinfo/users 

------------------------------------------------------------------
The contents of this email are confidential to AsureQuality. If you have received this communication in error please notify the sender immediately and delete the message and any attachments. The opinions expressed in this email are not necessarily those of AsureQuality. This message has been scanned for known viruses before delivery. AsureQuality supports the Unsolicited Electronic Messages Act 2007. If you do not wish to receive similar communications in future, please notify the sender of this message.
------------------------------------------------------------------


This message has been scanned for malware by SurfControl plc. www.surfcontrol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100322/e20a2876/attachment.html


More information about the Users mailing list