Skip to content

Commit

Permalink
Merge pull request #13 from datapartyjs/render-all-gpx
Browse files Browse the repository at this point in the history
ensure all gpx path segments are displayed
  • Loading branch information
sevenbitbyte authored Apr 24, 2022
2 parents 9233249 + b0350c6 commit 109fab4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rfparty",
"version": "0.1.3",
"version": "0.1.4",
"description": "",
"source": "src/index.html",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"json5": "^2.2.0",
"jsonpath-plus": "^6.0.1",
"last-eventemitter": "^1.1.1",
"leaflet": "^1.7.1",
"leaflet": "1.7.1",
"lokijs": "^1.5.12",
"moment": "^2.17.1",
"moment-timezone": "^0.5.11",
Expand All @@ -27,7 +27,11 @@
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"buffer": "^6.0.3",
"events": "^3.3.0",
"http-server": "^14.1.0",
"parcel": "^2.2.1"
"parcel": "^2.2.1",
"process": "^0.11.10",
"stream-browserify": "^3.0.0"
}
}
7 changes: 3 additions & 4 deletions src/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ export class MainWindow {
window.loadingState.completeStep('read '+file.name)



resolve(window.rfparty.addGpx(json, file.name))
window.rfparty.addGpx.bind(window.rfparty)(json, file.name).then(resolve).catch(reject)

}
reader.onabort = reject
Expand All @@ -225,7 +224,7 @@ export class MainWindow {
}


const fileContent = await Promise.all(fileLoaders)
await Promise.all(fileLoaders)



Expand Down Expand Up @@ -336,4 +335,4 @@ export class MainWindow {

return suggestions
}
}
}
41 changes: 33 additions & 8 deletions src/rfparty.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class RFParty extends EventEmitter {
constructor(divId) {
super()

this.showAllTracks = false
this.showAllTracks = true
this.showAwayTracks = false

this.detailsViewer = null
Expand Down Expand Up @@ -128,12 +128,24 @@ export class RFParty extends EventEmitter {
this.lastQuery = null

this.scanDb = null
//this.gpx = {}
this.gpx = {}
this.gpxLines = {}
this.gpxLayer = Leaflet.layerGroup()


}

async start() {
console.log('starting')

if(this.showAllTracks){

for(let name in this.gpxLines){
this.gpxLayer.addLayer(this.gpxLines[name])
}

this.gpxLayer.addTo(this.map)
}

this.emit('search-start')
let searchStartTime = new moment()
Expand Down Expand Up @@ -660,7 +672,7 @@ export class RFParty extends EventEmitter {
getTrackPointByTime(timestamp) {
let bestDeltaMs = null
let bestPoint = null
let track = this.getTrackByTime(timestamp - 60000, timestamp + 6000)
let track = this.getTrackByTime(timestamp - 1200000, timestamp + 6000)

for (let point of track) {
let deltaMs = Math.abs(moment(point.timestamp).diff(track.timestamp))
Expand All @@ -671,6 +683,7 @@ export class RFParty extends EventEmitter {
}
}


return bestPoint
}

Expand Down Expand Up @@ -986,11 +999,18 @@ export class RFParty extends EventEmitter {

//this.gpx[name]=obj

const trackPoints = JSONPath({ json: obj, path: '$..trkpt' })[0]
const trackPoints = JSONPath({ json: obj, path: '$..trkpt', flatten: true })

if(!trackPoints){
window.loadingState.startStep('index '+name, 1)
window.loadingState.completeStep('index '+name)
console.log('added gpx', name, 'with', undefined, 'points')
return
}

window.loadingState.startStep('index '+name, trackPoints.length)

const latlngs = []
let latlngs = []

let count = 0
for (let point of trackPoints) {
Expand Down Expand Up @@ -1032,12 +1052,17 @@ export class RFParty extends EventEmitter {
//console.log('loaded gpx', name)

if(this.showAllTracks){
/*this.gpxLines[name] =*/ Leaflet.polyline(latlngs, { color: 'white', opacity: 0.4, weight: '2' }).addTo(this.map)
this.gpxLines[name] = Leaflet.polyline(latlngs, { color: 'red', opacity: 0.4, weight: '2' })

//this.gpxLines[name].addLayer(this.gpxLayer)
//this.gpxLayer.addLayer(this.gpxLines[name])
}


window.loadingState.completeStep('index '+name)
//console.log('added gpx', name, 'with', trackPoints.length, 'points')
console.log('added gpx', name, 'with', trackPoints.length, 'points')
//console.log('latlong', latlngs)
//console.log('tracks', trackPoints)
}

static get Version() {
Expand Down Expand Up @@ -1117,4 +1142,4 @@ export class RFParty extends EventEmitter {

return names
}
}
}

0 comments on commit 109fab4

Please sign in to comment.