Merge branch 'three' of https://github.com/tschaub/openlayers into three
Conflicts: src/api/loc.js src/api/map.js src/ol/Map.js
This commit is contained in:
+1
-6
@@ -49,12 +49,7 @@ ol.bounds = function(opt_arg){
|
|||||||
throw new Error('ol.bounds');
|
throw new Error('ol.bounds');
|
||||||
}
|
}
|
||||||
|
|
||||||
var bounds = new ol.Bounds();
|
var bounds = new ol.Bounds(minX, minY, maxX, maxY, projection);
|
||||||
bounds.setMinX(minX);
|
|
||||||
bounds.setMinY(minY);
|
|
||||||
bounds.setMaxX(maxX);
|
|
||||||
bounds.setMaxY(maxY);
|
|
||||||
bounds.setProjection(projection);
|
|
||||||
return bounds;
|
return bounds;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+25
-33
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.loc');
|
goog.provide('ol.loc');
|
||||||
|
|
||||||
goog.require('ol.Loc');
|
goog.require('ol.Loc');
|
||||||
|
goog.require('ol.projection');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,13 +13,13 @@ ol.LocLike;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @export
|
* @export
|
||||||
* @param {ol.LocLike} loc Location.
|
* @param {ol.LocLike} opt_arg Location.
|
||||||
* @return {ol.Loc} Location.
|
* @return {ol.Loc} Location.
|
||||||
*/
|
*/
|
||||||
ol.loc = function(loc){
|
ol.loc = function(opt_arg){
|
||||||
|
|
||||||
if (loc instanceof ol.Loc) {
|
if (opt_arg instanceof ol.Loc) {
|
||||||
return loc;
|
return opt_arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = 0;
|
var x = 0;
|
||||||
@@ -26,37 +27,28 @@ ol.loc = function(loc){
|
|||||||
var z;
|
var z;
|
||||||
var projection;
|
var projection;
|
||||||
|
|
||||||
if (goog.isArray(loc)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
if (loc.length >= 1) {
|
if (goog.isArray(opt_arg)) {
|
||||||
x = loc[0];
|
x = opt_arg[0];
|
||||||
if (loc.length >= 2) {
|
y = opt_arg[1];
|
||||||
y = loc[1];
|
z = opt_arg[2];
|
||||||
if (loc.length >= 3) {
|
projection = opt_arg[3];
|
||||||
z = loc[2];
|
} else if (goog.isObject(opt_arg)) {
|
||||||
}
|
x = opt_arg['x'];
|
||||||
}
|
y = opt_arg['y'];
|
||||||
}
|
z = opt_arg['z'];
|
||||||
}
|
projection = opt_arg['projection'];
|
||||||
else
|
} else {
|
||||||
if (goog.isObject(loc)) {
|
|
||||||
if (goog.isDef(loc.x)) {
|
|
||||||
x = loc.x;
|
|
||||||
}
|
|
||||||
if (goog.isDef(loc.y)) {
|
|
||||||
y = loc.y;
|
|
||||||
}
|
|
||||||
if (goog.isDef(loc.z)) {
|
|
||||||
z = loc.z;
|
|
||||||
}
|
|
||||||
if (goog.isDef(loc.projection)) {
|
|
||||||
projection = loc.projection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('ol.loc');
|
throw new Error('ol.loc');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goog.isDef(projection)) {
|
||||||
|
projection = ol.projection(projection);
|
||||||
|
}
|
||||||
|
|
||||||
return new ol.Loc(x, y, z, projection);
|
var loc = new ol.Loc(x, y, z, projection);
|
||||||
|
return loc;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,7 +60,7 @@ ol.loc = function(loc){
|
|||||||
*/
|
*/
|
||||||
ol.Loc.prototype.projection = function(opt_arg){
|
ol.Loc.prototype.projection = function(opt_arg){
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
return this.setProjection(opt_arg);
|
return this.setProjection(ol.projection(opt_arg));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return this.getProjection();
|
return this.getProjection();
|
||||||
|
|||||||
+23
-54
@@ -19,57 +19,38 @@ ol.MapLike;
|
|||||||
*/
|
*/
|
||||||
ol.map = function(opt_arg){
|
ol.map = function(opt_arg){
|
||||||
|
|
||||||
/** @type {ol.Loc|undefined} */
|
|
||||||
var center;
|
var center;
|
||||||
/** @type {number|undefined} */
|
|
||||||
var zoom;
|
|
||||||
/** @type {number|undefined} */
|
|
||||||
var numZoomLevels;
|
|
||||||
/** @type {ol.Projection|undefined} */
|
|
||||||
var projection;
|
|
||||||
var target;
|
var target;
|
||||||
|
var zoom;
|
||||||
var map = new ol.Map();
|
|
||||||
|
|
||||||
if (arguments.length == 1) {
|
if (arguments.length == 1) {
|
||||||
if (opt_arg instanceof ol.Map) {
|
if (opt_arg instanceof ol.Map) {
|
||||||
return opt_arg;
|
return opt_arg;
|
||||||
}
|
}
|
||||||
else
|
else if (goog.isObject(opt_arg)) {
|
||||||
if (goog.isObject(opt_arg)) {
|
center = opt_arg['center'];
|
||||||
var config = opt_arg;
|
target = opt_arg['target'];
|
||||||
if (goog.isDef(config.center)) {
|
zoom = opt_arg['zoom'];
|
||||||
center = ol.loc(config.center);
|
}
|
||||||
map.setCenter(center);
|
else {
|
||||||
}
|
throw new Error('ol.map');
|
||||||
if (goog.isDef(config.zoom)) {
|
}
|
||||||
zoom = config.zoom;
|
|
||||||
map.setZoom(zoom);
|
|
||||||
}
|
|
||||||
if (goog.isDef(config.numZoomLevels)) {
|
|
||||||
numZoomLevels = config.numZoomLevels;
|
|
||||||
map.setNumZoomLevels(numZoomLevels);
|
|
||||||
}
|
|
||||||
if (goog.isDef(config.projection)) {
|
|
||||||
projection = config.projection;
|
|
||||||
map.setProjection(projection);
|
|
||||||
}
|
|
||||||
if (goog.isDef(config.target)) {
|
|
||||||
target = config.target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('ol.map');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var map = new ol.Map();
|
||||||
|
if (goog.isDef(center)) {
|
||||||
|
map.setCenter(ol.loc(center));
|
||||||
|
}
|
||||||
|
if (goog.isDef(zoom)) {
|
||||||
|
map.setZoom(zoom);
|
||||||
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.LocLike=} opt_arg Get or set the map center.
|
* @param {ol.LocLike=} opt_arg
|
||||||
* @returns {ol.Map|ol.Loc|undefined} The map center, or the map on set.
|
* @returns {ol.Map|ol.Loc|undefined} Map center.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.center = function(opt_arg) {
|
ol.Map.prototype.center = function(opt_arg) {
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
@@ -80,8 +61,8 @@ ol.Map.prototype.center = function(opt_arg) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Projection|string|undefined} opt_arg Get or set the map projection.
|
* @param {ol.ProjectionLike=} opt_arg
|
||||||
* @returns {ol.Map|number|undefined} the current zoom level, or the map on set.
|
* @returns {ol.Map|ol.Projection|undefined}
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.projection = function(opt_arg) {
|
ol.Map.prototype.projection = function(opt_arg) {
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
@@ -93,7 +74,7 @@ ol.Map.prototype.projection = function(opt_arg) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.ProjectionLike=} opt_arg
|
* @param {ol.ProjectionLike=} opt_arg
|
||||||
* @returns {ol.Map|ol.Loc|undefined}
|
* @returns {ol.Map|ol.Projection|undefined}
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.userProjection = function(opt_arg) {
|
ol.Map.prototype.userProjection = function(opt_arg) {
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
@@ -104,8 +85,8 @@ ol.Map.prototype.userProjection = function(opt_arg) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number|undefined} opt_arg Get or set the current zoom level.
|
* @param {number=} opt_arg
|
||||||
* @returns {ol.Map|number|undefined} current zoom level on get or the map.
|
* @returns {ol.Map|number|undefined} Map center.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.zoom = function(opt_arg) {
|
ol.Map.prototype.zoom = function(opt_arg) {
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
@@ -114,15 +95,3 @@ ol.Map.prototype.zoom = function(opt_arg) {
|
|||||||
return this.getZoom();
|
return this.getZoom();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number|undefined} opt_arg Get or set the number of zoom levels.
|
|
||||||
* @returns {ol.Map|number|undefined} the number of zoom levels, or the map on set.
|
|
||||||
*/
|
|
||||||
ol.Map.prototype.numZoomLevels = function(opt_arg) {
|
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
|
||||||
return this.setNumZoomLevels(opt_arg);
|
|
||||||
} else {
|
|
||||||
return this.getNumZoomLevels();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
+2
-2
@@ -30,13 +30,13 @@ ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.minX_ = minX;
|
this.maxX_ = maxX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.minY_ = minY;
|
this.maxY_ = maxY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
+4
-4
@@ -14,13 +14,13 @@ ol.Map = function() {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.Projection}
|
* @type {ol.Projection}
|
||||||
*/
|
*/
|
||||||
this.projection_ ;
|
this.projection_ = new ol.Projection('EPSG:900913');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Projection}
|
* @type {ol.Projection}
|
||||||
*/
|
*/
|
||||||
this.userProjection_;
|
this.userProjection_ = new ol.Projection('EPSG:4326');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -120,8 +120,8 @@ ol.Map.prototype.setProjection = function(projection) {
|
|||||||
* @param {ol.Projection} projection set the user projection.
|
* @param {ol.Projection} projection set the user projection.
|
||||||
* @return {ol.Map} This.
|
* @return {ol.Map} This.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.setUserProjection = function(projection) {
|
ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||||
this.userProjection_ = projection;
|
this.userProjection_ = userProjection;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
describe("ol.Loc", function() {
|
describe("ol.Loc", function() {
|
||||||
|
|
||||||
it("allows flexible construction", function() {
|
it("allows empty construction", function() {
|
||||||
var loc;
|
var loc;
|
||||||
|
|
||||||
// nowhere
|
// nowhere
|
||||||
loc = ol.loc();
|
loc = ol.loc();
|
||||||
expect(loc instanceof ol.Loc).toBe(true);
|
expect(loc instanceof ol.Loc).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows construction from an obj config", function() {
|
||||||
|
var loc;
|
||||||
|
|
||||||
// obj config
|
// obj config
|
||||||
loc = ol.loc({x: 10, y: 20});
|
loc = ol.loc({x: 10, y: 20});
|
||||||
|
|
||||||
expect(loc.x()).toBe(10);
|
expect(loc.x()).toBe(10);
|
||||||
expect(loc.y()).toBe(20);
|
expect(loc.y()).toBe(20);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows construction from an array config", function() {
|
||||||
|
var loc;
|
||||||
// array config
|
// array config
|
||||||
loc = ol.loc([30, 40]);
|
loc = ol.loc([30, 40]);
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ describe("ol.Map", function() {
|
|||||||
|
|
||||||
center = map.center();
|
center = map.center();
|
||||||
zoom = map.zoom();
|
zoom = map.zoom();
|
||||||
expect(center.x().toFixed(3)).toBe("4.000");
|
expect(center.x().toFixed(3)).toBe("1.000");
|
||||||
expect(center.y().toFixed(3)).toBe("5.000");
|
expect(center.y().toFixed(3)).toBe("2.000");
|
||||||
expect(zoom).toBe(6);
|
expect(zoom).toBe(6);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user