Changeset 7615
- Timestamp:
- 07/30/08 14:23:19 (5 years ago)
- Location:
- trunk/openlayers/lib/OpenLayers
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/openlayers/lib/OpenLayers/Control/PanZoomBar.js
r7341 r7615 166 166 this.slider = slider; 167 167 168 this.sliderEvents = new OpenLayers.Events(this, slider, null, true); 168 this.sliderEvents = new OpenLayers.Events(this, slider, null, true, 169 {includeXY: true}); 169 170 this.sliderEvents.on({ 170 171 "mousedown": this.zoomBarDown, … … 198 199 this.zoombarDiv = div; 199 200 200 this.divEvents = new OpenLayers.Events(this, div, null, true); 201 this.divEvents = new OpenLayers.Events(this, div, null, true, 202 {includeXY: true}); 201 203 this.divEvents.on({ 202 204 "mousedown": this.divClick, -
trunk/openlayers/lib/OpenLayers/Events.js
r7610 r7615 393 393 fallThrough: null, 394 394 395 /** 396 * APIProperty: includeXY 397 * {Boolean} Should the .xy property automatically be created for browser 398 * mouse events? In general, this should be false. If it is true, then 399 * mouse events will automatically generate a '.xy' property on the 400 * event object that is passed. (Prior to OpenLayers 2.7, this was true 401 * by default.) Otherwise, you can call the getMousePosition on the 402 * relevant events handler on the object available via the 'evt.object' 403 * property of the evt object. So, for most events, you can call: 404 * function named(evt) { 405 * this.xy = this.object.events.getMousePosition(evt) 406 * } 407 * 408 * This option typically defaults to false for performance reasons: 409 * when creating an events object whose primary purpose is to manage 410 * relatively positioned mouse events within a div, it may make 411 * sense to set it to true. 412 * 413 * This option is also used to control whether the events object caches 414 * offsets. If this is false, it will not: the reason for this is that 415 * it is only expected to be called many times if the includeXY property 416 * is set to true. If you set this to true, you are expected to clear 417 * the offset cache manually (using this.clearMouseCache()) if: 418 * the border of the element changes 419 * the location of the element in the page changes 420 */ 421 includeXY: false, 422 395 423 /** 396 424 * Constructor: OpenLayers.Events … … 403 431 * fallThrough - {Boolean} Allow events to fall through after these have 404 432 * been handled? 405 */ 406 initialize: function (object, element, eventTypes, fallThrough) { 433 * options - {Object} Options for the events object. 434 */ 435 initialize: function (object, element, eventTypes, fallThrough, options) { 436 OpenLayers.Util.extend(this, options); 407 437 this.object = object; 408 438 this.element = element; … … 692 722 */ 693 723 handleBrowserEvent: function (evt) { 694 evt.xy = this.getMousePosition(evt); 724 if (this.includeXY) { 725 evt.xy = this.getMousePosition(evt); 726 } 695 727 this.triggerEvent(evt.type, evt); 696 728 }, 729 730 /** 731 * APIMethod: clearMouseCache 732 * Clear cached data about the mouse position. This should be called any 733 * time the element that events are registered on changes position 734 * within the page. 735 */ 736 clearMouseCache: function() { 737 this.element.scrolls = null; 738 this.element.lefttop = null; 739 this.element.offsets = null; 740 }, 697 741 698 742 /** … … 707 751 */ 708 752 getMousePosition: function (evt) { 753 if (!this.includeXY) { 754 this.clearMouseCache(); 755 } else if (!this.element.hasScrollEvent) { 756 OpenLayers.Event.observe(window, 'scroll', 757 OpenLayers.Function.bind(this.clearMouseCache, this)); 758 this.element.hasScrollEvent = true; 759 } 760 761 if (!this.element.scrolls) { 762 this.element.scrolls = []; 763 this.element.scrolls[0] = (document.documentElement.scrollLeft 764 || document.body.scrollLeft); 765 this.element.scrolls[1] = (document.documentElement.scrollTop 766 || document.body.scrollTop); 767 } 768 769 if (!this.element.lefttop) { 770 this.element.lefttop = []; 771 this.element.lefttop[0] = (document.documentElement.clientLeft || 0); 772 this.element.lefttop[1] = (document.documentElement.clientTop || 0); 773 } 774 709 775 if (!this.element.offsets) { 710 776 this.element.offsets = OpenLayers.Util.pagePosition(this.element); 711 this.element.offsets[0] += (document.documentElement.scrollLeft 712 || document.body.scrollLeft); 713 this.element.offsets[1] += (document.documentElement.scrollTop 714 || document.body.scrollTop); 777 this.element.offsets[0] += this.element.scrolls[0]; 778 this.element.offsets[1] += this.element.scrolls[1]; 715 779 } 716 780 return new OpenLayers.Pixel( 717 (evt.clientX + (document.documentElement.scrollLeft 718 || document.body.scrollLeft)) - this.element.offsets[0] 719 - (document.documentElement.clientLeft || 0), 720 (evt.clientY + (document.documentElement.scrollTop 721 || document.body.scrollTop)) - this.element.offsets[1] 722 - (document.documentElement.clientTop || 0) 781 (evt.clientX + this.element.scrolls[0]) - this.element.offsets[0] 782 - this.element.lefttop[0], 783 (evt.clientY + this.element.scrolls[1]) - this.element.offsets[1] 784 - this.element.lefttop[1] 723 785 ); 724 786 }, -
trunk/openlayers/lib/OpenLayers/Map.js
r7596 r7615 427 427 this.div, 428 428 this.EVENT_TYPES, 429 this.fallThrough); 429 this.fallThrough, 430 {includeXY: true}); 430 431 this.updateSize(); 431 432 if(this.eventListeners instanceof Object) { … … 1203 1204 updateSize: function() { 1204 1205 // the div might have moved on the page, also 1205 this.events. element.offsets = null;1206 this.events.clearMouseCache(); 1206 1207 var newSize = this.getCurrentSize(); 1207 1208 var oldSize = this.getSize();
