Skip to content

Commit

Permalink
feat: can calculate org map initial view
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed Apr 14, 2021
1 parent de65bd9 commit 3c35918
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/models/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,13 @@ export default class Map{

async loadInitialView(){
let view;
if(this.filters.userid || this.filters.wallet){
log.warn("try to get initial bounds");
const calculateInitialView = async () => {
const url = `${this.apiServerUrl}trees?clusterRadius=${Map.getClusterRadius(10)}&zoom_level=10&${this.getFilterParameters()}`;
log.info("calculate initial view with url:", url);
const response = await this.requester.request({
url: `${this.apiServerUrl}trees?clusterRadius=${Map.getClusterRadius(10)}&zoom_level=10&${this.getFilterParameters()}`,
url,
});
view = getInitialBounds(
const view = getInitialBounds(
response.data.map(i => {
if(i.type === "cluster"){
const c = JSON.parse(i.centroid);
Expand All @@ -438,6 +439,11 @@ export default class Map{
this.width,
this.height,
);
return view;
}
if(this.filters.userid || this.filters.wallet){
log.warn("try to get initial bounds");
view = await calculateInitialView();
}else if(this.filters.treeid){
const res = await this.requester.request({
url: `${this.apiServerUrl}tree?tree_id=${this.filters.treeid}`,
Expand All @@ -462,6 +468,8 @@ export default class Map{
},
zoomLevel: zoom,
}
}else{
view = await calculateInitialView();
}
}

Expand Down

0 comments on commit 3c35918

Please sign in to comment.