diff --git a/examples/geojson.js b/examples/geojson.js index 247ec4d9f2..176f0b46d4 100644 --- a/examples/geojson.js +++ b/examples/geojson.js @@ -44,7 +44,7 @@ var styleFunction = function(feature) { }; var vectorSource = new ol.source.Vector(); -ol.format.GeoJSON.readObject({ +new ol.format.GeoJSON().readObject({ 'type': 'FeatureCollection', 'features': [ { diff --git a/src/ol/format/geojson/geojsonformat.js b/src/ol/format/geojson/geojsonformat.js index 3b1b51085e..39bc2b311a 100644 --- a/src/ol/format/geojson/geojsonformat.js +++ b/src/ol/format/geojson/geojsonformat.js @@ -7,6 +7,7 @@ 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'); @@ -17,6 +18,7 @@ goog.require('ol.geom.Polygon'); /** * @constructor + * @implements {ol.format.IReader} */ ol.format.GeoJSON = function() { }; @@ -124,30 +126,21 @@ ol.format.GeoJSON.readFeatureCollection_ = function(object, callback, opt_obj) { /** - * @param {GeoJSONObject} object Object. - * @param {function(this: S, ol.Feature): T} callback Callback. - * @param {S=} opt_obj Scope. - * @return {T} Callback result. - * @template S,T + * @inheritDoc */ -ol.format.GeoJSON.readObject = function(object, callback, opt_obj) { - var objectReader = ol.format.GeoJSON.OBJECT_READERS_[object.type]; +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(object, callback, opt_obj); + return objectReader(geoJSONObject, callback, opt_obj); }; /** - * @param {string} string String. - * @param {function(ol.Feature): T} callback Callback. - * @param {S=} opt_obj Scope. - * @return {T} Callback result. - * @template S,T + * @inheritDoc */ -ol.format.GeoJSON.readString = function(string, callback, opt_obj) { - var object = goog.json.parse(string); - return ol.format.GeoJSON.readObject( - /** @type {GeoJSONObject} */ (object), callback); +ol.format.GeoJSON.prototype.readString = function(string, callback, opt_obj) { + return this.readObject(goog.json.parse(string), callback, opt_obj); }; diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index 88fb403766..d088fd3591 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -47,10 +47,12 @@ describe('ol.format.GeoJSON', function() { 'features': [pointGeoJSON, lineStringGeoJSON, polygonGeoJSON] }; + var format = new ol.format.GeoJSON(); + describe('readObject', function() { it('can read a single point feature', function() { - var feature = ol.format.GeoJSON.readObject(pointGeoJSON, function(f) { + var feature = format.readObject(pointGeoJSON, function(f) { return f; }); expect(feature).to.be.an(ol.Feature); @@ -61,7 +63,7 @@ describe('ol.format.GeoJSON', function() { }); it('can read a single line string feature', function() { - var feature = ol.format.GeoJSON.readObject(lineStringGeoJSON, + var feature = format.readObject(lineStringGeoJSON, function(f) { return f; }); @@ -75,7 +77,7 @@ describe('ol.format.GeoJSON', function() { }); it('can read a single polygon feature', function() { - var feature = ol.format.GeoJSON.readObject(polygonGeoJSON, function(f) { + var feature = format.readObject(polygonGeoJSON, function(f) { return f; }); expect(feature).to.be.an(ol.Feature); @@ -90,7 +92,7 @@ describe('ol.format.GeoJSON', function() { it('can read a feature collection', function() { var features = []; - ol.format.GeoJSON.readObject(featureCollectionGeoJSON, function(f) { + format.readObject(featureCollectionGeoJSON, function(f) { features.push(f); }); expect(features).to.have.length(3);