Changeset 99
- Timestamp:
- 05/17/06 11:51:37 (3 years ago)
- Files:
-
- trunk/openlayers/example.html (modified) (1 diff)
- trunk/openlayers/google.html (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Control/PanZoom.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (7 diffs)
- trunk/openlayers/lib/OpenLayers/Marker.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Tile.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Util.js (modified) (4 diffs)
- trunk/openlayers/tests/list-tests.html (modified) (1 diff)
- trunk/openlayers/tests/test_LonLat.html (moved) (moved from trunk/openlayers/tests/test_LatLon.html) (1 diff)
- trunk/openlayers/tests/test_Map.html (modified) (3 diffs)
- trunk/openlayers/tests/test_Marker.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/example.html
r94 r99 21 21 22 22 map.addLayer(layer); 23 map.setCenter(new OpenLayers.L atLon(0, 0), 0);23 map.setCenter(new OpenLayers.LonLat(0, 0), 0); 24 24 map.addControl(new OpenLayers.Control.LayerSwitcher()); 25 25 } trunk/openlayers/google.html
r31 r99 27 27 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} ); 28 28 29 map.setCenter(new OpenLayers.L atLon(lat, lon), zoom);29 map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); 30 30 map.addLayer(layer); 31 31 map.addLayer(gmap); trunk/openlayers/lib/OpenLayers/Control/PanZoom.js
r51 r99 66 66 var center = this.map.getCenter(); 67 67 this.map.setCenter( 68 new OpenLayers.LatLon(center.lat + (resolution * 50), 69 center.lon 70 ) 71 ); 68 new OpenLayers.LonLat(center.lon, 69 center.lat + (resolution * 50)) 70 ); 72 71 break; 73 72 case "pandown": … … 75 74 var center = this.map.getCenter(); 76 75 this.map.setCenter( 77 new OpenLayers.LatLon(center.lat - (resolution * 50), 78 center.lon 79 ) 80 ); 76 new OpenLayers.LonLat(center.lon, 77 center.lat - (resolution * 50)) 78 ); 81 79 break; 82 80 case "panleft": … … 84 82 var center = this.map.getCenter(); 85 83 this.map.setCenter( 86 new OpenLayers.LatLon(center.lat, 87 center.lon - (resolution * 50) 88 ) 89 ); 84 new OpenLayers.LonLat(center.lon - (resolution * 50), 85 center.lat) 86 ); 90 87 break; 91 88 case "panright": … … 93 90 var center = this.map.getCenter(); 94 91 this.map.setCenter( 95 new OpenLayers.LatLon(center.lat, 96 center.lon + (resolution * 50) 97 ) 98 ); 92 new OpenLayers.LonLat(center.lon + (resolution * 50), 93 center.lat) 94 ); 99 95 break; 100 96 case "zoomin": this.map.zoomIn(); break; trunk/openlayers/lib/OpenLayers/Map.js
r93 r99 46 46 controls: null, 47 47 48 // OpenLayers.L atLon48 // OpenLayers.LonLat 49 49 center: null, 50 50 … … 173 173 174 174 /** 175 * @return {OpenLayers.L atLon}175 * @return {OpenLayers.LonLat} 176 176 */ 177 177 getCenter: function () { … … 220 220 * @param {OpenLayers.Pixel} point 221 221 * 222 * @return {OpenLayers.L atLon}223 */ 224 getL atLonFromPixel: function (point) {222 * @return {OpenLayers.LonLat} 223 */ 224 getLonLatFromPixel: function (point) { 225 225 var center = this.getCenter(); //map center lat/lon 226 226 var res = this.getResolution(); … … 230 230 var delta_y = point.y - (size.h / 2); 231 231 232 return new OpenLayers.LatLon( 233 center.lat - delta_y * res, 234 center.lon + delta_x * res ); 235 }, 236 237 /** 238 * @param {OpenLayers.LatLon} latlon 232 return new OpenLayers.LonLat(center.lon + delta_x * res , 233 center.lat - delta_y * res); 234 }, 235 236 /** 237 * @param {OpenLayers.LonLat} lonlat 239 238 * @param {int} zoom 240 239 */ 241 setCenter: function (l atlon, zoom) {240 setCenter: function (lonlat, zoom) { 242 241 if (this.center) { // otherwise there's nothing to move yet 243 this.moveLayerContainer(l atlon);244 } 245 this.center = l atlon.copyOf();242 this.moveLayerContainer(lonlat); 243 } 244 this.center = lonlat.copyOf(); 246 245 var zoomChanged = null; 247 246 if (zoom != null && zoom != this.zoom … … 309 308 this.zoom = this.getZoomForExtent( fullExtent ); 310 309 this.setCenter( 311 new OpenLayers.LatLon( 312 (fullExtent.minlat+fullExtent.maxlat)/2, 313 (fullExtent.minlon+fullExtent.maxlon)/2 314 ) 315 ); 316 }, 317 318 /** 319 * @param {OpenLayers.LatLon} latlon 320 */ 321 moveLayerContainer: function (latlon) { 310 new OpenLayers.LonLat((fullExtent.minlon+fullExtent.maxlon)/2, 311 (fullExtent.minlat+fullExtent.maxlat)/2) 312 ); 313 }, 314 315 /** 316 * @param {OpenLayers.LonLat} lonlat 317 */ 318 moveLayerContainer: function (lonlat) { 322 319 var container = this.layerContainerDiv; 323 320 var resolution = this.getResolution(); 324 321 325 var deltaX = Math.round((this.center.lon - l atlon.lon) / resolution);326 var deltaY = Math.round((this.center.lat - l atlon.lat) / resolution);322 var deltaX = Math.round((this.center.lon - lonlat.lon) / resolution); 323 var deltaY = Math.round((this.center.lat - lonlat.lat) / resolution); 327 324 328 325 var offsetLeft = parseInt(container.style.left); … … 337 334 */ 338 335 defaultDblClick: function (evt) { 339 var newCenter = this.getL atLonFromPixel( evt.xy );336 var newCenter = this.getLonLatFromPixel( evt.xy ); 340 337 this.setCenter(newCenter, this.zoom + 1); 341 338 }, … … 360 357 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 361 358 size.h / 2 + deltaY); 362 var newCenter = this.getL atLonFromPixel( newXY );359 var newCenter = this.getLonLatFromPixel( newXY ); 363 360 this.setCenter(newCenter); 364 361 this.mouseDragStart = evt.xy.copyOf(); trunk/openlayers/lib/OpenLayers/Marker.js
r89 r99 2 2 OpenLayers.Marker.prototype = { 3 3 4 / / icon: {OpenLayers.Icon} for marker4 /** @type OpenLayers.Icon */ 5 5 icon: null, 6 6 7 / / latlon: {OpenLayers.LatLon}location of object8 latlon: null,9 7 /** location of object 8 * @type OpenLayers.LonLat */ 9 lonlat: null, 10 10 11 11 /** the data object associated with the marker … … 13 13 data: null, 14 14 15 / / events15 /** @type */ 16 16 events: null, 17 17 18 / / map18 /** @type OpenLayers.Map */ 19 19 map: null, 20 20 21 initialize: function(icon, latlon) { 21 22 /** 23 * @param {OpenLayers.Icon} icon 24 * @param {OpenLayers.LonLat lonlat 25 */ 26 initialize: function(icon, lonlat) { 22 27 this.icon = icon; 23 this.l atlon = latlon;28 this.lonlat = lonlat; 24 29 }, 25 30 31 /** 32 */ 26 33 draw: function() { 27 34 var resolution = this.map.getResolution(); 28 35 var extent = this.map.getExtent(); 29 if (this.latlon.lat > extent.minlat && 30 this.latlon.lat < extent.maxlat && 31 this.lonlon.lon > extent.minlon && 32 this.lonlon.lon < extent.maxlon) { 36 if ( (this.lonlat.lat > extent.minlat) 37 && (this.lonlat.lat < extent.maxlat) 38 && (this.lonlat.lon > extent.minlon) 39 && (this.lonlat.lon < extent.maxlon)) { 40 33 41 var pixel = new OpenLayers.Pixel( 34 resolution * (this.l atlon.lon - extent.minlon),35 resolution * (extent.maxlat - this.l atlon.lat)42 resolution * (this.lonlat.lon - extent.minlon), 43 resolution * (extent.maxlat - this.lonlat.lat) 36 44 ); 37 45 // need to account for how much layer has moved... trunk/openlayers/lib/OpenLayers/Tile.js
r52 r99 25 25 /** 26 26 * @param {OpenLayers.Layer} layer 27 * @param {OpenLayers.L atLon} coord27 * @param {OpenLayers.LonLat} coord 28 28 */ 29 29 initialize: function(bounds,url,size) { trunk/openlayers/lib/OpenLayers/Util.js
r95 r99 149 149 * @class This class represents a latitude and longitude pair 150 150 */ 151 OpenLayers.L atLon= Class.create();152 OpenLayers.L atLon.prototype = {151 OpenLayers.LonLat = Class.create(); 152 OpenLayers.LonLat.prototype = { 153 153 154 154 /** … … 158 158 * @param {float} lon 159 159 */ 160 initialize: function(l at, lon) {160 initialize: function(lon, lat) { 161 161 this.lat = lat; 162 162 this.lon = lon; … … 164 164 165 165 /** 166 * @return String representation of OpenLayers.L atLonobject.166 * @return String representation of OpenLayers.LonLat object. 167 167 * (ex. "lat=42,lon=5") 168 168 * @type String 169 169 */ 170 170 toString:function() { 171 return ("l at=" + this.lat + ",lon=" + this.lon);172 }, 173 174 /** 175 * @return Shortened String representation of OpenLayers.L atLonobject.171 return ("lon=" + this.lon + ",lat=" + this.lat); 172 }, 173 174 /** 175 * @return Shortened String representation of OpenLayers.LonLat object. 176 176 * (ex. "42,5") 177 177 * @type String 178 178 */ 179 179 toShortString:function() { 180 return (this.l at + ", " + this.lon);181 }, 182 183 /** 184 * @return New OpenLayers.L atLonobject with the same lat and lon values185 * @type OpenLayers.L atLon180 return (this.lon + ", " + this.lat); 181 }, 182 183 /** 184 * @return New OpenLayers.LonLat object with the same lat and lon values 185 * @type OpenLayers.LonLat 186 186 */ 187 187 copyOf:function() { 188 return new OpenLayers.L atLon(this.lat, this.lon);189 }, 190 191 /** 192 * @param {OpenLayers.L atLon} ll193 * 194 * @return a LatLonobject with the difference between the two coords188 return new OpenLayers.LonLat(this.lon, this.lat); 189 }, 190 191 /** 192 * @param {OpenLayers.LonLat} ll 193 * 194 * @return an OpenLayers.LonLat object with the difference between the two coords 195 195 * @type OpenLayers.Pixel 196 196 */ 197 197 diff:function(ll) { 198 return new OpenLayers.L atLon(this.lat - ll.lat, this.lon - ll.lon);199 }, 200 201 /** 202 * @param {OpenLayers.L atLon} ll203 * @returns Boolean value indicating whether the passed-in OpenLayers.L atLon198 return new OpenLayers.LonLat(this.lon - ll.lon, this.lat - ll.lat); 199 }, 200 201 /** 202 * @param {OpenLayers.LonLat} ll 203 * @returns Boolean value indicating whether the passed-in OpenLayers.LonLat 204 204 * object has the same lat and lon components as this 205 205 * … … 211 211 212 212 /** @type String */ 213 CLASS_NAME: "OpenLayers.L atLon"214 }; 215 216 /** Alternative constructor that builds a new OpenLayers.L atLonfrom a213 CLASS_NAME: "OpenLayers.LonLat" 214 }; 215 216 /** Alternative constructor that builds a new OpenLayers.LonLat from a 217 217 * parameter string 218 218 * 219 219 * @constructor 220 220 * 221 * @param {String} str Comma-separated coordinate string. (ex. "40,5")222 * 223 * @returns New OpenLayers.L atLonobject built from the passed-in String.224 * @type OpenLayers.L atLon225 */ 226 OpenLayers.L atLon.fromString = function(str) {221 * @param {String} str Comma-separated Lon,Lat coordinate string. (ex. "5,40") 222 * 223 * @returns New OpenLayers.LonLat object built from the passed-in String. 224 * @type OpenLayers.LonLat 225 */ 226 OpenLayers.LonLat.fromString = function(str) { 227 227 var pair = str.split(","); 228 return new OpenLayers.L atLon(pair[1], pair[0]);228 return new OpenLayers.LonLat(pair[0], pair[1]); 229 229 }; 230 230 trunk/openlayers/tests/list-tests.html
r98 r99 1 1 <ul id="testlist"> 2 <li>test_L atLon.html</li>2 <li>test_LonLat.html</li> 3 3 <li>test_Pixel.html</li> 4 4 <li>test_Icon.html</li> trunk/openlayers/tests/test_LonLat.html
r22 r99 3 3 <script src="../lib/OpenLayers.js"></script> 4 4 <script type="text/javascript"><!-- 5 var l atlon;6 function test_01_L atLon_constructor (t) {5 var lonlat; 6 function test_01_LonLat_constructor (t) { 7 7 t.plan( 3 ); 8 l atlon = new OpenLayers.LatLon(5,6);9 t.ok( l atlon instanceof OpenLayers.LatLon, "new OpenLayers.LatLon returns LatLonobject" );10 t.eq( l atlon.lat, 5, "latlon.lat is set correctly");11 t.eq( l atlon.lon, 6, "latlon.lon is set correctly");8 lonlat = new OpenLayers.LonLat(6, 5); 9 t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" ); 10 t.eq( lonlat.lat, 5, "lonlat.lat is set correctly"); 11 t.eq( lonlat.lon, 6, "lonlat.lon is set correctly"); 12 12 } 13 13 // --> trunk/openlayers/tests/test_Map.html
r66 r99 24 24 t.plan(5); 25 25 map = new OpenLayers.Map($('map')); 26 map.setCenter(new OpenLayers.L atLon(1,2), 0);27 t.ok( map.getCenter() instanceof OpenLayers.L atLon, "map.getCenter returns a LatLon");26 map.setCenter(new OpenLayers.LonLat(2,1), 0); 27 t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat"); 28 28 t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter"); 29 29 t.eq( map.getResolution(), map.maxResolution, "map.getResolution() == map.maxResolution"); … … 57 57 t.plan(4); 58 58 map = new OpenLayers.Map($('map')); 59 map.setCenter(new OpenLayers.L atLon(1,2), 0);59 map.setCenter(new OpenLayers.LonLat(2, 1), 0); 60 60 map.zoomIn(); 61 61 t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in"); … … 72 72 t.ok(true, "zoomend event was triggered " + this.count + " times"); 73 73 }); 74 map.setCenter(new OpenLayers.L atLon(1,2), 0);74 map.setCenter(new OpenLayers.LonLat(2, 1), 0); 75 75 map.zoomIn(); 76 76 map.zoomOut(); trunk/openlayers/tests/test_Marker.html
r87 r99 7 7 function test_01_Marker_constructor (t) { 8 8 t.plan( 5 ); 9 marker = new OpenLayers.Marker(new OpenLayers.Icon(),new OpenLayers.L atLon(1,2));9 marker = new OpenLayers.Marker(new OpenLayers.Icon(),new OpenLayers.LonLat(2,1)); 10 10 t.ok( marker instanceof OpenLayers.Marker, "new OpenLayers.Marker returns Marker object" ); 11 11 t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" ); 12 t.ok( marker.l atlon instanceof OpenLayers.LatLon, "new marker.latlon returns LatLonobject" );13 t.eq( marker.l atlon.lat, 1, "marker.latlon.lat returns correct lat" );14 t.eq( marker.l atlon.lon, 2, "marker.latlon.lon returns correct lon" );12 t.ok( marker.lonlat instanceof OpenLayers.LonLat, "new marker.lonlat returns LonLat object" ); 13 t.eq( marker.lonlat.lat, 1, "marker.lonlat.lat returns correct lat" ); 14 t.eq( marker.lonlat.lon, 2, "marker.lonlat.lon returns correct lon" ); 15 15 } 16 16
