OpenLayers OpenLayers

Ticket #738: text-layer-event-handling-060307.patch

File text-layer-event-handling-060307.patch, 2.4 kB (added by elemoine, 2 years ago)
  • lib/OpenLayers/Layer/Text.js

    old new  
    1717    * @type str */ 
    1818    location:null, 
    1919 
     20    /** 
     21     * Hashtable of event callbacks - keys are event names, values 
     22     * are callback functions. 
     23     * @type Object */ 
     24    callbacks: null, 
     25 
    2026    /** @type Array(OpenLayers.Feature) */ 
    2127    features: null, 
    2228 
     
    3642        if (this.location != null) { 
    3743            OpenLayers.loadURL(this.location, null, this, this.parseData); 
    3844        } 
     45        if (this.callbacks == null) { 
     46            // if no callback passed use default onclick callback 
     47            this.callbacks = { click: this.markerClick }; 
     48        } 
    3949    }, 
    4050 
    4151   /** 
     
    127137                      this.features.push(feature); 
    128138                      var marker = feature.createMarker(); 
    129139                      if ((title != null) && (description != null)) { 
    130                         marker.events.register('click', feature, this.markerClick); 
     140                          for (var callback in this.callbacks) { 
     141                              marker.events.register(callback, feature, this.callbacks[callback]); 
     142                          } 
    131143                      } 
    132144                      this.addMarker(marker); 
    133145                    } 
  • examples/markersTextLayer.html

    old new  
    2020                 
    2121            map.addLayer(layer); 
    2222 
    23             var newl = new OpenLayers.Layer.Text( "text", {location: "./textfile.txt"} ); 
     23            var newl = new OpenLayers.Layer.Text( "text", { 
     24                location: "./textfile.txt", 
     25                callbacks: { 
     26                    mouseover: callback 
     27                } 
     28            }); 
    2429            map.addLayer(newl); 
    2530 
    2631            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
    2732            map.zoomToMaxExtent(); 
    2833        } 
     34 
     35        function callback(evt) { 
     36           for (var i = 0; i < map.popups.length; i++) { 
     37               map.removePopup(map.popups[i]); 
     38           } 
     39           map.addPopup(this.createPopup(true));  
     40           OpenLayers.Event.stop(evt); 
     41       } 
     42 
    2943        // --> 
    3044    </script> 
    3145  </head>