On Sunday, June 7, 2009, Asle Benoni <[email protected]> wrote:
> Hello,
> I have a map using a MapFish framework but I think this must be a OpenLayers
> question.
> I have several WFS layers from GeoServer where I use the attributes to fill
> the popup. Only problem is that I can only click on markers in one layer at
> a time. The user sees all the layers, some buildings, another layer with
> churches etc. but can only click on on layer. How do I solve this? I have now
> one layer for each type of buildings and I want to be able to turn on and off
> different buildings so that is why they are in separate layers. Is it
> possible to still use many layers and bee able to click on popups from
> different layers. Or is my approach unnecessary difficult? Glad for any help!
>
> I use this for the WFS layer:
>
> createWfsLayer(
> "Teknisk industri",
>
> "http://naturkart.no:8080/geoserver/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&SRS=EPSG%3A32633&BBOX=40484.8125,6401353.125,760135.8125,6687724.125",
> {
> typename: "kulturminner_ns:tekniskindustrielt",
> srsName: "EPSG:32633",
> maxfeatures: 200},{
> extractAttributes:true,
> visibility:false
> }
> );
>
> ...same code for each layer....
>
> // Popup code, define for each layer with markers:
> selectControl = new
> OpenLayers.Control.SelectFeature(map.layers[0],{onSelect: onFeatureSelect,
> onUnselect: onFeatureUnselect});
> map.addControl(selectControl);
> selectControl.activate();
> function onPopupClose(evt) {
> selectControl1.unselect(selectedFeature);
> }
> selectControl1 = new
> OpenLayers.Control.SelectFeature(map.layers[1],{onSelect: onFeatureSelect,
> onUnselect: onFeatureUnselect});
> map.addControl(selectControl1);
> selectControl1.activate();
> function onPopupClose(evt) {
> selectControl1.unselect(selectedFeature);
> }
> // etc...... for every layer with marker
Instead of creating one select control for each layer create only one
and give it all the layers:
sc = new OpenLayers.Control.SelectFeature(array_of_layers, {...});
you'll need OL 2.8 for this (or trunk)
Cheers,
> // Now the popup functions used:
>
> function onFeatureSelect(feature) {
> selectedFeature = feature;
> popup = new OpenLayers.Popup.FramedCloud("chicken",
>
> feature.geometry.getBounds().getCenterLonLat(),
> new OpenLayers.Size(100,200),
> "<h2>" +feature.attributes.gardsnavn +
> "</h2>Type: "+ feature.attributes.art +
> "<br />Kommune: "+ feature.attributes.komm +
> "<br />Beskrivelse<br /><a href='" +
> feature.attributes.urltilpdfark +
> "' target=blank><img
> src='http://naturkart.no:8080/geoserver/images/logo.png' border='0'
> alt='naturkart'></a>", null, true, onPopupClose);
> feature.popup = popup;
> map.addPopup(popup);
> }
> function onFeatureUnselect(feature) {
> map.removePopup(feature.popup);
> feature.popup.destroy();
> feature.popup = null;
> }
>
>
>
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users