[Users] Need some help with GeoExt PopUps / Zoom to POI
Ben Leetz
ben.leetz at googlemail.com
Tue Jun 29 14:50:43 CEST 2010
Hi,
thanks. I don't know why, but i didn't even need the first 2 lines of your
code. I think i had it allready correct but the ..getBounds and
map.setCenter was at the wrong place in my code. Now everything is working,
even the popup.destroy(). ;)
Thanks for your help, Ben
here is the working code:
var bounds;
function createPopup(feature) {
popup = new GeoExt.Popup({
title: 'Kneipen Infos: ' +feature.attributes.name,
feature: feature,
width:250,
height:100,
html: "<h2> Name: " +feature.attributes.name + "</h2>
<p>Stadtteil: " + feature.attributes.stadtteil + "</p><p>Preis kleiner
Shoppen: " +feature.attributes.preis +"</p>", //Definition der Attribute,
hier eventuell Tabelle
maximizable: false,
collapsible: true,
listeners: {
"close": function() {
selectCtrl.unselect(this.feature);
}
}
}
);
// unselect feature when the popup is closed
popup.on({
close: function() {
if(OpenLayers.Util.indexOf(layer.selectedFeatures,
this.feature) > -1) {
selectCtrl.unselect(this.feature);
}
}
});
feature.popup = popup;
popup.show();
* bounds = feature.geometry.getBounds();
map.setCenter(bounds.getCenterLonLat(),map.getZoomForExtent(bounds));*
}
//Popup erzeugen wenn Feature selektiert
layer.events.on({
featureselected: function(e) {
createPopup(e.feature)
},//Popup verbergen wenn ein anderes Feature
selektiert wird
* featureunselected: function(e) {
popup.destroy(e.feature)
}*
});
2010/6/29 Sarah Schuessler <sarah_flip at yahoo.de>
> Hi,
>
> did you tried this for your zoom?:
> var r = grid.getStore().getAt(rowIndex);
> var feature = r.get('feature');
> var bounds = feature.geometry.getBounds();
> map.setCenter(bounds.getCenterLonLat(),map.getZoomForExtent(bounds));
>
> HTH
>
> best regards
> Sarah
>
>
> ------------------------------
> *Von:* Ben Leetz <ben.leetz at googlemail.com>
> *An:* users at geoext.org
> *Gesendet:* Dienstag, den 29. Juni 2010, 9:25:07 Uhr
> *Betreff:* [Users] Need some help with GeoExt PopUps / Zoom to POI
>
> 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/38af5051/attachment-0001.htm
More information about the Users
mailing list