Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed May 22, 2023
1 parent 09866b1 commit 0aa4ba4
Show file tree
Hide file tree
Showing 32 changed files with 733 additions and 618 deletions.
60 changes: 35 additions & 25 deletions demos/schm/demo.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@

import TrackManager from '../../src/interaction/TrackManager';
import GraphHopperRouter from '../../src/router/GraphHopper';
import {ExtractFromSegmentProfiler, FallbackProfiler, SwisstopoProfiler} from '../../src/profiler/index';
import {
ExtractFromSegmentProfiler,
FallbackProfiler,
SwisstopoProfiler,
} from '../../src/profiler/index';
import Profile from '../../src/Profile';
import {styleFunction} from './style';
import {Style, Circle, Fill} from 'ol/style';
import {createMap} from './swisstopo';
import {getTrack, getPOIs} from './track';
import {click} from 'ol/events/condition';

const ROUTING_URL = 'https://graphhopper-all.schweizmobil.ch/route?vehicle=schmwander&type=json&weighting=fastest&elevation=true&way_point_max_distance=0&instructions=false&points_encoded=true';

const ROUTING_URL =
'https://graphhopper-all.schweizmobil.ch/route?vehicle=schmwander&type=json&weighting=fastest&elevation=true&way_point_max_distance=0&instructions=false&points_encoded=true';

async function main() {

const {map, trackLayer, shadowTrackLayer} = createMap('map');

const projection = map.getView().getProjection();
const router = new GraphHopperRouter({
url: ROUTING_URL,
mapProjection: projection
mapProjection: projection,
});

const profiler = new FallbackProfiler({
profilers: [
new ExtractFromSegmentProfiler(),
new SwisstopoProfiler({
projection: projection
})
]
projection: projection,
}),
],
});

