Files
openlayers/examples/jsts.js
Tim Schaub ad62739a6e Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
2018-01-12 00:50:30 -07:00

52 lines
1.5 KiB
JavaScript

// NOCOMPILE
// this example uses JSTS for which we don't have an externs file.
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.js';
import TileLayer from '../src/ol/layer/Tile.js';
import VectorLayer from '../src/ol/layer/Vector.js';
import {fromLonLat} from '../src/ol/proj.js';
import OSM from '../src/ol/source/OSM.js';
import VectorSource from '../src/ol/source/Vector.js';
const source = new VectorSource();
fetch('data/geojson/roads-seoul.geojson').then(function(response) {
return response.json();
}).then(function(json) {
const format = new GeoJSON();
const features = format.readFeatures(json, {featureProjection: 'EPSG:3857'});
const parser = new jsts.io.OL3Parser();
for (let i = 0; i < features.length; i++) {
const feature = features[i];
// convert the OpenLayers geometry to a JSTS geometry
const jstsGeom = parser.read(feature.getGeometry());
// create a buffer of 40 meters around each line
const buffered = jstsGeom.buffer(40);
// convert back from JSTS and replace the geometry on the feature
feature.setGeometry(parser.write(buffered));
}
source.addFeatures(features);
});
const vectorLayer = new VectorLayer({
source: source
});
const rasterLayer = new TileLayer({
source: new OSM()
});
const map = new Map({
layers: [rasterLayer, vectorLayer],
target: document.getElementById('map'),
view: new View({
center: fromLonLat([126.979293, 37.528787]),
zoom: 15
})
});