Use reader in GeoJSON example, instead of source
This commit is contained in:
+60
-59
@@ -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,65 +31,62 @@ var styleFunction = function(feature) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var geoJSONSource = new ol.source.GeoJSON(
|
var features = ol.reader.readAllFromObject(ol.reader.GeoJSON.readObject, {
|
||||||
/** @type {ol.source.GeoJSONOptions} */ ({
|
'type': 'FeatureCollection',
|
||||||
geoJSON: {
|
'features': [
|
||||||
'type': 'FeatureCollection',
|
{
|
||||||
features: [
|
'type': 'Feature',
|
||||||
{
|
'geometry': {
|
||||||
'type': 'Feature',
|
'type': 'Point',
|
||||||
'geometry': {
|
'coordinates': [0, 0]
|
||||||
'type': 'Point',
|
}
|
||||||
'coordinates': [0, 0]
|
},
|
||||||
}
|
{
|
||||||
},
|
'type': 'Feature',
|
||||||
{
|
'geometry': {
|
||||||
'type': 'Feature',
|
'type': 'LineString',
|
||||||
'geometry': {
|
'coordinates': [[-1e7, -1e7], [1e7, 1e7]]
|
||||||
'type': 'LineString',
|
}
|
||||||
'coordinates': [[-1e7, -1e7], [1e7, 1e7]]
|
},
|
||||||
}
|
{
|
||||||
},
|
'type': 'Feature',
|
||||||
{
|
'geometry': {
|
||||||
'type': 'Feature',
|
'type': 'LineString',
|
||||||
'geometry': {
|
'coordinates': [[-1e7, 1e7], [1e7, -1e7]]
|
||||||
'type': 'LineString',
|
}
|
||||||
'coordinates': [[-1e7, 1e7], [1e7, -1e7]]
|
},
|
||||||
}
|
{
|
||||||
},
|
'type': 'Feature',
|
||||||
{
|
'geometry': {
|
||||||
'type': 'Feature',
|
'type': 'Polygon',
|
||||||
'geometry': {
|
'coordinates': [[[-5e6, -5e6], [0, 5e6], [5e6, -5e6]]]
|
||||||
'type': 'Polygon',
|
}
|
||||||
'coordinates': [[[-5e6, -5e6], [0, 5e6], [5e6, -5e6]]]
|
},
|
||||||
}
|
{
|
||||||
},
|
'type': 'Feature',
|
||||||
{
|
'geometry': {
|
||||||
'type': 'Feature',
|
'type': 'MultiLineString',
|
||||||
'geometry': {
|
'coordinates': [
|
||||||
'type': 'MultiLineString',
|
[[-1e6, -7.5e5], [-1e6, 7.5e5]],
|
||||||
'coordinates': [
|
[[1e6, -7.5e5], [1e6, 7.5e5]],
|
||||||
[[-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]],
|
|
||||||
[[-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 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
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user