Remove experimental ol.format code
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
goog.provide('ol.format');
|
||||
|
||||
|
||||
/**
|
||||
* @param {function(Object, function(this: S, ol.Feature): T, S=)} reader
|
||||
* Reader.
|
||||
* @param {Object} object Object.
|
||||
* @return {Array.<ol.Feature>}
|
||||
* @template S,T
|
||||
*/
|
||||
ol.format.readAllFromObject = function(reader, object) {
|
||||
var features = [];
|
||||
reader(object, function(feature) {
|
||||
features.push(feature);
|
||||
});
|
||||
return features;
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
@exportClass ol.format.GeoJSON ol.format.GeoJSONOptions
|
||||
@exportProperty ol.format.GeoJSON.prototype.readObject
|
||||
@exportProperty ol.format.GeoJSON.prototype.readString
|
||||
@@ -1,171 +0,0 @@
|
||||
// FIXME coordinate order
|
||||
// FIXME reprojection
|
||||
// FIXME support other geometry types
|
||||
|
||||
goog.provide('ol.format.GeoJSON');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.json');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.format.IReader');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.format.IReader}
|
||||
* @param {ol.format.GeoJSONOptions=} opt_options Options.
|
||||
*/
|
||||
ol.format.GeoJSON = function(opt_options) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} geometry Geometry.
|
||||
* @private
|
||||
* @return {ol.geom.Point} Point.
|
||||
*/
|
||||
ol.format.GeoJSON.readPointGeometry_ = function(geometry) {
|
||||
goog.asserts.assert(geometry.type == 'Point');
|
||||
return new ol.geom.Point(geometry.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} geometry Geometry.
|
||||
* @private
|
||||
* @return {ol.geom.LineString} LineString.
|
||||
*/
|
||||
ol.format.GeoJSON.readLineStringGeometry_ = function(geometry) {
|
||||
goog.asserts.assert(geometry.type == 'LineString');
|
||||
return new ol.geom.LineString(geometry.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} geometry Geometry.
|
||||
* @private
|
||||
* @return {ol.geom.MultiLineString} MultiLineString.
|
||||
*/
|
||||
ol.format.GeoJSON.readMultiLineStringGeometry_ = function(geometry) {
|
||||
goog.asserts.assert(geometry.type == 'MultiLineString');
|
||||
return new ol.geom.MultiLineString(geometry.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} geometry Geometry.
|
||||
* @private
|
||||
* @return {ol.geom.MultiPolygon} MultiPolygon.
|
||||
*/
|
||||
ol.format.GeoJSON.readMultiPolygonGeometry_ = function(geometry) {
|
||||
goog.asserts.assert(geometry.type == 'MultiPolygon');
|
||||
return new ol.geom.MultiPolygon(geometry.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} geometry Geometry.
|
||||
* @private
|
||||
* @return {ol.geom.Polygon} Polygon.
|
||||
*/
|
||||
ol.format.GeoJSON.readPolygonGeometry_ = function(geometry) {
|
||||
goog.asserts.assert(geometry.type == 'Polygon');
|
||||
return new ol.geom.Polygon(geometry.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONObject} object Object.
|
||||
* @param {function(this: S, ol.Feature): T} callback Callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
* @private
|
||||
* @return {T} Callback result.
|
||||
* @template S,T
|
||||
*/
|
||||
ol.format.GeoJSON.readFeature_ = function(object, callback, opt_obj) {
|
||||
goog.asserts.assert(object.type == 'Feature');
|
||||
var feature = /** @type {GeoJSONFeature} */ (object);
|
||||
var geometryReader =
|
||||
ol.format.GeoJSON.GEOMETRY_READERS_[feature.geometry.type];
|
||||
goog.asserts.assert(goog.isDef(geometryReader));
|
||||
var geometry = geometryReader(feature.geometry);
|
||||
var f = new ol.Feature(geometry);
|
||||
f.setId(feature.id);
|
||||
if (goog.isDef(feature.properties)) {
|
||||
f.setValues(feature.properties);
|
||||
}
|
||||
return callback.call(opt_obj, f);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONObject} object Object.
|
||||
* @param {function(this: S, ol.Feature): T} callback Callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
* @private
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template S,T
|
||||
*/
|
||||
ol.format.GeoJSON.readFeatureCollection_ = function(object, callback, opt_obj) {
|
||||
goog.asserts.assert(object.type == 'FeatureCollection');
|
||||
var featureCollection = /** @type {GeoJSONFeatureCollection} */ (object);
|
||||
var features = featureCollection.features;
|
||||
var i, ii;
|
||||
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||
var result = ol.format.GeoJSON.readFeature_(features[i], callback, opt_obj);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GeoJSON.prototype.readObject = function(object, callback, opt_obj) {
|
||||
var geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||
var objectReader = ol.format.GeoJSON.OBJECT_READERS_[geoJSONObject.type];
|
||||
goog.asserts.assert(goog.isDef(objectReader));
|
||||
return objectReader(geoJSONObject, callback, opt_obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GeoJSON.prototype.readString = function(string, callback, opt_obj) {
|
||||
return this.readObject(goog.json.parse(string), callback, opt_obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @private
|
||||
* @type {Object.<string, function(GeoJSONGeometry): ol.geom.Geometry>}
|
||||
*/
|
||||
ol.format.GeoJSON.GEOMETRY_READERS_ = {
|
||||
'Point': ol.format.GeoJSON.readPointGeometry_,
|
||||
'LineString': ol.format.GeoJSON.readLineStringGeometry_,
|
||||
'Polygon': ol.format.GeoJSON.readPolygonGeometry_,
|
||||
'MultiLineString': ol.format.GeoJSON.readMultiLineStringGeometry_,
|
||||
'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @private
|
||||
* @type {Object.<string, function(GeoJSONObject, function(ol.Feature): *, *): *>}
|
||||
*/
|
||||
ol.format.GeoJSON.OBJECT_READERS_ = {
|
||||
'Feature': ol.format.GeoJSON.readFeature_,
|
||||
'FeatureCollection': ol.format.GeoJSON.readFeatureCollection_
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
// FIXME add XML
|
||||
// FIXME add IWriter
|
||||
|
||||
goog.provide('ol.format.IReader');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.format.IReader = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} object Object.
|
||||
* @param {function(this: S, ol.Feature): T} callback Callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template S,T
|
||||
*/
|
||||
ol.format.IReader.prototype.readObject = function(object, callback, opt_obj) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} string String.
|
||||
* @param {function(this: S, ol.Feature): T} callback Callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template S,T
|
||||
*/
|
||||
ol.format.IReader.prototype.readString = function(string, callback, opt_obj) {
|
||||
};
|
||||
@@ -1,113 +0,0 @@
|
||||
goog.provide('ol.test.reader.GeoJSON');
|
||||
|
||||
|
||||
describe('ol.format.GeoJSON', function() {
|
||||
|
||||
var pointGeoJSON = {
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [102.0, 0.5]
|
||||
},
|
||||
'properties': {
|
||||
'prop0': 'value0'
|
||||
}
|
||||
};
|
||||
|
||||
var lineStringGeoJSON = {
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'LineString',
|
||||
'coordinates': [
|
||||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
|
||||
]
|
||||
},
|
||||
'properties': {
|
||||
'prop0': 'value0',
|
||||
'prop1': 0.0
|
||||
}
|
||||
};
|
||||
|
||||
var polygonGeoJSON = {
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Polygon',
|
||||
'coordinates': [[
|
||||
[100.0, 0.0], [100.0, 1.0], [101.0, 1.0], [101.0, 0.0]
|
||||
]]
|
||||
},
|
||||
'properties': {
|
||||
'prop0': 'value0',
|
||||
'prop1': {'this': 'that'}
|
||||
}
|
||||
};
|
||||
|
||||
var featureCollectionGeoJSON = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [pointGeoJSON, lineStringGeoJSON, polygonGeoJSON]
|
||||
};
|
||||
|
||||
var format = new ol.format.GeoJSON();
|
||||
|
||||
describe('readObject', function() {
|
||||
|
||||
it('can read a single point feature', function() {
|
||||
var feature = format.readObject(pointGeoJSON, function(f) {
|
||||
return f;
|
||||
});
|
||||
expect(feature).to.be.an(ol.Feature);
|
||||
var geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.an(ol.geom.Point);
|
||||
expect(geometry.getCoordinates()).to.eql([102.0, 0.5]);
|
||||
expect(feature.get('prop0')).to.be('value0');
|
||||
});
|
||||
|
||||
it('can read a single line string feature', function() {
|
||||
var feature = format.readObject(lineStringGeoJSON,
|
||||
function(f) {
|
||||
return f;
|
||||
});
|
||||
expect(feature).to.be.an(ol.Feature);
|
||||
var geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.an(ol.geom.LineString);
|
||||
expect(geometry.getCoordinates()).to.eql(
|
||||
[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]);
|
||||
expect(feature.get('prop0')).to.be('value0');
|
||||
expect(feature.get('prop1')).to.be(0.0);
|
||||
});
|
||||
|
||||
it('can read a single polygon feature', function() {
|
||||
var feature = format.readObject(polygonGeoJSON, function(f) {
|
||||
return f;
|
||||
});
|
||||
expect(feature).to.be.an(ol.Feature);
|
||||
var geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.an(ol.geom.Polygon);
|
||||
expect(geometry.getCoordinates()).to.eql([[
|
||||
[100.0, 0.0], [100.0, 1.0], [101.0, 1.0], [101.0, 0.0]
|
||||
]]);
|
||||
expect(feature.get('prop0')).to.be('value0');
|
||||
expect(feature.get('prop1')).to.eql({'this': 'that'});
|
||||
});
|
||||
|
||||
it('can read a feature collection', function() {
|
||||
var features = [];
|
||||
format.readObject(featureCollectionGeoJSON, function(f) {
|
||||
features.push(f);
|
||||
});
|
||||
expect(features).to.have.length(3);
|
||||
expect(features[0].getGeometry()).to.be.an(ol.geom.Point);
|
||||
expect(features[1].getGeometry()).to.be.an(ol.geom.LineString);
|
||||
expect(features[2].getGeometry()).to.be.an(ol.geom.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.format.GeoJSON');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
Reference in New Issue
Block a user