Skip to content

Commit

Permalink
Merge branch 'routing'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihkel Oviir committed Oct 1, 2019
2 parents a5aa5cf + e03ddd2 commit 76eeddd
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 73 deletions.
14 changes: 12 additions & 2 deletions src/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export const app = {
debug: false, // collect all console debug, info and error into downloadable file
debugFile: 'geop_debug.log',
nominatimCountries: 'ee',
routing: true
routing: {
provider: 'openrouteservice', // provider key or null
profile: 'driving'// driving, hiking, ''
}
}
export const map = {
el: '#map',
Expand All @@ -38,7 +41,14 @@ export const apiUrls = {
nominatim: 'https://nominatim.openstreetmap.org',
jsonstore: 'https://www.jsonstore.io/4d04eefd7ed4c19866cefcf038d0bebe95786bf33f0e60fdfbd8a554e6ae2670',
qrcode: 'http://api.qrserver.com/v1/create-qr-code/?size=150x150&data=',
osrm: 'https://router.project-osrm.org/route/v1/driving/',
osrm: {
directions: 'https://router.project-osrm.org/route/v1/'
},
openrouteservice: {
key: '5b3ce3597851110001cf6248b99b83882966492086eee3c4a0522e9c',
directions: 'https://api.openrouteservice.org/v2/directions/',
optimize: 'https://api.openrouteservice.org/optimization/'
},
google: {
streetview: 'https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=',
directions: 'https://www.google.com/maps/dir/?api=1&destination='
Expand Down
36 changes: 30 additions & 6 deletions src/config/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@
"Debug mode. Will write debug logs into file. App will reload after change!": "Debug mode. Will write debug logs into file. App will reload after change!",
"Directions from here": "Directions from here",
"Directions to here": "Directions to here",
"Disabled": "Disabled",
"Download": "Download",
"Download debug log": "Download debug log",
"download GPX from": "download GPX from",
"Driving": "Driving",
"Driving directions between points or from your current location": "Driving directions between points or from your current location",
"Edit OSM here": "Edit OSM here",
"Empty file": "Empty file",
"Enter geopeitus.ee or geocaching.com username. App will reload after change!": "Enter geopeitus.ee or geocaching.com username. App will reload after change!",
"Error creating layer": "Error creating layer",
"Feature": "Feature",
"features": "features",
"Features": "Features",
"features": "features",
"Filter": "Filter",
"Filter and search caches on map.": "Filter and search caches on map.",
"Find streetview link and measure tools from context menu.": "Find streetview link and measure tools from context menu.",
Expand All @@ -67,14 +69,17 @@
"Geocache|Whereigo Cache": "Whereigo Cache",
"Geop is progressive web application with partial offline support.": "Geop is progressive web application with partial offline support.",
"Geotrip": "Geotrip",
"Geotrip reordered by optimum path": "Geotrip reordered by optimum path",
"Go to": "Go to",
"gpxActive": "Active caches",
"gpxAll": "All caches (active, archived, unavailable)",
"here": "here",
"Hiking": "Hiking",
"Insert WMS v.1.1.1 URL with LAYERS and SRS parameters": "Insert WMS v.1.1.1 URL with LAYERS and SRS parameters",
"Install app to home screen": "Install app to home screen",
"Install it to Your home screen.": "Install it to Your home screen.",
"Install web app to your home screen.": "Install web app to your home screen.",
"Invalid route": "Invalid route",
"Keep awake": "Keep awake",
"Keep screen on. Use with caution, might train device battery!": "Keep screen on. Use with caution, might train device battery!",
"Language": "Language",
Expand All @@ -89,6 +94,7 @@
"Measure": "Measure",
"Micro": "Micro",
"Missing LAYERS parameter": "Missing LAYERS parameter",
"Missing provider, aborting!": "Missing provider, aborting!",
"Missing SRS parameter": "Missing SRS parameter",
"My location": "My location",
"Navigate to cache with two tracking mode": "Navigate to cache with two tracking mode",
Expand All @@ -97,12 +103,14 @@
"No baselyers added": "No baselyers added",
"No overlays added": "No overlays added",
"No result": "No result",
"No route between start and destination": "No route between start and destination",
"No valid input coordinates, aborting!": "No valid input coordinates, aborting!",
"North up!": "North up!",
"Not Found": "Not Found",
"Not valid GeoJSON": "Not valid GeoJSON",
"Off": "Off",
"On": "On",
"Optimize": "Optimize",
"or": "or",
"or open": "or open",
"Owner": "Owner",
Expand All @@ -115,9 +123,13 @@
"Reset app": "Reset app",
"Reset app to default. App will reload!": "Reset app to default. App will reload!",
"Retry directions": "Retry directions",
"Routing": "Routing",
"Routing disabled": "Routing disabled",
"Routing input test failed, aborting!": "Routing input test failed, aborting!",
"Search": "Search",
"Search and display coordinates in WGS, L-Est, UTM and MGRS system.": "Search and display coordinates in WGS, L-Est, UTM and MGRS system.",
"Search coordinates": "Search coordinates",
"Select routing profile or disable routing": "Select routing profile or disable routing",
"Settings": "Settings",
"Share": "Share",
"Share bookmark": "Share bookmark",
Expand All @@ -135,6 +147,7 @@
"Topo": "Topo",
"Unable to copy to clipboard": "Unable to copy to clipboard",
"Unable to delete bookmark": "Unable to delete bookmark",
"Unable to determine ordering": "Unable to determine ordering",
"Unable to find layer extent": "Unable to find layer extent",
"Unable to find location.": "Unable to find location.",
"Unable to find route": "Unable to find route",
Expand All @@ -157,8 +170,7 @@
"Waypoint|Trailhead": "Trailhead",
"Waypoint|Virtual Stage": "Virtual Stage",
"Zoom in": "Zoom in",
"Zoom out": "Zoom out",
"No route between start and destination": "No route between start and destination"
"Zoom out": "Zoom out"
},
"et": {
"Account": "Konto",
Expand Down Expand Up @@ -200,17 +212,19 @@
"Debug mode. Will write debug logs into file. App will reload after change!": "Silumisrežiim. Silumise logid kirjutatakse faili. Rakendus taaskäivitub peale muutmist!",
"Directions from here": "Teekonna algus",
"Directions to here": "Teekonna lõpp",
"Disabled": "Keelatud",
"Download": "Lae alla",
"Download debug log": "Lae alla logifail",
"download GPX from": "lae GPX",
"Driving": "Auto",
"Driving directions between points or from your current location": "Teekonna arvutus kahe punkti või kaardiobjekti vahel ja kasutaja asukohast sihtpunkti.",
"Edit OSM here": "Muuda OSMi",
"Empty file": "Tühi fail",
"Enter geopeitus.ee or geocaching.com username. App will reload after change!": "Sisesta geopeitus.ee või geocaching.com kasutajanimi. Rakendus taaskäivitub peale muutmist!",
"Error creating layer": "Kihi loomine ebaõnnestus",
"Feature": "Objekt",
"features": "objekti",
"Features": "Objektid",
"features": "objekti",
"Filter": "Filter",
"Filter and search caches on map.": "Filtreeri ja otsi aardeid.",
"Find streetview link and measure tools from context menu.": "Parema kliki menüüst leiad tänavavaate ja mõõtmise tööriistad.",
Expand All @@ -228,14 +242,17 @@
"Geocache|Whereigo Cache": "Whereigo aare",
"Geop is progressive web application with partial offline support.": "Geop on progressiivne veebirakendus (PWA) osalise võrguta töötamise toega.",
"Geotrip": "Geotuur",
"Geotrip reordered by optimum path": "Geotuur järjestatud lühima teekonna järgi",
"Go to": "Mine",
"gpxActive": "Aktiivsed aarded",
"gpxAll": "Kõik aarded (aktiivsed, arhiveeritud, ajutiselt kättesaamatud)",
"here": "siit",
"Hiking": "Matk",
"Insert WMS v.1.1.1 URL with LAYERS and SRS parameters": "Sisesta siia kasti WMS (1.1.1) aadress koos LAYERS ja SRS parameetriga",
"Install app to home screen": "Paigalda rakendus",
"Install it to Your home screen.": "Paigalda rakendus avalehele.",
"Install web app to your home screen.": "Paigalda rakendus oma seadmesse.",
"Invalid route": "Vale teekond",
"Keep awake": "Hoia ekraan töös",
"Keep screen on. Use with caution, might train device battery!": "Hoia ekraan aktiivne. Pidevalt töötav ekraan kulutab akut!",
"Language": "Keel",
Expand All @@ -250,6 +267,7 @@
"Measure": "Mõõda",
"Micro": "Mikro",
"Missing LAYERS parameter": "WMS aadress peab sisaldama LAYERS parameetrit",
"Missing provider, aborting!": "Puudub teenus!",
"Missing SRS parameter": "WMS aadress peab sisaldama SRS parameetrit",
"My location": "Asukoht",
"Navigate to cache with two tracking mode": "Asukoha näitamine kahes režiimis (asukoht liigub ekraanil; asukoht on ekraanil fikseeritud).",
Expand All @@ -258,12 +276,14 @@
"No baselyers added": "Pole aluskaarte",
"No overlays added": "Pole kaardikihte",
"No result": "Otsingutulemused puuduvad",
"No route between start and destination": "Teekond alguse ja sihtpunkti vahel puudub",
"No valid input coordinates, aborting!": "Sisendkoordinaadid ei vasta nõuetele, ei otsi!",
"North up!": "Põhi!",
"Not Found": "Leidmata",
"Not valid GeoJSON": "Ei ole korrektne GeoJSON",
"Off": "Off",
"On": "On",
"Optimize": "Optimeeri",
"or": "või",
"or open": "või ava",
"Owner": "Omanik",
Expand All @@ -276,9 +296,13 @@
"Reset app": "Rakenduse vaikeseaded",
"Reset app to default. App will reload!": "Taasta rakenduse vaikeseaded. Rakendus taaskäivitub peale muutmist!",
"Retry directions": "Uuesti",
"Routing": "Teekond",
"Routing disabled": "Teekonna leidmine keelatud",
"Routing input test failed, aborting!": "Teekonna sisendid ei ole õiged!",
"Search": "Otsi",
"Search and display coordinates in WGS, L-Est, UTM and MGRS system.": "Otsi ja kuva koordinaate WGS, L-Est, UTM ja MGRS koordinaatsüsteemides.",
"Search coordinates": "Otsi koordinaate",
"Select routing profile or disable routing": "Vali teekonna profiil või keela teekond",
"Settings": "Seaded",
"Share": "Jaga",
"Share bookmark": "Jaga järjehoidjat",
Expand All @@ -296,6 +320,7 @@
"Topo": "Põhikaart",
"Unable to copy to clipboard": "Ei saanud kopeerida",
"Unable to delete bookmark": "Ei saanud järjehoidjat kustutada!",
"Unable to determine ordering": "Ei saa järjekorda määrata!",
"Unable to find layer extent": "Ei leia kihi ulatust",
"Unable to find location.": "Ei leia asukohta!",
"Unable to find route": "Ei leia teekonda",
Expand All @@ -318,7 +343,6 @@
"Waypoint|Trailhead": "Matkaraja algus",
"Waypoint|Virtual Stage": "Virtuaalne vahepunkt",
"Zoom in": "Suurenda",
"Zoom out": "Vähenda",
"No route between start and destination": "Teekond alguse ja sihtpunkti vahel puudub"
"Zoom out": "Vähenda"
}
}
9 changes: 9 additions & 0 deletions src/geop/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class Provider {
this.xhr.abort()
}
}
test (coords) {
return !(coords.length < 2)
}
formatInput (coords, join = false) {
return coords.filter(lonLat => !!lonLat).map(lonLat => {
const pair = lonLat.slice(0, 2)
return join ? pair.join() : pair
})
}
toGeoJSON (data) {
data.id = data.id || uid()
return {
Expand Down
81 changes: 77 additions & 4 deletions src/geop/components/geocache/Geotrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { geocache as cacheConf } from 'Conf/settings'
import { t } from 'Utilities/translate'
import { getState, setState } from 'Utilities/store'
import { gpxExport, formatDate, formatTime } from 'Utilities/util'
import log from 'Utilities/log'
import Component from 'Geop/Component'
import { findRoute, optimize } from 'Components/routing/Routing'
import Collection from 'ol/Collection'
import { createLayer } from 'Components/layer/LayerCreator'
import Sortable from 'sortablejs'
import Point from 'ol/geom/Point'
import LineString from 'ol/geom/LineString'
import Feature from 'ol/Feature'
import { toLonLat } from 'ol/proj'
import { getLength } from 'ol/sphere'
import lineSliceAlong from '@turf/line-slice-along'
import $ from 'jquery'
Expand Down Expand Up @@ -86,8 +89,22 @@ class Geotrip extends Component {
</li>`}
</ul>
${this.state.collection.getLength()
? `<button type="button" class="btn btn-link sortby-found" ${found.length ? '' : 'disabled'}>
<i class="fas fa-sort-amount-down"></i> ${t('Found')}
? `<div class="dropdown sort">
<button class="btn btn-link dropdown-toggle"
type="button"
id="geotripSort"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">
<i class="fas fa-sort-amount-down"></i>
</button>
<div class="dropdown-menu" aria-labelledby="geotripSort">
<a class="dropdown-item sortby-found ${found.length ? '' : 'disabled'}" href="#">${t('Found')}</a>
<a class="dropdown-item sortby-routing" href="#">${t('Optimize')}</a>
</div>
</div>
<button type="button" class="btn btn-link routing">
<i class="fas fa-directions"></i> ${t('Routing')}
</button>
<div class="btn-group float-right" role="group">
<a role="button" class="btn btn-secondary export" title="${t('Download')}">
Expand Down Expand Up @@ -181,10 +198,18 @@ class Geotrip extends Component {
e.preventDefault()
this.export()
})
// share trip
this.el.on('click', 'button.sortby-found', e => {
// order trip by found date
this.el.on('click', 'a.sortby-found', e => {
this.sortByFound()
})
// order trip by routing
this.el.on('click', 'a.sortby-routing', e => {
this.sortByRouting()
})
// routing
this.el.on('click', 'button.routing', e => {
this.routing()
})
}
reorderCollection (collection, order) {
for (let i = 0, len = order.length; i < len; i++) {
Expand Down Expand Up @@ -212,6 +237,54 @@ class Geotrip extends Component {
found.sort(compare)
this.reorderCollection(this.state.collection, found.map(item => item.id))
}
sortByRouting () {
const routingProfile = (typeof getState('routing/profile') !== 'undefined')
? getState('routing/profile') : getState('app/routing').profile
if (routingProfile) {
const position = getState('map/geolocation/position')
const locations = this.state.collection.getArray().map(f => toLonLat(f.getGeometry().getCoordinates()))
let start = locations[0]
let end = locations[locations.length - 1]
if (position) {
start = toLonLat(position)
}
optimize(start, end, locations)
.then(route => {
const order = route.steps
.filter(item => item.type === 'job')
.map(item => {
const f = this.state.collection.getArray()[item.job]
return f.getId()
})
this.reorderCollection(this.state.collection, order)
log('success', t('Geotrip reordered by optimum path'))
})
.catch(e => {
console.error(e)
log('error', t('Unable to determine ordering'))
})
} else {
log('error', t('Routing disabled'))
}
}
routing () {
const routingProfile = (typeof getState('routing/profile') !== 'undefined')
? getState('routing/profile') : getState('app/routing').profile
if (routingProfile) {
const position = getState('map/geolocation/position')
const locations = this.state.collection.getArray().map(f => toLonLat(f.getGeometry().getCoordinates()))
if (position) {
locations.unshift(toLonLat(position))
}
findRoute(locations)
.then(route => {

})
.catch(e => log('error', t('Unable to find route')))
} else {
log('error', t('Routing disabled'))
}
}
loadState () {
const ids = getState('geocache/trip/ids')
const found = getState('geocache/trip/found')
Expand Down
6 changes: 6 additions & 0 deletions src/geop/components/geocache/Geotrip.styl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
color: #4c9900
.timestamp
padding-left: 23px
.sort
display: inline-block
button.btn-link
text-decoration: none
&:focus
background-color: inherit
a.export
color: white
cursor: pointer
Loading

0 comments on commit 76eeddd

Please sign in to comment.