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:
Tim Schaub
2008-02-08 23:31:27 +00:00
parent 464fb30589
commit f27833f1db
20 changed files with 326 additions and 118 deletions
+14 -8
View File
@@ -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;
+14 -8
View File
@@ -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
});
},
/**
+19 -13
View File
@@ -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);
},
/**
+18 -12
View File
@@ -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();
+6 -3
View File
@@ -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;
+5 -3
View File
@@ -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);
},
+28 -15
View File
@@ -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();
+6 -3
View File
@@ -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;
},
+2
View File
@@ -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);
},