This commit is contained in:
Râu Cao 2022-09-03 11:15:23 +02:00
parent 0631c710d2
commit 068fc0fddd
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
2 changed files with 38 additions and 2 deletions

BIN
data/van-100px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

40
main.js
View File

@ -1,8 +1,9 @@
import './style.css';
import {Map, View} from 'ol';
// import Feature from 'ol/Feature';
import Feature from 'ol/Feature';
import GeoJSON from 'ol/format/GeoJSON';
import Overlay from 'ol/Overlay';
import Point from 'ol/geom/Point';
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
import {Circle as CircleStyle, Fill, Icon, Stroke, Style} from 'ol/style';
import {OSM, Vector as VectorSource} from 'ol/source';
@ -35,6 +36,14 @@ const styles = {
src: 'data/icon.png',
}),
}),
iconVan: new Style({
image: new Icon({
anchor: [0.5, 16],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'data/van-100px.png',
}),
}),
circleBlack: new Style({
image: new CircleStyle({
radius: 7,
@ -47,6 +56,10 @@ const styles = {
})
}
//
// Route
//
const lastStageFinished = 4;
const stagesCompleted = geojsonRoute.features.slice(0, lastStageFinished);
const stagesAhead = geojsonRoute.features.slice(lastStageFinished);
@ -70,6 +83,10 @@ const stagesAheadLayer = new VectorLayer({
style: styles.lineGrey
});
//
// Points of Interest
//
const vectorSourcePOI = new VectorSource({
features: new GeoJSON().readFeatures(geojsonPOI),
});
@ -79,6 +96,24 @@ const poiLayer = new VectorLayer({
style: styles.circleBlack,
});
const vectorSourceVan = new VectorSource();
const vanFeature= new Feature({
geometry: new Point([ 12.498556, 45.780383 ]),
name: 'Support Van'
});
vectorSourceVan.addFeature(vanFeature);
const vanLayer = new VectorLayer({
source: vectorSourceVan,
style: styles.iconVan
});
//
// Map initialization
//
const view = new View({
center: [10.6, 46.9],
zoom: 6.6
@ -92,7 +127,8 @@ const map = new Map({
}),
stagesCompletedLayer,
stagesAheadLayer,
poiLayer
poiLayer,
vanLayer
],
view: view
});