[OpenLayers-Users] problems with popups and selecting features

Rauch, Barbara rauch at rvr-online.de
Mon Jan 11 03:15:48 EST 2010


Hi Ryan,

 

I had the same problem some weeks ago and remember, that the example
http://docs.openlayers.org/library/overlays.html#transition-markers-to-v
ectors was somehow incomplete (concerning the FeatureSelectControl), but
I don't remember in detail. So here my code, that really works:

 

thema = new OpenLayers.Layer.GML("Your Layer",

                                               "Your URL",

                                               { format:
OpenLayers.Format.Text });

                                   map.addLayer(thema);

                                   map.zoomToMaxExtent();

                                   

                                   var selectControl = new
OpenLayers.Control.SelectFeature([thema]);

                                                                       

                                   thema.events.on({

                                               'featureselected':
onFeatureSelect,

                                               'featureunselected':
onFeatureUnselect

                                   });         

                                   map.addControl(selectControl);

            selectControl.activate();


                                   

                                   function onPopupClose(evt) {

                                               // 'this' is the popup.

 
selectControl.unselect(this.feature);


                                   }

                                   

                                   function onFeatureSelect(evt) {

                                               feature = evt.feature;

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

 
feature.geometry.getBounds().getCenterLonLat(),

                             new OpenLayers.Size(100,100),

                             "<h2>"+feature.attributes.title + "</h2>" +

                             feature.attributes.description,

                             null, true, onPopupClose);

                                               feature.popup = popup;

                                               popup.feature = feature;

                                               map.addPopup(popup);


                                   }

                                   

                                   function onFeatureUnselect(evt) {

                                               feature = evt.feature;

                                               if (feature.popup) {

                                                           popup.feature
= null;

 
map.removePopup(feature.popup);

 
feature.popup.destroy();

                                                           feature.popup
= null;

                                               }


                                   } 

 

Hope it will help you.

Best wishes

Barbara

 

 

Hello, OLers! This is my first OpenLayers map and I'm having serious
difficulty selecting features and seeing popups. I've literally spent
days trying to figure this out, so please forgive me if it's already
been discussed somewhere.

Let me first give some background. I have three layers. One is a GML
layer from a text file of points (the text file is generated by a PHP
script reading from a MySQL spatially-enabled database). Another is a
marker layer (only one point), the location of which I have hard-coded.
The third is a KML generated in Google Earth.

I've never been able to get popups in my map, or to select the point
features. Is there something terribly wrong with my code? In the OL
example (here <http://openlayers.org/dev/examples/markersTextLayer.html>
), there doesn't seem to be anything special in the map that enabled
popups. I even followed the example code here
<http://docs.openlayers.org/library/overlays.html#transition-markers-to-
vectors>  for selecting features.

My site is here <http://128.95.212.135/mapyouth_php.php> , so that you
can see my code. Please forgive me if it's sloppy - I'm not much of a
programmer. 

Thank you much in advance!!! I sincerely appreciate any help you can
give me!

ryan

-- 
Department of Geography
University of Washington

BurnsR77 at gmail.com
rlburns at uw.edu
859-582-9125

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100111/5e740767/attachment.html


More information about the Users mailing list