Skip to content

Commit

Permalink
Add estimated map location based on other posts
Browse files Browse the repository at this point in the history
Remove the default map location, and instead base it on the location
of existing posts.

Ref: #121
  • Loading branch information
samwilson authored Nov 12, 2022
1 parent b582831 commit 4b9e015
Show file tree
Hide file tree
Showing 33 changed files with 2,494 additions and 2,666 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ The user manual is at [twyne.readthedocs.io](https://twyne.readthedocs.io/).
## Attribution

* [assets/img/feed-icon.png](https://commons.wikimedia.org/wiki/File:Feed-icon.svg) Originally distributed by the Mozilla Foundation under a MPL/GPL/LGPL tri-license.
* [Feather Icons](https://feathericons.com), MIT license.
Binary file added assets/img/send-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/send.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/img/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 39 additions & 7 deletions assets/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function moveMap () {

// Marker.
let marker = null;
let defaultView = [-32.054178, 115.7475];
let defaultView = [0, 0];
const mapData = document.getElementById('map').dataset;
if (mapData && mapData.latitude && mapData.longitude) {
defaultView = new L.LatLng(mapData.latitude, mapData.longitude);
Expand Down Expand Up @@ -92,15 +92,47 @@ map.on('click', clickEvent => {
moveMarker(clickEvent.latlng);
});

const dateInput = document.querySelector('input[name="date"]');
let estimatedMarker = null;
dateInput.addEventListener('change', (event) => {
setEstimatedLocation(event.target.value);
});
setEstimatedLocation(dateInput.value);

function setEstimatedLocation (date) {
// eslint-disable-next-line no-undef
const geojsonUrl = appBaseUrl + 'map/estimates.json?date=' + date;
const dataRequest = new XMLHttpRequest();
dataRequest.addEventListener('load', function () {
const data = JSON.parse(this.responseText);
const estimatedLatLng = [data.lat, data.lng];
if (estimatedMarker === null) {
estimatedMarker = new L.Marker(estimatedLatLng, {
icon: getIcon('send', [23, 23], [23, 0])
});
map.addLayer(estimatedMarker);
} else {
estimatedMarker.setLatLng(estimatedLatLng);
}
map.setView(estimatedLatLng, 12);
});
dataRequest.open('GET', geojsonUrl);
dataRequest.send();
}

function getIcon (name, size, anchor) {
return L.icon({
iconUrl: '/build/images/' + name + '.png',
iconRetinaUrl: '/build/images/' + name + '-2x.png',
iconSize: size,
iconAnchor: anchor
});
}

function makeMarker (latLng) {
marker = new L.Marker(latLng, {
draggable: mapData.edit,
icon: L.icon({
iconUrl: '/build/images/map-pin.png',
iconRetinaUrl: '/build/images/map-pin-2x.png',
iconSize: [20, 24],
iconAnchor: [10, 24]
})
icon: getIcon('map-pin', [20, 24], [10, 24])
});
map.addLayer(marker);
marker.on('dragend', dragEvent => {
Expand Down
4,928 changes: 2,323 additions & 2,605 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
"license": "GPL-3.0-or-later",
"private": true,
"devDependencies": {
"@symfony/webpack-encore": "^1.7.0",
"codemirror": "^5.65.0",
"core-js": "^3.20.2",
"@symfony/webpack-encore": "^1.8.2",
"codemirror": "^5.65.9",
"core-js": "^3.26.0",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-standard": "^5.0.0",
"file-loader": "^6.2.0",
"jquery": "^3.6.0",
"leaflet": "^1.7.1",
"less": "^4.1.2",
"jquery": "^3.6.1",
"leaflet": "^1.9.2",
"less": "^4.1.3",
"less-loader": "^8.1.1",
"normalize.css": "^8.0.1",
"postcss": "^8.4.5",
"postcss": "^8.4.19",
"postcss-loader": "^5.3.0",
"regenerator-runtime": "^0.13.9",
"regenerator-runtime": "^0.13.10",
"select2": "^4.0.13",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^22.0.0",
Expand Down
1 change: 1 addition & 0 deletions public/build/53.59dd341e.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion public/build/53.ef753eab.js

This file was deleted.

2 changes: 2 additions & 0 deletions public/build/805.3e825de1.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/build/805.3e825de1.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* @preserve
* Leaflet 1.9.2, a JS library for interactive maps. https://leafletjs.com
* (c) 2010-2022 Vladimir Agafonkin, (c) 2010-2011 CloudMade
*/
2 changes: 0 additions & 2 deletions public/build/805.93aa7c75.js

This file was deleted.

4 changes: 0 additions & 4 deletions public/build/805.93aa7c75.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion public/build/98.5d084e7d.js

This file was deleted.

Loading

0 comments on commit 4b9e015

Please sign in to comment.