On 6/3/07, Eric Lemoine <[EMAIL PROTECTED]> wrote:
I understand what the text layer is for. What I don't understand is
why OpenLayers provides a default onclick callback. Would you accept a
patch where the programmer can specify events and callbacks at layer
creation time?
layer = new OpenLayers.Layer.Text("foo", {
location: "file.txt",
events : {
"click" : click_callback,
"mouseover" : mouseover_callback
}
});
Attached is a patch (against current trunk) that implements the above.
Christopher, could you give it a quick review? I can provide some test
if inclusion into main branch is conceivable.
Kaka, to get the closebox working, you can try applying my patch,
implementing your own "onclick" callback and passing that callback to
the text layer constructor. See the markersTextLayer.html example.
Your onclick callback will ressemble the default click handler located
in lib/OpenLayers/Layer/Text.js (markerClick), but it will use
createPopup(true) as opposed to createPopup().
Note: I've created a ticket for this (see
<http://trac.openlayers.org/ticket/738>) and attached the patch to the
ticket as well.
Thanks,
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : [EMAIL PROTECTED]
http://www.camptocamp.com
Index: lib/OpenLayers/Layer/Text.js
===================================================================
--- lib/OpenLayers/Layer/Text.js (revision 3225)
+++ lib/OpenLayers/Layer/Text.js (working copy)
@@ -17,6 +17,12 @@
* @type str */
location:null,
+ /**
+ * Hashtable of event callbacks - keys are event names, values
+ * are callback functions.
+ * @type Object */
+ callbacks: null,
+
/** @type Array(OpenLayers.Feature) */
features: null,
@@ -36,6 +42,10 @@
if (this.location != null) {
OpenLayers.loadURL(this.location, null, this, this.parseData);
}
+ if (this.callbacks == null) {
+ // if no callback passed use default onclick callback
+ this.callbacks = { click: this.markerClick };
+ }
},
/**
@@ -127,7 +137,9 @@
this.features.push(feature);
var marker = feature.createMarker();
if ((title != null) && (description != null)) {
- marker.events.register('click', feature, this.markerClick);
+ for (var callback in this.callbacks) {
+ marker.events.register(callback, feature, this.callbacks[callback]);
+ }
}
this.addMarker(marker);
}
Index: examples/markersTextLayer.html
===================================================================
--- examples/markersTextLayer.html (revision 3225)
+++ examples/markersTextLayer.html (working copy)
@@ -20,12 +20,26 @@
map.addLayer(layer);
- var newl = new OpenLayers.Layer.Text( "text", {location: "./textfile.txt"} );
+ var newl = new OpenLayers.Layer.Text( "text", {
+ location: "./textfile.txt",
+ callbacks: {
+ mouseover: callback
+ }
+ });
map.addLayer(newl);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
}
+
+ function callback(evt) {
+ for (var i = 0; i < map.popups.length; i++) {
+ map.removePopup(map.popups[i]);
+ }
+ map.addPopup(this.createPopup(true));
+ OpenLayers.Event.stop(evt);
+ }
+
// -->
</script>
</head>
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users