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:
+1
-1
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
+1
-1
@@ -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'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -579,8 +579,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.
|
||||||
@@ -593,8 +594,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.
|
||||||
@@ -607,8 +609,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.
|
||||||
*/
|
*/
|
||||||
@@ -649,8 +652,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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user