5 Commits

Author SHA1 Message Date
Râu Cao
068fc0fddd Add van 2022-09-03 11:15:23 +02:00
Râu Cao
0631c710d2 Popups 2022-09-02 16:21:13 +02:00
Râu Cao
0e9aa5a27f Adjust zoom 2022-09-02 15:54:53 +02:00
Râu Cao
481b80e0e7 Move center 2022-09-02 15:33:57 +02:00
Râu Cao
b20634462e POIs 2022-09-02 14:49:27 +02:00
5 changed files with 156573 additions and 156294 deletions

BIN
data/van-100px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@@ -1,18 +1,200 @@
{ {
"type": "FeatureCollection", "type": "FeatureCollection",
"features": [ "features": [
{ {
"type": "Feature", "type": "Feature",
"properties": { "properties": {
"name": "Start in Genoa" "name": "Start in Genoa"
}, },
"geometry": { "geometry": {
"type": "Point", "type": "Point",
"coordinates": [ "coordinates": [
8.918618, 8.918618,
44.407408 44.407408
] ]
} }
} },
] {
"type": "Feature",
"properties": {
"name": "Start/Finish in Borgonovo"
},
"geometry": {
"type": "Point",
"coordinates": [
9.378806,
44.391897
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Parma"
},
"geometry": {
"type": "Point",
"coordinates": [
10.327455,
44.804661
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Legnago"
},
"geometry": {
"type": "Point",
"coordinates": [
11.311988,
45.192941
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Treviso"
},
"geometry": {
"type": "Point",
"coordinates": [
12.245634,
45.666013
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Udine"
},
"geometry": {
"type": "Point",
"coordinates": [
13.235893,
46.064534
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Villach"
},
"geometry": {
"type": "Point",
"coordinates": [
13.843945,
46.615745
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Bad Mitterndorf"
},
"geometry": {
"type": "Point",
"coordinates": [
13.931899,
47.555034
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Fuschl am See"
},
"geometry": {
"type": "Point",
"coordinates": [
13.29709,
47.802267
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Halfing"
},
"geometry": {
"type": "Point",
"coordinates": [
12.276169,
47.951902
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in München"
},
"geometry": {
"type": "Point",
"coordinates": [
11.574704,
48.137281
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Regensburg"
},
"geometry": {
"type": "Point",
"coordinates": [
12.094785,
49.020419
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Rothenburg o. d. Tauber"
},
"geometry": {
"type": "Point",
"coordinates": [
10.179171,
49.376898
]
}
},
{
"type": "Feature",
"properties": {
"name": "Start/Finish in Karlsruhe"
},
"geometry": {
"type": "Point",
"coordinates": [
8.404369,
49.013486
]
}
},
{
"type": "Feature",
"properties": {
"name": "Finish in Straßbourg"
},
"geometry": {
"type": "Point",
"coordinates": [
7.767981,
48.598389
]
}
}
]
} }

File diff suppressed because it is too large Load Diff

View File

@@ -5,9 +5,11 @@
<!-- <link rel="icon" type="image/x&#45;icon" href="https://openlayers.org/favicon.ico" /> --> <!-- <link rel="icon" type="image/x&#45;icon" href="https://openlayers.org/favicon.ico" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Road2Bitcoin Live Map</title> <title>Road2Bitcoin Live Map</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css">
</head> </head>
<body> <body>
<div id="map"></div> <div id="map"><div id="popup"></div></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"></script>
<script type="module" src="./main.js"></script> <script type="module" src="./main.js"></script>
</body> </body>
</html> </html>

107
main.js
View File

@@ -1,9 +1,11 @@
import './style.css'; 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 GeoJSON from 'ol/format/GeoJSON';
import {Map, View} from 'ol'; import Overlay from 'ol/Overlay';
import Point from 'ol/geom/Point';
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer'; import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
import {Icon, Stroke, Style} from 'ol/style'; import {Circle as CircleStyle, Fill, Icon, Stroke, Style} from 'ol/style';
import {OSM, Vector as VectorSource} from 'ol/source'; import {OSM, Vector as VectorSource} from 'ol/source';
import {useGeographic} from 'ol/proj'; import {useGeographic} from 'ol/proj';
import geojsonRoute from './geo/route.json' import geojsonRoute from './geo/route.json'
@@ -33,9 +35,31 @@ const styles = {
anchorYUnits: 'pixels', anchorYUnits: 'pixels',
src: 'data/icon.png', 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,
fill: new Fill({color: '#FF9900'}),
stroke: new Stroke({
color: 'white',
width: 2,
}),
})
}) })
} }
//
// Route
//
const lastStageFinished = 4; const lastStageFinished = 4;
const stagesCompleted = geojsonRoute.features.slice(0, lastStageFinished); const stagesCompleted = geojsonRoute.features.slice(0, lastStageFinished);
const stagesAhead = geojsonRoute.features.slice(lastStageFinished); const stagesAhead = geojsonRoute.features.slice(lastStageFinished);
@@ -59,18 +83,40 @@ const stagesAheadLayer = new VectorLayer({
style: styles.lineGrey style: styles.lineGrey
}); });
//
// Points of Interest
//
const vectorSourcePOI = new VectorSource({ const vectorSourcePOI = new VectorSource({
features: new GeoJSON().readFeatures(geojsonPOI), features: new GeoJSON().readFeatures(geojsonPOI),
}); });
const poiLayer = new VectorLayer({ const poiLayer = new VectorLayer({
source: vectorSourcePOI, source: vectorSourcePOI,
style: styles.iconStop, 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({ const view = new View({
center: [10.6, 46.5], center: [10.6, 46.9],
zoom: 6 zoom: 6.6
}) })
const map = new Map({ const map = new Map({
@@ -81,7 +127,56 @@ const map = new Map({
}), }),
stagesCompletedLayer, stagesCompletedLayer,
stagesAheadLayer, stagesAheadLayer,
poiLayer poiLayer,
vanLayer
], ],
view: view view: view
}); });
//
// Popups
//
const popupEl = document.getElementById('popup');
const popup = new Overlay({
element: popupEl,
positioning: 'bottom-center',
stopEvent: false,
});
map.addOverlay(popup);
let popover;
function disposePopover() {
if (popover) {
popover.dispose();
popover = undefined;
}
}
// display popup on click
map.on('click', function (evt) {
const feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
return feature;
});
disposePopover();
if (!feature) {
return;
}
popup.setPosition(evt.coordinate);
popover = new bootstrap.Popover(popupEl, {
placement: 'top',
html: true,
content: feature.get('name'),
});
popover.show();
});
// change mouse cursor when over marker
map.on('pointermove', function (evt) {
map.getTargetElement().style.cursor = map.hasFeatureAtPixel(evt.pixel)
? 'pointer'
: '';
});
// Close the popup when the map is moved
map.on('movestart', disposePopover);