Ticket #1244: ovmap.patch
| File ovmap.patch, 18.3 kB (added by tschaub, 1 year ago) |
|---|
-
theme/default/style.css
old new 64 64 } 65 65 66 66 .olControlOverviewMapExtentRectangle { 67 cursor: move; 67 overflow: hidden; 68 background-image: url("img/blank.gif"); 69 cursor: move; 68 70 border: 2px dotted red; 69 71 } 72 .olControlOverviewMapRectReplacement { 73 overflow: hidden; 74 cursor: move; 75 background-image: url("img/overview_replacement.gif"); 76 background-repeat: no-repeat; 77 background-position: center; 78 } 79 70 80 .olLayerGeoRSSDescription { 71 81 float:left; 72 82 width:100%; -
tests/Control/test_OverviewMap.html
old new 51 51 t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon"); 52 52 t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat"); 53 53 54 control.rectMouseDown({'xy':new OpenLayers.Pixel(5,5), 'which':1}); 55 control.rectMouseMove({'xy':new OpenLayers.Pixel(15,15), 'which':1}); 56 control.rectMouseUp({'xy':new OpenLayers.Pixel(15,15), 'which':1}); 54 control.dragHandler = { 55 last: new OpenLayers.Pixel(5,5), 56 destroy: function() {} 57 }; 58 control.rectDrag(new OpenLayers.Pixel(15, 15)); 59 control.updateMapToRect(); 57 60 58 61 var cent = map.getCenter(); 59 62 t.eq(cent.lon, -71.2734375, "Dragging on the Overview Map has the correct effect on map lon"); -
lib/OpenLayers/Map.js
old new 53 53 * {DOMElement} The element that contains the map 54 54 */ 55 55 div: null, 56 57 /** 58 * Property: dragging 59 * {Boolean} The map is currently being dragged. 60 */ 61 dragging: false, 56 62 57 63 /** 58 64 * Property: size … … 1221 1227 * TBD: reconsider forceZoomChange in 3.0 1222 1228 */ 1223 1229 setCenter: function (lonlat, zoom, dragging, forceZoomChange) { 1224 1230 this.dragging = !!dragging; 1231 1225 1232 if (!this.center && !this.isValidLonLat(lonlat)) { 1226 1233 lonlat = this.maxExtent.getCenterLonLat(); 1227 1234 } -
lib/OpenLayers/Control/OverviewMap.js
old new 20 20 OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, { 21 21 22 22 /** 23 * Property: id24 * {String} For div.id25 */26 id: "OverviewMap",27 28 /**29 23 * Property: element 30 24 * {DOMElement} The DOM element that contains the overview map 31 25 */ … … 36 30 * {<OpenLayers.Map>} A reference to the overvew map itself. 37 31 */ 38 32 ovmap: null, 39 33 40 34 /** 41 35 * APIProperty: size 42 36 * {<OpenLayers.Size>} The overvew map size in pixels. Note that this is … … 52 46 * If none are sent at construction, the base layer for the main map is used. 53 47 */ 54 48 layers: null, 49 50 /** 51 * APIProperty: minRectSize 52 * {Integer} The minimum width or height (in pixels) of the extent 53 * rectangle on the overview map. When the extent rectangle reaches 54 * this size, it will be replaced depending on the value of the 55 * <minRectDisplayClass> property. Default is 10 pixels. 56 */ 57 minRectSize: 15, 58 59 /** 60 * APIProperty: minRectDisplayClass 61 * {String} Replacement style class name for the extent rectangle when 62 * <minRectSize> is reached. This string will be suffixed on to the 63 * displayClass. Default is "RectReplacement". 64 * 65 * Example CSS declaration: 66 * (code) 67 * .olControlOverviewMapRectReplacement { 68 * background-image: url("img/overview_replacement.png"); 69 * background-repeat: no-repeat; 70 * background-position: center; 71 * } 72 * (end) 73 */ 74 minRectDisplayClass: "RectReplacement", 55 75 56 76 /** 57 77 * APIProperty: minRatio … … 74 94 * options that the main map was constructed with. 75 95 */ 76 96 mapOptions: null, 97 98 /** 99 * Property: dragHandler 100 * {<OpenLayers.Handler.Drag>} A handler for dragging the extent rectangle. 101 */ 102 dragHandler: null, 77 103 78 104 /** 79 105 * Constructor: OpenLayers.Control.OverviewMap … … 97 123 if (!this.mapDiv) { // we've already been destroyed 98 124 return; 99 125 } 126 this.dragHandler.destroy(); 127 this.clickHandler.destroy(); 128 100 129 this.mapDiv.removeChild(this.extentRectangle); 101 130 this.extentRectangle = null; 102 131 this.rectEvents.destroy(); … … 107 136 108 137 this.element.removeChild(this.mapDiv); 109 138 this.mapDiv = null; 110 this.mapDivEvents.destroy();111 this.mapDivEvents = null;112 139 113 140 this.div.removeChild(this.element); 114 141 this.element = null; 115 this.elementEvents.destroy();116 this.elementEvents = null;117 142 118 143 if (this.maximizeDiv) { 119 144 OpenLayers.Event.stopObservingElement(this.maximizeDiv); … … 165 190 this.extentRectangle = document.createElement('div'); 166 191 this.extentRectangle.style.position = 'absolute'; 167 192 this.extentRectangle.style.zIndex = 1000; //HACK 168 this.extentRectangle.style.overflow = 'hidden';169 this.extentRectangle.style.backgroundImage = 'url(' +170 OpenLayers.Util.getImagesLocation() +171 'blank.gif)';172 193 this.extentRectangle.className = this.displayClass+'ExtentRectangle'; 173 194 this.mapDiv.appendChild(this.extentRectangle); 174 195 175 196 this.element.appendChild(this.mapDiv); 176 197 177 198 this.div.appendChild(this.element); 178 199 179 200 this.map.events.register('moveend', this, this.update); 180 181 // Set up events. The image div recenters the map on click.182 // The extent rectangle can be dragged to recenter the map.183 // If the mousedown happened elsewhere, then mousemove and mouseup184 // should slip through.185 this.elementEvents = new OpenLayers.Events(this, this.element);186 this.elementEvents.register('mousedown', this, function(e) {187 OpenLayers.Event.stop(e);188 });189 this.elementEvents.register('click', this, function(e) {190 OpenLayers.Event.stop(e);191 });192 this.elementEvents.register('dblclick', this, function(e) {193 OpenLayers.Event.stop(e);194 });195 this.rectEvents = new OpenLayers.Events(this, this.extentRectangle,196 null, true);197 this.rectEvents.register('mouseout', this, this.rectMouseOut);198 this.rectEvents.register('mousedown', this, this.rectMouseDown);199 this.rectEvents.register('mousemove', this, this.rectMouseMove);200 this.rectEvents.register('mouseup', this, this.rectMouseUp);201 this.rectEvents.register('click', this, function(e) {202 OpenLayers.Event.stop(e);203 });204 this.rectEvents.register('dblclick', this, this.rectDblClick );205 this.mapDivEvents = new OpenLayers.Events(this, this.mapDiv);206 this.mapDivEvents.register('click', this, this.mapDivClick);207 201 208 202 // Optionally add min/max buttons if the control will go in the 209 203 // map viewport. … … 276 270 }, 277 271 278 272 /** 279 * Method: rect MouseOut280 * Handle browser events273 * Method: rectDrag 274 * Handle extent rectangle drag 281 275 * 282 276 * Parameters: 283 * evt - {<OpenLayers.Event>} evt277 * px - {<OpenLayers.Pixel>} The pixel location of the drag. 284 278 */ 285 rectMouseOut: function (evt) { 286 if(this.rectDragStart != null) { 287 if(this.performedRectDrag) { 288 this.rectMouseMove(evt); 289 var rectPxBounds = this.getRectPxBounds(); 290 // if we're off of the overview map, update the main map 291 // otherwise, keep moving the rect 292 if((rectPxBounds.top <= 0) || (rectPxBounds.left <= 0) || 293 (rectPxBounds.bottom >= this.size.h - this.hComp) || 294 (rectPxBounds.right >= this.size.w - this.wComp)) { 295 this.updateMapToRect(); 296 } else { 297 return; 298 } 299 } 300 document.onselectstart = null; 301 this.rectDragStart = null; 302 } 303 }, 304 305 /** 306 * Method: rectMouseDown 307 * Handle browser events 308 * 309 * Parameters: 310 * evt - {<OpenLayers.Event>} evt 311 */ 312 rectMouseDown: function (evt) { 313 if(!OpenLayers.Event.isLeftClick(evt)) { 314 return; 315 } 316 this.rectDragStart = evt.xy.clone(); 317 this.performedRectDrag = false; 318 OpenLayers.Event.stop(evt); 319 }, 320 321 /** 322 * Method: rectMouseMove 323 * Handle browser events 324 * 325 * Parameters: 326 * evt - {<OpenLayers.Event>} evt 327 */ 328 rectMouseMove: function(evt) { 329 if(this.rectDragStart != null) { 330 var deltaX = this.rectDragStart.x - evt.xy.x; 331 var deltaY = this.rectDragStart.y - evt.xy.y; 332 var rectPxBounds = this.getRectPxBounds(); 333 var rectTop = rectPxBounds.top; 334 var rectLeft = rectPxBounds.left; 335 var rectHeight = Math.abs(rectPxBounds.getHeight()); 336 var rectWidth = rectPxBounds.getWidth(); 279 rectDrag: function(px) { 280 var deltaX = this.dragHandler.last.x - px.x; 281 var deltaY = this.dragHandler.last.y - px.y; 282 if(deltaX != 0 || deltaY != 0) { 283 var rectTop = this.rectPxBounds.top; 284 var rectLeft = this.rectPxBounds.left; 285 var rectHeight = Math.abs(this.rectPxBounds.getHeight()); 286 var rectWidth = this.rectPxBounds.getWidth(); 337 287 // don't allow dragging off of parent element 338 288 var newTop = Math.max(0, (rectTop - deltaY)); 339 289 newTop = Math.min(newTop, … … 345 295 newTop + rectHeight, 346 296 newLeft + rectWidth, 347 297 newTop)); 348 this.rectDragStart = evt.xy.clone();349 this.performedRectDrag = true;350 OpenLayers.Event.stop(evt);351 298 } 352 299 }, 353 354 /**355 * Method: rectMouseUp356 * Handle browser events357 *358 * Parameters:359 * evt - {<OpenLayers.Event>} evt360 */361 rectMouseUp: function(evt) {362 if(!OpenLayers.Event.isLeftClick(evt)) {363 return;364 }365 if(this.performedRectDrag) {366 this.updateMapToRect();367 OpenLayers.Event.stop(evt);368 }369 document.onselectstart = null;370 this.rectDragStart = null;371 },372 300 373 301 /** 374 * Method: rectDblClick375 * Handle browser events376 *377 * Parameters:378 * evt - {<OpenLayers.Event>} evt379 */380 rectDblClick: function(evt) {381 this.performedRectDrag = false;382 OpenLayers.Event.stop(evt);383 this.updateOverview();384 },385 386 /**387 302 * Method: mapDivClick 388 303 * Handle browser events 389 304 * … … 391 306 * evt - {<OpenLayers.Event>} evt 392 307 */ 393 308 mapDivClick: function(evt) { 394 var pxBounds = this.getRectPxBounds(); 395 var pxCenter = pxBounds.getCenterPixel(); 309 var pxCenter = this.rectPxBounds.getCenterPixel(); 396 310 var deltaX = evt.xy.x - pxCenter.x; 397 311 var deltaY = evt.xy.y - pxCenter.y; 398 var top = pxBounds.top;399 var left = pxBounds.left;400 var height = Math.abs( pxBounds.getHeight());401 var width = pxBounds.getWidth();312 var top = this.rectPxBounds.top; 313 var left = this.rectPxBounds.left; 314 var height = Math.abs(this.rectPxBounds.getHeight()); 315 var width = this.rectPxBounds.getWidth(); 402 316 var newTop = Math.max(0, (top + deltaY)); 403 317 newTop = Math.min(newTop, this.ovmap.size.h - height); 404 318 var newLeft = Math.max(0, (left + deltaX)); … … 532 446 parseInt(OpenLayers.Element.getStyle(this.extentRectangle, 533 447 'border-bottom-width')); 534 448 this.hComp = (this.hComp) ? this.hComp : 2; 449 450 this.dragHandler = new OpenLayers.Handler.Drag( 451 this, {move: this.rectDrag, done: this.updateMapToRect}, 452 {map: this.ovmap} 453 ); 454 this.clickHandler = new OpenLayers.Handler.Click( 455 this, { 456 "click": this.mapDivClick 457 },{ 458 "single": true, "double": false, 459 "stopSingle": true, "stopDouble": true, 460 "pixelTolerance": 1, 461 map: this.ovmap 462 } 463 ); 464 this.clickHandler.activate(); 465 466 this.rectEvents = new OpenLayers.Events(this, this.extentRectangle, 467 null, true); 468 this.rectEvents.register("mouseover", this, function(e) { 469 if(!this.dragHandler.active && !this.map.dragging) { 470 // this click handler de/activation can be removed when 471 // ticket #1247 is addressed 472 this.clickHandler.deactivate(); 473 this.dragHandler.activate(); 474 this.clickHandler.activate(); 475 } 476 }); 477 this.rectEvents.register("mouseout", this, function(e) { 478 if(!this.dragHandler.dragging) { 479 this.dragHandler.deactivate(); 480 } 481 }); 482 535 483 }, 536 484 537 485 /** … … 548 496 } 549 497 var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent()); 550 498 if (pxBounds) { 551 this.setRectPxBounds(pxBounds);499 this.setRectPxBounds(pxBounds); 552 500 } 553 501 }, 554 502 … … 557 505 * Updates the map extent to match the extent rectangle position and size 558 506 */ 559 507 updateMapToRect: function() { 560 var pxBounds = this.getRectPxBounds(); 561 var lonLatBounds = this.getMapBoundsFromRectBounds(pxBounds); 508 var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); 562 509 this.map.setCenter(lonLatBounds.getCenterLonLat(), this.map.zoom); 563 510 }, 564 565 /**566 * Method: getRectPxBounds567 * Get extent rectangle pixel bounds568 *569 * Returns:570 * {<OpenLayers.Bounds>} A bounds which is the extent rectangle's pixel571 * bounds (relative to the parent element)572 */573 getRectPxBounds: function() {574 var top = parseInt(this.extentRectangle.style.top);575 var left = parseInt(this.extentRectangle.style.left);576 var height = parseInt(this.extentRectangle.style.height);577 var width = parseInt(this.extentRectangle.style.width);578 return new OpenLayers.Bounds(left, top + height, left + width, top);579 },580 511 581 512 /** 582 513 * Method: setRectPxBounds … … 592 523 this.ovmap.size.h - this.hComp); 593 524 var right = Math.min(pxBounds.left + pxBounds.getWidth(), 594 525 this.ovmap.size.w - this.wComp); 595 this.extentRectangle.style.top = parseInt(top) + 'px'; 596 this.extentRectangle.style.left = parseInt(left) + 'px'; 597 this.extentRectangle.style.height = parseInt(Math.max(bottom - top, 0))+ 'px'; 598 this.extentRectangle.style.width = parseInt(Math.max(right - left, 0)) + 'px'; 526 var width = Math.max(right - left, 0); 527 var height = Math.max(bottom - top, 0); 528 if(width < this.minRectSize || height < this.minRectSize) { 529 this.extentRectangle.className = this.displayClass + 530 this.minRectDisplayClass; 531 var rLeft = left + (width / 2) - (this.minRectSize / 2); 532 var rTop = top + (height / 2) - (this.minRectSize / 2); 533 this.extentRectangle.style.top = Math.round(rTop) + 'px'; 534 this.extentRectangle.style.left = Math.round(rLeft) + 'px'; 535 this.extentRectangle.style.height = this.minRectSize + 'px'; 536 this.extentRectangle.style.width = this.minRectSize + 'px'; 537 } else { 538 this.extentRectangle.className = this.displayClass + 539 'ExtentRectangle'; 540 this.extentRectangle.style.top = Math.round(top) + 'px'; 541 this.extentRectangle.style.left = Math.round(left) + 'px'; 542 this.extentRectangle.style.height = Math.round(height) + 'px'; 543 this.extentRectangle.style.width = Math.round(width) + 'px'; 544 } 545 this.rectPxBounds = new OpenLayers.Bounds( 546 Math.round(left), Math.round(bottom), 547 Math.round(right), Math.round(top) 548 ); 599 549 }, 600 550 601 551 /** -
examples/overviewmap.html
old new 86 86 map2.addLayers([bos]); 87 87 map2.addControl(new OpenLayers.Control.LayerSwitcher()); 88 88 89 // create an overview map control with thedefault options89 // create an overview map control with non-default options 90 90 var controlOptions = { 91 91 mapOptions: mapOptions 92 92 }