/**
* @param {MapBrowserEvent} mapBrowserEvent
* @param {string} pointType
* @return {boolean}
*/
const deleteCondition = function(mapBrowserEvent, pointType) {
const deleteCondition = function (mapBrowserEvent, pointType) {
return click(mapBrowserEvent) && pointType !== 'POI';
};

Expand All @@ -54,8 +56,8 @@ async function main() {
const trackId = search.get('trackId');
if (trackId) {
trackManager.restoreFeatures([
...await getTrack(trackId, projection),
...await getPOIs(trackId, projection),
...(await getTrack(trackId, projection)),
...(await getPOIs(trackId, projection)),
]);
map.getView().fit(trackLayer.getSource().getExtent(), {
padding: [50, 50, 50, 50],
Expand All @@ -70,7 +72,6 @@ async function main() {
profileTarget: '#profile',
});


trackManager.addTrackChangeEventListener(() => {
const segments = trackManager.getSegments();
d3Profile.refreshProfile(segments);
Expand All @@ -86,10 +87,13 @@ async function main() {

trackManager.mode = 'edit';
const tmEl = document.querySelector('#trackmode');
tmEl.addEventListener('change', evt => trackManager.mode = evt.target.value);
tmEl.addEventListener(
'change',
(evt) => (trackManager.mode = evt.target.value)
);

document.querySelector('#snap').addEventListener('click', () => {
trackManager.snapping = ! trackManager.snapping;
trackManager.snapping = !trackManager.snapping;
});
document.querySelector('#delete').addEventListener('click', () => {
trackManager.deleteLastPoint();
Expand All @@ -98,28 +102,34 @@ async function main() {
trackManager.clear();
});

document.querySelector('#undo').addEventListener('click', () => trackManager.undo());
document.querySelector('#redo').addEventListener('click', () => trackManager.redo());
document
.querySelector('#undo')
.addEventListener('click', () => trackManager.undo());
document
.querySelector('#redo')
.addEventListener('click', () => trackManager.redo());
document.querySelector('#getTrackData').addEventListener('click', () => {
trackManager.getTrackFeature();
const features = [
...trackManager.getControlPoints(),
...trackManager.getSegments()
...trackManager.getSegments(),
];
trackManager.restoreFeatures(features)
trackManager.restoreFeatures(features);
});
document.querySelector('#reverse').addEventListener('click', () => {
trackManager.reverse();
});

d3Profile.setTrackHoverStyle(new Style({
image: new Circle({
fill: new Fill({
color: 'blue',
d3Profile.setTrackHoverStyle(
new Style({
image: new Circle({
fill: new Fill({
color: 'blue',
}),
radius: 9,
}),
radius: 9
})
}));
);
}

main();
108 changes: 57 additions & 51 deletions demos/schm/schm.html
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Edit track demo</title>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/openlayers/7.3.0/ol.css"
integrity="sha512-wMgv53RaFRJEYY55kgTe9rv1s3A75Ph6q8N42gB6SqupPnIQveEO00rpsC+v/g66hDZ8YRbnB/R8MySKSG6tZg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<script src="./demo.js" type="module"></script>
<style>
html,
body,
main {
height: 100%;
margin: 0;
}
main {
display: flex;
}
#map {
height: 100vh;
width: 100%;
}
#profile {
height: 150px;
width: 300px;
}
</style>
</head>

<head>
<title>Edit track demo</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/openlayers/7.3.0/ol.css" integrity="sha512-wMgv53RaFRJEYY55kgTe9rv1s3A75Ph6q8N42gB6SqupPnIQveEO00rpsC+v/g66hDZ8YRbnB/R8MySKSG6tZg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="./demo.js" type="module"></script>
<style>
html, body, main {
height: 100%;
margin: 0;
}
main {
display: flex;
}
#map {
height: 100vh;
width: 100%;
}
#profile {
height: 150px;
width: 300px;
}
</style>
</head>

<body>
<main>
<div>
<div id="profile"></div>
<select id="trackmode">
<option value="edit">edit</option>
<option value="">view</option>
</select>
<br />
<a href="#" id="snap">Snap</a>
<br />
<a href="#" id="delete">delete last point</a>
<br />
<a href="#" id="undo">Undo</a>
<br />
<a href="#" id="redo">Redo</a>
<br />
<a href="#" id="clear">clear track</a>
<br />
<a href="#" id="getTrackData">save & restore</a>
<br />
<a href="#" id="reverse">reverse</a>
</div>
<div id="map"></div>
</main>
</body>

<body>
<main>
<div>
<div id="profile"></div>
<select id="trackmode">
<option value="edit">edit</option>
<option value="">view</option>
</select>
<br />
<a href="#" id="snap">Snap</a>
<br />
<a href="#" id="delete">delete last point</a>
<br />
<a href="#" id="undo">Undo</a>
<br />
<a href="#" id="redo">Redo</a>
<br />
<a href="#" id="clear">clear track</a>
<br />
<a href="#" id="getTrackData">save & restore</a>
<br />
<a href="#" id="reverse">reverse</a>
</div>
<div id="map"></div>
</main>
</body>
</html>
7 changes: 3 additions & 4 deletions demos/schm/shadowtrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import {Style, Stroke} from 'ol/style';
import VectorSource from 'ol/source/Vector.js';
import VectorLayer from 'ol/layer/Vector.js';


/**
* @type {Style}
*/
export const style = new Style({
export const style = new Style({
stroke: new Stroke({
color: '#00cc33aa',
width: 6
})
width: 6,
}),
});

/**
Expand Down
58 changes: 30 additions & 28 deletions demos/schm/style.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Fill, Stroke, Style, Icon, Text, RegularShape } from "ol/style";
import { toString } from "ol/color";
import {Fill, Stroke, Style, Icon, Text, RegularShape} from 'ol/style';
import {toString} from 'ol/color';

const color = [227, 6, 19];
const lightColor = [...color, 0.6];

const poiSvg = `
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="33">
<path d="M10 0C5 0 .5 3 .5 9c0 4 9.5 24 9.5 24s9.5-20 9.5-24c0-6-4.5-9-9.5-9z" fill="${toString(color)}"/>
<path d="M10 0C5 0 .5 3 .5 9c0 4 9.5 24 9.5 24s9.5-20 9.5-24c0-6-4.5-9-9.5-9z" fill="${toString(
color
)}"/>
</svg>
`;

Expand All @@ -25,7 +27,7 @@ export const controlPoint = new Style({
}),
text: new Text({
fill: new Fill({
color: "#fff",
color: '#fff',
}),
}),
});
Expand All @@ -35,10 +37,10 @@ export const sketchControlPoint = controlPoint.clone();
export const numberedControlPoint = controlPoint.clone();

export const firstControlPoint = controlPoint.clone();
firstControlPoint.getText().setText("A");
firstControlPoint.getText().setText('A');

export const lastControlPoint = controlPoint.clone();
lastControlPoint.getText().setText("B");
lastControlPoint.getText().setText('B');

export const poiPoint = new Style({
zIndex: 100,
Expand All @@ -51,35 +53,35 @@ export const poiPoint = new Style({
const sketchLabel = {
POI: new Style({
text: new Text({
font: "20px sans-serif",
font: '20px sans-serif',
offsetX: 20,
textAlign: "left",
textAlign: 'left',
backgroundFill: new Fill({
color: "#ffffffaa",
color: '#ffffffaa',
}),
text: "drag to move POI",
text: 'drag to move POI',
}),
}),
cp: new Style({
text: new Text({
font: "20px sans-serif",
font: '20px sans-serif',
offsetX: 20,
textAlign: "left",
textAlign: 'left',
backgroundFill: new Fill({
color: "#ffffffaa",
color: '#ffffffaa',
}),
text: "click to delete\ndrag to move point",
text: 'click to delete\ndrag to move point',
}),
}),
segment: new Style({
text: new Text({
backgroundFill: new Fill({
color: "#ffffffaa",
color: '#ffffffaa',
}),
offsetX: 20,
textAlign: "left",
font: "20px sans-serif",
text: "drag to create point",
textAlign: 'left',
font: '20px sans-serif',
text: 'drag to create point',
}),
}),
};
Expand All @@ -101,24 +103,24 @@ trackLineModifying.getStroke().setLineDash([1, 12]);
* @return {?Style}
*/
export function styleFunction(feature, _) {
const type = feature.get("type");
const subtype = feature.get("subtype");
const index = feature.get("index");
const type = feature.get('type');
const subtype = feature.get('subtype');
const index = feature.get('index');

switch (type) {
case "sketch": {
case 'sketch': {
if (subtype) {
return [sketchControlPoint, sketchLabel[subtype]];
}
return sketchControlPoint;
}
case "POI":
case 'POI':
return poiPoint;
case "controlPoint":
case 'controlPoint':
switch (subtype) {
case "first":
case 'first':
return firstControlPoint;
case "last":
case 'last':
return lastControlPoint;
default:
if (index !== undefined) {
Expand All @@ -127,9 +129,9 @@ export function styleFunction(feature, _) {
}
return controlPoint;
}
case "segment":
case 'segment':
switch (subtype) {
case "modifying":
case 'modifying':
return trackLineModifying;
default:
return trackLine;
Expand Down
Loading

0 comments on commit 0aa4ba4

Please sign in to comment.