Add GeoJSON example

This commit is contained in:
Tom Payne
2013-11-07 15:07:11 +01:00
parent f0b4a5a35e
commit e403f10de5
2 changed files with 104 additions and 0 deletions

54
examples/geojson.js Normal file
View File

@@ -0,0 +1,54 @@
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.source.GeoJSON');
goog.require('ol.source.OSM');
var geoJSONSource = new ol.source.GeoJSON(
/** @type {ol.source.GeoJSONOptions} */ ({
geoJSON: {
'type': 'FeatureCollection',
features: [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [0, 0]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [[-1e7, -1e7], [1e7, 1e7]]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [[-1e7, 1e7], [1e7, -1e7]]
}
}
]
}
}));
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Vector({
source: geoJSONSource
})
],
renderer: ol.RendererHint.CANVAS,
target: 'map',
view: new ol.View2D({
center: [0, 0],
zoom: 2
})
});