[Users] Need some help with GeoExt PopUps / Zoom to POI

Ben Leetz ben.leetz at googlemail.com
Tue Jun 29 09:25:07 CEST 2010


 Hi all,

i just started with GeoExt and OL, so its probably an easy (maybe stupid
;) ) question. I already tried a lot of different code, but i don't get
it working. Maybe someone can give me a hint.

What i did is, i already got my application working with OSM as
Baselayers and an GML with POI as an overlay. The GML is stored in an
GridPanel, so i can select the POI over the map or the Panel. All fine,
thanks to all the tutorials!
Now i want OL to zoom to my POI when clicked. With the code below it
zooms to the POI, but not in the middle. When i use map.setCenter, it
zooms in the right direction but my POI are in the right or left corner
of my map. When i use map.zoomToExtent(new OpenLayers.Bounds()) it zooms
somewhere to the south-pole ;).  As you can see i tried some different
functions but it won't work.

My second question is, how can i close (hide) the Popup, when a new POI
is selected, at the moment you have to close them by your own. Some Code
Snippets or advise would be perfect. If you need some more of my code
just tell me.

Thanks for any help!

Ben
ps: sorry for possible double post, i don't know why my E-Mail from Saturday
was not mailed to the list.
http://www.geoext.org/pipermail/users/2010-June/000975.html


--------Part of my Code---------------
//Load GML
                 layer = new OpenLayers.Layer.GML('GML','./daten/ows.gml', {

                 projection: new OpenLayers.Projection("EPSG:4326"),
                 styleMap: ebbMap
                 });


//POPUP
// create select feature control
      var selectCtrl = new OpenLayers.Control.SelectFeature(layer);
     var lonlat;
     function createPopup(feature) {
         popup = new GeoExt.Popup({
             title: 'Kneipen Infos',
             feature: feature,
             width:250,
             height:100,
             html:  "<h2>  Name: " +feature.attributes.name + "</h2>
Stadtteil: " + feature.attributes.stadtteil, //Definition der Attribute
             maximizable: false,
             collapsible: true,
             //lonlat: feature.geometry.getBounds().getCenterLonLat(),
             //lonlat: feature.geometry.getCenterLonLat(),
             //lonlat: feature.geometry.getBounds(),
             listeners: {
                "close": function() {
                 selectCtrl.unselect(this.feature);
                 }
                         }
             },
             //map.setCenter(new OpenLayers.LonLat(), 18)
             //map.setCenter(new OpenLayers.Geometry.getCentroid(), 18)
             //map.zoomToExtent(new OpenLayers.Bounds(lonlat), 18)
             map.setCenter(new OpenLayers.LonLat(), 18)

             );
         // unselect feature when the popup
         // is closed
         popup.on({
             close: function() {
                 if(OpenLayers.Util.indexOf(layer.selectedFeatures,
                                            this.feature)>  -1) {
                     selectCtrl.unselect(this.feature);
                 }
             }
         });
         popup.show();
     }

             // create popup on "featureselected"
             layer.events.on({
                 featureselected: function(e) {
                     createPopup(e.feature)

                 }
             });

         /* On unselection the GeoExt-Popup closes */
         function onFeatureUnselect(event) {
             popup.destroy();
             }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20100629/c24965a8/attachment.htm 


More information about the Users mailing list