[OpenLayers-Users] Adding a popup to markers
Grant Maxwell
grant.maxwell at maxan.com.au
Mon Mar 25 04:03:36 PDT 2013
Well hey its great to solve ones own issues. The sample code did not have a line "selectControl.activate()" on it. Found this and -- it worked.
kewl.
regards to all
Grant
On 25/03/2013, at 6:43 PM, Grant Maxwell <grant.maxwell at maxan.com.au> wrote:
> Hi All
>
> I'm sure this has been asked many times and yes I've found samples but I just can't make it work. I want to have a popup when I hover the mouse over the objects on the layer.
> My code is below.
>
> I've spent several hours on this and really would appreciate some help
>
> kind regards
> Grant
>
>
>
>
>
> this.addVectorLayer = function(name){
> var drawControls, selectedFeature = null, selectControl = null;
> var newLayer = new OpenLayers.Layer.Vector(name);
> selectControl = new OpenLayers.Control.SelectFeature(newLayer, {
> hover: true,
> onSelect: onFeatureSelect,
> onUnselect: onFeatureUnselect
>
> });
>
> function onPopupClose(evt) {
> selectControl.unselect(selectedFeature);
> }
> function onFeatureSelect(feature) {
> selectedFeature = feature;
> popup = new OpenLayers.Popup.FramedCloud("popup",
> feature.geometry.getBounds().getCenterLonLat(),
> null,
> "<div style='font-size:.8em'>Feature: " + feature.id +"<br>Area: " + feature.geometry.getArea()+"</div>",
> null, true, onPopupClose);
> feature.popup = popup;
> map.addPopup(popup);
> }
> function onFeatureUnselect(feature) {
> map.removePopup(feature.popup);
> feature.popup.destroy();
> feature.popup = null;
> }
> drawControls = {
> polygon: new OpenLayers.Control.DrawFeature(newLayer, OpenLayers.Handler.Polygon),
> select: selectControl
> };
>
> for(var key in drawControls) {
> map.addControl(drawControls[key]);
> }
> layers.push({"id":name, "layer":newLayer, "features":[]});
> };
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130325/63403286/attachment.html>
More information about the Users
mailing list