<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt">Hi,<br><br>did you tried this for your zoom?:<br>var r = grid.getStore().getAt(rowIndex);<br>var feature = r.get('feature');<br>var bounds = feature.geometry.getBounds();<br>map.setCenter(bounds.getCenterLonLat(),map.getZoomForExtent(bounds));<br><br>HTH<br><br>best regards<br>Sarah<br><div><br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">Von:</span></b> Ben Leetz <ben.leetz@googlemail.com><br><b><span style="font-weight: bold;">An:</span></b> users@geoext.org<br><b><span style="font-weight: bold;">Gesendet:</span></b> Dienstag, den 29. Juni 2010, 9:25:07 Uhr<br><b><span style="font-weight:
bold;">Betreff:</span></b> [Users] Need some help with GeoExt PopUps / Zoom to POI<br></font><br>
<div class="moz-text-flowed" style="font-family: -moz-fixed; font-size: 14px;" lang="x-western">
Hi all,
<br>
<br>i just started with GeoExt and OL, so its probably an easy (maybe
stupid
<br><span class="moz-smiley-s3" title=";)"><span>;)</span></span> )
question. I already tried a lot of different code, but i don't get
<br>it working. Maybe someone can give me a hint.
<br>
<br>What i did is, i already got my application working with OSM as
<br>Baselayers and an GML with POI as an overlay. The GML is stored in
an
<br>GridPanel, so i can select the POI over the map or the Panel. All
fine,
<br>thanks to all the tutorials!
<br>Now i want OL to zoom to my POI when clicked. With the code below it
<br>zooms to the POI, but not in the middle. When i use map.setCenter,
it
<br>zooms in the right direction but my POI are in the right or left
corner
<br>of my map. When i use map.zoomToExtent(new OpenLayers.Bounds()) it
zooms
<br>somewhere to the south-pole <span class="moz-smiley-s3" title=";)"><span>;)</span></span>.
As you can see i tried some different
<br>functions but it won't work.
<br>
<br>My second question is, how can i close (hide) the Popup, when a new
POI
<br>is selected, at the moment you have to close them by your own. Some
Code
<br>Snippets or advise would be perfect. If you need some more of my
code
<br>just tell me.
<br>
<br>Thanks for any help!
<br>
<br>Ben
<br>
ps: sorry for possible double post, i don't know why my E-Mail from Saturday
was not mailed to the list.<br>
<a rel="nofollow" target="_blank" href="http://www.geoext.org/pipermail/users/2010-June/000975.html">http://www.geoext.org/pipermail/users/2010-June/000975.html</a><br>
<br>
<br>--------Part of my Code---------------
<br>//Load GML
<br> layer = new
OpenLayers.Layer.GML('GML','./daten/ows.gml', {
<br> projection: new OpenLayers.Projection("EPSG:4326"),
<br> styleMap: ebbMap
<br> });
<br>
<br>
<br>//POPUP
<br>// create select feature control
<br> var selectCtrl = new OpenLayers.Control.SelectFeature(layer);
<br> var lonlat;
<br> function createPopup(feature) {
<br> popup = new GeoExt.Popup({
<br> title: 'Kneipen Infos',
<br> feature: feature,
<br> width:250,
<br> height:100,
<br> html: "<h2> Name: " +<a rel="nofollow" target="_blank" href="http://feature.attributes.name">feature.attributes.name</a> +
"</h2>
<br>Stadtteil: " + feature.attributes.stadtteil, //Definition der
Attribute
<br> maximizable: false,
<br> collapsible: true,
<br> //lonlat:
feature.geometry.getBounds().getCenterLonLat(),
<br> //lonlat: feature.geometry.getCenterLonLat(),
<br> //lonlat: feature.geometry.getBounds(),
<br> listeners: {
<br> "close": function() {
<br> selectCtrl.unselect(this.feature);
<br> }
<br> }
<br> },
<br> //map.setCenter(new OpenLayers.LonLat(), 18)
<br> //map.setCenter(new OpenLayers.Geometry.getCentroid(),
18)
<br> //map.zoomToExtent(new OpenLayers.Bounds(lonlat), 18)
<br> map.setCenter(new OpenLayers.LonLat(), 18)
<br>
<br> );
<br> // unselect feature when the popup
<br> // is closed
<br> popup.on({
<br> close: function() {
<br> if(OpenLayers.Util.indexOf(layer.selectedFeatures,
<br> this.feature)> -1) {
<br> selectCtrl.unselect(this.feature);
<br> }
<br> }
<br> });
<br> popup.show();
<br> }
<br>
<br> // create popup on "featureselected"
<br> layer.events.on({
<br> featureselected: function(e) {
<br> createPopup(e.feature)
<br>
<br> }
<br> });
<br>
<br> /* On unselection the GeoExt-Popup closes */
<br> function onFeatureUnselect(event) {
<br> popup.destroy();
<br> }
<br>
<br></div>
</div></div>
</div><br></body></html>