Use reader in GeoJSON example, instead of source

This commit is contained in:
Tom Payne
2013-11-08 16:55:51 +01:00
parent 5f7f388714
commit 430949046f
+9 -8
View File
@@ -3,8 +3,10 @@ goog.require('ol.RendererHint');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.layer.Tile'); goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector'); goog.require('ol.layer.Vector');
goog.require('ol.source.GeoJSON'); goog.require('ol.reader');
goog.require('ol.reader.GeoJSON');
goog.require('ol.source.OSM'); goog.require('ol.source.OSM');
goog.require('ol.source.Vector');
goog.require('ol.style.DefaultStyleFunction'); goog.require('ol.style.DefaultStyleFunction');
@@ -29,11 +31,9 @@ var styleFunction = function(feature) {
} }
}; };
var geoJSONSource = new ol.source.GeoJSON( var features = ol.reader.readAllFromObject(ol.reader.GeoJSON.readObject, {
/** @type {ol.source.GeoJSONOptions} */ ({
geoJSON: {
'type': 'FeatureCollection', 'type': 'FeatureCollection',
features: [ 'features': [
{ {
'type': 'Feature', 'type': 'Feature',
'geometry': { 'geometry': {
@@ -86,8 +86,7 @@ var geoJSONSource = new ol.source.GeoJSON(
} }
} }
] ]
} });
}));
var map = new ol.Map({ var map = new ol.Map({
layers: [ layers: [
@@ -95,7 +94,9 @@ var map = new ol.Map({
source: new ol.source.OSM() source: new ol.source.OSM()
}), }),
new ol.layer.Vector({ new ol.layer.Vector({
source: geoJSONSource, source: new ol.source.Vector({
features: features
}),
styleFunction: styleFunction styleFunction: styleFunction
}) })
], ],