[OpenLayers-Users] Add Feature and Pan into View
Alexandre Dube
adube at mapgears.com
Thu May 21 13:34:41 EDT 2009
Hi,
You could register a "beforefeatureselected" event on your vector layer
and set the map extent according to the feature's extent. I think that
if you use the BBOX strategy, since the feature was already drawn it
should remain the same when the map automatically pan/zoom to the
feature's extent.
What do you think ?
Alexandre
soatley wrote:
> Hello,
>
> Does anyone know how to have the map pan when adding a feature to a vector
> layer so that the entire feature is in view?
>
> Here's my code so far that works:
> //define the popup
> infoPopup = new OpenLayers.Popup.FramedCloud("info",
> mouseLoc,
> null,
> "<div
> style=\"padding:5px;font-size:0.8em;\">Loading...</div>",
> null, true, onPopupClose);
> map.addPopup(infoPopup);
>
> //load the url for the popup data
> OpenLayers.loadURL(infoUrl, '', this, showTip);
>
>
> In the showTip function, I parse the data that is returned, update the
> content popup and create a feature. The feature coordinates (WKT) are
> passed with the response.
>
> var f = new OpenLayers.Format.WKT();
> infoFeature = f.read(marker.find("points").text());
> infoLayer.addFeatures([infoFeature], { style: "default" });
> infoPopup.contentHTML = marker.find("result").text();
> infoPopup.setContentHTML();
> infoFeature.popup = infoPopup;
>
> This code works great. If the popup is off the screen it pans into view.
> Great! But, how can I do the same if the feature (a parcel) is partially
> off the screen?
>
>
>
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list