-
Notifications
You must be signed in to change notification settings - Fork 7
/
micapse.html
139 lines (135 loc) · 4.83 KB
/
micapse.html
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
<!DOCTYPE html>
<html>
<head>
<title>maptalks.GridLayer demo</title>
<script src="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.js"></script>
<script src="../dist/maptalks.gridlayer.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maptalks@>=0.35.1/dist/maptalks.css">
<style>
#map { width: 960px; height: 600px; }
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = new maptalks.Map("map",{
center: [121.66662529687505, 27.605691554813063],
zoom: 7,
hitDetect : false,
attributionControl : {
'content' : '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
},
baseLayer : new maptalks.TileLayer("tile",{
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains : ['a','b','c','d']
})
});
maptalks.Ajax.get('micapse_12h_1km.txt', function (err, data) {
if (err || !data) {
throw new Error('error when loading midcapse_12h_1km.txt');
}
var gridData = readData(data);
// map.setCenter(gridData.center);
var grid = new maptalks.GridLayer('grid', gridData, {
symbol : {
'lineWidth' : 0
}
}).addTo(map);
});
function readData(content) {
const data = [];
// grid's southwest and northeast
var sw, ne,
// grid width and grid height
width, height,
center,
cols, rows,
centerCol = 0,
centerRow = 0;
var line = 0;
var dataRows = 0, dataLineCnt = 0;
var dataLine = '';
var currentLine = '';
var cols;
for (var i = 0, l = content.length; i < l; i++) {
var chr = content.charAt(i);
if (line < 2) {
currentLine += chr;
}
if (chr === '\n') {
if (line === 1) {
var descripts = currentLine.split(' ');
width = +(descripts[6]);
height = +(descripts[7]);
sw = new maptalks.Coordinate(descripts[8], descripts[10]);
ne = new maptalks.Coordinate(descripts[9], descripts[11]);
cols = +(descripts[12]),
rows = +(descripts[13]),
center = sw.add(ne)._multi(1 / 2);
centerCol = Math.floor((center.x - sw.x) / width);
centerRow = Math.floor((center.y - sw.y) / height);
}
if (line < 2) {
currentLine = '';
}
line++;
} else if (line === 2) {
dataLine += chr;
if (chr === ' ') {
dataRows++;
}
if (dataRows === cols) {
var cells = dataLine.split(' ');
for (var ii = 0; ii < cells.length; ii++) {
var value = +cells[ii];
if (value !== 0) {
data.push([
ii - centerCol,
dataLineCnt - centerRow,
{
symbol : {
'polygonFill' : gridValue2FillColor(value),
'polygonOpacity' : 0.7,
'lineWidth' : 0,
'lineColor' : '#bbb',
'lineOpacity' : 0
// 'textName' : '{value}',
// 'textSize' : { stops: [[14, 0], [18, 48]] }
},
properties : {
value : value.toFixed(1)
}
}
]);
}
}
dataLine = '';
dataRows = 0;
dataLineCnt++;
}
}
}
return {
unit : 'degree',
center : center,
width : width,
height : height,
cols : [centerCol - cols, cols - centerCol],
rows : [centerRow - rows, rows - centerRow],
data : data
};
}
function gridValue2FillColor(value) {
if (value < 0.5) {
return "#f8eb58";
} else if (value < 1.5) {
return "#ff8a00";
} else if (value < 2.5) {
return "#ff009c";
} else {
return "#ff0000";
}
}
</script>
</body>
</html>