mirror of
https://github.com/Findus23/RainbowRoad.git
synced 2024-09-18 14:53:51 +02:00
initial version
This commit is contained in:
commit
4918bcd59b
22 changed files with 2790 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.idea/
|
||||
node_modules/
|
||||
dist/
|
8
assets/prideflag.svg
Normal file
8
assets/prideflag.svg
Normal file
|
@ -0,0 +1,8 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 777 480" width="777" height="480">
|
||||
<path fill="#750787" d="M0 0h777v480H0z"/>
|
||||
<path fill="#004dff" d="M0 0h777v400H0z"/>
|
||||
<path fill="#008026" d="M0 0h777v320H0z"/>
|
||||
<path fill="#ffed00" d="M0 0h777v240H0z"/>
|
||||
<path fill="#ff8c00" d="M0 0h777v160H0z"/>
|
||||
<path fill="#e40303" d="M0 0h777v80H0z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 376 B |
5
assets/transflag.svg
Normal file
5
assets/transflag.svg
Normal file
|
@ -0,0 +1,5 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 480" width="800" height="480">
|
||||
<path fill="#5BCEFA" d="M0 0h800v480H0z"/>
|
||||
<path fill="#F5A9B8" d="M0 96h800v288H0z"/>
|
||||
<path fill="#FFF" d="M0 192h800v96H0z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 235 B |
13
canvastest.html
Normal file
13
canvastest.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Rainbow Road</title>
|
||||
<meta name="description" content="Eine Karte aller momentan verfügbaren Fahrräder bei WienMobilRad">
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" width="300" height="300"></canvas>
|
||||
<script type="module" src="/src/simpledraw.ts"></script>
|
||||
</body>
|
||||
</html>
|
80
commands/fetch.ts
Normal file
80
commands/fetch.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
import * as fs from "fs";
|
||||
import type {Crossing, OSMNodeSource, OSMWaySource, OverPassNode, OverPassResponse, OverpassWay} from "../interfaces";
|
||||
import {nodeData, wayData} from "./overpass";
|
||||
import {lineLengthInM} from "../utils/geo";
|
||||
|
||||
async function runfetch() {
|
||||
const data: Crossing[] = JSON.parse(fs.readFileSync("../data/data.json", 'utf8'));
|
||||
|
||||
function firstLastNodeCoords(nodeMap: { [id: number]: OverPassNode }, nodeList: number[]) {
|
||||
const coords: number[][] = []
|
||||
const firstNode = nodeMap[nodeList[0]]
|
||||
const lastNode = nodeMap[nodeList[nodeList.length - 1]]
|
||||
coords.push([firstNode.lon, firstNode.lat])
|
||||
coords.push([lastNode.lon, lastNode.lat])
|
||||
return coords;
|
||||
}
|
||||
|
||||
async function fetchWayData(geosource: OSMWaySource) {
|
||||
const coords: number[][] = []
|
||||
const response = await wayData(geosource.wayID)
|
||||
const data: OverPassResponse = response.data
|
||||
const nodes: { [key: number]: OverPassNode } = {}
|
||||
data.elements.forEach(e => {
|
||||
if (e.type != "node") {
|
||||
return
|
||||
}
|
||||
nodes[e.id] = e
|
||||
})
|
||||
const way = data.elements.find(e => e.type == "way") as OverpassWay
|
||||
return firstLastNodeCoords(nodes, way.nodes)
|
||||
}
|
||||
|
||||
|
||||
async function fetchNodeData(geosource: OSMNodeSource) {
|
||||
const response = await nodeData(geosource.nodes)
|
||||
const data: OverPassResponse = response.data
|
||||
console.log("data.elements")
|
||||
console.log(data.elements)
|
||||
const nodes: { [key: number]: OverPassNode } = {}
|
||||
data.elements.forEach(e => {
|
||||
if (e.type != "node") {
|
||||
return
|
||||
}
|
||||
nodes[e.id] = e
|
||||
})
|
||||
console.log(geosource.nodes)
|
||||
return firstLastNodeCoords(nodes, geosource.nodes);
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (const d of data) {
|
||||
if (typeof d.geo !== "undefined") {
|
||||
continue
|
||||
}
|
||||
const geosource = d.geosource
|
||||
console.log("fetching")
|
||||
let coords: number[][];
|
||||
switch (geosource.type) {
|
||||
case "OSMway":
|
||||
coords = await fetchWayData(geosource);
|
||||
break
|
||||
case "OSMnodes":
|
||||
coords = await fetchNodeData(geosource);
|
||||
break
|
||||
}
|
||||
|
||||
d.geo = {
|
||||
coords: coords,
|
||||
length: lineLengthInM(coords[0], coords[1])
|
||||
}
|
||||
// crossings[i] = d
|
||||
d.geo.length = lineLengthInM(d.geo.coords[0], d.geo.coords[1])
|
||||
}
|
||||
|
||||
|
||||
fs.writeFileSync("../data/data.json", JSON.stringify(data, null, 2))
|
||||
}
|
||||
|
||||
runfetch()
|
25
commands/overpass.ts
Normal file
25
commands/overpass.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import axios from 'axios'
|
||||
import {URLSearchParams} from "url";
|
||||
|
||||
const overpassURL = "https://overpass-api.de/api/interpreter?data="
|
||||
|
||||
|
||||
export async function overpassAPI(query: string) {
|
||||
return axios.post(overpassURL, new URLSearchParams({
|
||||
data: query
|
||||
}))
|
||||
}
|
||||
|
||||
export async function wayData(wayID: number) {
|
||||
const query = "[out:json];(way(THEID););(._;>;);out;"
|
||||
.replace("THEID", wayID.toString())
|
||||
return await overpassAPI(query)
|
||||
}
|
||||
|
||||
export async function nodeData(nodeIDs: number[]) {
|
||||
let query = "[out:json];node(id:"
|
||||
query += nodeIDs.join(",")
|
||||
query += ");out;"
|
||||
console.log(query)
|
||||
return await overpassAPI(query)
|
||||
}
|
7
commands/tsconfig.json
Normal file
7
commands/tsconfig.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "ts-node/node16/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
4
custom.d.ts
vendored
Normal file
4
custom.d.ts
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
declare module "*.svg" {
|
||||
const content: any;
|
||||
export default content;
|
||||
}
|
67
data/data.json
Normal file
67
data/data.json
Normal file
|
@ -0,0 +1,67 @@
|
|||
[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Praterstern",
|
||||
"sources": [
|
||||
{
|
||||
"type": "streetview",
|
||||
"date": "2022-07-01"
|
||||
},
|
||||
{
|
||||
"type": "news",
|
||||
"date": "2021-04-22",
|
||||
"url": "https://www.meinbezirk.at/leopoldstadt/c-lokales/neuer-regenbogen-zebrastreifen-am-praterstern_a4591199"
|
||||
}
|
||||
],
|
||||
"bezirk": 2,
|
||||
"type": "prideFlag",
|
||||
"geosource": {
|
||||
"type": "OSMway",
|
||||
"wayID": 191209754
|
||||
},
|
||||
"geo": {
|
||||
"coords": [
|
||||
[
|
||||
16.3934161,
|
||||
48.217841
|
||||
],
|
||||
[
|
||||
16.3936921,
|
||||
48.217809
|
||||
]
|
||||
],
|
||||
"length": 30.88
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Spitalgasse/Lazarettgasse",
|
||||
"bezirk": 5,
|
||||
"type": "transFlag",
|
||||
"geosource": {
|
||||
"type": "OSMnodes",
|
||||
"nodes": [
|
||||
4688793755,
|
||||
248435078,
|
||||
4688793750,
|
||||
4688793751,
|
||||
4688793749,
|
||||
2507395460,
|
||||
4688793762
|
||||
]
|
||||
},
|
||||
"geo": {
|
||||
"coords": [
|
||||
[
|
||||
16.3519972,
|
||||
48.2191707
|
||||
],
|
||||
[
|
||||
16.3516333,
|
||||
48.2190409
|
||||
]
|
||||
],
|
||||
"length": 42.77
|
||||
}
|
||||
}
|
||||
]
|
97
data/schema.json
Normal file
97
data/schema.json
Normal file
|
@ -0,0 +1,97 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/crossing"
|
||||
},
|
||||
"definitions": {
|
||||
"source": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"news",
|
||||
"streetview",
|
||||
"in person"
|
||||
]
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"format": "date"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"format": "url"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"date",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"geo": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"wayID": {
|
||||
"type": "integer"
|
||||
},
|
||||
"coords": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"length": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"crossing": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"bezirk": {
|
||||
"type": "integer"
|
||||
},
|
||||
"sources": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/source"
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"prideFlag",
|
||||
"transFlag"
|
||||
]
|
||||
},
|
||||
"geo": {
|
||||
"type": "object",
|
||||
"$ref": "#/geo"
|
||||
},
|
||||
"geosource": {}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"bezirk",
|
||||
"name",
|
||||
"type"
|
||||
],
|
||||
"title": "Zebrastreifen"
|
||||
}
|
||||
}
|
||||
}
|
18
index.html
Normal file
18
index.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Rainbow Road</title>
|
||||
<meta name="description" content="Eine Karte aller momentan verfügbaren Fahrräder bei WienMobilRad">
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<div id="popup" class="ol-popup">
|
||||
<a href="#" id="popup-closer" class="ol-popup-closer"></a>
|
||||
<div id="popup-content"></div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
52
interfaces.ts
Normal file
52
interfaces.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
export type FlagType = "prideFlag" | "transFlag"
|
||||
|
||||
|
||||
export interface OSMWaySource {
|
||||
type: "OSMway",
|
||||
wayID: number
|
||||
}
|
||||
|
||||
export interface OSMNodeSource {
|
||||
type: "OSMnodes",
|
||||
nodes: number[]
|
||||
}
|
||||
|
||||
export interface GeoData {
|
||||
coords: number[][],
|
||||
length: number // in meter
|
||||
}
|
||||
|
||||
export interface Crossing {
|
||||
id: number
|
||||
name: string
|
||||
bezirk: number
|
||||
type: FlagType
|
||||
geosource: OSMWaySource | OSMNodeSource,
|
||||
geo: GeoData
|
||||
}
|
||||
|
||||
export interface Tags {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export interface OverpassElement {
|
||||
id: number
|
||||
tags: Tags
|
||||
}
|
||||
|
||||
export interface OverPassNode extends OverpassElement {
|
||||
type: "node"
|
||||
lat: number
|
||||
lon: number
|
||||
}
|
||||
|
||||
export interface OverpassWay extends OverpassElement {
|
||||
type: "way"
|
||||
nodes: number[] // corresponding to OverPassNode.id
|
||||
}
|
||||
|
||||
export interface OverPassResponse {
|
||||
version: number
|
||||
generator: string
|
||||
elements: (OverPassNode | OverpassWay)[]
|
||||
}
|
1817
package-lock.json
generated
Normal file
1817
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
24
package.json
Normal file
24
package.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "rainbowroad",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"fetch": "cd commands && ts-node fetch.ts",
|
||||
"dev": "vite",
|
||||
"build": "tsc --skipLibCheck && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.6.3",
|
||||
"typescript": "^4.5.4",
|
||||
"vite": "^3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"node-fetch": "^3.2.10",
|
||||
"ol": "^6.14.1",
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
189
src/main.ts
Normal file
189
src/main.ts
Normal file
|
@ -0,0 +1,189 @@
|
|||
import Map from "ol/Map";
|
||||
import {OSM, Vector as VectorSource} from "ol/source";
|
||||
import TileLayer from "ol/layer/Tile";
|
||||
import {Feature, Overlay, View} from "ol";
|
||||
import {fromLonLat, transform, transformExtent} from "ol/proj";
|
||||
|
||||
import {LineString, Point} from "ol/geom";
|
||||
import {Vector as VectorLayer} from "ol/layer";
|
||||
import "./style.css"
|
||||
import {Circle, Fill, Icon, Stroke, Style} from "ol/style";
|
||||
import {Coordinate} from "ol/coordinate";
|
||||
import {State} from "ol/render";
|
||||
import {Line, Vector2d} from "./vectorUtils";
|
||||
import {drawZebraCrossing, zebraPatterns} from "./zebraUtils";
|
||||
import importdata from "../data/data.json"
|
||||
import {Crossing} from "../interfaces";
|
||||
import prideFlag from "../assets/prideflag.svg"
|
||||
import transFlag from "../assets/transflag.svg"
|
||||
|
||||
|
||||
function averageCoords(coords: number[][]): number[] {
|
||||
return [
|
||||
(coords[0][0] + coords[1][0]) / 2,
|
||||
(coords[0][1] + coords[1][1]) / 2
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
const data = importdata as Crossing[]
|
||||
const map = new Map({
|
||||
target: 'map',
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new OSM({url: "https://maps.lw1.at/tiles/1.0.0/osm/GLOBAL_MERCATOR/{z}/{x}/{y}.png"})
|
||||
}),
|
||||
],
|
||||
// view: new View({
|
||||
// center: fromLonLat([16.3787, 48.2089]),
|
||||
// zoom: 12,
|
||||
// extent: transformExtent([16.2988, 48.1353, 16.4986, 48.2974], 'EPSG:4326', 'EPSG:3857'),
|
||||
// constrainOnlyCenter: true
|
||||
// })
|
||||
view: new View({
|
||||
center: fromLonLat([16.3787, 48.2089]),
|
||||
zoom: 13,
|
||||
extent: transformExtent([16.2988, 48.1353, 16.4986, 48.2974], 'EPSG:4326', 'EPSG:3857'),
|
||||
constrainOnlyCenter: true
|
||||
})
|
||||
});
|
||||
var vectorLine = new VectorSource({});
|
||||
const metaData: { [id: number]: Crossing } = {}
|
||||
data.forEach(c => {
|
||||
const points = c.geo.coords.map(coord => transform(coord, 'EPSG:4326', 'EPSG:3857'));
|
||||
|
||||
const featureLine = new Feature({
|
||||
geometry: new LineString(points)
|
||||
});
|
||||
const featureDot = new Feature({
|
||||
geometry: new Point(averageCoords(points))
|
||||
});
|
||||
featureLine.setId(c.id)
|
||||
featureDot.setId(c.id + 10000)
|
||||
metaData[c.id] = c
|
||||
vectorLine.addFeature(featureLine);
|
||||
vectorLine.addFeature(featureDot);
|
||||
})
|
||||
|
||||
|
||||
const greenLine = new Style({
|
||||
fill: new Fill({color: '#00FF00'}),
|
||||
stroke: new Stroke({color: '#00FF00', width: 2})
|
||||
})
|
||||
|
||||
function renderer(coordinates: Coordinate | Coordinate[] | Coordinate[][], state: State): void {
|
||||
const start = Vector2d.fromCoordList(coordinates[0] as Coordinate)
|
||||
const end = Vector2d.fromCoordList(coordinates[1] as Coordinate)
|
||||
const line = new Line(start, end)
|
||||
// console.log(line.vec.length())
|
||||
const ctx = state.context;
|
||||
const featureID = Number(state.feature.getId())
|
||||
if (!featureID || featureID > 10000) {
|
||||
return
|
||||
}
|
||||
const crossing = metaData[featureID]
|
||||
let numStripes = crossing.geo.length / 0.5
|
||||
if (state.resolution > 0.3) {
|
||||
numStripes /= 2
|
||||
}
|
||||
if (state.resolution > 0.1) {
|
||||
numStripes /= 2
|
||||
}
|
||||
numStripes = Math.floor(numStripes)
|
||||
|
||||
drawZebraCrossing(ctx, line, line.vec.length() / 2, zebraPatterns[crossing.type], numStripes)
|
||||
}
|
||||
|
||||
const crossingsStyle = new Style({renderer: renderer})
|
||||
const prideFlagStyle = new Style({
|
||||
image: new Icon({
|
||||
src: prideFlag,
|
||||
scale: 0.05
|
||||
})
|
||||
})
|
||||
const transFlagStyle = new Style({
|
||||
image: new Icon({
|
||||
src: transFlag,
|
||||
scale: 0.05
|
||||
})
|
||||
})
|
||||
const circleStyle = new Style({
|
||||
image: new Circle({
|
||||
fill: new Fill({color: "red"}),
|
||||
stroke: new Stroke({color: "green"}),
|
||||
radius: 10,
|
||||
}),
|
||||
})
|
||||
var vectorLineLayer = new VectorLayer({
|
||||
source: vectorLine,
|
||||
style: function (feature, resolution) {
|
||||
const zoom = map.getView().getZoomForResolution(resolution);
|
||||
if (!zoom) {
|
||||
return
|
||||
}
|
||||
if (zoom > 17) {
|
||||
return crossingsStyle
|
||||
}
|
||||
const featureID = Number(feature.getId()) - 10000
|
||||
if (!featureID || featureID < 0) {
|
||||
return
|
||||
}
|
||||
const crossing = metaData[featureID]
|
||||
switch (crossing.type) {
|
||||
case "prideFlag":
|
||||
return prideFlagStyle;
|
||||
case "transFlag":
|
||||
return transFlagStyle;
|
||||
}
|
||||
}
|
||||
});
|
||||
map.addLayer(vectorLineLayer);
|
||||
|
||||
|
||||
// popups
|
||||
|
||||
const container = document.getElementById('popup')!;
|
||||
const content = document.getElementById('popup-content')!;
|
||||
const closer = document.getElementById('popup-closer')!;
|
||||
|
||||
var overlay = new Overlay({
|
||||
element: container,
|
||||
autoPan: true,
|
||||
autoPanAnimation: {
|
||||
duration: 250
|
||||
}
|
||||
});
|
||||
map.addOverlay(overlay);
|
||||
|
||||
closer.onclick = function () {
|
||||
overlay.setPosition(undefined);
|
||||
closer.blur();
|
||||
return false;
|
||||
};
|
||||
map.on('singleclick', function (event) {
|
||||
map.forEachFeatureAtPixel(event.pixel, feature => {
|
||||
var coordinate = event.coordinate;
|
||||
let id = Number(feature.getId())
|
||||
if (!id) {
|
||||
return
|
||||
}
|
||||
if (id > 10000) {
|
||||
id -= 10000
|
||||
}
|
||||
console.info(id)
|
||||
const crossing = metaData[id]
|
||||
|
||||
content.innerHTML = "";
|
||||
const p = document.createElement("p")
|
||||
p.innerText = crossing.name
|
||||
content.appendChild(p)
|
||||
|
||||
overlay.setPosition(coordinate);
|
||||
|
||||
}, {hitTolerance: 20})
|
||||
if (!map.hasFeatureAtPixel(event.pixel, {hitTolerance: 2})) {
|
||||
overlay.setPosition(undefined);
|
||||
closer.blur();
|
||||
}
|
||||
});
|
||||
|
24
src/simpledraw.ts
Normal file
24
src/simpledraw.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import "./style.css"
|
||||
import {Line, Vector2d} from "./vectorUtils";
|
||||
import {drawZebraCrossing, prideZebraPattern, transZebraPattern, zebraPattern} from "./zebraUtils";
|
||||
|
||||
|
||||
function main() {
|
||||
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
|
||||
const ctx = canvas.getContext('2d')!;
|
||||
ctx.lineWidth = 10;
|
||||
|
||||
const start = new Vector2d(10, 110)
|
||||
const end = new Vector2d(110, 60)
|
||||
const line = new Line(start, end)
|
||||
drawZebraCrossing(ctx, new Line(start, new Vector2d(50, 50)),30, zebraPattern)
|
||||
drawZebraCrossing(ctx, line,30, prideZebraPattern)
|
||||
drawZebraCrossing(ctx, new Line(end, new Vector2d(160, 80)),30, transZebraPattern)
|
||||
// line.draw(ctx)
|
||||
// const line = new Line(start, end)
|
||||
//
|
||||
// line.draw(ctx)
|
||||
// normalline.draw(ctx)
|
||||
}
|
||||
|
||||
main()
|
65
src/style.css
Normal file
65
src/style.css
Normal file
|
@ -0,0 +1,65 @@
|
|||
@import "../node_modules/ol/ol.css";
|
||||
|
||||
html, body {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#map {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#canvas{
|
||||
background: #fcd6a4;
|
||||
}
|
||||
|
||||
.ol-popup {
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
|
||||
padding: 15px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #cccccc;
|
||||
bottom: 12px;
|
||||
left: -50px;
|
||||
min-width: 280px;
|
||||
}
|
||||
.ol-popup:after, .ol-popup:before {
|
||||
top: 100%;
|
||||
border: solid transparent;
|
||||
content: " ";
|
||||
height: 0;
|
||||
width: 0;
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
}
|
||||
.ol-popup:after {
|
||||
border-top-color: white;
|
||||
border-width: 10px;
|
||||
left: 48px;
|
||||
margin-left: -10px;
|
||||
}
|
||||
.ol-popup:before {
|
||||
border-top-color: #cccccc;
|
||||
border-width: 11px;
|
||||
left: 48px;
|
||||
margin-left: -11px;
|
||||
}
|
||||
.ol-popup-closer {
|
||||
text-decoration: none;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 8px;
|
||||
}
|
||||
.ol-popup-closer:after {
|
||||
content: "✖";
|
||||
}
|
||||
|
||||
|
||||
p {
|
||||
margin-top: 0;
|
||||
margin-bottom: .5rem;
|
||||
}
|
88
src/vectorUtils.ts
Normal file
88
src/vectorUtils.ts
Normal file
|
@ -0,0 +1,88 @@
|
|||
export class Vector2d {
|
||||
x: number
|
||||
y: number
|
||||
|
||||
constructor(x: number, y: number) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
static fromCoordList(coords: number[]): Vector2d {
|
||||
return new Vector2d(coords[0], coords[1])
|
||||
}
|
||||
|
||||
add(b: Vector2d): Vector2d {
|
||||
return new Vector2d(this.x + b.x, this.y + b.y)
|
||||
}
|
||||
|
||||
mtpl(n: number): Vector2d {
|
||||
return new Vector2d(this.x * n, this.y * n)
|
||||
}
|
||||
|
||||
subtract(b: Vector2d): Vector2d {
|
||||
return new Vector2d(this.x + b.x, this.y + b.y)
|
||||
}
|
||||
|
||||
rotate(angle: number): Vector2d {
|
||||
return new Vector2d(
|
||||
this.x * Math.cos(angle) + this.y * Math.sin(angle),
|
||||
-this.x * Math.sin(angle) + this.y * Math.cos(angle)
|
||||
)
|
||||
}
|
||||
|
||||
rotate90deg(): Vector2d {
|
||||
return new Vector2d(this.y, -this.x)
|
||||
}
|
||||
|
||||
length(): number {
|
||||
return Math.sqrt(this.x ** 2 + this.y ** 2)
|
||||
}
|
||||
|
||||
|
||||
toLength(length: number): Vector2d {
|
||||
const fact = length / this.length()
|
||||
return new Vector2d(this.x * fact, this.y * fact)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function draw(ctx: CanvasRenderingContext2D, start: Vector2d, end: Vector2d): void {
|
||||
ctx.moveTo(start.x, start.y)
|
||||
ctx.lineTo(end.x, end.y)
|
||||
}
|
||||
|
||||
|
||||
export class Line {
|
||||
start: Vector2d
|
||||
end: Vector2d
|
||||
vec: Vector2d
|
||||
|
||||
constructor(start: Vector2d, end: Vector2d) {
|
||||
this.start = start
|
||||
this.end = end
|
||||
this.vec = new Vector2d(end.x - start.x, end.y - start.y)
|
||||
}
|
||||
|
||||
static fromStartandVector(start: Vector2d, vec: Vector2d): Line {
|
||||
const end = start.add(vec)
|
||||
return new Line(start, end)
|
||||
}
|
||||
|
||||
|
||||
drawInCoord(ctx: CanvasRenderingContext2D, ex: Vector2d, ey: Vector2d, eoff: Vector2d): void {
|
||||
const newStart = ex.mtpl(this.start.x).add(ey.mtpl(this.start.y)).add(eoff)
|
||||
const newEnd = ex.mtpl(this.end.x).add(ey.mtpl(this.end.y)).add(eoff)
|
||||
draw(ctx, newStart, newEnd)
|
||||
}
|
||||
|
||||
draw(ctx: CanvasRenderingContext2D): void {
|
||||
ctx.beginPath()
|
||||
ctx.lineWidth = 10
|
||||
draw(ctx, this.start, this.end)
|
||||
ctx.stroke()
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
61
src/zebraUtils.ts
Normal file
61
src/zebraUtils.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import {Line, Vector2d} from "./vectorUtils";
|
||||
import {FlagType} from "../interfaces";
|
||||
|
||||
export const prideFlagColors = ["#e40303", "#ff8c00", "#ffed00", "#008026", "#004dff", "#750787"]
|
||||
export const transFlagColors = ["#5BCEFA", "#F5A9B8"]
|
||||
|
||||
export type PatternFunction = (i: number) => string
|
||||
|
||||
export function zebraPattern(i: number): string {
|
||||
return i % 2 == 0 ? "white" : "black";
|
||||
}
|
||||
|
||||
export function generateFlagZebraPattern(colors: string[]):PatternFunction {
|
||||
return (i: number): string => {
|
||||
if (i % 2) {
|
||||
return "white"
|
||||
} else {
|
||||
const j = Math.floor(i / 2) % colors.length
|
||||
return colors[j]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const prideZebraPattern = generateFlagZebraPattern(prideFlagColors)
|
||||
export const transZebraPattern = generateFlagZebraPattern(transFlagColors)
|
||||
|
||||
export const zebraPatterns: { [d in FlagType]: PatternFunction } = {
|
||||
"prideFlag": prideZebraPattern,
|
||||
"transFlag": transZebraPattern
|
||||
}
|
||||
|
||||
|
||||
export function drawZebraCrossing(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
line: Line,
|
||||
zebraWidth: number,
|
||||
pattern: (i: number) => string, numStripes?: number
|
||||
): void {
|
||||
const ex = line.vec
|
||||
const ey = line.vec.rotate90deg().toLength(zebraWidth)
|
||||
const eoff = line.start
|
||||
// console.log(line.length())
|
||||
// console.log(line.vec)
|
||||
if (typeof numStripes === "undefined") {
|
||||
numStripes = Math.floor(line.vec.length() / 6)
|
||||
}
|
||||
// console.log(numStripes)
|
||||
|
||||
const stripeLength = 1
|
||||
const stripeWidth = stripeLength / numStripes
|
||||
for (let i = 0; i < numStripes; i++) {
|
||||
const x = i * stripeWidth
|
||||
ctx.beginPath()
|
||||
ctx.lineWidth = stripeWidth * ex.length()
|
||||
ctx.strokeStyle = pattern(i)
|
||||
const stripe = new Line(new Vector2d(x, -0.5), new Vector2d(x, 0.5))
|
||||
stripe.drawInCoord(ctx, ex, ey, eoff)
|
||||
ctx.stroke()
|
||||
}
|
||||
|
||||
}
|
104
tsconfig.json
Normal file
104
tsconfig.json
Normal file
|
@ -0,0 +1,104 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "esnext",
|
||||
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
"resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
"noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
23
utils/geo.ts
Normal file
23
utils/geo.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
const earthRadius = 6371; // km
|
||||
|
||||
function toRad(val: number) {
|
||||
return val * Math.PI / 180;
|
||||
}
|
||||
|
||||
export function lineLengthInM(start: number[], end: number[]) {
|
||||
let lat1 = start[0]
|
||||
let lat2 = end[0]
|
||||
const lon1 = start[1]
|
||||
const lon2 = end[1]
|
||||
|
||||
let dLat = toRad(lat2 - lat1)
|
||||
let dLon = toRad(lon2 - lon1)
|
||||
lat1 = toRad(lat1);
|
||||
lat2 = toRad(lat2);
|
||||
|
||||
let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
||||
Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
|
||||
let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
const value = earthRadius * c * 1000
|
||||
return Math.round(value * 100) / 100
|
||||
}
|
16
vite.config.js
Normal file
16
vite.config.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import {defineConfig} from "vite";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
// splitVendorChunkPlugin(),
|
||||
// visualizer(),
|
||||
],
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
"index": 'index.html',
|
||||
"canvastest": 'canvastest.html',
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in a new issue