-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
153 lines (139 loc) · 6.29 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import {onEachFeature,preplotpoints,editableLayers, info, mypagefn} from "./app";
export async function getLoadData(num_states){
var stateshapes = [];
// let num_states = 30
const starttime = Date.now();
//https://medium.com/@maptastik/loading-external-geojson-a-nother-way-to-do-it-with-jquery-c72ae3b41c01 dynamically load geojson
for(var i = 1 ; i <= num_states; i++){
let statenumber=(i < 10)? '0'+i.toString():i.toString()
let filename='cb_2018_'+statenumber+'_tract_500k.json';
stateshapes[i] = $.ajax({
url: "https://raw.githubusercontent.com/mehrotrasan16/us-census-tracts-shapefiles-and-geojson/master/USA-cb_tract_500k-geojson/"+filename,
dataType: "json",
success: function (data){
console.log(filename + " Retrieved");
// console.log(performanceAnalyzerData);
editableLayers.addLayer(L.geoJSON(data,{
onEachFeature: onEachFeature
})
);
var updateProps = {
name: preplotpoints.length,
timestamp: Date.now() - starttime,
};
info.update(updateProps);
},
error: function (xhr){
console.log(xhr.statusText);
//alert(xhr.statusText);
},
complete: function(data) {
if(i === num_states-1){
console.log(" plotting "+ preplotpoints.length.toString() +"stored tracts takes " + ((Date.now() - starttime)/1000).toString() +" seconds ");
console.log(" plotting "+ preplotpoints.length.toString() +"stored tracts takes " + (performance.memory.usedJSHeapSize / 1000000).toString() + " Mbytes ");
}
}
})
}
}
export function getGeneratePoints(num_points) {
const starttime = Date.now();
let geojson_fc = random.point(num_points,[-60.95, 25.84 , -130.67, 49.38]); //WSEN
console.log(geojson_fc);
editableLayers.addLayer(L.geoJson(geojson_fc,{
onEachFeature: onEachFeature,
pointToLayer: function (geoJsonPoint,latlng){
return L.circle(latlng);
}
}));
var updateProps = {
name: preplotpoints.length,
timestamp: Date.now() - starttime,
};
info.update(updateProps);
console.log(" plotting "+ preplotpoints.length.toString() +"stored points takes " + ((Date.now() - starttime)/1000).toString() +" seconds ");
console.log(" plotting "+ preplotpoints.length.toString() +"stored points takes " + (performance.memory.usedJSHeapSize / 1000000).toString() + " Mbytes ");
}
export async function getLoadPoints(num_point_files){
var points = [];
const starttime = Date.now();
performance.mark("all points: loading");
for(var i = 1 ; i <= num_point_files; i++){
let filename='points_run_'+ i.toString()+'.json';
points[i] = $.ajax({
url: "https://raw.githubusercontent.com/mehrotrasan16/us-census-tracts-shapefiles-and-geojson/master/point-data/"+filename,
dataType: "json",
success: function (data){
console.log(filename + " Retrieved");
performance.mark("one point file: adding to map");
editableLayers.addLayer(L.geoJSON(data,{
onEachFeature: onEachFeature,
pointToLayer: function (geoJsonPoint,latlng){
return L.circle(latlng);
}
}
)
);
performance.mark("one point file: loaded and added to map");
var updateProps = {
name: preplotpoints.length,
timestamp: Date.now() - starttime,
};
info.update(updateProps);
},
error: function (xhr){
console.log(xhr.statusText);
//alert(xhr.statusText);
},
complete: function(data) {
performance.mark("all points: loaded")
if(i === num_point_files-1){
console.log(" plotting "+ preplotpoints.length.toString() +"stored points takes " + ((Date.now() - starttime)/1000).toString() +" seconds ");
console.log(" plotting "+ preplotpoints.length.toString() +"stored points takes " + (performance.memory.usedJSHeapSize / 1000000).toString() + " Mbytes ");
}
}
})
}
return i;
}
// getLoadPoints(4)
export async function getLoadShapes(num_shape_files){
var shapes = [];
const starttime = Date.now();
performance.mark("all shapes: loading");
for(var i = 1 ; i <= num_shape_files; i++){
let filename='pentagons_run_' + i.toString() + '.json' //petagons_run_'+ i.toString()+'.json';
shapes[i] = $.ajax({
url: "https://raw.githubusercontent.com/mehrotrasan16/us-census-tracts-shapefiles-and-geojson/master/shape-data/"+filename,
dataType: "json",
success: function (data){
console.log(filename + " Retrieved");
performance.mark('Adding Shape Layer to map')
editableLayers.addLayer(L.geoJSON(data,{
onEachFeature: onEachFeature,
}
)
);
performance.mark('Done Adding Shape Layer to map')
var updateProps = {
name: preplotpoints.length,
timestamp: Date.now() - starttime,
};
info.update(updateProps);
},
error: function (xhr){
console.log(xhr.statusText);
//alert(xhr.statusText);
},
complete: function(data) {
if(i === num_shape_files-1){
console.log(" plotting "+ preplotpoints.length.toString() +"stored shapes takes " + ((Date.now() - starttime)/1000).toString() +" seconds ");
console.log(" plotting "+ preplotpoints.length.toString() +"stored shapes takes " + (performance.memory.usedJSHeapSize / 1000000).toString() + " Mbytes ");
}
}
})
}
}
export function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}