Merge branch 'master' of github.com:openlayers/ol3 into vector

This commit is contained in:
Tim Schaub
2013-03-03 15:52:40 +01:00
40 changed files with 746 additions and 327 deletions

View File

@@ -15,6 +15,7 @@ goog.require('ol.Pixel');
goog.require('ol.Projection');
goog.require('ol.TransformFunction');
goog.require('ol.control.Control');
goog.require('ol.projection');
@@ -71,7 +72,7 @@ ol.control.MousePosition = function(mousePositionOptions) {
* @private
* @type {ol.TransformFunction}
*/
this.transform_ = ol.Projection.identityTransform;
this.transform_ = ol.projection.identityTransform;
/**
* @private
@@ -166,10 +167,10 @@ ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
if (!goog.isNull(pixel)) {
if (this.renderedProjection_ != this.mapProjection_) {
if (goog.isDef(this.projection_)) {
this.transform_ = ol.Projection.getTransform(
this.transform_ = ol.projection.getTransform(
this.mapProjection_, this.projection_);
} else {
this.transform_ = ol.Projection.identityTransform;
this.transform_ = ol.projection.identityTransform;
}
this.renderedProjection_ = this.mapProjection_;
}

View File

@@ -30,13 +30,13 @@ ol.control.Zoom = function(zoomOptions) {
var inElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomIn',
'class': 'ol-zoom-in'
}, '+');
});
goog.events.listen(inElement, eventType, this.handleIn_, false, this);
var outElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomOut',
'class': 'ol-zoom-out'
}, '\u2212');
});
goog.events.listen(outElement, eventType, this.handleOut_, false, this);
var element = goog.dom.createDom(

View File

@@ -9,6 +9,7 @@ goog.require('goog.math');
goog.require('ol.Coordinate');
goog.require('ol.Object');
goog.require('ol.Projection');
goog.require('ol.projection');
/**
@@ -75,8 +76,8 @@ ol.Geolocation.prototype.disposeInternal = function() {
ol.Geolocation.prototype.handleProjectionChanged_ = function() {
var projection = this.getProjection();
if (goog.isDefAndNotNull(projection)) {
this.transformCoords_ = ol.Projection.getTransform(
ol.Projection.getFromCode('EPSG:4326'), projection);
this.transformCoords_ = ol.projection.getTransform(
ol.projection.getFromCode('EPSG:4326'), projection);
if (!goog.isNull(this.position_)) {
this.set(ol.GeolocationProperty.POSITION,
this.transformCoords_(this.position_));

View File

@@ -14,16 +14,16 @@ ol.ImageUrlFunctionType;
/**
* @param {string} baseUrl Base URL (may have query data).
* @param {string} axisOrientation Axis orientation.
* @return {ol.ImageUrlFunctionType} Image URL function.
*/
ol.ImageUrlFunction.createBboxParam = function(baseUrl) {
ol.ImageUrlFunction.createBboxParam = function(baseUrl, axisOrientation) {
return function(extent, size) {
// FIXME Projection dependant axis order.
var bboxValue = [
extent.minX, extent.minY, extent.maxX, extent.maxY
].join(',');
var bboxValues = axisOrientation.substr(0, 2) == 'ne' ?
[extent.minY, extent.minX, extent.maxY, extent.maxX] :
[extent.minX, extent.minY, extent.maxX, extent.maxY];
return goog.uri.utils.appendParams(baseUrl,
'BBOX', bboxValue,
'BBOX', bboxValues.join(','),
'HEIGHT', size.height,
'WIDTH', size.width);
};

View File

@@ -58,6 +58,8 @@ goog.require('ol.interaction.TouchPan');
goog.require('ol.interaction.TouchRotateAndZoom');
goog.require('ol.interaction.condition');
goog.require('ol.layer.Layer');
goog.require('ol.projection');
goog.require('ol.projection.addCommonProjections');
goog.require('ol.renderer.Map');
goog.require('ol.renderer.canvas.Map');
goog.require('ol.renderer.canvas.SUPPORTED');
@@ -1027,3 +1029,6 @@ ol.RendererHints.createFromQueryData = function(opt_queryData) {
return ol.DEFAULT_RENDERER_HINTS;
}
};
ol.projection.addCommonProjections();

57
src/ol/math.js Normal file
View File

@@ -0,0 +1,57 @@
goog.provide('ol.math');
/**
* @param {number} x X.
* @return {number} Hyperbolic cosine of x.
*/
ol.math.cosh = function(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
};
/**
* @param {number} x X.
* @return {number} Hyperbolic cotangent of x.
*/
ol.math.coth = function(x) {
var expMinusTwoX = Math.exp(-2 * x);
return (1 + expMinusTwoX) / (1 - expMinusTwoX);
};
/**
* @param {number} x X.
* @return {number} Hyperbolic cosecant of x.
*/
ol.math.csch = function(x) {
return 2 / (Math.exp(x) - Math.exp(-x));
};
/**
* @param {number} x X.
* @return {number} Hyperbolic secant of x.
*/
ol.math.sech = function(x) {
return 2 / (Math.exp(x) + Math.exp(-x));
};
/**
* @param {number} x X.
* @return {number} Hyperbolic sine of x.
*/
ol.math.sinh = function(x) {
return (Math.exp(x) - Math.exp(-x)) / 2;
};
/**
* @param {number} x X.
* @return {number} Hyperbolic tangent of x.
*/
ol.math.tanh = function(x) {
var expMinusTwoX = Math.exp(-2 * x);
return (1 - expMinusTwoX) / (1 + expMinusTwoX);
};

View File

@@ -1,9 +1,9 @@
goog.provide('ol.parser.ogc.WMTSCapabilities_v1_0_0');
goog.require('goog.dom.xml');
goog.require('ol.Coordinate');
goog.require('ol.Projection');
goog.require('ol.parser.XML');
goog.require('ol.parser.ogc.OWSCommon_v1_1_0');
goog.require('ol.projection');
@@ -76,9 +76,10 @@ ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
'TopLeftCorner': function(node, obj) {
var topLeftCorner = this.getChildValue(node);
var coords = topLeftCorner.split(' ');
var axis = ol.Projection.getFromCode(obj['supportedCRS']).getAxis();
var axisOrientation =
ol.projection.getFromCode(obj['supportedCRS']).getAxisOrientation();
obj['topLeftCorner'] = ol.Coordinate.fromProjectedArray(
[parseFloat(coords[0]), parseFloat(coords[1])], axis);
[parseFloat(coords[0]), parseFloat(coords[1])], axisOrientation);
},
'TileWidth': function(node, obj) {
obj['tileWidth'] = parseInt(this.getChildValue(node), 10);

View File

@@ -1,10 +1,5 @@
@exportSymbol ol.Projection
@exportProperty ol.Projection.addProjection
@exportProperty ol.Projection.getFromCode
@exportProperty ol.Projection.getTransform
@exportProperty ol.Projection.getTransformFromCodes
@exportProperty ol.Projection.transform
@exportProperty ol.Projection.transformWithCodes
@exportProperty ol.Projection.prototype.getAxisOrientation
@exportProperty ol.Projection.prototype.getCode
@exportProperty ol.Projection.prototype.getExtent
@exportProperty ol.Projection.prototype.getUnits
@@ -12,3 +7,10 @@
@exportSymbol ol.ProjectionUnits
@exportProperty ol.ProjectionUnits.DEGREES
@exportProperty ol.ProjectionUnits.METERS
@exportSymbol ol.projection.addProjection
@exportSymbol ol.projection.getFromCode
@exportSymbol ol.projection.getTransform
@exportSymbol ol.projection.getTransformFromCodes
@exportSymbol ol.projection.transform
@exportSymbol ol.projection.transformWithCodes

View File

@@ -1,5 +1,6 @@
goog.provide('ol.Projection');
goog.provide('ol.ProjectionUnits');
goog.provide('ol.projection');
goog.require('goog.array');
goog.require('goog.asserts');
@@ -36,9 +37,9 @@ ol.ProjectionUnits = {
* @param {string} code Code.
* @param {ol.ProjectionUnits} units Units.
* @param {ol.Extent} extent Extent.
* @param {string=} opt_axis Axis order.
* @param {string=} opt_axisOrientation Axis orientation.
*/
ol.Projection = function(code, units, extent, opt_axis) {
ol.Projection = function(code, units, extent, opt_axisOrientation) {
/**
* @private
@@ -62,7 +63,8 @@ ol.Projection = function(code, units, extent, opt_axis) {
* @private
* @type {string}
*/
this.axis_ = opt_axis || 'enu';
this.axisOrientation_ = goog.isDef(opt_axisOrientation) ?
opt_axisOrientation : 'enu';
};
@@ -92,10 +94,10 @@ ol.Projection.prototype.getUnits = function() {
/**
* @return {string} Axis.
* @return {string} Axis orientation.
*/
ol.Projection.prototype.getAxis = function() {
return this.axis_;
ol.Projection.prototype.getAxisOrientation = function() {
return this.axisOrientation_;
};
@@ -105,12 +107,13 @@ ol.Projection.prototype.getAxis = function() {
* @extends {ol.Projection}
* @param {string} code Code.
* @param {Proj4js.Proj} proj4jsProj Proj4js projection.
* @private
*/
ol.Proj4jsProjection = function(code, proj4jsProj) {
ol.Proj4jsProjection_ = function(code, proj4jsProj) {
var units = /** @type {ol.ProjectionUnits} */ (proj4jsProj.units);
goog.base(this, code, units, null);
goog.base(this, code, units, null, proj4jsProj.axis);
/**
* @private
@@ -119,36 +122,36 @@ ol.Proj4jsProjection = function(code, proj4jsProj) {
this.proj4jsProj_ = proj4jsProj;
};
goog.inherits(ol.Proj4jsProjection, ol.Projection);
goog.inherits(ol.Proj4jsProjection_, ol.Projection);
/**
* @return {Proj4js.Proj} Proj4js projection.
*/
ol.Proj4jsProjection.prototype.getProj4jsProj = function() {
ol.Proj4jsProjection_.prototype.getProj4jsProj = function() {
return this.proj4jsProj_;
};
/**
* @private
* @type {Object.<string, ol.Proj4jsProjection>}
* @type {Object.<string, ol.Proj4jsProjection_>}
*/
ol.Projection.proj4jsProjections_ = {};
ol.projection.proj4jsProjections_ = {};
/**
* @private
* @type {Object.<string, ol.Projection>}
*/
ol.Projection.projections_ = {};
ol.projection.projections_ = {};
/**
* @private
* @type {Object.<string, Object.<string, ol.TransformFunction>>}
*/
ol.Projection.transforms_ = {};
ol.projection.transforms_ = {};
/**
@@ -156,15 +159,14 @@ ol.Projection.transforms_ = {};
* to transform between projections with equal meaning.
*
* @param {Array.<ol.Projection>} projections Projections.
* @private
*/
ol.Projection.addEquivalentProjections_ = function(projections) {
ol.Projection.addProjections(projections);
ol.projection.addEquivalentProjections = function(projections) {
ol.projection.addProjections(projections);
goog.array.forEach(projections, function(source) {
goog.array.forEach(projections, function(destination) {
if (source !== destination) {
ol.Projection.addTransform(
source, destination, ol.Projection.cloneTransform);
ol.projection.addTransform(
source, destination, ol.projection.cloneTransform);
}
});
});
@@ -181,24 +183,24 @@ ol.Projection.addEquivalentProjections_ = function(projections) {
* projection in projection1 to any projection in projection2.
* @param {ol.TransformFunction} inverseTransform Transform from any projection
* in projection2 to any projection in projection1..
* @private
*/
ol.Projection.addEquivalentTransforms_ =
ol.projection.addEquivalentTransforms =
function(projections1, projections2, forwardTransform, inverseTransform) {
goog.array.forEach(projections1, function(projection1) {
goog.array.forEach(projections2, function(projection2) {
ol.Projection.addTransform(projection1, projection2, forwardTransform);
ol.Projection.addTransform(projection2, projection1, inverseTransform);
ol.projection.addTransform(projection1, projection2, forwardTransform);
ol.projection.addTransform(projection2, projection1, inverseTransform);
});
});
};
/**
* @param {ol.Proj4jsProjection} proj4jsProjection Proj4js projection.
* @param {ol.Proj4jsProjection_} proj4jsProjection Proj4js projection.
* @private
*/
ol.Projection.addProj4jsProjection = function(proj4jsProjection) {
var proj4jsProjections = ol.Projection.proj4jsProjections_;
ol.projection.addProj4jsProjection_ = function(proj4jsProjection) {
var proj4jsProjections = ol.projection.proj4jsProjections_;
var code = proj4jsProjection.getCode();
goog.asserts.assert(!goog.object.containsKey(proj4jsProjections, code));
proj4jsProjections[code] = proj4jsProjection;
@@ -208,36 +210,48 @@ ol.Projection.addProj4jsProjection = function(proj4jsProjection) {
/**
* @param {ol.Projection} projection Projection.
*/
ol.Projection.addProjection = function(projection) {
var projections = ol.Projection.projections_;
ol.projection.addProjection = function(projection) {
var projections = ol.projection.projections_;
var code = projection.getCode();
goog.asserts.assert(!goog.object.containsKey(projections, code));
projections[code] = projection;
ol.Projection.addTransform(
projection, projection, ol.Projection.cloneTransform);
ol.projection.addTransform(
projection, projection, ol.projection.cloneTransform);
};
/**
* @param {Array.<ol.Projection>} projections Projections.
*/
ol.Projection.addProjections = function(projections) {
ol.projection.addProjections = function(projections) {
goog.array.forEach(projections, function(projection) {
ol.Projection.addProjection(projection);
ol.projection.addProjection(projection);
});
};
/**
* FIXME empty description for jsdoc
*/
ol.projection.clearAllProjections = function() {
if (ol.ENABLE_PROJ4JS) {
ol.projection.proj4jsProjections_ = {};
}
ol.projection.projections_ = {};
ol.projection.transforms_ = {};
};
/**
* @param {ol.Projection|string|undefined} projection Projection.
* @param {string} defaultCode Default code.
* @return {ol.Projection} Projection.
*/
ol.Projection.createProjection = function(projection, defaultCode) {
ol.projection.createProjection = function(projection, defaultCode) {
if (!goog.isDefAndNotNull(projection)) {
return ol.Projection.getFromCode(defaultCode);
return ol.projection.getFromCode(defaultCode);
} else if (goog.isString(projection)) {
return ol.Projection.getFromCode(projection);
return ol.projection.getFromCode(projection);
} else {
goog.asserts.assert(projection instanceof ol.Projection);
return projection;
@@ -253,10 +267,10 @@ ol.Projection.createProjection = function(projection, defaultCode) {
* @param {ol.Projection} destination Destination.
* @param {ol.TransformFunction} transformFn Transform.
*/
ol.Projection.addTransform = function(source, destination, transformFn) {
ol.projection.addTransform = function(source, destination, transformFn) {
var sourceCode = source.getCode();
var destinationCode = destination.getCode();
var transforms = ol.Projection.transforms_;
var transforms = ol.projection.transforms_;
if (!goog.object.containsKey(transforms, sourceCode)) {
transforms[sourceCode] = {};
}
@@ -275,10 +289,10 @@ ol.Projection.addTransform = function(source, destination, transformFn) {
* @param {ol.Projection} destination Destination projection.
* @return {ol.TransformFunction} transformFn The unregistered transform.
*/
ol.Projection.removeTransform = function(source, destination) {
ol.projection.removeTransform = function(source, destination) {
var sourceCode = source.getCode();
var destinationCode = destination.getCode();
var transforms = ol.Projection.transforms_;
var transforms = ol.projection.transforms_;
goog.asserts.assert(sourceCode in transforms);
goog.asserts.assert(destinationCode in transforms[sourceCode]);
var transform = transforms[sourceCode][destinationCode];
@@ -296,10 +310,10 @@ ol.Projection.removeTransform = function(source, destination) {
* such as “EPSG:4326”.
* @return {ol.Projection} Projection.
*/
ol.Projection.getFromCode = function(code) {
var projection = ol.Projection.projections_[code];
ol.projection.getFromCode = function(code) {
var projection = ol.projection.projections_[code];
if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) {
projection = ol.Projection.getProj4jsProjectionFromCode_(code);
projection = ol.projection.getProj4jsProjectionFromCode_(code);
}
if (!goog.isDef(projection)) {
goog.asserts.assert(goog.isDef(projection));
@@ -312,14 +326,14 @@ ol.Projection.getFromCode = function(code) {
/**
* @param {string} code Code.
* @private
* @return {ol.Proj4jsProjection} Proj4js projection.
* @return {ol.Proj4jsProjection_} Proj4js projection.
*/
ol.Projection.getProj4jsProjectionFromCode_ = function(code) {
var proj4jsProjections = ol.Projection.proj4jsProjections_;
ol.projection.getProj4jsProjectionFromCode_ = function(code) {
var proj4jsProjections = ol.projection.proj4jsProjections_;
var proj4jsProjection = proj4jsProjections[code];
if (!goog.isDef(proj4jsProjection)) {
var proj4jsProj = new Proj4js.Proj(code);
proj4jsProjection = new ol.Proj4jsProjection(code, proj4jsProj);
proj4jsProjection = new ol.Proj4jsProjection_(code, proj4jsProj);
proj4jsProjections[code] = proj4jsProjection;
}
return proj4jsProjection;
@@ -335,14 +349,14 @@ ol.Projection.getProj4jsProjectionFromCode_ = function(code) {
* @param {ol.Projection} projection2 Projection 2.
* @return {boolean} Equivalent.
*/
ol.Projection.equivalent = function(projection1, projection2) {
ol.projection.equivalent = function(projection1, projection2) {
if (projection1 === projection2) {
return true;
} else if (projection1.getUnits() != projection2.getUnits()) {
return false;
} else {
var transformFn = ol.Projection.getTransform(projection1, projection2);
return transformFn === ol.Projection.cloneTransform;
var transformFn = ol.projection.getTransform(projection1, projection2);
return transformFn === ol.projection.cloneTransform;
}
};
@@ -355,8 +369,8 @@ ol.Projection.equivalent = function(projection1, projection2) {
* @param {ol.Projection} destination Destination.
* @return {ol.TransformFunction} Transform.
*/
ol.Projection.getTransform = function(source, destination) {
var transforms = ol.Projection.transforms_;
ol.projection.getTransform = function(source, destination) {
var transforms = ol.projection.transforms_;
var sourceCode = source.getCode();
var destinationCode = destination.getCode();
var transform;
@@ -366,19 +380,19 @@ ol.Projection.getTransform = function(source, destination) {
}
if (ol.HAVE_PROJ4JS && !goog.isDef(transform)) {
var proj4jsSource;
if (source instanceof ol.Proj4jsProjection) {
if (source instanceof ol.Proj4jsProjection_) {
proj4jsSource = source;
} else {
proj4jsSource =
ol.Projection.getProj4jsProjectionFromCode_(source.getCode());
ol.projection.getProj4jsProjectionFromCode_(source.getCode());
}
var sourceProj4jsProj = proj4jsSource.getProj4jsProj();
var proj4jsDestination;
if (destination instanceof ol.Proj4jsProjection) {
if (destination instanceof ol.Proj4jsProjection_) {
proj4jsDestination = destination;
} else {
proj4jsDestination =
ol.Projection.getProj4jsProjectionFromCode_(destination.getCode());
ol.projection.getProj4jsProjectionFromCode_(destination.getCode());
}
var destinationProj4jsProj = proj4jsDestination.getProj4jsProj();
transform =
@@ -392,11 +406,11 @@ ol.Projection.getTransform = function(source, destination) {
sourceProj4jsProj, destinationProj4jsProj, proj4jsPoint);
return new ol.Coordinate(proj4jsPoint.x, proj4jsPoint.y);
};
ol.Projection.addTransform(source, destination, transform);
ol.projection.addTransform(source, destination, transform);
}
if (!goog.isDef(transform)) {
goog.asserts.assert(goog.isDef(transform));
transform = ol.Projection.identityTransform;
transform = ol.projection.identityTransform;
}
return transform;
};
@@ -411,10 +425,10 @@ ol.Projection.getTransform = function(source, destination) {
* @param {string} destinationCode Destination code.
* @return {ol.TransformFunction} Transform.
*/
ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
var source = ol.Projection.getFromCode(sourceCode);
var destination = ol.Projection.getFromCode(destinationCode);
return ol.Projection.getTransform(source, destination);
ol.projection.getTransformFromCodes = function(sourceCode, destinationCode) {
var source = ol.projection.getFromCode(sourceCode);
var destination = ol.projection.getFromCode(destinationCode);
return ol.projection.getTransform(source, destination);
};
@@ -422,7 +436,7 @@ ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Unaltered point (same reference).
*/
ol.Projection.identityTransform = function(point) {
ol.projection.identityTransform = function(point) {
return point;
};
@@ -431,7 +445,7 @@ ol.Projection.identityTransform = function(point) {
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Equal point (different reference).
*/
ol.Projection.cloneTransform = function(point) {
ol.projection.cloneTransform = function(point) {
return new ol.Coordinate(point.x, point.y);
};
@@ -444,8 +458,8 @@ ol.Projection.cloneTransform = function(point) {
* @param {ol.Projection} destination Destination.
* @return {ol.Coordinate} Point.
*/
ol.Projection.transform = function(point, source, destination) {
var transformFn = ol.Projection.getTransform(source, destination);
ol.projection.transform = function(point, source, destination) {
var transformFn = ol.projection.getTransform(source, destination);
return transformFn(point);
};
@@ -456,149 +470,9 @@ ol.Projection.transform = function(point, source, destination) {
* @param {string} destinationCode Destination code.
* @return {ol.Coordinate} Point.
*/
ol.Projection.transformWithCodes =
ol.projection.transformWithCodes =
function(point, sourceCode, destinationCode) {
var transformFn = ol.Projection.getTransformFromCodes(
var transformFn = ol.projection.getTransformFromCodes(
sourceCode, destinationCode);
return transformFn(point);
};
/**
* @const
* @type {number}
*/
ol.Projection.EPSG_3857_RADIUS = 6378137;
/**
* Transformation from EPSG:4326 to EPSG:3857.
*
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Point.
*/
ol.Projection.forwardSphericalMercator = function(point) {
var x = ol.Projection.EPSG_3857_RADIUS * Math.PI * point.x / 180;
var y = ol.Projection.EPSG_3857_RADIUS *
Math.log(Math.tan(Math.PI * (point.y + 90) / 360));
return new ol.Coordinate(x, y);
};
/**
* Transformation from EPSG:3857 to EPSG:4326.
*
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Point.
*/
ol.Projection.inverseSphericalMercator = function(point) {
var x = 180 * point.x / (ol.Projection.EPSG_3857_RADIUS * Math.PI);
var y = 360 * Math.atan(
Math.exp(point.y / ol.Projection.EPSG_3857_RADIUS)) / Math.PI - 90;
return new ol.Coordinate(x, y);
};
/**
* @const
* @type {number}
*/
ol.Projection.EPSG_3857_HALF_SIZE = Math.PI * ol.Projection.EPSG_3857_RADIUS;
/**
* @const
* @type {ol.Extent}
*/
ol.Projection.EPSG_3857_EXTENT = new ol.Extent(
-ol.Projection.EPSG_3857_HALF_SIZE,
-ol.Projection.EPSG_3857_HALF_SIZE,
ol.Projection.EPSG_3857_HALF_SIZE,
ol.Projection.EPSG_3857_HALF_SIZE);
/**
* Lists several projection codes with the same meaning as EPSG:3857.
*
* @private
* @type {Array.<string>}
*/
ol.Projection.EPSG_3857_LIKE_CODES_ = [
'EPSG:3857',
'EPSG:102100',
'EPSG:102113',
'EPSG:900913'
];
/**
* Projections equal to EPSG:3857.
*
* @const
* @private
* @type {Array.<ol.Projection>}
*/
ol.Projection.EPSG_3857_LIKE_PROJECTIONS_ = goog.array.map(
ol.Projection.EPSG_3857_LIKE_CODES_,
function(code) {
return new ol.Projection(
code,
ol.ProjectionUnits.METERS,
ol.Projection.EPSG_3857_EXTENT);
});
/**
* Extent of the EPSG:4326 projection which is the whole world.
*
* @const
* @private
* @type {ol.Extent}
*/
ol.Projection.EPSG_4326_EXTENT_ = new ol.Extent(-180, -90, 180, 90);
/**
* Several projection code with the same meaning as EPSG:4326.
* @private
* @type {Array.<string>}
*/
ol.Projection.EPSG_4326_LIKE_CODES_ = [
'CRS:84',
'urn:ogc:def:crs:OGC:1.3:CRS84',
'EPSG:4326',
'urn:ogc:def:crs:EPSG:6.6:4326'
];
/**
* Projections equal to EPSG:4326.
*
* @const
* @type {Array.<ol.Projection>}
*/
ol.Projection.EPSG_4326_LIKE_PROJECTIONS = goog.array.map(
ol.Projection.EPSG_4326_LIKE_CODES_,
function(code) {
return new ol.Projection(
code,
ol.ProjectionUnits.DEGREES,
ol.Projection.EPSG_4326_EXTENT_,
code === 'CRS:84' || code === 'urn:ogc:def:crs:OGC:1.3:CRS84' ?
'enu' : 'neu');
});
// Add transformations that don't alter coordinates to convert within set of
// projections with equal meaning.
ol.Projection.addEquivalentProjections_(
ol.Projection.EPSG_3857_LIKE_PROJECTIONS_);
ol.Projection.addEquivalentProjections_(
ol.Projection.EPSG_4326_LIKE_PROJECTIONS);
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
// coordinates and back.
ol.Projection.addEquivalentTransforms_(
ol.Projection.EPSG_4326_LIKE_PROJECTIONS,
ol.Projection.EPSG_3857_LIKE_PROJECTIONS_,
ol.Projection.forwardSphericalMercator,
ol.Projection.inverseSphericalMercator);

View File

@@ -0,0 +1,23 @@
goog.provide('ol.projection.addCommonProjections');
goog.require('ol.projection');
goog.require('ol.projection.EPSG3857');
goog.require('ol.projection.EPSG4326');
/**
* FIXME empty description for jsdoc
*/
ol.projection.addCommonProjections = function() {
// Add transformations that don't alter coordinates to convert within set of
// projections with equal meaning.
ol.projection.addEquivalentProjections(ol.projection.EPSG3857.PROJECTIONS);
ol.projection.addEquivalentProjections(ol.projection.EPSG4326.PROJECTIONS);
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
// coordinates and back.
ol.projection.addEquivalentTransforms(
ol.projection.EPSG4326.PROJECTIONS,
ol.projection.EPSG3857.PROJECTIONS,
ol.projection.EPSG3857.fromEPSG4326,
ol.projection.EPSG3857.toEPSG4326);
};

View File

@@ -0,0 +1,98 @@
goog.provide('ol.projection.EPSG3857');
goog.require('goog.array');
goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.ProjectionUnits');
goog.require('ol.projection');
/**
* @constructor
* @extends {ol.Projection}
* @param {string} code Code.
*/
ol.projection.EPSG3857 = function(code) {
goog.base(
this, code, ol.ProjectionUnits.METERS, ol.projection.EPSG3857.EXTENT);
};
goog.inherits(ol.projection.EPSG3857, ol.Projection);
/**
* @const
* @type {number}
*/
ol.projection.EPSG3857.RADIUS = 6378137;
/**
* @const
* @type {number}
*/
ol.projection.EPSG3857.HALF_SIZE = Math.PI * ol.projection.EPSG3857.RADIUS;
/**
* @const
* @type {ol.Extent}
*/
ol.projection.EPSG3857.EXTENT = new ol.Extent(
-ol.projection.EPSG3857.HALF_SIZE, -ol.projection.EPSG3857.HALF_SIZE,
ol.projection.EPSG3857.HALF_SIZE, ol.projection.EPSG3857.HALF_SIZE);
/**
* Lists several projection codes with the same meaning as EPSG:3857.
*
* @type {Array.<string>}
*/
ol.projection.EPSG3857.CODES = [
'EPSG:3857',
'EPSG:102100',
'EPSG:102113',
'EPSG:900913'
];
/**
* Projections equal to EPSG:3857.
*
* @const
* @type {Array.<ol.Projection>}
*/
ol.projection.EPSG3857.PROJECTIONS = goog.array.map(
ol.projection.EPSG3857.CODES,
function(code) {
return new ol.projection.EPSG3857(code);
});
/**
* Transformation from EPSG:4326 to EPSG:3857.
*
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Point.
*/
ol.projection.EPSG3857.fromEPSG4326 = function(point) {
var x = ol.projection.EPSG3857.RADIUS * Math.PI * point.x / 180;
var y = ol.projection.EPSG3857.RADIUS *
Math.log(Math.tan(Math.PI * (point.y + 90) / 360));
return new ol.Coordinate(x, y);
};
/**
* Transformation from EPSG:3857 to EPSG:4326.
*
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Point.
*/
ol.projection.EPSG3857.toEPSG4326 = function(point) {
var x = 180 * point.x / (ol.projection.EPSG3857.RADIUS * Math.PI);
var y = 360 * Math.atan(
Math.exp(point.y / ol.projection.EPSG3857.RADIUS)) / Math.PI - 90;
return new ol.Coordinate(x, y);
};

View File

@@ -0,0 +1,43 @@
goog.provide('ol.projection.EPSG4326');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.ProjectionUnits');
goog.require('ol.projection');
/**
* @constructor
* @extends {ol.Projection}
* @param {string} code Code.
* @param {string=} opt_axisOrientation Axis orientation.
*/
ol.projection.EPSG4326 = function(code, opt_axisOrientation) {
goog.base(this, code, ol.ProjectionUnits.DEGREES,
ol.projection.EPSG4326.EXTENT, opt_axisOrientation);
};
goog.inherits(ol.projection.EPSG4326, ol.Projection);
/**
* Extent of the EPSG:4326 projection which is the whole world.
*
* @const
* @type {ol.Extent}
*/
ol.projection.EPSG4326.EXTENT = new ol.Extent(-180, -90, 180, 90);
/**
* Projections equal to EPSG:4326.
*
* @const
* @type {Array.<ol.Projection>}
*/
ol.projection.EPSG4326.PROJECTIONS = [
new ol.projection.EPSG4326('CRS:84'),
new ol.projection.EPSG4326('EPSG:4326', 'neu'),
new ol.projection.EPSG4326('urn:ogc:def:crs:EPSG:6.6:4326', 'neu'),
new ol.projection.EPSG4326('urn:ogc:def:crs:OGC:1.3:CRS84')
];

View File

@@ -6,11 +6,11 @@ goog.require('goog.array');
goog.require('goog.net.Jsonp');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.Size');
goog.require('ol.TileCoord');
goog.require('ol.TileRange');
goog.require('ol.TileUrlFunction');
goog.require('ol.projection');
goog.require('ol.source.ImageTileSource');
goog.require('ol.tilegrid.XYZ');
@@ -36,7 +36,7 @@ ol.BingMapsStyle = {
ol.source.BingMaps = function(bingMapsOptions) {
goog.base(this, {
projection: ol.Projection.getFromCode('EPSG:3857')
projection: ol.projection.getFromCode('EPSG:3857')
});
/**
@@ -123,8 +123,8 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
};
})));
var transform = ol.Projection.getTransform(
ol.Projection.getFromCode('EPSG:4326'), this.getProjection());
var transform = ol.projection.getTransform(
ol.projection.getFromCode('EPSG:4326'), this.getProjection());
var attributions = goog.array.map(
resource.imageryProviders,
function(imageryProvider) {

View File

@@ -4,8 +4,8 @@ goog.require('goog.uri.utils');
goog.require('ol.Extent');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.Projection');
goog.require('ol.Size');
goog.require('ol.projection');
goog.require('ol.source.ImageSource');
@@ -17,7 +17,7 @@ goog.require('ol.source.ImageSource');
*/
ol.source.SingleImageWMS = function(options) {
var projection = ol.Projection.createProjection(
var projection = ol.projection.createProjection(
options.projection, 'EPSG:3857');
var projectionExtent = projection.getExtent();
@@ -38,11 +38,13 @@ ol.source.SingleImageWMS = function(options) {
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
goog.object.extend(baseParams, options.params);
var axisOrientation = projection.getAxisOrientation();
var imageUrlFunction;
if (options.url) {
var url = goog.uri.utils.appendParamsFromMap(
options.url, baseParams);
imageUrlFunction = ol.ImageUrlFunction.createBboxParam(url);
imageUrlFunction =
ol.ImageUrlFunction.createBboxParam(url, axisOrientation);
} else {
imageUrlFunction =
ol.ImageUrlFunction.nullImageUrlFunction;

View File

@@ -7,9 +7,9 @@ goog.require('goog.array');
goog.require('goog.object');
goog.require('goog.uri.utils');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.projection');
goog.require('ol.source.ImageTileSource');
@@ -20,7 +20,7 @@ goog.require('ol.source.ImageTileSource');
* @param {ol.source.TiledWMSOptions} tiledWMSOptions options.
*/
ol.source.TiledWMS = function(tiledWMSOptions) {
var projection = ol.Projection.createProjection(
var projection = ol.projection.createProjection(
tiledWMSOptions.projection, 'EPSG:3857');
var projectionExtent = projection.getExtent();
@@ -52,19 +52,22 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
goog.object.extend(baseParams, tiledWMSOptions.params);
var axisOrientation = projection.getAxisOrientation();
var tileUrlFunction;
if (tiledWMSOptions.urls) {
var tileUrlFunctions = goog.array.map(
tiledWMSOptions.urls, function(url) {
url = goog.uri.utils.appendParamsFromMap(url, baseParams);
return ol.TileUrlFunction.createBboxParam(url, tileGrid);
return ol.TileUrlFunction.createBboxParam(
url, tileGrid, axisOrientation);
});
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
tileUrlFunctions);
} else if (tiledWMSOptions.url) {
var url = goog.uri.utils.appendParamsFromMap(
tiledWMSOptions.url, baseParams);
tileUrlFunction = ol.TileUrlFunction.createBboxParam(url, tileGrid);
tileUrlFunction =
ol.TileUrlFunction.createBboxParam(url, tileGrid, axisOrientation);
} else {
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
}

View File

@@ -13,10 +13,10 @@ goog.require('goog.asserts');
goog.require('goog.net.jsloader');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.TileCoord');
goog.require('ol.TileRange');
goog.require('ol.TileUrlFunction');
goog.require('ol.projection');
goog.require('ol.source.ImageTileSource');
goog.require('ol.tilegrid.XYZ');
@@ -52,7 +52,7 @@ goog.exportSymbol('grid', grid);
ol.source.TileJSON = function(tileJsonOptions) {
goog.base(this, {
projection: ol.Projection.getFromCode('EPSG:3857')
projection: ol.projection.getFromCode('EPSG:3857')
});
/**
@@ -80,7 +80,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
var tileJSON = ol.tilejson.grids_.pop();
var epsg4326Projection = ol.Projection.getFromCode('EPSG:4326');
var epsg4326Projection = ol.projection.getFromCode('EPSG:4326');
var epsg4326Extent, extent;
if (goog.isDef(tileJSON.bounds)) {
@@ -88,7 +88,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
epsg4326Extent = new ol.Extent(
bounds[0], bounds[1], bounds[2], bounds[3]);
extent = epsg4326Extent.transform(
ol.Projection.getTransform(epsg4326Projection, this.getProjection()));
ol.projection.getTransform(epsg4326Projection, this.getProjection()));
this.setExtent(extent);
} else {
epsg4326Extent = null;

View File

@@ -10,6 +10,7 @@ goog.require('ol.Projection');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
goog.require('ol.projection');
goog.require('ol.source.ImageTileSource');
goog.require('ol.tilegrid.XYZ');
@@ -36,7 +37,7 @@ ol.source.XYZOptions;
ol.source.XYZ = function(xyzOptions) {
var projection = xyzOptions.projection ||
ol.Projection.getFromCode('EPSG:3857');
ol.projection.getFromCode('EPSG:3857');
/**
* @type {ol.TileUrlFunctionType}

View File

@@ -1,9 +1,10 @@
goog.provide('ol.tilegrid.XYZ');
goog.require('ol.Coordinate');
goog.require('ol.Projection');
goog.require('ol.Size');
goog.require('ol.TileRange');
goog.require('ol.projection');
goog.require('ol.projection.EPSG3857');
goog.require('ol.tilegrid.TileGrid');
@@ -17,15 +18,14 @@ ol.tilegrid.XYZ = function(xyzOptions) {
var resolutions = new Array(xyzOptions.maxZoom + 1);
var z;
var size = 2 * ol.Projection.EPSG_3857_HALF_SIZE / ol.DEFAULT_TILE_SIZE;
var size = 2 * ol.projection.EPSG3857.HALF_SIZE / ol.DEFAULT_TILE_SIZE;
for (z = 0; z <= xyzOptions.maxZoom; ++z) {
resolutions[z] = size / Math.pow(2, z);
}
goog.base(this, {
extent: ol.Projection.EPSG_3857_EXTENT,
origin: new ol.Coordinate(-ol.Projection.EPSG_3857_HALF_SIZE,
ol.Projection.EPSG_3857_HALF_SIZE),
origin: new ol.Coordinate(-ol.projection.EPSG3857.HALF_SIZE,
ol.projection.EPSG3857.HALF_SIZE),
resolutions: resolutions,
tileSize: new ol.Size(ol.DEFAULT_TILE_SIZE, ol.DEFAULT_TILE_SIZE)
});

View File

@@ -73,19 +73,20 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
/**
* @param {string} baseUrl Base URL (may have query data).
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @param {string} axisOrientation Axis orientation.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.createBboxParam = function(baseUrl, tileGrid) {
ol.TileUrlFunction.createBboxParam =
function(baseUrl, tileGrid, axisOrientation) {
return function(tileCoord) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
// FIXME Projection dependant axis order.
var bboxValue = [
tileExtent.minX, tileExtent.minY, tileExtent.maxX, tileExtent.maxY
].join(',');
return goog.uri.utils.appendParam(baseUrl, 'BBOX', bboxValue);
var bboxValues = axisOrientation.substr(0, 2) == 'ne' ?
[tileExtent.minY, tileExtent.minX, tileExtent.maxY, tileExtent.maxX] :
[tileExtent.minX, tileExtent.minY, tileExtent.maxX, tileExtent.maxY];
return goog.uri.utils.appendParam(baseUrl, 'BBOX', bboxValues.join(','));
}
};
};

View File

@@ -15,6 +15,7 @@ goog.require('ol.RotationConstraint');
goog.require('ol.Size');
goog.require('ol.View');
goog.require('ol.animation');
goog.require('ol.projection');
/**
@@ -46,7 +47,7 @@ ol.View2D = function(opt_view2DOptions) {
var values = {};
values[ol.View2DProperty.CENTER] = goog.isDef(view2DOptions.center) ?
view2DOptions.center : null;
values[ol.View2DProperty.PROJECTION] = ol.Projection.createProjection(
values[ol.View2DProperty.PROJECTION] = ol.projection.createProjection(
view2DOptions.projection, 'EPSG:3857');
if (goog.isDef(view2DOptions.resolution)) {
values[ol.View2DProperty.RESOLUTION] = view2DOptions.resolution;
@@ -353,7 +354,7 @@ ol.View2D.createConstraints_ = function(view2DOptions) {
numZoomLevels = view2DOptions.numZoomLevels;
zoomFactor = view2DOptions.zoomFactor;
} else {
var projectionExtent = ol.Projection.createProjection(
var projectionExtent = ol.projection.createProjection(
view2DOptions.projection, 'EPSG:3857').getExtent();
maxResolution = Math.max(
projectionExtent.maxX - projectionExtent.minX,