Use ol.source.GeoJSON in geojson example

This commit is contained in:
Tom Payne
2013-12-04 19:17:44 +01:00
parent df975aa558
commit 94d392c0c6
+65 -65
View File
@@ -2,14 +2,13 @@ goog.require('ol.Feature');
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.geom.LineString'); goog.require('ol.geom.LineString');
goog.require('ol.geom.Point'); goog.require('ol.geom.Point');
goog.require('ol.layer.Tile'); goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector'); goog.require('ol.layer.Vector');
goog.require('ol.shape'); goog.require('ol.shape');
goog.require('ol.source.GeoJSON');
goog.require('ol.source.OSM'); goog.require('ol.source.OSM');
goog.require('ol.source.Vector');
goog.require('ol.style.Fill'); goog.require('ol.style.Fill');
goog.require('ol.style.Stroke'); goog.require('ol.style.Stroke');
goog.require('ol.style.Style'); goog.require('ol.style.Style');
@@ -62,73 +61,74 @@ var styleFunction = function(feature, resolution) {
return styles[feature.getGeometry().getType()]; return styles[feature.getGeometry().getType()];
}; };
var features = new ol.format.GeoJSON().readFeatures({ var vectorSource = new ol.source.GeoJSON(
'type': 'FeatureCollection', /** @type {ol.source.GeoJSONOptions} */ ({
'crs': { object: {
'type': 'name', 'type': 'FeatureCollection',
'properties': { 'crs': {
'name': 'EPSG:3857' 'type': 'name',
} 'properties': {
}, 'name': 'EPSG:3857'
'features': [ }
{ },
'type': 'Feature', 'features': [
'geometry': { {
'type': 'Point', 'type': 'Feature',
'coordinates': [0, 0] 'geometry': {
} 'type': 'Point',
}, 'coordinates': [0, 0]
{ }
'type': 'Feature', },
'geometry': { {
'type': 'LineString', 'type': 'Feature',
'coordinates': [[4e6, -2e6], [8e6, 2e6]] 'geometry': {
} 'type': 'LineString',
}, 'coordinates': [[4e6, -2e6], [8e6, 2e6]]
{ }
'type': 'Feature', },
'geometry': { {
'type': 'LineString', 'type': 'Feature',
'coordinates': [[4e6, 2e6], [8e6, -2e6]] 'geometry': {
} 'type': 'LineString',
}, 'coordinates': [[4e6, 2e6], [8e6, -2e6]]
{ }
'type': 'Feature', },
'geometry': { {
'type': 'Polygon', 'type': 'Feature',
'coordinates': [[[-5e6, -1e6], [-4e6, 1e6], [-3e6, -1e6]]] 'geometry': {
} 'type': 'Polygon',
}, 'coordinates': [[[-5e6, -1e6], [-4e6, 1e6], [-3e6, -1e6]]]
{ }
'type': 'Feature', },
'geometry': { {
'type': 'MultiLineString', 'type': 'Feature',
'coordinates': [ 'geometry': {
[[-1e6, -7.5e5], [-1e6, 7.5e5]], 'type': 'MultiLineString',
[[1e6, -7.5e5], [1e6, 7.5e5]], 'coordinates': [
[[-7.5e5, -1e6], [7.5e5, -1e6]], [[-1e6, -7.5e5], [-1e6, 7.5e5]],
[[-7.5e5, 1e6], [7.5e5, 1e6]] [[1e6, -7.5e5], [1e6, 7.5e5]],
[[-7.5e5, -1e6], [7.5e5, -1e6]],
[[-7.5e5, 1e6], [7.5e5, 1e6]]
]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [
[[[-5e6, 6e6], [-5e6, 8e6], [-3e6, 8e6], [-3e6, 6e6]]],
[[[-2e6, 6e6], [-2e6, 8e6], [0e6, 8e6], [0e6, 6e6]]],
[[[1e6, 6e6], [1e6, 8e6], [3e6, 8e6], [3e6, 6e6]]]
]
}
}
] ]
} }
}, }));
{
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [
[[[-5e6, 6e6], [-5e6, 8e6], [-3e6, 8e6], [-3e6, 6e6]]],
[[[-2e6, 6e6], [-2e6, 8e6], [0e6, 8e6], [0e6, 6e6]]],
[[[1e6, 6e6], [1e6, 8e6], [3e6, 8e6], [3e6, 6e6]]]
]
}
}
]
});
var vectorLayer = new ol.layer.Vector({ var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ source: vectorSource,
features: features
}),
styleFunction: styleFunction styleFunction: styleFunction
}); });
var tmpLineFeature = new ol.Feature( var tmpLineFeature = new ol.Feature(