diff --git a/layers/index.js b/layers/index.js index 59ca460..4ae7f7b 100644 --- a/layers/index.js +++ b/layers/index.js @@ -12,6 +12,8 @@ import states from './states/index.js'; import national_land from './national-land/index.js'; import cellular from './cellular.js'; import light_pollution from './light_pollution.js'; +import state_land from './state-land/index.js'; +import trips from './trips/index.js'; const layerCategories = [ { // Base maps @@ -75,10 +77,12 @@ const layerCategories = [ }, ] }, + trips, chains, census_bureau, states, national_land, + state_land, cellular, light_pollution, ]; diff --git a/layers/state-land/get_data.sh b/layers/state-land/get_data.sh new file mode 100755 index 0000000..a989b8d --- /dev/null +++ b/layers/state-land/get_data.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# https://gisdata.mn.gov/dataset/bdry-dnr-lrs-prk +curl --silent --remote-name https://resources.gisdata.mn.gov/pub/gdrs/data/pub/us_mn_state_dnr/bdry_dnr_lrs_prk/shp_bdry_dnr_lrs_prk.zip +unzip shp_bdry_dnr_lrs_prk.zip +ogr2ogr -f GeoJSON mn-state-parks.geojson dnr_stat_plan_areas_prk.shp +# sed -i '/^"crs":/d' mn-state-parks.geojson # TODO: handle this projection properly +rm -r dnr_* metadata shp_bdry_dnr_lrs_prk.zip diff --git a/layers/state-land/index.js b/layers/state-land/index.js new file mode 100644 index 0000000..4d52dd8 --- /dev/null +++ b/layers/state-land/index.js @@ -0,0 +1,48 @@ +import GeoJSON from 'ol/format/GeoJSON.js'; +import VectorLayer from 'ol/layer/Vector.js'; +import VectorSource from 'ol/source/Vector.js'; + +import stateParks from './mn-state-parks.geojson?url'; + +import { Fill, Stroke, Style, Text } from 'ol/style.js'; + +// Projection stuff +import proj4 from 'proj4'; +import {register} from 'ol/proj/proj4.js'; +// https://epsg.io/26915.proj4js +proj4.defs("EPSG:26915","+proj=utm +zone=15 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs"); +register(proj4); + + +function style(feature){ + return new Style({ + text: new Text({ + text: feature.get('AREA_NAME') + ' ' + feature.get('AREA_TYPE'), + }), + fill: new Fill({ + color: 'rgba(255,255,255,0.4)', + }), + stroke: new Stroke({ + color: '#008800', + width: 1.25, + }), + }); +} + +const layers = { + name: "MN State Parks", + layers: [ + { + name: "State Parks", + layer: new VectorLayer({ + source: new VectorSource({ + url: stateParks, + format: new GeoJSON(), + }), + style: style, + }), + }, + ], +}; + +export default layers; diff --git a/layers/trips/index.js b/layers/trips/index.js new file mode 100644 index 0000000..a03a3ba --- /dev/null +++ b/layers/trips/index.js @@ -0,0 +1,13 @@ +import ncAug2023 from './trahan-north-carolina-august-2023/layer.js' + +const trips = { + name: "Trips", + layers: [ + { + name: "North Carolina 2023-08 with Trahans", + layer: ncAug2023, + }, + ], +}; + +export default trips; diff --git a/layers/trips/trahan-north-carolina-august-2023/get_data.sh b/layers/trips/trahan-north-carolina-august-2023/get_data.sh new file mode 100755 index 0000000..86e9f50 --- /dev/null +++ b/layers/trips/trahan-north-carolina-august-2023/get_data.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +FROM="2023-08-24T12:45:00.000Z" +TO="2023-09-01T21:50:00.000Z" +URL="https://whereis.chandlerswift.com/api/0/locations?from=$FROM&to=$TO&format=geojson&user=chandler&device=oneplus6t" + +curl --silent "$URL" \ + | python "$(dirname $0)/../../../util/process_owntracks_geojson_to_line.py" \ + > data.geojson diff --git a/layers/trips/trahan-north-carolina-august-2023/layer.js b/layers/trips/trahan-north-carolina-august-2023/layer.js new file mode 100644 index 0000000..1566dca --- /dev/null +++ b/layers/trips/trahan-north-carolina-august-2023/layer.js @@ -0,0 +1,26 @@ +import VectorLayer from 'ol/layer/Vector'; +import {Vector as VectorSource} from 'ol/source.js'; +import GeoJSON from 'ol/format/GeoJSON.js'; + +import {Style, Stroke} from 'ol/style.js'; + +import url from './data.geojson?url'; // TODO: remove `?url`? + +const colors = '135, 0, 226'; // Käthe says lavender + +const vectorLayer = new VectorLayer({ + source: new VectorSource({ + url: url, + format: new GeoJSON, + }), + style: function(feature, resolution){ + return new Style({ + stroke: new Stroke({ + color: `rgba(${colors},${Math.min(1, Math.pow(resolution/10, 1/4))})`, + width: 10/Math.pow(resolution, 1/4), + }) + }); + }, +}); + +export default vectorLayer; diff --git a/package-lock.json b/package-lock.json index 9c22214..280a28c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,10 +8,11 @@ "name": "maps.chandlerswift.com", "version": "0.0.0", "dependencies": { - "ol": "latest" + "ol": "latest", + "proj4": "2.9.0" }, "devDependencies": { - "vite": "^4.0.4" + "vite": "^4.3.9" } }, "node_modules/@esbuild/android-arm": { @@ -534,6 +535,11 @@ "resolved": "https://registry.npmjs.org/mapbox-to-css-font/-/mapbox-to-css-font-2.4.1.tgz", "integrity": "sha512-QQ/iKiM43DM9+aujTL45Iz5o7gDeSFmy4LPl3HZmNcwCE++NxGazf+yFpY+wCb+YS23sDa1ghpo3zrNFOcHlow==" }, + "node_modules/mgrs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/mgrs/-/mgrs-1.0.0.tgz", + "integrity": "sha512-awNbTOqCxK1DBGjalK3xqWIstBZgN6fxsMSiXLs9/spqWkF2pAhb2rrYCFSsr1/tT7PhcDGjZndG8SWYn0byYA==" + }, "node_modules/minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", @@ -638,6 +644,15 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/proj4": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/proj4/-/proj4-2.9.0.tgz", + "integrity": "sha512-BoDXEzCVnRJVZoOKA0QHTFtYoE8lUxtX1jST38DJ8U+v1ixY70Kpwi0Llu6YqSWEH2xqu4XMEBNGcgeRIEywoA==", + "dependencies": { + "mgrs": "1.0.0", + "wkt-parser": "^1.3.1" + } + }, "node_modules/protocol-buffers-schema": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz", @@ -775,6 +790,11 @@ "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==" }, + "node_modules/wkt-parser": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/wkt-parser/-/wkt-parser-1.3.3.tgz", + "integrity": "sha512-ZnV3yH8/k58ZPACOXeiHaMuXIiaTk1t0hSUVisbO0t4RjA5wPpUytcxeyiN2h+LZRrmuHIh/1UlrR9e7DHDvTw==" + }, "node_modules/xml-utils": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.2.0.tgz", @@ -1065,6 +1085,11 @@ "resolved": "https://registry.npmjs.org/mapbox-to-css-font/-/mapbox-to-css-font-2.4.1.tgz", "integrity": "sha512-QQ/iKiM43DM9+aujTL45Iz5o7gDeSFmy4LPl3HZmNcwCE++NxGazf+yFpY+wCb+YS23sDa1ghpo3zrNFOcHlow==" }, + "mgrs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/mgrs/-/mgrs-1.0.0.tgz", + "integrity": "sha512-awNbTOqCxK1DBGjalK3xqWIstBZgN6fxsMSiXLs9/spqWkF2pAhb2rrYCFSsr1/tT7PhcDGjZndG8SWYn0byYA==" + }, "minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", @@ -1133,6 +1158,15 @@ "source-map-js": "^1.0.2" } }, + "proj4": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/proj4/-/proj4-2.9.0.tgz", + "integrity": "sha512-BoDXEzCVnRJVZoOKA0QHTFtYoE8lUxtX1jST38DJ8U+v1ixY70Kpwi0Llu6YqSWEH2xqu4XMEBNGcgeRIEywoA==", + "requires": { + "mgrs": "1.0.0", + "wkt-parser": "^1.3.1" + } + }, "protocol-buffers-schema": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz", @@ -1215,6 +1249,11 @@ "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==" }, + "wkt-parser": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/wkt-parser/-/wkt-parser-1.3.3.tgz", + "integrity": "sha512-ZnV3yH8/k58ZPACOXeiHaMuXIiaTk1t0hSUVisbO0t4RjA5wPpUytcxeyiN2h+LZRrmuHIh/1UlrR9e7DHDvTw==" + }, "xml-utils": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.2.0.tgz", diff --git a/package.json b/package.json index c78adfe..fe63e78 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "vite": "^4.3.9" }, "dependencies": { - "ol": "latest" + "ol": "latest", + "proj4": "2.9.0" } } diff --git a/util/process_owntracks_geojson_to_line.py b/util/process_owntracks_geojson_to_line.py new file mode 100644 index 0000000..0e03878 --- /dev/null +++ b/util/process_owntracks_geojson_to_line.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +import json +import math +import sys + +# https://stackoverflow.com/a/19412565 +# returns distance in kilometers +def distance(lat1, lon1, lat2, lon2): + R = 6373.0 # Approximate radius of earth in km + + lat1 = math.radians(52.2296756) + lon1 = math.radians(21.0122287) + lat2 = math.radians(52.406374) + lon2 = math.radians(16.9251681) + + dlon = lon2 - lon1 + dlat = lat2 - lat1 + + a = math.sin(dlat / 2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2)**2 + c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + + return R * c + +data = json.load(sys.stdin) + +coordinates = [] + +for feature in data['features']: + if feature['properties']['acc'] < 500: + coordinates.append(feature['geometry']['coordinates']) + # TODO: auto prune unnecessary points (e.g. too close to previous points?) + +print(json.dumps({ + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": coordinates, + }, +}))