Replace all instances and usages of LatLon to LonLat
git-svn-id: http://svn.openlayers.org/trunk/openlayers@99 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} );
|
||||
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LatLon(0, 0), 0);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
}
|
||||
// -->
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv",
|
||||
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} );
|
||||
|
||||
map.setCenter(new OpenLayers.LatLon(lat, lon), zoom);
|
||||
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||
map.addLayer(layer);
|
||||
map.addLayer(gmap);
|
||||
map.addControl( new OpenLayers.Control.LayerSwitcher() );
|
||||
|
||||
@@ -65,37 +65,33 @@ OpenLayers.Control.PanZoom.prototype =
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat + (resolution * 50),
|
||||
center.lon
|
||||
)
|
||||
);
|
||||
new OpenLayers.LonLat(center.lon,
|
||||
center.lat + (resolution * 50))
|
||||
);
|
||||
break;
|
||||
case "pandown":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat - (resolution * 50),
|
||||
center.lon
|
||||
)
|
||||
);
|
||||
new OpenLayers.LonLat(center.lon,
|
||||
center.lat - (resolution * 50))
|
||||
);
|
||||
break;
|
||||
case "panleft":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat,
|
||||
center.lon - (resolution * 50)
|
||||
)
|
||||
);
|
||||
new OpenLayers.LonLat(center.lon - (resolution * 50),
|
||||
center.lat)
|
||||
);
|
||||
break;
|
||||
case "panright":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat,
|
||||
center.lon + (resolution * 50)
|
||||
)
|
||||
);
|
||||
new OpenLayers.LonLat(center.lon + (resolution * 50),
|
||||
center.lat)
|
||||
);
|
||||
break;
|
||||
case "zoomin": this.map.zoomIn(); break;
|
||||
case "zoomout": this.map.zoomOut(); break;
|
||||
|
||||
@@ -45,7 +45,7 @@ OpenLayers.Map.prototype = {
|
||||
// Array(OpenLayers.Control)
|
||||
controls: null,
|
||||
|
||||
// OpenLayers.LatLon
|
||||
// OpenLayers.LonLat
|
||||
center: null,
|
||||
|
||||
// int
|
||||
@@ -172,7 +172,7 @@ OpenLayers.Map.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {OpenLayers.LatLon}
|
||||
* @return {OpenLayers.LonLat}
|
||||
*/
|
||||
getCenter: function () {
|
||||
return this.center;
|
||||
@@ -219,9 +219,9 @@ OpenLayers.Map.prototype = {
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} point
|
||||
*
|
||||
* @return {OpenLayers.LatLon}
|
||||
* @return {OpenLayers.LonLat}
|
||||
*/
|
||||
getLatLonFromPixel: function (point) {
|
||||
getLonLatFromPixel: function (point) {
|
||||
var center = this.getCenter(); //map center lat/lon
|
||||
var res = this.getResolution();
|
||||
var size = this.getSize();
|
||||
@@ -229,20 +229,19 @@ OpenLayers.Map.prototype = {
|
||||
var delta_x = point.x - (size.w / 2);
|
||||
var delta_y = point.y - (size.h / 2);
|
||||
|
||||
return new OpenLayers.LatLon(
|
||||
center.lat - delta_y * res,
|
||||
center.lon + delta_x * res );
|
||||
return new OpenLayers.LonLat(center.lon + delta_x * res ,
|
||||
center.lat - delta_y * res);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LatLon} latlon
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
* @param {int} zoom
|
||||
*/
|
||||
setCenter: function (latlon, zoom) {
|
||||
setCenter: function (lonlat, zoom) {
|
||||
if (this.center) { // otherwise there's nothing to move yet
|
||||
this.moveLayerContainer(latlon);
|
||||
this.moveLayerContainer(lonlat);
|
||||
}
|
||||
this.center = latlon.copyOf();
|
||||
this.center = lonlat.copyOf();
|
||||
var zoomChanged = null;
|
||||
if (zoom != null && zoom != this.zoom
|
||||
&& zoom >= 0 && zoom <= this.getZoomLevels()) {
|
||||
@@ -308,22 +307,20 @@ OpenLayers.Map.prototype = {
|
||||
var oldZoom = this.zoom;
|
||||
this.zoom = this.getZoomForExtent( fullExtent );
|
||||
this.setCenter(
|
||||
new OpenLayers.LatLon(
|
||||
(fullExtent.minlat+fullExtent.maxlat)/2,
|
||||
(fullExtent.minlon+fullExtent.maxlon)/2
|
||||
)
|
||||
);
|
||||
new OpenLayers.LonLat((fullExtent.minlon+fullExtent.maxlon)/2,
|
||||
(fullExtent.minlat+fullExtent.maxlat)/2)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LatLon} latlon
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*/
|
||||
moveLayerContainer: function (latlon) {
|
||||
moveLayerContainer: function (lonlat) {
|
||||
var container = this.layerContainerDiv;
|
||||
var resolution = this.getResolution();
|
||||
|
||||
var deltaX = Math.round((this.center.lon - latlon.lon) / resolution);
|
||||
var deltaY = Math.round((this.center.lat - latlon.lat) / resolution);
|
||||
var deltaX = Math.round((this.center.lon - lonlat.lon) / resolution);
|
||||
var deltaY = Math.round((this.center.lat - lonlat.lat) / resolution);
|
||||
|
||||
var offsetLeft = parseInt(container.style.left);
|
||||
var offsetTop = parseInt(container.style.top);
|
||||
@@ -336,7 +333,7 @@ OpenLayers.Map.prototype = {
|
||||
* @param {Event} evt
|
||||
*/
|
||||
defaultDblClick: function (evt) {
|
||||
var newCenter = this.getLatLonFromPixel( evt.xy );
|
||||
var newCenter = this.getLonLatFromPixel( evt.xy );
|
||||
this.setCenter(newCenter, this.zoom + 1);
|
||||
},
|
||||
|
||||
@@ -359,7 +356,7 @@ OpenLayers.Map.prototype = {
|
||||
var size = this.getSize();
|
||||
var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
|
||||
size.h / 2 + deltaY);
|
||||
var newCenter = this.getLatLonFromPixel( newXY );
|
||||
var newCenter = this.getLonLatFromPixel( newXY );
|
||||
this.setCenter(newCenter);
|
||||
this.mouseDragStart = evt.xy.copyOf();
|
||||
}
|
||||
|
||||
@@ -1,38 +1,46 @@
|
||||
OpenLayers.Marker = Class.create();
|
||||
OpenLayers.Marker.prototype = {
|
||||
|
||||
// icon: {OpenLayers.Icon} for marker
|
||||
/** @type OpenLayers.Icon */
|
||||
icon: null,
|
||||
|
||||
// latlon: {OpenLayers.LatLon} location of object
|
||||
latlon: null,
|
||||
|
||||
/** location of object
|
||||
* @type OpenLayers.LonLat */
|
||||
lonlat: null,
|
||||
|
||||
/** the data object associated with the marker
|
||||
* @type Object */
|
||||
data: null,
|
||||
|
||||
// events
|
||||
/** @type */
|
||||
events: null,
|
||||
|
||||
// map
|
||||
/** @type OpenLayers.Map */
|
||||
map: null,
|
||||
|
||||
initialize: function(icon, latlon) {
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Icon} icon
|
||||
* @param {OpenLayers.LonLat lonlat
|
||||
*/
|
||||
initialize: function(icon, lonlat) {
|
||||
this.icon = icon;
|
||||
this.latlon = latlon;
|
||||
this.lonlat = lonlat;
|
||||
},
|
||||
|
||||
/**
|
||||
*/
|
||||
draw: function() {
|
||||
var resolution = this.map.getResolution();
|
||||
var extent = this.map.getExtent();
|
||||
if (this.latlon.lat > extent.minlat &&
|
||||
this.latlon.lat < extent.maxlat &&
|
||||
this.lonlon.lon > extent.minlon &&
|
||||
this.lonlon.lon < extent.maxlon) {
|
||||
if ( (this.lonlat.lat > extent.minlat)
|
||||
&& (this.lonlat.lat < extent.maxlat)
|
||||
&& (this.lonlat.lon > extent.minlon)
|
||||
&& (this.lonlat.lon < extent.maxlon)) {
|
||||
|
||||
var pixel = new OpenLayers.Pixel(
|
||||
resolution * (this.latlon.lon - extent.minlon),
|
||||
resolution * (extent.maxlat - this.latlon.lat)
|
||||
resolution * (this.lonlat.lon - extent.minlon),
|
||||
resolution * (extent.maxlat - this.lonlat.lat)
|
||||
);
|
||||
// need to account for how much layer has moved...
|
||||
/* Psuedocode:
|
||||
|
||||
@@ -24,7 +24,7 @@ OpenLayers.Tile.prototype = {
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Layer} layer
|
||||
* @param {OpenLayers.LatLon} coord
|
||||
* @param {OpenLayers.LonLat} coord
|
||||
*/
|
||||
initialize: function(bounds,url,size) {
|
||||
if (arguments.length > 0) {
|
||||
|
||||
@@ -148,8 +148,8 @@ OpenLayers.Size.prototype = {
|
||||
/**
|
||||
* @class This class represents a latitude and longitude pair
|
||||
*/
|
||||
OpenLayers.LatLon = Class.create();
|
||||
OpenLayers.LatLon.prototype = {
|
||||
OpenLayers.LonLat = Class.create();
|
||||
OpenLayers.LonLat.prototype = {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -157,50 +157,50 @@ OpenLayers.LatLon.prototype = {
|
||||
* @param {float} lat
|
||||
* @param {float} lon
|
||||
*/
|
||||
initialize: function(lat, lon) {
|
||||
initialize: function(lon, lat) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return String representation of OpenLayers.LatLon object.
|
||||
* @return String representation of OpenLayers.LonLat object.
|
||||
* (ex. "lat=42,lon=5")
|
||||
* @type String
|
||||
*/
|
||||
toString:function() {
|
||||
return ("lat=" + this.lat + ",lon=" + this.lon);
|
||||
return ("lon=" + this.lon + ",lat=" + this.lat);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return Shortened String representation of OpenLayers.LatLon object.
|
||||
* @return Shortened String representation of OpenLayers.LonLat object.
|
||||
* (ex. "42,5")
|
||||
* @type String
|
||||
*/
|
||||
toShortString:function() {
|
||||
return (this.lat + ", " + this.lon);
|
||||
return (this.lon + ", " + this.lat);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return New OpenLayers.LatLon object with the same lat and lon values
|
||||
* @type OpenLayers.LatLon
|
||||
* @return New OpenLayers.LonLat object with the same lat and lon values
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
copyOf:function() {
|
||||
return new OpenLayers.LatLon(this.lat, this.lon);
|
||||
return new OpenLayers.LonLat(this.lon, this.lat);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LatLon} ll
|
||||
* @param {OpenLayers.LonLat} ll
|
||||
*
|
||||
* @return a LatLon object with the difference between the two coords
|
||||
* @return an OpenLayers.LonLat object with the difference between the two coords
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
diff:function(ll) {
|
||||
return new OpenLayers.LatLon(this.lat - ll.lat, this.lon - ll.lon);
|
||||
return new OpenLayers.LonLat(this.lon - ll.lon, this.lat - ll.lat);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LatLon} ll
|
||||
* @returns Boolean value indicating whether the passed-in OpenLayers.LatLon
|
||||
* @param {OpenLayers.LonLat} ll
|
||||
* @returns Boolean value indicating whether the passed-in OpenLayers.LonLat
|
||||
* object has the same lat and lon components as this
|
||||
*
|
||||
* @type bool
|
||||
@@ -210,22 +210,22 @@ OpenLayers.LatLon.prototype = {
|
||||
},
|
||||
|
||||
/** @type String */
|
||||
CLASS_NAME: "OpenLayers.LatLon"
|
||||
CLASS_NAME: "OpenLayers.LonLat"
|
||||
};
|
||||
|
||||
/** Alternative constructor that builds a new OpenLayers.LatLon from a
|
||||
/** Alternative constructor that builds a new OpenLayers.LonLat from a
|
||||
* parameter string
|
||||
*
|
||||
* @constructor
|
||||
*
|
||||
* @param {String} str Comma-separated coordinate string. (ex. "40,5")
|
||||
* @param {String} str Comma-separated Lon,Lat coordinate string. (ex. "5,40")
|
||||
*
|
||||
* @returns New OpenLayers.LatLon object built from the passed-in String.
|
||||
* @type OpenLayers.LatLon
|
||||
* @returns New OpenLayers.LonLat object built from the passed-in String.
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
OpenLayers.LatLon.fromString = function(str) {
|
||||
OpenLayers.LonLat.fromString = function(str) {
|
||||
var pair = str.split(",");
|
||||
return new OpenLayers.LatLon(pair[1], pair[0]);
|
||||
return new OpenLayers.LonLat(pair[0], pair[1]);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<ul id="testlist">
|
||||
<li>test_LatLon.html</li>
|
||||
<li>test_LonLat.html</li>
|
||||
<li>test_Pixel.html</li>
|
||||
<li>test_Icon.html</li>
|
||||
<li>test_Marker.html</li>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var latlon;
|
||||
function test_01_LatLon_constructor (t) {
|
||||
t.plan( 3 );
|
||||
latlon = new OpenLayers.LatLon(5,6);
|
||||
t.ok( latlon instanceof OpenLayers.LatLon, "new OpenLayers.LatLon returns LatLon object" );
|
||||
t.eq( latlon.lat, 5, "latlon.lat is set correctly");
|
||||
t.eq( latlon.lon, 6, "latlon.lon is set correctly");
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
18
tests/test_LonLat.html
Normal file
18
tests/test_LonLat.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var lonlat;
|
||||
function test_01_LonLat_constructor (t) {
|
||||
t.plan( 3 );
|
||||
lonlat = new OpenLayers.LonLat(6, 5);
|
||||
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
|
||||
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
|
||||
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -23,8 +23,8 @@
|
||||
function test_02_Map_center(t) {
|
||||
t.plan(5);
|
||||
map = new OpenLayers.Map($('map'));
|
||||
map.setCenter(new OpenLayers.LatLon(1,2), 0);
|
||||
t.ok( map.getCenter() instanceof OpenLayers.LatLon, "map.getCenter returns a LatLon");
|
||||
map.setCenter(new OpenLayers.LonLat(2,1), 0);
|
||||
t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat");
|
||||
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter");
|
||||
t.eq( map.getResolution(), map.maxResolution, "map.getResolution() == map.maxResolution");
|
||||
t.eq( map.getCenter().lat, 1, "map center lat is correct after calling setCenter");
|
||||
@@ -56,7 +56,7 @@
|
||||
function test_05_Map_center(t) {
|
||||
t.plan(4);
|
||||
map = new OpenLayers.Map($('map'));
|
||||
map.setCenter(new OpenLayers.LatLon(1,2), 0);
|
||||
map.setCenter(new OpenLayers.LonLat(2, 1), 0);
|
||||
map.zoomIn();
|
||||
t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in");
|
||||
t.eq( map.getCenter().lat, 1, "map center lat is correct after calling setCenter,zoom in");
|
||||
@@ -71,7 +71,7 @@
|
||||
this.count++;
|
||||
t.ok(true, "zoomend event was triggered " + this.count + " times");
|
||||
});
|
||||
map.setCenter(new OpenLayers.LatLon(1,2), 0);
|
||||
map.setCenter(new OpenLayers.LonLat(2, 1), 0);
|
||||
map.zoomIn();
|
||||
map.zoomOut();
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
function test_01_Marker_constructor (t) {
|
||||
t.plan( 5 );
|
||||
marker = new OpenLayers.Marker(new OpenLayers.Icon(),new OpenLayers.LatLon(1,2));
|
||||
marker = new OpenLayers.Marker(new OpenLayers.Icon(),new OpenLayers.LonLat(2,1));
|
||||
t.ok( marker instanceof OpenLayers.Marker, "new OpenLayers.Marker returns Marker object" );
|
||||
t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" );
|
||||
t.ok( marker.latlon instanceof OpenLayers.LatLon, "new marker.latlon returns LatLon object" );
|
||||
t.eq( marker.latlon.lat, 1, "marker.latlon.lat returns correct lat" );
|
||||
t.eq( marker.latlon.lon, 2, "marker.latlon.lon returns correct lon" );
|
||||
t.ok( marker.lonlat instanceof OpenLayers.LonLat, "new marker.lonlat returns LonLat object" );
|
||||
t.eq( marker.lonlat.lat, 1, "marker.lonlat.lat returns correct lat" );
|
||||
t.eq( marker.lonlat.lon, 2, "marker.lonlat.lon returns correct lon" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user