Add ol.source.GeoJSON

This commit is contained in:
Tom Payne
2013-11-06 22:52:04 +01:00
parent db40842487
commit 61a217e8dd
2 changed files with 49 additions and 0 deletions

View File

@@ -429,6 +429,16 @@
* @todo stability experimental
*/
/**
* @typedef {Object} ol.source.GeoJSONOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {string|undefined} logo Logo.
* @property {GeoJSONObject|undefined} geoJSON Object.
* @property {ol.proj.ProjectionLike} projection Projection.
* @property {string|undefined} string String.
* @proprtty {string|undefined} url URL.
*/
/**
* @typedef {Object} ol.source.MapQuestOptions
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional

View File

@@ -0,0 +1,39 @@
// FIXME load from URL
goog.provide('ol.source.GeoJSON');
goog.require('goog.asserts');
goog.require('ol.proj');
goog.require('ol.reader.GeoJSON');
goog.require('ol.source.Vector');
/**
* @constructor
* @extends {ol.source.Vector}
* @param {ol.source.GeoJSONOptions=} opt_options Options.
*/
ol.source.GeoJSON = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
var projection = goog.isDef(options.projection) ?
options.projection : ol.proj.get('EPSG:3857');
goog.base(this, {
attributions: options.attributions,
logo: options.logo,
projection: projection
});
var addFeature = goog.bind(this.addFeature, this);
if (goog.isDef(options.geoJSON)) {
ol.reader.GeoJSON.readObject(options.geoJSON, addFeature);
}
if (goog.isDef(options.string)) {
ol.reader.GeoJSON.readString(options.string, addFeature);
}
};
goog.inherits(ol.source.GeoJSON, ol.source.Vector);