Allow setting center from array.
This commit is contained in:
@@ -38,6 +38,10 @@ OpenLayers.LonLat = OpenLayers.Class({
|
|||||||
* it will be the y coordinate of the map location in your map units.
|
* it will be the y coordinate of the map location in your map units.
|
||||||
*/
|
*/
|
||||||
initialize: function(lon, lat) {
|
initialize: function(lon, lat) {
|
||||||
|
if (OpenLayers.Util.isArray(lon)) {
|
||||||
|
lat = lon[1];
|
||||||
|
lon = lon[0];
|
||||||
|
}
|
||||||
this.lon = OpenLayers.Util.toFloat(lon);
|
this.lon = OpenLayers.Util.toFloat(lon);
|
||||||
this.lat = OpenLayers.Util.toFloat(lat);
|
this.lat = OpenLayers.Util.toFloat(lat);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1703,6 +1703,9 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
* options - {Object}
|
* options - {Object}
|
||||||
*/
|
*/
|
||||||
moveTo: function(lonlat, zoom, options) {
|
moveTo: function(lonlat, zoom, options) {
|
||||||
|
if (!(lonlat instanceof OpenLayers.LonLat)) {
|
||||||
|
lonlat = new OpenLayers.LonLat(lonlat);
|
||||||
|
}
|
||||||
if (!options) {
|
if (!options) {
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
var lonlat;
|
var lonlat;
|
||||||
|
|
||||||
function test_LonLat_constructor (t) {
|
function test_LonLat_constructor (t) {
|
||||||
t.plan( 6 );
|
t.plan( 8 );
|
||||||
lonlat = new OpenLayers.LonLat(6, 5);
|
lonlat = new OpenLayers.LonLat(6, 5);
|
||||||
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
|
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
|
||||||
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
|
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
|
||||||
@@ -17,6 +17,12 @@
|
|||||||
lonlat = new OpenLayers.LonLat(20037508.33999999, -20037508.33999999);
|
lonlat = new OpenLayers.LonLat(20037508.33999999, -20037508.33999999);
|
||||||
t.eq( lonlat.lon, 20037508.34, "lonlat.lon rounds correctly");
|
t.eq( lonlat.lon, 20037508.34, "lonlat.lon rounds correctly");
|
||||||
t.eq( lonlat.lat, -20037508.34, "lonlat.lat rounds correctly");
|
t.eq( lonlat.lat, -20037508.34, "lonlat.lat rounds correctly");
|
||||||
|
|
||||||
|
// allow construction from single arg
|
||||||
|
lonlat = new OpenLayers.LonLat([1, 2]);
|
||||||
|
t.eq(lonlat.lon, 1, "lon from array");
|
||||||
|
t.eq(lonlat.lat, 2, "lat from array");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_LonLat_constructorFromStrings (t) {
|
function test_LonLat_constructorFromStrings (t) {
|
||||||
|
|||||||
+27
-1
@@ -37,6 +37,25 @@
|
|||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Map_constructor_convenience(t) {
|
||||||
|
t.plan(3);
|
||||||
|
var map = new OpenLayers.Map({
|
||||||
|
layers: [
|
||||||
|
new OpenLayers.Layer(null, {isBaseLayer: true})
|
||||||
|
],
|
||||||
|
center: [-111, 45],
|
||||||
|
zoom: 3
|
||||||
|
});
|
||||||
|
|
||||||
|
var center = map.getCenter();
|
||||||
|
t.eq(center.lon, -111, "center lon");
|
||||||
|
t.eq(center.lat, 45, "center lat");
|
||||||
|
|
||||||
|
t.eq(map.getZoom(), 3, "zoom");
|
||||||
|
|
||||||
|
map.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
function test_Map_constructor_late_rendering(t) {
|
function test_Map_constructor_late_rendering(t) {
|
||||||
t.plan( 4 );
|
t.plan( 4 );
|
||||||
|
|
||||||
@@ -163,7 +182,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Map_center(t) {
|
function test_Map_center(t) {
|
||||||
t.plan(11);
|
t.plan(14);
|
||||||
var log = [];
|
var log = [];
|
||||||
map = new OpenLayers.Map('map', {
|
map = new OpenLayers.Map('map', {
|
||||||
eventListeners: {
|
eventListeners: {
|
||||||
@@ -205,6 +224,13 @@
|
|||||||
map.getCenter().lon = 10;
|
map.getCenter().lon = 10;
|
||||||
t.ok( map.getCenter().equals(ll), "map.getCenter returns a clone of map.center");
|
t.ok( map.getCenter().equals(ll), "map.getCenter returns a clone of map.center");
|
||||||
|
|
||||||
|
// allow calling setCenter with an array
|
||||||
|
map.setCenter([4, 2]);
|
||||||
|
var center = map.getCenter();
|
||||||
|
t.ok(center instanceof OpenLayers.LonLat, "(array) center is lonlat");
|
||||||
|
t.eq(center.lon, 4, "(array) center lon");
|
||||||
|
t.eq(center.lat, 2, "(array) center lat");
|
||||||
|
|
||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user