Refactor DOT cam layers; misc features

* Add more travel-iq states
 * Combine DOT cam layer UI into single place
 * Use standard schema for cam data
 * Differentiate between photo and video cameras
This commit is contained in:
Chandler Swift 2024-01-31 01:17:04 -06:00
parent 710930f428
commit dbcd151364
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
16 changed files with 324 additions and 276 deletions

View file

@ -4,13 +4,21 @@ import requests
import json
import re
with open('states.json') as f:
states = json.loads(f.read())
states = {
"Minnesota": "https://511mn.org/",
"Colorado": "https://maps.cotrip.org/",
"Iowa": "https://511ia.org/",
"Indiana": "https://511in.org/",
"Kansas": "https://www.kandrive.gov/",
"Massachusetts": "https://mass511.com/",
"Nebraska": "https://new.511.nebraska.gov/"
}
with open("query.graphql") as f:
QUERY = f.read()
for state, baseURL in states.items():
print(f"{state}: ", end="", flush=True)
PAYLOAD = [
{
"query": QUERY,
@ -38,6 +46,8 @@ for state, baseURL in states.items():
cameras = []
viewCount = 0
photoCount = 0
videoCount = 0
for c in camera_views:
if len(c['features']) != 1:
@ -47,22 +57,36 @@ for state, baseURL in states.items():
if re.match(r"Show .* cameras", c['tooltip']):
raise Exception(f"Not zoomed in enough! Finding aggregate cameras: {c}")
if len(c['views']) == 0:
raise Exception("Camera has no views")
for view in c['views']:
if len(view['sources']) != 1 if view['category'] == 'VIDEO' else 0:
print(view)
raise Exception(f"Unexpected number of sources ({len(view['sources'])})")
if view['category'] != c['views'][0]['category']:
print(f"warn: Differing types detected: {c['views']}")
if view['category'] == 'VIDEO':
if state == "Nebraska":
print(c)
videoCount += 1
if len(view['sources']) != 1:
raise Exception(f"Unexpected number of sources ({len(view['sources'])})")
else:
photoCount += 1
for source in view['sources'] or []:
if source['type'] != 'application/x-mpegURL':
raise Exception(f"Unexpected type {source['type']}")
viewCount += len(c['views'])
cameras.append({
"type": "Feature",
"geometry": c['features'][0]['geometry'],
"properties": {
'address': c['tooltip'],
'website': c['views'][0]['url'],
'originalData': c,
'name': c['tooltip'],
'views': [
{
'hasVideo': v['category'] == 'VIDEO',
'src': v['sources'][0]['src'] if v['category'] == 'VIDEO' else v['url'],
} for v in c['views']
],
# 'originalData': c,
},
})
@ -74,8 +98,8 @@ for state, baseURL in states.items():
with open(f"data/{state}.geojson", "w") as f:
f.write(json.dumps(geojson))
print(f"{len(cameras)} locations found for {state}")
print(f"{viewCount} total views for {state}")
print(f"{len(cameras)} locations found")
print(f"{state}: {photoCount} photo + {videoCount} video cameras")
# hack hack hack
#

View file

@ -1,75 +0,0 @@
import VectorLayer from 'ol/layer/Vector';
import {Vector as VectorSource} from 'ol/source.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import Hls from 'hls.js';
import {Style} from 'ol/style.js';
import Icon from 'ol/style/Icon.js';
import states from './data/states.js';
import pin from './pin.svg?url'; // TODO: remove `?url`?
// https://en.wikipedia.org/wiki/Department_of_transportation#List_of_U.S._state_and_insular_area_departments_of_transportation
const dot_names = {
mn: "Minnesota: MNDOT/511MN",
ia: "Iowa: Iowa DOT/511IA",
wi: "Wisconsin: WisDOT/511WI",
co: "Colorado: CDOT/COtrip",
ks: "Kansas: KDOT/KanDrive",
ne: "Nebraska: NDOT/Nebraska 511",
ma: "Massachusetts: MassDOT/Mass511",
}
let vectorLayers = []
for (let [state, url] of Object.entries(states)) {
const vectorLayer = new VectorLayer({
source: new VectorSource({
url: url,
format: new GeoJSON,
}),
style: new Style({
image: new Icon({
anchor: [0.5, 1],
src: pin,
}),
}),
});
vectorLayer.customPopup = function(feature) {
const view = feature.values_.originalData.views[0];
if (view.category.toLowerCase() == "video") {
return `<video style="max-width: 80vw; max-height: 80vh;" id="popupVideo" autoplay controls></video>`;
} else if (view.category.toLowerCase() == "image") {
return `<img style="max-width: 80vw; max-height: 80vh;" src="${view.url}">`;
} else {
throw new Exception(`unknown category ${view.category}`);
}
};
vectorLayer.customPopupCallback = function(feature) {
const view = feature.values_.originalData.views[0];
if (view.category.toLowerCase() == "video") {
const video = document.getElementById('popupVideo');
const videoSrc = view.sources[0].src;
if (Hls.isSupported()) {
var hls = new Hls();
hls.loadSource(videoSrc);
hls.attachMedia(video);
}
// iDevice support, untested (only works in Safari; required for iPhones)
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = videoSrc;
}
}
}
vectorLayers.push({
name: dot_names[state] ?? state,
layer: vectorLayer,
});
}
export default vectorLayers;

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 384 512"
width="40px"
height="30px"
version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. -->
<path
d="m 384,192 c 0,87.4 -117,243 -168.3,307.2 -12.3,15.3 -35.1,15.3 -47.4,0 C 116.1,435 0,279.4 0,192 0,85.96 85.96,0 192,0 245.96029,0 294.73775,22.275796 329.62577,58.136607 363.27205,92.721042 384,139.94065 384,192 Z"
style="fill:#000;fill-opacity:1" />
<g transform="translate(-10 -52.362) scale(0.4)">
<g transform="matrix(1.1311 0 0 1.1311 -76.881 -20.513)">
<rect style="stroke:#ffffff;stroke-width:7.7518;fill:#ffffff" ry="57.185" height="337.9" width="560.25" y="363.1" x="233.88" />
<rect style="stroke:#ffffff;stroke-width:7.2923;fill:#ffffff" ry="40.515" height="81.03" width="241.25" y="310.54" x="389.61" />
</g>
<path style="stroke:#000000;stroke-width:32;fill:#00000000" d="m508.57 188.08c0 32.348-26.223 58.571-58.571 58.571s-58.571-26.223-58.571-58.571 26.223-58.571 58.571-58.571c32.339 0 58.559 26.209 58.571 58.548" transform="matrix(1.4504 0 0 1.4504 -257.49 -204.11) matrix(1.274 0 0 1.274 -47.288 304.47)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -1,9 +0,0 @@
{
"mn": "https://511mn.org/",
"co": "https://maps.cotrip.org/",
"ia": "https://511ia.org/",
"in_": "https://511in.org/",
"ks": "https://www.kandrive.gov/",
"ma": "https://mass511.com/",
"ne": "https://new.511.nebraska.gov/"
}