Use projection option instead of reprojectTo

The projection option for vector file sources currently has no good meaning.  The reprojectTo option is used to set the projection for cached features.  This change makes it so the projection option is used for this purpose.  The getProjection method (not currently exported) can then be used to get the cached feature projection.

This also removes the default of 'EPSG:3857' for vector file sources.  If a projection is not configured, features will not be transformed.
This commit is contained in:
Tim Schaub
2014-02-03 18:10:52 -07:00
parent b567b888b0
commit d2cd0808a8
9 changed files with 28 additions and 31 deletions

View File

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

View File

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

View File

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

View File

@@ -571,8 +571,9 @@
* @property {ol.Extent|undefined} extent Extent. * @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo. * @property {string|undefined} logo Logo.
* @property {GeoJSONObject|undefined} object Object. * @property {GeoJSONObject|undefined} object Object.
* @property {ol.proj.ProjectionLike} projection Projection. * @property {ol.proj.ProjectionLike} projection Destination projection. If
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to. * provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text. * @property {string|undefined} text Text.
* @property {string|undefined} url URL. * @property {string|undefined} url URL.
* @property {Array.<string>|undefined} urls URLs. * @property {Array.<string>|undefined} urls URLs.
@@ -585,8 +586,9 @@
* @property {ol.Extent|undefined} extent Extent. * @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo. * @property {string|undefined} logo Logo.
* @property {Node|undefined| node Node. * @property {Node|undefined| node Node.
* @property {ol.proj.ProjectionLike} projection Projection. * @property {ol.proj.ProjectionLike} projection Destination projection. If
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to. * provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text. * @property {string|undefined} text Text.
* @property {string|undefined} url URL. * @property {string|undefined} url URL.
* @property {Array.<string>|undefined} urls URLs. * @property {Array.<string>|undefined} urls URLs.
@@ -599,8 +601,9 @@
* @property {ol.Extent|undefined} extent Extent. * @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo. * @property {string|undefined} logo Logo.
* @property {GeoJSONObject|undefined} object Object. * @property {GeoJSONObject|undefined} object Object.
* @property {ol.proj.ProjectionLike} projection Projection. * @property {ol.proj.ProjectionLike} projection Destination projection. If
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to. * provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text. * @property {string|undefined} text Text.
* @property {string|undefined} url URL. * @property {string|undefined} url URL.
*/ */
@@ -641,8 +644,9 @@
* @property {ol.Extent|undefined} extent Extent. * @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo. * @property {string|undefined} logo Logo.
* @property {Node|undefined| node Node. * @property {Node|undefined| node Node.
* @property {ol.proj.ProjectionLike} projection Projection. * @property {ol.proj.ProjectionLike} projection Destination projection. If
* @property {ol.proj.ProjectionLike} reprojectTo Re-project to. * provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {string|undefined} text Text. * @property {string|undefined} text Text.
* @property {string|undefined} url URL. * @property {string|undefined} url URL.
* @property {Array.<string>|undefined} urls URLs. * @property {Array.<string>|undefined} urls URLs.

View File

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

View File

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

View File

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

View File

@@ -24,7 +24,6 @@ ol.source.TopoJSON = function(opt_options) {
logo: options.logo, logo: options.logo,
object: options.object, object: options.object,
projection: options.projection, projection: options.projection,
reprojectTo: options.reprojectTo,
text: options.text, text: options.text,
url: options.url 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'); goog.provide('ol.source.VectorFile');
@@ -35,13 +36,6 @@ ol.source.VectorFile = function(opt_options) {
*/ */
this.format = options.format; 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)) { if (goog.isDef(options.doc)) {
this.readFeatures_(options.doc); this.readFeatures_(options.doc);
} }
@@ -121,14 +115,17 @@ ol.source.VectorFile.prototype.readFeatures_ = function(source) {
var format = this.format; var format = this.format;
var features = format.readFeatures(source); var features = format.readFeatures(source);
var featureProjection = format.readProjection(source); var featureProjection = format.readProjection(source);
if (!ol.proj.equivalent(featureProjection, this.reprojectTo_)) { var projection = this.getProjection();
var transform = ol.proj.getTransform(featureProjection, this.reprojectTo_); if (!goog.isNull(projection)) {
var i, ii; if (!ol.proj.equivalent(featureProjection, projection)) {
for (i = 0, ii = features.length; i < ii; ++i) { var transform = ol.proj.getTransform(featureProjection, projection);
var feature = features[i]; var i, ii;
var geometry = feature.getGeometry(); for (i = 0, ii = features.length; i < ii; ++i) {
if (!goog.isNull(geometry)) { var feature = features[i];
geometry.transform(transform); var geometry = feature.getGeometry();
if (!goog.isNull(geometry)) {
geometry.transform(transform);
}
} }
} }
} }