From 979d35b3b364c8a0bf83c03309c0b0d2c763548a Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Fri, 8 Nov 2013 19:57:27 +0100 Subject: [PATCH] Rename ol.reader to ol.format --- examples/geojson.js | 4 +- src/ol/{reader/reader.js => format/format.js} | 4 +- .../geojson/geojsonformat.js} | 48 +++++++++---------- .../geojsonformat.test.js} | 12 ++--- 4 files changed, 34 insertions(+), 34 deletions(-) rename src/ol/{reader/reader.js => format/format.js} (77%) rename src/ol/{reader/geojson/geojson.js => format/geojson/geojsonformat.js} (72%) rename test/spec/ol/{reader/geojson.test.js => format/geojsonformat.test.js} (89%) diff --git a/examples/geojson.js b/examples/geojson.js index 26610edea3..29cd29da1b 100644 --- a/examples/geojson.js +++ b/examples/geojson.js @@ -1,9 +1,9 @@ goog.require('ol.Map'); goog.require('ol.RendererHint'); goog.require('ol.View2D'); +goog.require('ol.format.GeoJSON'); goog.require('ol.layer.Tile'); goog.require('ol.layer.Vector'); -goog.require('ol.reader.GeoJSON'); goog.require('ol.source.OSM'); goog.require('ol.source.Vector'); goog.require('ol.style.DefaultStyleFunction'); @@ -31,7 +31,7 @@ var styleFunction = function(feature) { }; var vectorSource = new ol.source.Vector(); -ol.reader.GeoJSON.readObject({ +ol.format.GeoJSON.readObject({ 'type': 'FeatureCollection', 'features': [ { diff --git a/src/ol/reader/reader.js b/src/ol/format/format.js similarity index 77% rename from src/ol/reader/reader.js rename to src/ol/format/format.js index 94c9b0cfa2..30615c454b 100644 --- a/src/ol/reader/reader.js +++ b/src/ol/format/format.js @@ -1,4 +1,4 @@ -goog.provide('ol.reader'); +goog.provide('ol.format'); /** @@ -8,7 +8,7 @@ goog.provide('ol.reader'); * @return {Array.} * @template S,T */ -ol.reader.readAllFromObject = function(reader, object) { +ol.format.readAllFromObject = function(reader, object) { var features = []; reader(object, function(feature) { features.push(feature); diff --git a/src/ol/reader/geojson/geojson.js b/src/ol/format/geojson/geojsonformat.js similarity index 72% rename from src/ol/reader/geojson/geojson.js rename to src/ol/format/geojson/geojsonformat.js index 8664aa9bc6..3b1b51085e 100644 --- a/src/ol/reader/geojson/geojson.js +++ b/src/ol/format/geojson/geojsonformat.js @@ -2,7 +2,7 @@ // FIXME reprojection // FIXME support other geometry types -goog.provide('ol.reader.GeoJSON'); +goog.provide('ol.format.GeoJSON'); goog.require('goog.asserts'); goog.require('goog.json'); @@ -18,7 +18,7 @@ goog.require('ol.geom.Polygon'); /** * @constructor */ -ol.reader.GeoJSON = function() { +ol.format.GeoJSON = function() { }; @@ -27,7 +27,7 @@ ol.reader.GeoJSON = function() { * @private * @return {ol.geom.Point} Point. */ -ol.reader.GeoJSON.readPointGeometry_ = function(geometry) { +ol.format.GeoJSON.readPointGeometry_ = function(geometry) { goog.asserts.assert(geometry.type == 'Point'); return new ol.geom.Point(geometry.coordinates); }; @@ -38,7 +38,7 @@ ol.reader.GeoJSON.readPointGeometry_ = function(geometry) { * @private * @return {ol.geom.LineString} LineString. */ -ol.reader.GeoJSON.readLineStringGeometry_ = function(geometry) { +ol.format.GeoJSON.readLineStringGeometry_ = function(geometry) { goog.asserts.assert(geometry.type == 'LineString'); return new ol.geom.LineString(geometry.coordinates); }; @@ -49,7 +49,7 @@ ol.reader.GeoJSON.readLineStringGeometry_ = function(geometry) { * @private * @return {ol.geom.MultiLineString} MultiLineString. */ -ol.reader.GeoJSON.readMultiLineStringGeometry_ = function(geometry) { +ol.format.GeoJSON.readMultiLineStringGeometry_ = function(geometry) { goog.asserts.assert(geometry.type == 'MultiLineString'); return new ol.geom.MultiLineString(geometry.coordinates); }; @@ -60,7 +60,7 @@ ol.reader.GeoJSON.readMultiLineStringGeometry_ = function(geometry) { * @private * @return {ol.geom.MultiPolygon} MultiPolygon. */ -ol.reader.GeoJSON.readMultiPolygonGeometry_ = function(geometry) { +ol.format.GeoJSON.readMultiPolygonGeometry_ = function(geometry) { goog.asserts.assert(geometry.type == 'MultiPolygon'); return new ol.geom.MultiPolygon(geometry.coordinates); }; @@ -71,7 +71,7 @@ ol.reader.GeoJSON.readMultiPolygonGeometry_ = function(geometry) { * @private * @return {ol.geom.Polygon} Polygon. */ -ol.reader.GeoJSON.readPolygonGeometry_ = function(geometry) { +ol.format.GeoJSON.readPolygonGeometry_ = function(geometry) { goog.asserts.assert(geometry.type == 'Polygon'); return new ol.geom.Polygon(geometry.coordinates); }; @@ -85,11 +85,11 @@ ol.reader.GeoJSON.readPolygonGeometry_ = function(geometry) { * @return {T} Callback result. * @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'); var feature = /** @type {GeoJSONFeature} */ (object); var geometryReader = - ol.reader.GeoJSON.GEOMETRY_READERS_[feature.geometry.type]; + 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); @@ -108,13 +108,13 @@ ol.reader.GeoJSON.readFeature_ = function(object, callback, opt_obj) { * @return {T|undefined} Callback result. * @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'); var featureCollection = /** @type {GeoJSONFeatureCollection} */ (object); var features = featureCollection.features; var i, ii; 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) { return result; } @@ -130,8 +130,8 @@ ol.reader.GeoJSON.readFeatureCollection_ = function(object, callback, opt_obj) { * @return {T} Callback result. * @template S,T */ -ol.reader.GeoJSON.readObject = function(object, callback, opt_obj) { - var objectReader = ol.reader.GeoJSON.OBJECT_READERS_[object.type]; +ol.format.GeoJSON.readObject = function(object, callback, opt_obj) { + var objectReader = ol.format.GeoJSON.OBJECT_READERS_[object.type]; goog.asserts.assert(goog.isDef(objectReader)); return objectReader(object, callback, opt_obj); }; @@ -144,9 +144,9 @@ ol.reader.GeoJSON.readObject = function(object, callback, opt_obj) { * @return {T} Callback result. * @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); - return ol.reader.GeoJSON.readObject( + return ol.format.GeoJSON.readObject( /** @type {GeoJSONObject} */ (object), callback); }; @@ -156,12 +156,12 @@ ol.reader.GeoJSON.readString = function(string, callback, opt_obj) { * @private * @type {Object.} */ -ol.reader.GeoJSON.GEOMETRY_READERS_ = { - 'Point': ol.reader.GeoJSON.readPointGeometry_, - 'LineString': ol.reader.GeoJSON.readLineStringGeometry_, - 'Polygon': ol.reader.GeoJSON.readPolygonGeometry_, - 'MultiLineString': ol.reader.GeoJSON.readMultiLineStringGeometry_, - 'MultiPolygon': ol.reader.GeoJSON.readMultiPolygonGeometry_ +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_ }; @@ -170,7 +170,7 @@ ol.reader.GeoJSON.GEOMETRY_READERS_ = { * @private * @type {Object.} */ -ol.reader.GeoJSON.OBJECT_READERS_ = { - 'Feature': ol.reader.GeoJSON.readFeature_, - 'FeatureCollection': ol.reader.GeoJSON.readFeatureCollection_ +ol.format.GeoJSON.OBJECT_READERS_ = { + 'Feature': ol.format.GeoJSON.readFeature_, + 'FeatureCollection': ol.format.GeoJSON.readFeatureCollection_ }; diff --git a/test/spec/ol/reader/geojson.test.js b/test/spec/ol/format/geojsonformat.test.js similarity index 89% rename from test/spec/ol/reader/geojson.test.js rename to test/spec/ol/format/geojsonformat.test.js index c4ddb9debe..88fb403766 100644 --- a/test/spec/ol/reader/geojson.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -1,7 +1,7 @@ goog.provide('ol.test.reader.GeoJSON'); -describe('ol.reader.GeoJSON', function() { +describe('ol.format.GeoJSON', function() { var pointGeoJSON = { 'type': 'Feature', @@ -50,7 +50,7 @@ describe('ol.reader.GeoJSON', function() { describe('readObject', 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; }); 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() { - var feature = ol.reader.GeoJSON.readObject(lineStringGeoJSON, + var feature = ol.format.GeoJSON.readObject(lineStringGeoJSON, function(f) { return f; }); @@ -75,7 +75,7 @@ describe('ol.reader.GeoJSON', 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; }); expect(feature).to.be.an(ol.Feature); @@ -90,7 +90,7 @@ describe('ol.reader.GeoJSON', function() { it('can read a feature collection', function() { var features = []; - ol.reader.GeoJSON.readObject(featureCollectionGeoJSON, function(f) { + ol.format.GeoJSON.readObject(featureCollectionGeoJSON, function(f) { features.push(f); }); expect(features).to.have.length(3); @@ -105,7 +105,7 @@ describe('ol.reader.GeoJSON', function() { goog.require('ol.Feature'); +goog.require('ol.format.GeoJSON'); goog.require('ol.geom.LineString'); goog.require('ol.geom.Point'); goog.require('ol.geom.Polygon'); -goog.require('ol.reader.GeoJSON');