Skip to content

Commit

Permalink
Merge pull request #105 from dadiorchen/issue104
Browse files Browse the repository at this point in the history
single tree
  • Loading branch information
dadiorchen authored Aug 9, 2022
2 parents 48f5d57 + 7a3c653 commit 066d71e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
19 changes: 19 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@
return false;
}

function dosubmitTree() {
console.log("submitting...");
async function reload() {
//map.flyTo(0,0,5);
const treeid = document.getElementById("treeid").value;
map.setFilters({
treeid,
});
await map.loadInitialView();
map.rerender();
}
reload();
return false;
}

function dosubmitFlyto() {
console.log("dosubmit flyto...");
const lat = document.getElementById("lat").value;
Expand Down Expand Up @@ -95,6 +110,10 @@ <h5>Control the map</h5>
userid <input id="userid" name="userid" type="input" value="" placeholder="the planter/user id">
<input type="submit" name="controlSubmit" value="Submit" />
</form>
<form action="" onsubmit="return dosubmitTree();">
treeid <input id="treeid" name="treeid" type="input" value="" placeholder="the tree id">
<input type="submit" name="controlSubmit" value="Submit" />
</form>
</div>
<div class="panel">
<h5>Fly to</h5>
Expand Down
23 changes: 21 additions & 2 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ export default class Map {
this.spin.hide()
this.alert.hide()
},
onDestroy: () => {
log.warn('destroy')
this.spin.hide()
this.alert.hide()
},
})
this.layerTile.addTo(this.map)

Expand Down Expand Up @@ -985,8 +990,22 @@ export default class Map {
async rerender() {
log.info('rerender')
log.info('reload tile')
this.unloadTileServer()
this.loadTileServer()
await this.unloadTileServer()

// load tile
if (this.filters.treeid) {
log.info('treeid mode do not need tile server')
log.info('load tree by id')
await this.loadTree(this.filters.treeid)
this.tileLoadingMonitor && this.tileLoadingMonitor.destroy()
} else if (this.filters.tree_name) {
log.info('tree name mode do not need tile server')
log.info('load tree by name')
this.tileLoadingMonitor && this.tileLoadingMonitor.destroy()
await this.loadTree(undefined, this.filters.tree_name)
} else {
await this.loadTileServer()
}
}

/*
Expand Down
9 changes: 9 additions & 0 deletions src/TileLoadingMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class TileLoadingMonitor {
// TODO handle error
this.options.onLoad()
}

destroy() {
clearTimeout(this.showLoadingTimer)
clearTimeout(this.slowTimer)
this.options.onDestroy()
this.tileLayer.off('loading', this._handleLoading)
this.tileLayer.off('load', this._handleLoad)
this.tileLayer.off('tileerror', this._handleTileError)
}
}

module.exports = TileLoadingMonitor

0 comments on commit 066d71e

Please sign in to comment.