[OpenLayers-Users] light-basic popup

aparna aparna.mookerjee at gmail.com
Mon Jun 11 02:26:14 PDT 2012


Smaran,

You have 6 layers on your map. The names are
0 bio11
1 Climate Data
2 All Quebec Species
3 Pima Pines
4 Carribean Pines
5 Editable Vectors
6 Select Features

If you could change your code a bit Popups from All Quebec Species layer
will take place on click event..
Here is some working code..

Add this code after you wms layers and replace with your own wfs layer names
etc. 

var QS = new OpenLayers.Layer.Vector("Quebec", {
					strategies : [new OpenLayers.Strategy.Fixed()],
					projection : new OpenLayers.Projection("EPSG:4326"),
					visibility : true,
					protocol : new OpenLayers.Protocol.WFS({
						version : "1.1.0",
						url: "http://Aparna:8081/geoserver/wfs",
						//featurePrefix : 'iPlant', //geoserver worspace name
						featureType : "detail", //geoserver Layer Name
						featureNS: "http://opengeo.org/India" // Edit Workspace Namespace URI
						
					})

				});

map.addLayer(QS);
map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.addControl(new OpenLayers.Control.MousePosition());    

	map.zoomToMaxExtent();

var select= new OpenLayers.Control.SelectFeature(QS);

	QS.events.on({ "featureselected": onFeatureSelect, "featureunselected":
onFeatureUnselect});

		map.addControl(select);
		select.activate();

function onFeatureSelect(event) {

            var feature = event.feature;

            // Since KML is user-generated, do naive protection against
            // Javascript.
            //var X=feature.attributes.SCHCD;
            //var result=X.split
            
           
            var content = "<h7>Family: "+feature.attributes.FAMILY +"<br>"
+"</h7>" +"SPECIES: " +feature.attributes.SPECIES;	
            if (content.search("<script") != -1) { 

                content = "Content contained Javascript! Escaped
content below.<br>" + content.replace(/</g, "<");

            }

            popup = new OpenLayers.Popup.FramedCloud("chicken", 

            feature.geometry.getBounds().getCenterLonLat(), 
            new OpenLayers.Size(100,100),content,
            null, true, onPopupClose);

            feature.popup = popup;
            map.addPopup(popup);
        }
        
	 function onFeatureUnselect(event) {
            var feature = event.feature;
            if(feature.popup) {

                map.removePopup(feature.popup);
                feature.popup.destroy();
                delete feature.popup;
            }

}

	function onPopupClose(evt) {
            select.unselectAll();
        } 

Hope this works for you.
Regards,
Aparna

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/light-basic-popup-tp4979830p4980346.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list