Rename ol.reader to ol.format

This commit is contained in:
Tom Payne
2013-11-08 19:57:27 +01:00
parent 8aa6eb5cb7
commit 979d35b3b3
4 changed files with 34 additions and 34 deletions

View File

@@ -1,9 +1,9 @@
goog.require('ol.Map'); goog.require('ol.Map');
goog.require('ol.RendererHint'); goog.require('ol.RendererHint');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.format.GeoJSON');
goog.require('ol.layer.Tile'); goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector'); goog.require('ol.layer.Vector');
goog.require('ol.reader.GeoJSON');
goog.require('ol.source.OSM'); goog.require('ol.source.OSM');
goog.require('ol.source.Vector'); goog.require('ol.source.Vector');
goog.require('ol.style.DefaultStyleFunction'); goog.require('ol.style.DefaultStyleFunction');
@@ -31,7 +31,7 @@ var styleFunction = function(feature) {
}; };
var vectorSource = new ol.source.Vector(); var vectorSource = new ol.source.Vector();
ol.reader.GeoJSON.readObject({ ol.format.GeoJSON.readObject({
'type': 'FeatureCollection', 'type': 'FeatureCollection',
'features': [ 'features': [
{ {

View File

@@ -1,4 +1,4 @@
goog.provide('ol.reader'); goog.provide('ol.format');
/** /**
@@ -8,7 +8,7 @@ goog.provide('ol.reader');
* @return {Array.<ol.Feature>} * @return {Array.<ol.Feature>}
* @template S,T * @template S,T
*/ */
ol.reader.readAllFromObject = function(reader, object) { ol.format.readAllFromObject = function(reader, object) {
var features = []; var features = [];
reader(object, function(feature) { reader(object, function(feature) {
features.push(feature); features.push(feature);

View File

@@ -2,7 +2,7 @@
// FIXME reprojection // FIXME reprojection
// FIXME support other geometry types // FIXME support other geometry types
goog.provide('ol.reader.GeoJSON'); goog.provide('ol.format.GeoJSON');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.json'); goog.require('goog.json');
@@ -18,7 +18,7 @@ goog.require('ol.geom.Polygon');
/** /**
* @constructor * @constructor
*/ */
ol.reader.GeoJSON = function() { ol.format.GeoJSON = function() {
}; };
@@ -27,7 +27,7 @@ ol.reader.GeoJSON = function() {
* @private * @private
* @return {ol.geom.Point} Point. * @return {ol.geom.Point} Point.
*/ */
ol.reader.GeoJSON.readPointGeometry_ = function(geometry) { ol.format.GeoJSON.readPointGeometry_ = function(geometry) {
goog.asserts.assert(geometry.type == 'Point'); goog.asserts.assert(geometry.type == 'Point');
return new ol.geom.Point(geometry.coordinates); return new ol.geom.Point(geometry.coordinates);
}; };
@@ -38,7 +38,7 @@ ol.reader.GeoJSON.readPointGeometry_ = function(geometry) {
* @private * @private
* @return {ol.geom.LineString} LineString. * @return {ol.geom.LineString} LineString.
*/ */
ol.reader.GeoJSON.readLineStringGeometry_ = function(geometry) { ol.format.GeoJSON.readLineStringGeometry_ = function(geometry) {
goog.asserts.assert(geometry.type == 'LineString'); goog.asserts.assert(geometry.type == 'LineString');
return new ol.geom.LineString(geometry.coordinates); return new ol.geom.LineString(geometry.coordinates);
}; };
@@ -49,7 +49,7 @@ ol.reader.GeoJSON.readLineStringGeometry_ = function(geometry) {
* @private * @private
* @return {ol.geom.MultiLineString} MultiLineString. * @return {ol.geom.MultiLineString} MultiLineString.
*/ */
ol.reader.GeoJSON.readMultiLineStringGeometry_ = function(geometry) { ol.format.GeoJSON.readMultiLineStringGeometry_ = function(geometry) {
goog.asserts.assert(geometry.type == 'MultiLineString'); goog.asserts.assert(geometry.type == 'MultiLineString');
return new ol.geom.MultiLineString(geometry.coordinates); return new ol.geom.MultiLineString(geometry.coordinates);
}; };
@@ -60,7 +60,7 @@ ol.reader.GeoJSON.readMultiLineStringGeometry_ = function(geometry) {
* @private * @private
* @return {ol.geom.MultiPolygon} MultiPolygon. * @return {ol.geom.MultiPolygon} MultiPolygon.
*/ */
ol.reader.GeoJSON.readMultiPolygonGeometry_ = function(geometry) { ol.format.GeoJSON.readMultiPolygonGeometry_ = function(geometry) {
goog.asserts.assert(geometry.type == 'MultiPolygon'); goog.asserts.assert(geometry.type == 'MultiPolygon');
return new ol.geom.MultiPolygon(geometry.coordinates); return new ol.geom.MultiPolygon(geometry.coordinates);
}; };
@@ -71,7 +71,7 @@ ol.reader.GeoJSON.readMultiPolygonGeometry_ = function(geometry) {
* @private * @private
* @return {ol.geom.Polygon} Polygon. * @return {ol.geom.Polygon} Polygon.
*/ */
ol.reader.GeoJSON.readPolygonGeometry_ = function(geometry) { ol.format.GeoJSON.readPolygonGeometry_ = function(geometry) {
goog.asserts.assert(geometry.type == 'Polygon'); goog.asserts.assert(geometry.type == 'Polygon');
return new ol.geom.Polygon(geometry.coordinates); return new ol.geom.Polygon(geometry.coordinates);
}; };
@@ -85,11 +85,11 @@ ol.reader.GeoJSON.readPolygonGeometry_ = function(geometry) {
* @return {T} Callback result. * @return {T} Callback result.
* @template S,T * @template S,T
*/ */
ol.reader.GeoJSON.readFeature_ = function(object, callback, opt_obj) { ol.format.GeoJSON.readFeature_ = function(object, callback, opt_obj) {
goog.asserts.assert(object.type == 'Feature'); goog.asserts.assert(object.type == 'Feature');
var feature = /** @type {GeoJSONFeature} */ (object); var feature = /** @type {GeoJSONFeature} */ (object);
var geometryReader = var geometryReader =
ol.reader.GeoJSON.GEOMETRY_READERS_[feature.geometry.type]; ol.format.GeoJSON.GEOMETRY_READERS_[feature.geometry.type];
goog.asserts.assert(goog.isDef(geometryReader)); goog.asserts.assert(goog.isDef(geometryReader));
var geometry = geometryReader(feature.geometry); var geometry = geometryReader(feature.geometry);
var f = new ol.Feature(geometry); var f = new ol.Feature(geometry);
@@ -108,13 +108,13 @@ ol.reader.GeoJSON.readFeature_ = function(object, callback, opt_obj) {
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template S,T * @template S,T
*/ */
ol.reader.GeoJSON.readFeatureCollection_ = function(object, callback, opt_obj) { ol.format.GeoJSON.readFeatureCollection_ = function(object, callback, opt_obj) {
goog.asserts.assert(object.type == 'FeatureCollection'); goog.asserts.assert(object.type == 'FeatureCollection');
var featureCollection = /** @type {GeoJSONFeatureCollection} */ (object); var featureCollection = /** @type {GeoJSONFeatureCollection} */ (object);
var features = featureCollection.features; var features = featureCollection.features;
var i, ii; var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) { for (i = 0, ii = features.length; i < ii; ++i) {
var result = ol.reader.GeoJSON.readFeature_(features[i], callback, opt_obj); var result = ol.format.GeoJSON.readFeature_(features[i], callback, opt_obj);
if (result) { if (result) {
return result; return result;
} }
@@ -130,8 +130,8 @@ ol.reader.GeoJSON.readFeatureCollection_ = function(object, callback, opt_obj) {
* @return {T} Callback result. * @return {T} Callback result.
* @template S,T * @template S,T
*/ */
ol.reader.GeoJSON.readObject = function(object, callback, opt_obj) { ol.format.GeoJSON.readObject = function(object, callback, opt_obj) {
var objectReader = ol.reader.GeoJSON.OBJECT_READERS_[object.type]; var objectReader = ol.format.GeoJSON.OBJECT_READERS_[object.type];
goog.asserts.assert(goog.isDef(objectReader)); goog.asserts.assert(goog.isDef(objectReader));
return objectReader(object, callback, opt_obj); return objectReader(object, callback, opt_obj);
}; };
@@ -144,9 +144,9 @@ ol.reader.GeoJSON.readObject = function(object, callback, opt_obj) {
* @return {T} Callback result. * @return {T} Callback result.
* @template S,T * @template S,T
*/ */
ol.reader.GeoJSON.readString = function(string, callback, opt_obj) { ol.format.GeoJSON.readString = function(string, callback, opt_obj) {
var object = goog.json.parse(string); var object = goog.json.parse(string);
return ol.reader.GeoJSON.readObject( return ol.format.GeoJSON.readObject(
/** @type {GeoJSONObject} */ (object), callback); /** @type {GeoJSONObject} */ (object), callback);
}; };
@@ -156,12 +156,12 @@ ol.reader.GeoJSON.readString = function(string, callback, opt_obj) {
* @private * @private
* @type {Object.<string, function(GeoJSONGeometry): ol.geom.Geometry>} * @type {Object.<string, function(GeoJSONGeometry): ol.geom.Geometry>}
*/ */
ol.reader.GeoJSON.GEOMETRY_READERS_ = { ol.format.GeoJSON.GEOMETRY_READERS_ = {
'Point': ol.reader.GeoJSON.readPointGeometry_, 'Point': ol.format.GeoJSON.readPointGeometry_,
'LineString': ol.reader.GeoJSON.readLineStringGeometry_, 'LineString': ol.format.GeoJSON.readLineStringGeometry_,
'Polygon': ol.reader.GeoJSON.readPolygonGeometry_, 'Polygon': ol.format.GeoJSON.readPolygonGeometry_,
'MultiLineString': ol.reader.GeoJSON.readMultiLineStringGeometry_, 'MultiLineString': ol.format.GeoJSON.readMultiLineStringGeometry_,
'MultiPolygon': ol.reader.GeoJSON.readMultiPolygonGeometry_ 'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_
}; };
@@ -170,7 +170,7 @@ ol.reader.GeoJSON.GEOMETRY_READERS_ = {
* @private * @private
* @type {Object.<string, function(GeoJSONObject, function(ol.Feature): *, *): *>} * @type {Object.<string, function(GeoJSONObject, function(ol.Feature): *, *): *>}
*/ */
ol.reader.GeoJSON.OBJECT_READERS_ = { ol.format.GeoJSON.OBJECT_READERS_ = {
'Feature': ol.reader.GeoJSON.readFeature_, 'Feature': ol.format.GeoJSON.readFeature_,
'FeatureCollection': ol.reader.GeoJSON.readFeatureCollection_ 'FeatureCollection': ol.format.GeoJSON.readFeatureCollection_
}; };

View File

@@ -1,7 +1,7 @@
goog.provide('ol.test.reader.GeoJSON'); goog.provide('ol.test.reader.GeoJSON');
describe('ol.reader.GeoJSON', function() { describe('ol.format.GeoJSON', function() {
var pointGeoJSON = { var pointGeoJSON = {
'type': 'Feature', 'type': 'Feature',
@@ -50,7 +50,7 @@ describe('ol.reader.GeoJSON', function() {
describe('readObject', function() { describe('readObject', function() {
it('can read a single point feature', function() { it('can read a single point feature', function() {
var feature = ol.reader.GeoJSON.readObject(pointGeoJSON, function(f) { var feature = ol.format.GeoJSON.readObject(pointGeoJSON, function(f) {
return f; return f;
}); });
expect(feature).to.be.an(ol.Feature); expect(feature).to.be.an(ol.Feature);
@@ -61,7 +61,7 @@ describe('ol.reader.GeoJSON', function() {
}); });
it('can read a single line string feature', function() { it('can read a single line string feature', function() {
var feature = ol.reader.GeoJSON.readObject(lineStringGeoJSON, var feature = ol.format.GeoJSON.readObject(lineStringGeoJSON,
function(f) { function(f) {
return f; return f;
}); });
@@ -75,7 +75,7 @@ describe('ol.reader.GeoJSON', function() {
}); });
it('can read a single polygon feature', function() { it('can read a single polygon feature', function() {
var feature = ol.reader.GeoJSON.readObject(polygonGeoJSON, function(f) { var feature = ol.format.GeoJSON.readObject(polygonGeoJSON, function(f) {
return f; return f;
}); });
expect(feature).to.be.an(ol.Feature); expect(feature).to.be.an(ol.Feature);
@@ -90,7 +90,7 @@ describe('ol.reader.GeoJSON', function() {
it('can read a feature collection', function() { it('can read a feature collection', function() {
var features = []; var features = [];
ol.reader.GeoJSON.readObject(featureCollectionGeoJSON, function(f) { ol.format.GeoJSON.readObject(featureCollectionGeoJSON, function(f) {
features.push(f); features.push(f);
}); });
expect(features).to.have.length(3); expect(features).to.have.length(3);
@@ -105,7 +105,7 @@ describe('ol.reader.GeoJSON', function() {
goog.require('ol.Feature'); goog.require('ol.Feature');
goog.require('ol.format.GeoJSON');
goog.require('ol.geom.LineString'); goog.require('ol.geom.LineString');
goog.require('ol.geom.Point'); goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon'); goog.require('ol.geom.Polygon');
goog.require('ol.reader.GeoJSON');