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 17 17 * @type str */ 18 18 location:null, 19 19 20 /** 21 * Hashtable of event callbacks - keys are event names, values 22 * are callback functions. 23 * @type Object */ 24 callbacks: null, 25 20 26 /** @type Array(OpenLayers.Feature) */ 21 27 features: null, 22 28 … … 36 42 if (this.location != null) { 37 43 OpenLayers.loadURL(this.location, null, this, this.parseData); 38 44 } 45 if (this.callbacks == null) { 46 // if no callback passed use default onclick callback 47 this.callbacks = { click: this.markerClick }; 48 } 39 49 }, 40 50 41 51 /** … … 127 137 this.features.push(feature); 128 138 var marker = feature.createMarker(); 129 139 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 } 131 143 } 132 144 this.addMarker(marker); 133 145 } -
examples/markersTextLayer.html
old new 20 20 21 21 map.addLayer(layer); 22 22 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 }); 24 29 map.addLayer(newl); 25 30 26 31 map.addControl(new OpenLayers.Control.LayerSwitcher()); 27 32 map.zoomToMaxExtent(); 28 33 } 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 29 43 // --> 30 44 </script> 31 45 </head>
