[OpenLayers-Users] display different popup for different layer
Giuseppe Naponiello
beppenapo at gmail.com
Thu May 27 03:20:57 EDT 2010
Mmhh, I've tried but it's doesn't work, I think because the layer's
attributes are different and I cannot define the same popup content.
I've risolved writing a second function:
function onFeatureSelect(event) {
feature = event.feature;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
null,
"<div><b>Nome:</b> <a href=\"scheda_comune.php?comune=" +
feature.attributes.NOME + "\" target=\"eastFrame\"
onClick=\"outerLayout.open('east')\">" + feature.attributes.NOME
+"</a></div>",
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
and
function onFeatureSelect2(event) {
feature = event.feature;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
null,
"<h2>" + feature.attributes.title + "</h2>" +
feature.attributes.description,
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
...
...
toscana.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
poi.events.on({
"featureselected": onFeatureSelect2,
"featureunselected": onFeatureUnselect2
});
...maybe I could write better code but ... it works!!!
thanks
-beppe-
2010/5/25 Alessandro Pasotti <ale.pas at tiscali.it>
> In data lunedì 24 maggio 2010 15:14:54, Giuseppe Naponiello ha scritto:
> : > Hi all,
> > in my project I've 2 layers (layer1, layer2) with different attributes.
> > Layer 1 is in gml format, layer2 is a txt file
> > When I click on the layer1, I open a popup with this code:
> >
> > function onPopupClose(evt) {selectControl.unselect(feature);}
> >
> > //al click su un elemento, creo e visualizzo al popup
> > function onFeatureSelect(event) {
> > feature = event.feature;
> > popup = new OpenLayers.Popup.FramedCloud("chicken",
> > feature.geometry.getBounds().getCenterLonLat(),
> > null,
> > "<div><b>Nome:</b> <a href=\"scheda_comune.php?comune="
> +
> > feature.attributes.NOME + "\" target=\"eastFrame\"
> > onClick=\"outerLayout.open('east')\">" + feature.attributes.NOME
> > +"</a></div>",
> > null, true, onPopupClose);
> > feature.popup = popup;
> > map.addPopup(popup);
> > }
> >
> > function onFeatureUnselect(event) {
> > feature = event.feature;
> > if (feature.popup){
> > map.removePopup(feature.popup);
> > feature.popup.destroy();
> > feature.popup = null;
> > }
> > }
> > ....
> >
> > selectControl = new OpenLayers.Control.SelectFeature(layer1);
> > //{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
> > layer1.events.on({
> > "featureselected": onFeatureSelect,
> > "featureunselected": onFeatureUnselect
> > });
> >
> >
> > Now I'd like to display the same kind of popup for the layer2 but I don't
> > know what is the correct code to write!!!
> >
> >
> > thanks
>
> Hi,
>
> I think that passing both layers to the select control should work:
>
> selectControl = new OpenLayers.Control.SelectFeature([layer1, layer2]);
> selectControl.events.register("featureselected", map, onFeatureSelect);
> selectControl.events.register("featureunselected", map, onFeatureUnselect);
> map.addControl(selectControl);
> selectControl.activate();
>
>
> --
> Alessandro Pasotti
> itOpen - "Open Solutions for the Net Age"
> w3: www.itopen.it
> Linux User# 167502
>
--
-beppe-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100527/565233b7/attachment.html
More information about the Users
mailing list