OpenLayers popup does not respond to event

I have an OpenLayers map with a marker and a pop-up that should appear when I click on the marker. This works fine in IE8, but not in Firefox 3.6. Any ideas why? As far as I can tell, the mousedown event does not fire, as the log message does not appear. The map is at http://ndinfo.heroku.com/test.html , and the code that I use to create the marker and popup is as follows:

function addMarker() {
    var map = g_waze_map.map;

    var markers1 = new OpenLayers.Layer.Markers( "Markers1" );
    g_waze_map.map.addLayer(markers1);
    var size = new OpenLayers.Size(21,25);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);
    var marker = new OpenLayers.Marker(new OpenLayers.LonLat(34.7934759272249, 32.0835554760902),icon);

 markers1.addMarker(marker);
            marker.events.register('mousedown', marker, function(evt) {
                    console.log('hi');
                    var popup = new OpenLayers.Popup.FramedCloud(null,
                                       marker.lonlat,
                                       null,
                                       "<div style='background-color:red; width:150;height:100'>hi</div>",

 null,true,null);

                    map.addPopup(popup);

                    OpenLayers.Event.stop(evt);

                });
}
+3
source share
2 answers

The answer is here . The key has been canceled by function activate()c OpenLayers.Control.ModifyFeature. I did not understand that the control over the creation of the marker does not affect the markers, but it turns out that it is.

var shapes = new OpenLayers.Layer.Vector( "Shapes" );
map.addLayer(shapes);
var modifyControl =  new OpenLayers.Control.ModifyFeature(shapes, {
        activate: function() {
            var activated = false;
            if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {

                this.map.events.on({
                    "removelayer": this.handleMapEvents,
                    "changelayer": this.handleMapEvents,
                    scope: this
                });
                activated = true;
            }
            return activated;
        }
    });
+3

, marker "mousedown". OpenLayers.Markers, , . :

// Create your markers layer
var markerLayer = new OpenLayers.Layer.Markers( "Markers1" );

// do whatever you want, and then...

// Create your marker
var marker = new OpenLayers.Marker(
         new OpenLayers.LonLat(34.7934759272249, 32.0835554760902),
         icon);

// Add your recently created marker to your markers layer
markerLayer.addMarker(marker);

// And bind 'mousedown' event to 'markers' layer, not to 'marker' object
markerLayer.events.register('mousedown', markerLayer, function(evt) {
  console.log('hi');
  var popup = new OpenLayers.Popup.FramedCloud(null,marker.lonlat,null,
              "<div style='background-color:red; width:150;height:100'>hi</div>",
              null,true,null);
    map.addPopup(popup);
    OpenLayers.Event.stop(evt);
});

: http://jsbin.com/ezeno3 ( , , , ).

, . !

+1

All Articles