Use ol.source.GeoJSON in complex-geometry example

This commit is contained in:
Tom Payne
2013-12-10 15:35:43 +01:00
parent b31385fcb6
commit 7b3721fa3f

View File

@@ -5,15 +5,14 @@ goog.require('ol.View2D');
goog.require('ol.control'); goog.require('ol.control');
goog.require('ol.control.ScaleLine'); goog.require('ol.control.ScaleLine');
goog.require('ol.control.ScaleLineUnits'); goog.require('ol.control.ScaleLineUnits');
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.proj'); goog.require('ol.proj');
goog.require('ol.shape'); goog.require('ol.shape');
goog.require('ol.source.GeoJSON');
goog.require('ol.source.TileWMS'); goog.require('ol.source.TileWMS');
goog.require('ol.source.Vector');
goog.require('ol.style.Stroke'); goog.require('ol.style.Stroke');
goog.require('ol.style.Style'); goog.require('ol.style.Style');
@@ -23,6 +22,20 @@ var projection = ol.proj.configureProj4jsProjection({
extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864] extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864]
}); });
var vectorSource = new ol.source.GeoJSON({
defaultProjection: projection,
url: 'data/mtbland.geojson'
});
var styleArray = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(128,0,128,0.8)',
lineCap: 'round',
lineJoin: 'round',
width: 3
})
})];
var extent = [420000, 30000, 900000, 350000]; var extent = [420000, 30000, 900000, 350000];
var layers = [ var layers = [
new ol.layer.Tile({ new ol.layer.Tile({
@@ -41,6 +54,12 @@ var layers = [
}, },
extent: extent extent: extent
}) })
}),
new ol.layer.Vector({
source: vectorSource,
styleFunction: function(feature, resolution) {
return styleArray;
}
}) })
]; ];
@@ -61,28 +80,6 @@ var map = new ol.Map({
}) })
}); });
var styleArray = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(128,0,128,0.8)',
lineCap: 'round',
lineJoin: 'round',
width: 3
})
})];
var vectorSource = new ol.source.Vector();
$.getJSON('data/mtbland.geojson', function(data) {
var format = new ol.format.GeoJSON();
format.readObject(data, vectorSource.addFeature, vectorSource);
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
styleFunction: function(feature) {
return styleArray;
}
});
map.getLayers().push(vectorLayer);
});
var point = null; var point = null;
var line = null; var line = null;
var displaySnap = function(coordinate) { var displaySnap = function(coordinate) {