This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

OpenLayers - how to open the popup when marker is dragged

-1

I have created the draggable marker using vector layer. Now I have to open a popup at dragend I have tried the following code:

vectors = new OpenLayers.Layer.Vector("Vector Layer",{ styleMap: new OpenLayers.StyleMap({ externalGraphic: "images/red-dot.png", graphicOpacity: 1.0, graphicWith: 16, graphicHeight: 26, graphicYOffset: -26 }) });

        point = new OpenLayers.Geometry.Point(77.768553,23.402765);
        vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);
        map1.addLayer(vectors);

var drag=new OpenLayers.Control.DragFeature(vectors);

        map1.addControl(drag);
        drag.activate();

vectors.events.on( { 'dragend': onFeatureSelect, 'dragstart': onFeatureUnselect }

function onFeatureSelect(evt) { try {

    feature = evt.feature;
    var zoom = map1.getZoom();

    popup = new OpenLayers.Popup.FramedCloud("featurePopup",
                             feature.geometry.getBounds().getCenterLonLat(),
                             new OpenLayers.Size(100,100),
                             "<h2>"+feature.attributes.title + "</h2>" +
                             feature.attributes.description, 
                             null, true, onPopupClose);
    feature.popup = popup;
    popup.feature = feature;
    map1.addPopup(popup, true);
    }
    catch(e)
    {
        alert(e);
    }
}

function onFeatureUnselect(evt) { feature = evt.feature; if (feature.popup) { popup.feature = null; map1.removePopup(feature.popup); feature.popup.destroy(); feature.popup = null; } }

function onPopupClose(evt) {

    var feature = this.feature;
    if (feature.layer) {
        drag.unselect(feature);
    } else {

        this.destroy();
    }
}

but it is not working. Please suggest any solution.

asked 17 Sep '12, 12:33

Niki%20Kallurwar's gravatar image

Niki Kallurwar
11445
accept rate: 0%

edited 17 Sep '12, 13:26

SomeoneElse's gravatar image

SomeoneElse ♦
36.9k71370866

2

There are a bunch of OpenLayers mailing lists described here, and other useful resources, including an IRC channel, here.

(17 Sep '12, 13:31) SomeoneElse ♦

Source code available on GitHub .