[OpenLayers-Users] Highlighting Selected Tract

Jerome A. Wendell jawendell at digitalmapping.com
Sun Mar 3 16:21:36 PST 2013


I am trying to highlight the selected tract in a WMS layer using a
getfeatureinfo event.  I have seen many examples searching this topic, but I
can't get it to work.  The popup works fine, and I don't get any errors in
Firebug.  The code that I am using is below:

 

                                var highlightLayer = new
OpenLayers.Layer.Vector("Highlighted Features", {

                                                styleMap: myStyles,

                                                displayInLayerSwitcher:
false,

                                                isBaseLayer: false

                                                }

                                );

 

                                var popup = null;

 

                                var selectControl = new
OpenLayers.Control.WMSGetFeatureInfo({

                                                                url:
'myurl',

                                                                title:
'Identify features by clicking',

                                                                layers:
[mylayer],

 
queryVisible: true,

                                                                hover:
false,

 
eventListeners: {

 
getfeatureinfo: function(event) {

                                                                if
(!event.text.match(/<body>\s*<\/body>/)){

 
if (popup)

 
{

 
popup.destroy();

 
popup = null;

 
}

 
popup = new OpenLayers.Popup.FramedCloud(

 
"popup",

 
map.getLonLatFromPixel(event.xy),

 
null,

 
event.text,

 
null,

 
true

 
);

 
map.addPopup(popup);

                                                                }

                                                                }

                                                }

});

 

map.addLayers([mylayers, highlightLayer]);

 

selectControl.events.register("getfeatureinfo", this, showInfo);

 

map.addControl(selectControl);

selectControl.activate();

 

map.zoomToMaxExtent();

}

 

                                function showInfo(evt) {

                                                if (evt.features &&
evt.features.length) {

 
highlightLayer.destroyFeatures();

 
highlightLayer.addFeatures(evt.features);

                                                    highlightLayer.redraw();

                                                }

                                }

 

If someone can tell me what I am doing wrong, I would really appreciate it.

 

Thanks,

 

Jerome A. Wendell

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130303/54ce44ab/attachment.html>


More information about the Users mailing list