Changeset 1513
- Timestamp:
- 09/28/06 09:05:36 (2 years ago)
- Files:
-
- branches/openlayers/2.1/lib/OpenLayers/BaseTypes.js (modified) (1 diff)
- branches/openlayers/2.1/lib/OpenLayers/Feature.js (modified) (5 diffs)
- branches/openlayers/2.1/lib/OpenLayers/Layer.js (modified) (1 diff)
- branches/openlayers/2.1/lib/OpenLayers/Map.js (modified) (3 diffs)
- branches/openlayers/2.1/lib/OpenLayers/Marker.js (modified) (1 diff)
- branches/openlayers/2.1/tests/test_Bounds.html (modified) (2 diffs)
- branches/openlayers/2.1/tests/test_Feature.html (modified) (1 diff)
- branches/openlayers/2.1/tests/test_Layer.html (modified) (1 diff)
- branches/openlayers/2.1/tests/test_Layer_WMS.html (modified) (1 diff)
- branches/openlayers/2.1/tests/test_Marker.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/openlayers/2.1/lib/OpenLayers/BaseTypes.js
r1424 r1513 425 425 }, 426 426 427 /** 428 * @param {OpenLayers.LonLat} ll 429 * @param {Boolean} inclusive Whether or not to include the border. 430 * Default is true 431 * 432 * @return Whether or not the passed-in lonlat is within this bounds 433 * @type Boolean 434 */ 435 containsLonLat:function(ll, inclusive) { 436 return this.contains(ll.lon, ll.lat, inclusive); 437 }, 438 439 /** 440 * @param {OpenLayers.Pixel} px 441 * @param {Boolean} inclusive Whether or not to include the border. 442 * Default is true 443 * 444 * @return Whether or not the passed-in pixel is within this bounds 445 * @type Boolean 446 */ 447 containsPixel:function(px, inclusive) { 448 return this.contains(px.x, px.y, inclusive); 449 }, 450 427 451 /** 428 452 * @param {float} x branches/openlayers/2.1/lib/OpenLayers/Feature.js
r1501 r1513 68 68 } 69 69 if (this.popup != null) { 70 this. popup.destroy();70 this.destroyPopup(this.popup); 71 71 this.popup = null; 72 72 } 73 }, 74 75 /** 76 * @returns Whether or not the feature is currently visible on screen 77 * (based on its 'lonlat' property) 78 * @type Boolean 79 */ 80 onScreen:function() { 81 82 var onScreen = false; 83 if ((this.layer != null) && (this.layer.map != null)) { 84 var screenBounds = this.layer.map.getExtent(); 85 onScreen = screenBounds.containsLonLat(this.lonlat); 86 } 87 return onScreen; 73 88 }, 74 89 … … 77 92 * @returns A Marker Object created from the 'lonlat' and 'icon' properties 78 93 * set in this.data. If no 'lonlat' is set, returns null. If no 79 * 'icon' is set, OpenLayers.Marker() will load the default image 94 * 'icon' is set, OpenLayers.Marker() will load the default image. 95 * 96 * Note: this.marker is set to return value 97 * 80 98 * @type OpenLayers.Marker 81 99 */ … … 90 108 }, 91 109 110 /** If user overrides the createMarker() function, s/he should be able 111 * to also specify an alternative function for destroying it 112 */ 92 113 destroyMarker: function() { 93 114 this.marker.destroy(); … … 95 116 96 117 /** 118 * @returns A Popup Object created from the 'lonlat', 'popupSize', 119 * and 'popupContentHTML' properties set in this.data. It uses 120 * this.marker.icon as default anchor. 121 * 122 * If no 'lonlat' is set, returns null. 123 * If no this.marker has been created, no anchor is sent. 97 124 * 125 * Note: this.popup is set to return value 126 * 127 * @type OpenLayers.Popup.AnchoredBubble 98 128 */ 99 129 createPopup: function() { … … 113 143 }, 114 144 145 146 /** As with the marker, if user overrides the createPopup() function, s/he 147 * should also be able to override the destruction 148 */ 149 destroyPopup: function() { 150 this.popup.destroy() 151 }, 152 115 153 CLASS_NAME: "OpenLayers.Feature" 116 154 }; branches/openlayers/2.1/lib/OpenLayers/Layer.js
r1501 r1513 394 394 getZoomForResolution: function(resolution) { 395 395 396 for(var i=1; i < =this.resolutions.length; i++) {396 for(var i=1; i < this.resolutions.length; i++) { 397 397 if ( this.resolutions[i] < resolution) { 398 398 break; branches/openlayers/2.1/lib/OpenLayers/Map.js
r1501 r1513 355 355 356 356 // is newBaseLayer an already loaded layer? 357 var foundLayer = (this.layers.indexOf(newBaseLayer) != -1); 358 if (foundLayer) { 357 if (this.layers.indexOf(newBaseLayer) != -1) { 359 358 360 359 // make the old base layer invisible … … 456 455 457 456 /** 458 * @returns {OpenLayers.Size} 457 * @returns An OpenLayers.Size object that represents the size, in pixels, 458 * of the div into which OpenLayers has been loaded. 459 * 460 * Note: A clone() of this locally cached variable is returned, so 461 * as not to allow users to modify it. 462 * 463 * @type OpenLayers.Size 459 464 */ 460 465 getSize: function () { 461 return this.size; 466 var size = null; 467 if (this.size != null) { 468 size = this.size.clone(); 469 } 470 return size; 462 471 }, 463 472 … … 670 679 if (lonlat != null) { 671 680 var maxExtent = this.getMaxExtent(); 672 valid = maxExtent.contains (lonlat.lon, lonlat.lat);681 valid = maxExtent.containsLonLat(lonlat); 673 682 } 674 683 return valid; branches/openlayers/2.1/lib/OpenLayers/Marker.js
r1501 r1513 83 83 if (this.map) { 84 84 var screenBounds = this.map.getExtent(); 85 onScreen = screenBounds.contains (this.lonlat.lon, this.lonlat.lat);85 onScreen = screenBounds.containsLonLat(this.lonlat); 86 86 } 87 87 return onScreen; branches/openlayers/2.1/tests/test_Bounds.html
r1424 r1513 54 54 55 55 function test_04_Bounds_contains(t) { 56 t.plan( 4);56 t.plan( 6 ); 57 57 bounds = new OpenLayers.Bounds(10,10,40,40); 58 58 t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" ); … … 60 60 t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" ); 61 61 t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" ); 62 63 var px = new OpenLayers.Pixel(15,30); 64 t.eq( bounds.containsPixel(px), bounds.contains(px.x, px.y), "containsPixel works"); 65 66 var ll = new OpenLayers.LonLat(15,30); 67 t.eq( bounds.containsLonLat(ll), bounds.contains(ll.lon, ll.lat), "containsLonLat works"); 68 62 69 } 63 70 branches/openlayers/2.1/tests/test_Feature.html
r1424 r1513 77 77 */ 78 78 } 79 80 function test_03_Feature_onScreen(t) { 81 t.plan( 2 ); 82 83 var map = new OpenLayers.Map("map"); 84 85 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 86 var wms = new OpenLayers.Layer.WMS(name, url); 87 88 map.addLayer(wms); 89 90 var layer = new OpenLayers.Layer("foo"); 91 map.addLayer(layer); 92 93 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 94 95 //onscreen feature 96 var feature1 = new OpenLayers.Feature(layer, 97 new OpenLayers.LonLat(0,0)); 98 t.ok( feature1.onScreen(), "feature knows it's onscreen" ); 99 100 //onscreen feature 101 var feature2 = new OpenLayers.Feature(layer, 102 new OpenLayers.LonLat(100,100)); 103 t.ok( !feature2.onScreen(), "feature knows it's offscreen" ); 104 } 79 105 80 106 // --> branches/openlayers/2.1/tests/test_Layer.html
r1424 r1513 127 127 128 128 129 function test_06_Layer_getZoomForResolution(t) { 130 131 t.plan(4); 132 133 var layer = new OpenLayers.Layer('Test Layer'); 134 135 //make some dummy resolutions 136 layer.resolutions = [128, 64, 32, 16, 8, 4, 2]; 137 138 t.eq(layer.getZoomForResolution(200), 0, "zoom all the way out"); 139 t.eq(layer.getZoomForResolution(25), 2, "zoom in middle"); 140 t.eq(layer.getZoomForResolution(3), 5, "zoom allmost all the way in"); 141 t.eq(layer.getZoomForResolution(1), 6, "zoom all the way in"); 142 143 } 144 145 129 146 /****** 130 147 * branches/openlayers/2.1/tests/test_Layer_WMS.html
r1433 r1513 14 14 function test_01_Layer_WMS_constructor (t) { 15 15 t.plan( 4 ); 16 17 layer = new OpenLayers.Layer.WMS();18 16 19 17 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; branches/openlayers/2.1/tests/test_Marker.html
r1424 r1513 15 15 } 16 16 17 function test_02_Marker_onScreen(t) { 18 t.plan( 2 ); 19 20 var map = new OpenLayers.Map("map"); 21 22 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 23 layer = new OpenLayers.Layer.WMS(name, url); 24 25 map.addLayer(layer); 26 27 mlayer = new OpenLayers.Layer.Markers('Test Layer'); 28 map.addLayer(mlayer); 29 30 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 31 32 //onscreen marker 33 var ll = new OpenLayers.LonLat(0,0); 34 var marker = new OpenLayers.Marker(ll); 35 mlayer.addMarker(marker); 36 37 t.ok( marker.onScreen(), "marker knows it's onscreen" ); 38 39 //offscreen marker 40 var ll = new OpenLayers.LonLat(100,100); 41 var marker2 = new OpenLayers.Marker(ll); 42 mlayer.addMarker(marker2); 43 44 t.ok( !marker2.onScreen(), "marker knows it's offscreen" ); 45 46 } 47 17 48 18 49 // --> … … 20 51 </head> 21 52 <body> 53 <div id="map" style="width:500px;height:550px"></div> 22 54 </body> 23 55 </html>
