Merge pull request #1640 from tschaub/reproject

Use projection option instead of reprojectTo for vector file sources.  The projection of the vector source represents the projection of the cached features.
This commit is contained in:
Tim Schaub
2014-02-04 17:07:59 -08:00
9 changed files with 28 additions and 31 deletions

View File

@@ -46,7 +46,7 @@ var style = {
var vector = new ol.layer.Vector({
source: new ol.source.GPX({
reprojectTo: 'EPSG:3857',
projection: 'EPSG:3857',
url: 'data/gpx/fells_loop.gpx'
}),
styleFunction: function(feature, resolution) {

View File

@@ -40,7 +40,7 @@ var styleFunction = function(feature, resolution) {
var vector = new ol.layer.Vector({
source: new ol.source.KML({
reprojectTo: 'EPSG:3857',
projection: 'EPSG:3857',
url: 'data/kml/2012_Earthquakes_Mag5.kml'
}),
styleFunction: styleFunction

View File

@@ -15,7 +15,7 @@ var raster = new ol.layer.Tile({
var vector = new ol.layer.Vector({
source: new ol.source.KML({
reprojectTo: 'EPSG:3857',
projection: 'EPSG:3857',
url: 'data/kml/2012-02-10.kml'
})
});

View File

@@ -579,8 +579,9 @@
* @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo.
* @property {GeoJSONObject|undefined} object Object.
* @property {ol.proj.ProjectionLike} projection Projection.
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to.
* @property {ol.proj.ProjectionLike} projection Destination projection. If
* provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text.
* @property {string|undefined} url URL.
* @property {Array.<string>|undefined} urls URLs.
@@ -593,8 +594,9 @@
* @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo.
* @property {Node|undefined| node Node.
* @property {ol.proj.ProjectionLike} projection Projection.
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to.
* @property {ol.proj.ProjectionLike} projection Destination projection. If
* provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text.
* @property {string|undefined} url URL.
* @property {Array.<string>|undefined} urls URLs.
@@ -607,8 +609,9 @@
* @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo.
* @property {GeoJSONObject|undefined} object Object.
* @property {ol.proj.ProjectionLike} projection Projection.
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to.
* @property {ol.proj.ProjectionLike} projection Destination projection. If
* provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text.
* @property {string|undefined} url URL.
*/
@@ -649,8 +652,9 @@
* @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo.
* @property {Node|undefined| node Node.
* @property {ol.proj.ProjectionLike} projection Projection.
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to.
* @property {ol.proj.ProjectionLike} projection Destination projection. If
* provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text.
* @property {string|undefined} url URL.
* @property {Array.<string>|undefined} urls URLs.

View File

@@ -24,7 +24,6 @@ ol.source.GeoJSON = function(opt_options) {
logo: options.logo,
object: options.object,
projection: options.projection,
reprojectTo: options.reprojectTo,
text: options.text,
url: options.url,
urls: options.urls

View File

@@ -23,7 +23,6 @@ ol.source.GPX = function(opt_options) {
logo: options.logo,
node: options.node,
projection: options.projection,
reprojectTo: options.reprojectTo,
text: options.text,
url: options.url,
urls: options.urls

View File

@@ -25,7 +25,6 @@ ol.source.KML = function(opt_options) {
logo: options.logo,
node: options.node,
projection: options.projection,
reprojectTo: options.reprojectTo,
text: options.text,
url: options.url,
urls: options.urls

View File

@@ -24,7 +24,6 @@ ol.source.TopoJSON = function(opt_options) {
logo: options.logo,
object: options.object,
projection: options.projection,
reprojectTo: options.reprojectTo,
text: options.text,
url: options.url
});

View File

@@ -1,4 +1,5 @@
// FIXME remove reprojectTo
// FIXME consider delaying feature reading so projection can be provided by
// consumer (e.g. the view)
goog.provide('ol.source.VectorFile');
@@ -35,13 +36,6 @@ ol.source.VectorFile = function(opt_options) {
*/
this.format = options.format;
/**
* @type {ol.proj.Projection}
* @private
*/
this.reprojectTo_ = goog.isDef(options.reprojectTo) ?
ol.proj.get(options.reprojectTo) : ol.proj.get('EPSG:3857');
if (goog.isDef(options.doc)) {
this.readFeatures_(options.doc);
}
@@ -121,14 +115,17 @@ ol.source.VectorFile.prototype.readFeatures_ = function(source) {
var format = this.format;
var features = format.readFeatures(source);
var featureProjection = format.readProjection(source);
if (!ol.proj.equivalent(featureProjection, this.reprojectTo_)) {
var transform = ol.proj.getTransform(featureProjection, this.reprojectTo_);
var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) {
var feature = features[i];
var geometry = feature.getGeometry();
if (!goog.isNull(geometry)) {
geometry.transform(transform);
var projection = this.getProjection();
if (!goog.isNull(projection)) {
if (!ol.proj.equivalent(featureProjection, projection)) {
var transform = ol.proj.getTransform(featureProjection, projection);
var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) {
var feature = features[i];
var geometry = feature.getGeometry();
if (!goog.isNull(geometry)) {
geometry.transform(transform);
}
}
}
}