Trigger feature related events with feature information and layer related events with layer information. Also adding events.on and events.un convenience methods. r=crschmidt (closes #1343)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6149 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -35,10 +35,13 @@ OpenLayers.Control.Attribution =
|
||||
* Destroy control.
|
||||
*/
|
||||
destroy: function() {
|
||||
this.map.events.unregister("removelayer", this, this.updateAttribution);
|
||||
this.map.events.unregister("addlayer", this, this.updateAttribution);
|
||||
this.map.events.unregister("changelayer", this, this.updateAttribution);
|
||||
this.map.events.unregister("changebaselayer", this, this.updateAttribution);
|
||||
this.map.events.un({
|
||||
"removelayer": this.updateAttribution,
|
||||
"addlayer": this.updateAttribution,
|
||||
"changelayer": this.updateAttribution,
|
||||
"changebaselayer": this.updateAttribution,
|
||||
scope: this
|
||||
});
|
||||
|
||||
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
@@ -53,10 +56,13 @@ OpenLayers.Control.Attribution =
|
||||
draw: function() {
|
||||
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||
|
||||
this.map.events.register('changebaselayer', this, this.updateAttribution);
|
||||
this.map.events.register('changelayer', this, this.updateAttribution);
|
||||
this.map.events.register('addlayer', this, this.updateAttribution);
|
||||
this.map.events.register('removelayer', this, this.updateAttribution);
|
||||
this.map.events.on({
|
||||
'changebaselayer': this.updateAttribution,
|
||||
'changelayer': this.updateAttribution,
|
||||
'addlayer': this.updateAttribution,
|
||||
'removelayer': this.updateAttribution,
|
||||
scope: this
|
||||
});
|
||||
this.updateAttribution();
|
||||
|
||||
return this.div;
|
||||
|
||||
@@ -113,10 +113,13 @@ OpenLayers.Control.LayerSwitcher =
|
||||
this.clearLayersArray("base");
|
||||
this.clearLayersArray("data");
|
||||
|
||||
this.map.events.unregister("addlayer", this, this.redraw);
|
||||
this.map.events.unregister("changelayer", this, this.redraw);
|
||||
this.map.events.unregister("removelayer", this, this.redraw);
|
||||
this.map.events.unregister("changebaselayer", this, this.redraw);
|
||||
this.map.events.un({
|
||||
"addlayer": this.redraw,
|
||||
"changelayer": this.redraw,
|
||||
"removelayer": this.redraw,
|
||||
"changebaselayer": this.redraw,
|
||||
scope: this
|
||||
});
|
||||
|
||||
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
@@ -130,10 +133,13 @@ OpenLayers.Control.LayerSwitcher =
|
||||
setMap: function(map) {
|
||||
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
||||
|
||||
this.map.events.register("addlayer", this, this.redraw);
|
||||
this.map.events.register("changelayer", this, this.redraw);
|
||||
this.map.events.register("removelayer", this, this.redraw);
|
||||
this.map.events.register("changebaselayer", this, this.redraw);
|
||||
this.map.events.on({
|
||||
"addlayer": this.redraw,
|
||||
"changelayer": this.redraw,
|
||||
"removelayer": this.redraw,
|
||||
"changebaselayer": this.redraw,
|
||||
scope: this
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,17 +182,16 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
var selectOptions = {
|
||||
geometryTypes: this.geometryTypes,
|
||||
clickout: this.clickout,
|
||||
toggle: this.toggle,
|
||||
onSelect: function(feature) {
|
||||
control.selectFeature.apply(control, [feature]);
|
||||
},
|
||||
onUnselect: function(feature) {
|
||||
control.unselectFeature.apply(control, [feature]);
|
||||
}
|
||||
toggle: this.toggle
|
||||
};
|
||||
this.selectControl = new OpenLayers.Control.SelectFeature(
|
||||
layer, selectOptions
|
||||
);
|
||||
this.layer.events.on({
|
||||
"featureselected": this.selectFeature,
|
||||
"featureunselected": this.unselectFeature,
|
||||
scope: this
|
||||
});
|
||||
|
||||
// configure the drag control
|
||||
var dragOptions = {
|
||||
@@ -226,6 +225,11 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Take care of things that are not handled in superclass.
|
||||
*/
|
||||
destroy: function() {
|
||||
this.layer.events.un({
|
||||
"featureselected": this.selectFeature,
|
||||
"featureunselected": this.unselectFeature,
|
||||
scope: this
|
||||
});
|
||||
this.layer = null;
|
||||
this.selectControl.destroy();
|
||||
this.dragControl.destroy();
|
||||
@@ -276,10 +280,11 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Called when the select feature control selects a feature.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature.Vector>} The selected feature.
|
||||
* object - {Object} Object with a feature property referencing the
|
||||
* selected feature.
|
||||
*/
|
||||
selectFeature: function(feature) {
|
||||
this.feature = feature;
|
||||
selectFeature: function(object) {
|
||||
this.feature = object.feature;
|
||||
this.resetVertices();
|
||||
this.dragControl.activate();
|
||||
this.onModificationStart(this.feature);
|
||||
@@ -290,9 +295,10 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Called when the select feature control unselects a feature.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature.Vector>} The unselected feature.
|
||||
* object - {Object} Object with a feature property referencing the
|
||||
* unselected feature.
|
||||
*/
|
||||
unselectFeature: function(feature) {
|
||||
unselectFeature: function(object) {
|
||||
this.layer.removeFeatures(this.vertices);
|
||||
this.vertices = [];
|
||||
this.layer.destroyFeatures(this.virtualVertices);
|
||||
@@ -307,7 +313,7 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
this.feature = null;
|
||||
this.dragControl.deactivate();
|
||||
this.onModificationEnd(feature);
|
||||
this.onModificationEnd(object.feature);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,12 +47,15 @@ OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
this.handler = null;
|
||||
|
||||
this.map.events.unregister( "click", this, this.defaultClick );
|
||||
this.map.events.unregister( "dblclick", this, this.defaultDblClick );
|
||||
this.map.events.unregister( "mousedown", this, this.defaultMouseDown );
|
||||
this.map.events.unregister( "mouseup", this, this.defaultMouseUp );
|
||||
this.map.events.unregister( "mousemove", this, this.defaultMouseMove );
|
||||
this.map.events.unregister( "mouseout", this, this.defaultMouseOut );
|
||||
this.map.events.un({
|
||||
"click": this.defaultClick,
|
||||
"dblclick": this.defaultDblClick,
|
||||
"mousedown": this.defaultMouseDown,
|
||||
"mouseup": this.defaultMouseUp,
|
||||
"mousemove": this.defaultMouseMove,
|
||||
"mouseout": this.defaultMouseOut,
|
||||
scope: this
|
||||
});
|
||||
|
||||
//unregister mousewheel events specifically on the window and document
|
||||
OpenLayers.Event.stopObserving(window, "DOMMouseScroll",
|
||||
@@ -70,12 +73,15 @@ OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Method: draw
|
||||
*/
|
||||
draw: function() {
|
||||
this.map.events.register( "click", this, this.defaultClick );
|
||||
this.map.events.register( "dblclick", this, this.defaultDblClick );
|
||||
this.map.events.register( "mousedown", this, this.defaultMouseDown );
|
||||
this.map.events.register( "mouseup", this, this.defaultMouseUp );
|
||||
this.map.events.register( "mousemove", this, this.defaultMouseMove );
|
||||
this.map.events.register( "mouseout", this, this.defaultMouseOut );
|
||||
this.map.events.on({
|
||||
"click": this.defaultClick,
|
||||
"dblclick": this.defaultDblClick,
|
||||
"mousedown": this.defaultMouseDown,
|
||||
"mouseup": this.defaultMouseUp,
|
||||
"mousemove": this.defaultMouseMove,
|
||||
"mouseout": this.defaultMouseOut,
|
||||
scope: this
|
||||
});
|
||||
|
||||
this.registerWheelEvents();
|
||||
|
||||
|
||||
@@ -105,9 +105,12 @@ OpenLayers.Control.MouseToolbar = OpenLayers.Class(
|
||||
btn.activeImgLocation = activeImgLocation;
|
||||
|
||||
btn.events = new OpenLayers.Events(this, btn, null, true);
|
||||
btn.events.register("mousedown", this, this.buttonDown);
|
||||
btn.events.register("mouseup", this, this.buttonUp);
|
||||
btn.events.register("dblclick", this, OpenLayers.Event.stop);
|
||||
btn.events.on({
|
||||
"mousedown": this.buttonDown,
|
||||
"mouseup": this.buttonUp,
|
||||
"dblclick": OpenLayers.Event.stop,
|
||||
scope: this
|
||||
});
|
||||
btn.action = id;
|
||||
btn.title = title;
|
||||
btn.alt = title;
|
||||
|
||||
@@ -154,9 +154,11 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.minimizeDiv = null;
|
||||
}
|
||||
|
||||
this.map.events.unregister('moveend', this, this.update);
|
||||
this.map.events.unregister("changebaselayer", this,
|
||||
this.baseLayerDraw);
|
||||
this.map.events.un({
|
||||
"moveend": this.update,
|
||||
"changebaselayer": this.baseLayerDraw,
|
||||
scope: this
|
||||
});
|
||||
|
||||
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
@@ -79,8 +79,11 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
||||
this.divEvents.destroy();
|
||||
this.divEvents = null;
|
||||
|
||||
this.map.events.unregister("zoomend", this, this.moveZoomBar);
|
||||
this.map.events.unregister("changebaselayer", this, this.redraw);
|
||||
this.map.events.un({
|
||||
"zoomend": this.moveZoomBar,
|
||||
"changebaselayer": this.redraw,
|
||||
scope: this
|
||||
});
|
||||
|
||||
OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
@@ -164,11 +167,13 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
||||
this.slider = slider;
|
||||
|
||||
this.sliderEvents = new OpenLayers.Events(this, slider, null, true);
|
||||
this.sliderEvents.register("mousedown", this, this.zoomBarDown);
|
||||
this.sliderEvents.register("mousemove", this, this.zoomBarDrag);
|
||||
this.sliderEvents.register("mouseup", this, this.zoomBarUp);
|
||||
this.sliderEvents.register("dblclick", this, this.doubleClick);
|
||||
this.sliderEvents.register("click", this, this.doubleClick);
|
||||
this.sliderEvents.on({
|
||||
"mousedown": this.zoomBarDown,
|
||||
"mousemove": this.zoomBarDrag,
|
||||
"mouseup": this.zoomBarUp,
|
||||
"dblclick": this.doubleClick,
|
||||
"click": this.doubleClick
|
||||
});
|
||||
|
||||
var sz = new OpenLayers.Size();
|
||||
sz.h = this.zoomStopHeight * this.map.getNumZoomLevels();
|
||||
@@ -194,10 +199,12 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
||||
this.zoombarDiv = div;
|
||||
|
||||
this.divEvents = new OpenLayers.Events(this, div, null, true);
|
||||
this.divEvents.register("mousedown", this, this.divClick);
|
||||
this.divEvents.register("mousemove", this, this.passEventToSlider);
|
||||
this.divEvents.register("dblclick", this, this.doubleClick);
|
||||
this.divEvents.register("click", this, this.doubleClick);
|
||||
this.divEvents.on({
|
||||
"mousedown": this.divClick,
|
||||
"mousemove": this.passEventToSlider,
|
||||
"dblclick": this.doubleClick,
|
||||
"click": this.doubleClick
|
||||
});
|
||||
|
||||
this.div.appendChild(div);
|
||||
|
||||
@@ -250,8 +257,11 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
||||
if (!OpenLayers.Event.isLeftClick(evt)) {
|
||||
return;
|
||||
}
|
||||
this.map.events.register("mousemove", this, this.passEventToSlider);
|
||||
this.map.events.register("mouseup", this, this.passEventToSlider);
|
||||
this.map.events.on({
|
||||
"mousemove": this.passEventToSlider,
|
||||
"mouseup": this.passEventToSlider,
|
||||
scope: this
|
||||
});
|
||||
this.mouseDragStart = evt.xy.clone();
|
||||
this.zoomStart = evt.xy.clone();
|
||||
this.div.style.cursor = "move";
|
||||
@@ -298,8 +308,11 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
||||
}
|
||||
if (this.zoomStart) {
|
||||
this.div.style.cursor="";
|
||||
this.map.events.unregister("mouseup", this, this.passEventToSlider);
|
||||
this.map.events.unregister("mousemove", this, this.passEventToSlider);
|
||||
this.map.events.un({
|
||||
"mouseup": this.passEventToSlider,
|
||||
"mousemove": this.passEventToSlider,
|
||||
scope: this
|
||||
});
|
||||
var deltaY = this.zoomStart.y - evt.xy.y;
|
||||
this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight));
|
||||
this.moveZoomBar();
|
||||
|
||||
@@ -115,9 +115,12 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.element.href="";
|
||||
this.div.appendChild(this.element);
|
||||
}
|
||||
this.map.events.register('moveend', this, this.updateLink);
|
||||
this.map.events.register('changelayer', this, this.updateLink);
|
||||
this.map.events.register('changebaselayer', this, this.updateLink);
|
||||
this.map.events.on({
|
||||
'moveend': this.updateLink,
|
||||
'changelayer': this.updateLink,
|
||||
'changebaselayer': this.updateLink,
|
||||
scope: this
|
||||
});
|
||||
return this.div;
|
||||
},
|
||||
|
||||
|
||||
@@ -266,6 +266,7 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
OpenLayers.Util.extend(feature.style, selectStyle);
|
||||
|
||||
this.layer.drawFeature(feature);
|
||||
this.layer.events.triggerEvent("featureselected", {feature: feature});
|
||||
this.onSelect(feature);
|
||||
},
|
||||
|
||||
@@ -284,6 +285,7 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
this.layer.drawFeature(feature);
|
||||
OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature);
|
||||
this.layer.events.triggerEvent("featureunselected", {feature: feature});
|
||||
this.onUnselect(feature);
|
||||
},
|
||||
|
||||
|
||||
@@ -482,6 +482,27 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: on
|
||||
* Convenience method for registering listeners with a common scope.
|
||||
*
|
||||
* Example use:
|
||||
* (code)
|
||||
* events.on({
|
||||
* "loadstart": loadStartListener,
|
||||
* "loadend": loadEndListener,
|
||||
* scope: object
|
||||
* });
|
||||
* (end)
|
||||
*/
|
||||
on: function(object) {
|
||||
for(var type in object) {
|
||||
if(type != "scope") {
|
||||
this.register(type, object.scope, object[type]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: register
|
||||
* Register an event on the events object.
|
||||
@@ -552,6 +573,27 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: un
|
||||
* Convenience method for unregistering listeners with a common scope.
|
||||
*
|
||||
* Example use:
|
||||
* (code)
|
||||
* events.un({
|
||||
* "loadstart": loadStartListener,
|
||||
* "loadend": loadEndListener,
|
||||
* scope: object
|
||||
* });
|
||||
* (end)
|
||||
*/
|
||||
un: function(object) {
|
||||
for(var type in object) {
|
||||
if(type != "scope") {
|
||||
this.unregister(type, object.scope, object[type]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: unregister
|
||||
*
|
||||
@@ -596,13 +638,12 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* Parameters:
|
||||
* type - {String}
|
||||
* evt - {Event}
|
||||
* args - {Array} Optional array of arguments to call the listener with.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The last listener return. If a listener returns false, the
|
||||
* chain of listeners will stop getting called.
|
||||
*/
|
||||
triggerEvent: function (type, evt, args) {
|
||||
triggerEvent: function (type, evt) {
|
||||
|
||||
// prep evt object with object & div references
|
||||
if (evt == null) {
|
||||
@@ -611,12 +652,6 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
evt.object = this.object;
|
||||
evt.element = this.element;
|
||||
|
||||
if(!args) {
|
||||
args = [evt];
|
||||
} else {
|
||||
args.unshift(evt);
|
||||
}
|
||||
|
||||
// execute all callbacks registered for specified type
|
||||
// get a clone of the listeners array to
|
||||
// allow for splicing during callbacks
|
||||
@@ -627,7 +662,7 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
for (var i = 0; i < listeners.length; i++) {
|
||||
var callback = listeners[i];
|
||||
// bind the context to callback.obj
|
||||
continueChain = callback.func.apply(callback.obj, args);
|
||||
continueChain = callback.func.apply(callback.obj, [evt]);
|
||||
|
||||
if ((continueChain != undefined) && (continueChain == false)) {
|
||||
// if callback returns false, execute no more callbacks.
|
||||
|
||||
@@ -39,7 +39,24 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* (code)
|
||||
* layer.events.register(type, obj, listener);
|
||||
* (end)
|
||||
*
|
||||
* Listeners will be called with a reference to an event object. The
|
||||
* properties of this event depends on exactly what happened.
|
||||
*
|
||||
* All event objects have at least the following properties:
|
||||
* - *object* {Object} A reference to layer.events.object.
|
||||
* - *element* {DOMElement} A reference to layer.events.element.
|
||||
*
|
||||
* Supported map event types:
|
||||
* - *loadstart* Triggered when layer loading starts.
|
||||
* - *loadend* Triggered when layer loading ends.
|
||||
* - *loadcancel* Triggered when layer loading is canceled.
|
||||
* - *visibilitychanged* Triggered when layer visibility is changed.
|
||||
*/
|
||||
EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged"],
|
||||
|
||||
@@ -327,7 +344,10 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
if (newName != this.name) {
|
||||
this.name = newName;
|
||||
if (this.map != null) {
|
||||
this.map.events.triggerEvent("changelayer");
|
||||
this.map.events.triggerEvent("changelayer", {
|
||||
layer: this,
|
||||
property: "name"
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -530,7 +550,10 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
this.display(visibility);
|
||||
this.redraw();
|
||||
if (this.map != null) {
|
||||
this.map.events.triggerEvent("changelayer");
|
||||
this.map.events.triggerEvent("changelayer", {
|
||||
layer: this,
|
||||
property: "visibility"
|
||||
});
|
||||
}
|
||||
this.events.triggerEvent("visibilitychanged");
|
||||
}
|
||||
@@ -576,7 +599,9 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
if (isBaseLayer != this.isBaseLayer) {
|
||||
this.isBaseLayer = isBaseLayer;
|
||||
if (this.map != null) {
|
||||
this.map.events.triggerEvent("changebaselayer");
|
||||
this.map.events.triggerEvent("changebaselayer", {
|
||||
layer: this
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -526,8 +526,11 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* tile - {<OpenLayers.Tile>}
|
||||
*/
|
||||
removeTileMonitoringHooks: function(tile) {
|
||||
tile.events.unregister("loadstart", this, tile.onLoadStart);
|
||||
tile.events.unregister("loadend", this, tile.onLoadEnd);
|
||||
tile.events.un({
|
||||
"loadstart": tile.onLoadStart,
|
||||
"loadend": tile.onLoadEnd,
|
||||
scope: this
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,46 @@
|
||||
*/
|
||||
OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* (code)
|
||||
* layer.events.register(type, obj, listener);
|
||||
* (end)
|
||||
*
|
||||
* Listeners will be called with a reference to an event object. The
|
||||
* properties of this event depends on exactly what happened.
|
||||
*
|
||||
* All event objects have at least the following properties:
|
||||
* - *object* {Object} A reference to layer.events.object.
|
||||
* - *element* {DOMElement} A reference to layer.events.element.
|
||||
*
|
||||
* Supported map event types:
|
||||
* - *loadstart* Triggered when layer loading starts.
|
||||
* - *loadend* Triggered when layer loading ends.
|
||||
* - *loadcancel* Triggered when layer loading is canceled.
|
||||
* - *visibilitychanged* Triggered when layer visibility is changed.
|
||||
* - *beforefeatureadded* Triggered before a feature is added. Listeners
|
||||
* will receive an object with a *feature* property referencing the
|
||||
* feature to be added.
|
||||
* - *featureadded* Triggered after a feature is added. The event
|
||||
* object passed to listeners will have a *feature* property with a
|
||||
* reference to the added feature.
|
||||
* - *featuresadded* Triggered after features are added. The event
|
||||
* object passed to listeners will have a *features* property with a
|
||||
* reference to an array of added features.
|
||||
* - *featureselected* Triggered after a feature is selected. Listeners
|
||||
* will receive an object with a *feature* property referencing the
|
||||
* selected feature.
|
||||
* - *featureunselected* Triggered after a feature is unselected.
|
||||
* Listeners will receive an object with a *feature* property
|
||||
* referencing the unselected feature.
|
||||
*/
|
||||
EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged",
|
||||
"beforefeatureadded", "featureadded",
|
||||
"featuresadded", "featureselected", "featureunselected"],
|
||||
|
||||
/**
|
||||
* APIProperty: isBaseLayer
|
||||
* {Boolean} The layer is a base layer. Default is true. Set this property
|
||||
@@ -273,6 +313,9 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
this.events.triggerEvent("beforefeatureadded", {
|
||||
feature: feature
|
||||
});
|
||||
this.preFeatureInsert(feature);
|
||||
}
|
||||
|
||||
@@ -281,9 +324,16 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
this.events.triggerEvent("featureadded", {
|
||||
feature: feature
|
||||
});
|
||||
this.onFeatureInsert(feature);
|
||||
}
|
||||
}
|
||||
|
||||
if(notify) {
|
||||
this.events.triggerEvent("featuresadded", {features: features});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -353,8 +353,11 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
|
||||
* tile - {<OpenLayers.Tile>}
|
||||
*/
|
||||
removeTileMonitoringHooks: function(tile) {
|
||||
tile.events.unregister("loadstart", tile, tile.onLoadStart);
|
||||
tile.events.unregister("loadend", tile, tile.onLoadEnd);
|
||||
tile.events.un({
|
||||
"loadstart": tile.onLoadStart,
|
||||
"loadend": tile.onLoadEnd,
|
||||
scope: tile
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,11 +32,30 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
* map.events.register(type, obj, listener);
|
||||
* (end)
|
||||
*
|
||||
* Listeners will be called with a reference to an event object. The
|
||||
* properties of this event depends on exactly what happened.
|
||||
*
|
||||
* All event objects have at least the following properties:
|
||||
* - *object* {Object} A reference to map.events.object.
|
||||
* - *element* {DOMElement} A reference to map.events.element.
|
||||
*
|
||||
* Browser events have the following additional properties:
|
||||
* - *xy* {<OpenLayers.Pixel>} The pixel location of the event (relative
|
||||
* to the the map viewport).
|
||||
* - other properties that come with browser events
|
||||
*
|
||||
* Supported map event types:
|
||||
* - *addlayer* triggered after a layer has been added
|
||||
* - *removelayer* triggered after a layer has been removed
|
||||
* - *addlayer* triggered after a layer has been added. The event object
|
||||
* will include a *layer* property that references the added layer.
|
||||
* - *removelayer* triggered after a layer has been removed. The event
|
||||
* object will include a *layer* property that references the removed
|
||||
* layer.
|
||||
* - *changelayer* triggered after a layer name change, order change, or
|
||||
* visibility change (due to resolution thresholds)
|
||||
* visibility change (due to resolution thresholds). Listeners will
|
||||
* receive an event object with *layer* and *property* properties. The
|
||||
* *layer* property will be a reference to the changed layer. The
|
||||
* *property* property will be a key to the changed property (name,
|
||||
* visibility, or order).
|
||||
* - *movestart* triggered after the start of a drag, pan, or zoom
|
||||
* - *move* triggered after each drag, pan, or zoom
|
||||
* - *moveend* triggered after a drag, pan, or zoom completes
|
||||
@@ -735,7 +754,7 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
layer.redraw();
|
||||
}
|
||||
|
||||
this.events.triggerEvent("addlayer");
|
||||
this.events.triggerEvent("addlayer", {layer: layer});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -808,7 +827,7 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
|
||||
this.resetLayersZIndex();
|
||||
|
||||
this.events.triggerEvent("removelayer");
|
||||
this.events.triggerEvent("removelayer", {layer: layer});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -860,7 +879,9 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
for (var i = 0; i < this.layers.length; i++) {
|
||||
this.setLayerZIndex(this.layers[i], i);
|
||||
}
|
||||
this.events.triggerEvent("changelayer");
|
||||
this.events.triggerEvent("changelayer", {
|
||||
layer: layer, property: "order"
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -933,7 +954,9 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
this.setCenter(newCenter, newZoom, false, true);
|
||||
}
|
||||
|
||||
this.events.triggerEvent("changebaselayer");
|
||||
this.events.triggerEvent("changebaselayer", {
|
||||
layer: this.baseLayer
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1453,7 +1476,9 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
if (!inRange) {
|
||||
layer.display(false);
|
||||
}
|
||||
this.events.triggerEvent("changelayer");
|
||||
this.events.triggerEvent("changelayer", {
|
||||
layer: layer, property: "visibility"
|
||||
});
|
||||
}
|
||||
if (inRange && layer.visibility) {
|
||||
layer.moveTo(bounds, zoomChanged, dragging);
|
||||
|
||||
@@ -403,12 +403,16 @@ OpenLayers.Popup = OpenLayers.Class({
|
||||
registerEvents:function() {
|
||||
this.events = new OpenLayers.Events(this, this.div, null, true);
|
||||
|
||||
this.events.register("mousedown", this, this.onmousedown);
|
||||
this.events.register("mousemove", this, this.onmousemove);
|
||||
this.events.register("mouseup", this, this.onmouseup);
|
||||
this.events.register("click", this, this.onclick);
|
||||
this.events.register("mouseout", this, this.onmouseout);
|
||||
this.events.register("dblclick", this, this.ondblclick);
|
||||
this.events.on({
|
||||
"mousedown": this.onmousedown,
|
||||
"mousemove": this.onmousemove,
|
||||
"mouseup": this.onmouseup,
|
||||
"click": this.onclick,
|
||||
"mouseout": this.onmouseout,
|
||||
"dblclick": this.ondblclick,
|
||||
scope: this
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
|
||||
function test_ModifyFeature_constructor(t) {
|
||||
t.plan(3);
|
||||
var layer = "foo";
|
||||
var layer = {
|
||||
events: {
|
||||
on: function() {}
|
||||
}
|
||||
};
|
||||
var options = {
|
||||
geometryTypes: "bar"
|
||||
};
|
||||
var control = new OpenLayers.Control.ModifyFeature(layer, options);
|
||||
|
||||
t.eq(control.layer, "foo",
|
||||
t.ok(control.layer == layer,
|
||||
"constructor sets layer correctly");
|
||||
t.eq(control.selectControl.geometryTypes, "bar",
|
||||
"constructor sets options correctly on feature handler");
|
||||
@@ -72,7 +76,12 @@
|
||||
* In the future, feature deletion may be added to the control.
|
||||
*/
|
||||
|
||||
var control = new OpenLayers.Control.ModifyFeature({style: null});
|
||||
var control = new OpenLayers.Control.ModifyFeature({
|
||||
style: null,
|
||||
events: {
|
||||
on: function() {}
|
||||
}
|
||||
});
|
||||
var delKey = 46;
|
||||
var dKey = 100;
|
||||
control.deleteCodes = [delKey, dKey];
|
||||
@@ -197,7 +206,7 @@
|
||||
layer.destroyFeatures = function(verts) {
|
||||
t.ok(verts == 'b', "Virtual verts destroyed correctly");
|
||||
}
|
||||
control.unselectFeature(fakeFeature);
|
||||
control.unselectFeature({feature: fakeFeature});
|
||||
t.eq(control.feature, null, "feature is set to null");
|
||||
}
|
||||
function test_ModifyFeature_selectFeature(t) {
|
||||
@@ -216,7 +225,7 @@
|
||||
var fakeFeature = {'id':'myFakeFeature','geometry':{'CLASS_NAME':'OpenLayers.Geometry.Point'}};
|
||||
|
||||
// Points don't call collectVertices
|
||||
control.selectFeature(fakeFeature);
|
||||
control.selectFeature({feature: fakeFeature});
|
||||
|
||||
control.collectVertices = function() {
|
||||
t.ok(true, "collectVertices called");
|
||||
@@ -232,7 +241,7 @@
|
||||
fakeFeature.geometry.CLASS_NAME='OpenLayers.Geometry.Polygon';
|
||||
|
||||
// OnSelect calls collectVertices and passes features to layer
|
||||
control.selectFeature(fakeFeature);
|
||||
control.selectFeature({feature: fakeFeature});
|
||||
|
||||
control.vertices = ['a'];
|
||||
control.virtualVertices = ['b'];
|
||||
@@ -244,7 +253,7 @@
|
||||
}
|
||||
|
||||
// Features are removed whenever they exist
|
||||
control.selectFeature(fakeFeature);
|
||||
control.selectFeature({feature: fakeFeature});
|
||||
|
||||
}
|
||||
|
||||
@@ -389,7 +398,7 @@
|
||||
t.eq(feature.id, testFeature.id,
|
||||
"onModificationStart called with the right feature");
|
||||
};
|
||||
control.selectFeature(testFeature);
|
||||
control.selectFeature({feature: testFeature});
|
||||
}
|
||||
|
||||
function test_ModifyFeature_onModification(t) {
|
||||
@@ -450,7 +459,7 @@
|
||||
t.eq(feature.id, testFeature.id,
|
||||
"onModificationEnd called with the right feature");
|
||||
};
|
||||
control.unselectFeature(testFeature);
|
||||
control.unselectFeature({feature: testFeature});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +78,10 @@
|
||||
// mock up layer
|
||||
var layer = {
|
||||
selectedFeatures: [],
|
||||
drawFeature: function() {}
|
||||
drawFeature: function() {},
|
||||
events: {
|
||||
triggerEvent: function() {}
|
||||
}
|
||||
};
|
||||
// mock up active control
|
||||
var control = new OpenLayers.Control.SelectFeature(layer);
|
||||
|
||||
@@ -499,7 +499,8 @@
|
||||
events: {
|
||||
unregister: function(name, obj, func) {
|
||||
g_unregistered[name] = [obj, func];
|
||||
}
|
||||
},
|
||||
un: OpenLayers.Events.prototype.un
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,19 +205,22 @@
|
||||
eventTypes = ["something"];
|
||||
events = new OpenLayers.Events(null, null, eventTypes);
|
||||
var instance = {id: Math.random()};
|
||||
var listener = function() {
|
||||
var listener = function(obj) {
|
||||
t.eq(this.id, instance.id,
|
||||
"listener called with proper scope");
|
||||
t.eq(arguments[0].id, evt.id,
|
||||
"listener called with evt as first arg");
|
||||
t.eq(arguments[1], "arg1",
|
||||
"listener called with correct extra arg1");
|
||||
t.eq(arguments[2], "arg2",
|
||||
"listener called with correct extra arg2");
|
||||
t.eq(arguments.length, 1,
|
||||
"listener called with a single argument");
|
||||
t.eq(typeof arguments, "object",
|
||||
"listener called with an object");
|
||||
t.eq(obj.foo, evt.foo,
|
||||
"foo property set on the layer");
|
||||
};
|
||||
events.register("something", instance, listener);
|
||||
var evt = {id: Math.random()};
|
||||
events.triggerEvent("something", evt, ["arg1", "arg2", "arg3"]);
|
||||
var evt = {
|
||||
id: Math.random(),
|
||||
"foo": "bar"
|
||||
};
|
||||
events.triggerEvent("something", evt);
|
||||
events.unregister("something", instance, listener);
|
||||
|
||||
// test return from triggerEvent
|
||||
|
||||
Reference in New Issue
Block a user