|
| 1 | +// const locations = [ |
| 2 | +// { timestamp: new Date(2022, 5, 15), lat: 47.22797, lng: -79.9651 }, |
| 3 | +// { timestamp: new Date(2022, 5, 15), lat: 48.22797, lng: -79.9651 }, |
| 4 | +// { timestamp: new Date(2022, 5, 15), lat: 47.22797, lng: -80.9651 }, |
| 5 | +// ]; |
| 6 | + |
| 7 | +import { locations } from "./locations.js"; |
| 8 | + |
| 9 | +function createGeoJsonTripPoints(locations) { |
| 10 | + return { |
| 11 | + type: "FeatureCollection", |
| 12 | + features: locations.map((location) => ({ |
| 13 | + type: "Feature", |
| 14 | + properties: { |
| 15 | + date: location.timestamp, |
| 16 | + }, |
| 17 | + geometry: { |
| 18 | + type: "Point", |
| 19 | + coordinates: [location.lng, location.lat], |
| 20 | + }, |
| 21 | + })), |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +const map = L.map("map").setView([47.22797, -79.9651], 13); |
| 26 | + |
| 27 | +const tiles = L.tileLayer( |
| 28 | + "https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw", |
| 29 | + { |
| 30 | + maxZoom: 18, |
| 31 | + attribution: |
| 32 | + 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, ' + |
| 33 | + 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>', |
| 34 | + id: "mapbox/streets-v11", |
| 35 | + tileSize: 512, |
| 36 | + zoomOffset: -1, |
| 37 | + } |
| 38 | +).addTo(map); |
| 39 | + |
| 40 | +const points = createGeoJsonTripPoints(locations) |
| 41 | + |
| 42 | +L.geoJSON(points).addTo(map); |
| 43 | +// var marker = L.marker([47.22797, -79.9651]) |
| 44 | +// var marker = L.marker([locations[0].lat, locations[0].lng]) |
| 45 | +// .addTo(map) |
| 46 | +// .bindPopup("2022-05-15") |
| 47 | +// .openPopup(); |
| 48 | + |
| 49 | +// var circle = L.circle([51.508, -0.11], { |
| 50 | +// color: "red", |
| 51 | +// fillColor: "#f03", |
| 52 | +// fillOpacity: 0.5, |
| 53 | +// radius: 500, |
| 54 | +// }) |
| 55 | +// .addTo(map) |
| 56 | +// .bindPopup("I am a circle."); |
| 57 | + |
| 58 | +// var polygon = L.polygon([ |
| 59 | +// [51.509, -0.08], |
| 60 | +// [51.503, -0.06], |
| 61 | +// [51.51, -0.047], |
| 62 | +// ]) |
| 63 | +// .addTo(map) |
| 64 | +// .bindPopup("I am a polygon."); |
| 65 | + |
| 66 | +// var popup = L.popup() |
| 67 | +// .setLatLng([51.513, -0.09]) |
| 68 | +// .setContent("I am a standalone popup.") |
| 69 | +// .openOn(map); |
| 70 | + |
| 71 | +// function onMapClick(e) { |
| 72 | +// popup |
| 73 | +// .setLatLng(e.latlng) |
| 74 | +// .setContent("You clicked the map at " + e.latlng.toString()) |
| 75 | +// .openOn(map); |
| 76 | +// } |
| 77 | + |
| 78 | + |
| 79 | +// function createGeoJsonTripLines(locations) { |
| 80 | +// return { |
| 81 | +// “type”: “FeatureCollection”, |
| 82 | +// “features”: locations.map((stop = {}, index) => { |
| 83 | +// const prevStop = locations[index - 1]; |
| 84 | + |
| 85 | +// if ( !prevStop ) return []; |
| 86 | + |
| 87 | +// const { placename, location = {}, date, todo = [] } = stop; |
| 88 | +// const { lat, lng } = location; |
| 89 | +// const properties = { |
| 90 | +// placename, |
| 91 | +// todo, |
| 92 | +// date |
| 93 | +// }; |
| 94 | + |
| 95 | +// const { location: prevLocation = {} } = prevStop; |
| 96 | +// const { lat: prevLat, lng: prevLng } = prevLocation; |
| 97 | + |
| 98 | +// return { |
| 99 | +// type: ‘Feature’, |
| 100 | +// properties, |
| 101 | +// geometry: { |
| 102 | +// type: ‘LineString’, |
| 103 | +// coordinates: [ |
| 104 | +// [ prevLng, prevLat ], |
| 105 | +// [ lng, lat ] |
| 106 | +// ] |
| 107 | +// } |
| 108 | +// } |
| 109 | +// }) |
| 110 | +// } |
| 111 | +// } |
| 112 | + |
| 113 | +// map.on("click", onMapClick); |
0 commit comments