-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
344 lines (310 loc) · 15 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
}
body {
width: 100%;
height: 100%;
position: fixed;
margin: 0;
display: flex;
align-content: stretch;
align-items: center;
}
.controlls {
width: 30%;
flex-grow: 1;
height: 100%;
display: flex;
flex-wrap: wrap;
position: fixed;
right: 0;
top: 0;
z-index: 2;
background: #fff;
}
textarea,
#munics {
width: 100%;
height: calc(100% - 270px);
overflow-y: scroll;
display: flex;
flex-wrap: wrap;
}
#munics>div {
width: 50%;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
padding: 0 7px;
}
#munics>div>label {
font-family: mono;
}
#munics>div>input {
width: 10%;
}
#upload,
#download {
width: 100%;
height: 50px;
display: block;
background: #26b75e;
color: #fff;
text-decoration: none;
display: flex;
justify-content: center;
align-items: center;
font-family: mono;
}
#upload {
background: #26b288;
}
#input {
display: none;
}
.controlls>div.info {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
height: 40px;
box-sizing: border-box;
padding: 8px 10px;
}
.basemap {
height: 50px;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 0 17px;
font-family: mono;
}
i {
text-transform: none;
}
svg {
/* background-image: url('./base-maps/15.png'); */
position: fixed;
top: 0;
left: 0;
z-index:10
}
#bg{
z-index:1;
background-position: -4.9vw 9vh;
background-size: 100vw auto;
background-repeat: no-repeat;
position: fixed;
top: 0;
left: 0;
}
button {
background: #26b288;
border: none;
height: 28px;
display: inline-flex;
align-items: center;
color: #fff;
font-weight: bold;
width: 28px;
cursor: pointer;
outline: none;
}
.cols{
height: 80px;
font-family: mono;
padding: 0 17px;
font-size: 12px;
box-sizing: border-box;
}
.cols i{
display: inline-block;
width: 12px;
height: 12px;
border: 1px solid gray;
}
.cols span{
display: inline-block;
width: 48%;
}
</style>
<script src="https://unpkg.com/[email protected]/bundle/read-excel-file.min.js"></script>
<title>Georgian Map Generator</title>
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="https://d3js.org/d3-geo-projection.v2.min.js"></script>
</head>
<body>
<!-- Create an element where the map will take place -->
<div id="bg" ><img id="bg-img"/></div>
<svg id="my_dataviz" width="" height=""></svg>
<div class="controlls">
<input type="file" id="input" />
<a id="upload" onclick="document.getElementById('input').click()" href="#">Upload the Excel with data</a>
<div class="info">
* <a href="https://github.com/DatoJanez/geo-map-generator/raw/master/sample-map-data-input.xlsx">Download the
sample excel file for data input</a>
</div>
<div class="basemap"> <span>Base-map style</span> <button id="prev">
< </button><span id="base-val">None</span><button id="next"> > </button></div>
<div class="cols">
<span><i style="background-color: #fff;"></i> No Data </span>
<span><i style="background-color:#bdc3c7"></i> From 45 to 55</span>
<span><i style="background-color:#c0392b"></i> Less or equal to 15</span>
<span><i style="background-color:#91CEF8"></i> From 56 to 70</span>
<span><i style="background-color:#e74c3c"></i> From 15 to 30</span>
<span><i style="background-color:#3498db"></i> From 70 to 85</span>
<span><i style="background-color:#F4877B"></i> From 30 to 45</span>
<span><i style="background-color:#1c5c85"></i> More then 85 </span>
</div>
<!-- <textarea></textarea> -->
<div id="munics"></div>
<a id="download" href="#">Download the map</a>
</div>
<script>
var curr_base = 0;
const setBase = (val) => {
curr_base = val
//document.getElementById('bg-img').setAttribute('src', 'https://raw.githubusercontent.com/DatoJanez/geo-map-generator/master/base-maps/_'+curr_base+'.png')
document.getElementById("base-val").innerHTML = Boolean(curr_base) ? curr_base : 'None'
}
document.getElementById("prev").onclick = () => setBase(curr_base > 0 ? curr_base - 1 : 7)
document.getElementById("next").onclick = () => setBase(curr_base < 7 ? curr_base + 1 : 0)
</script>
<script>
var input = document.getElementById('input')
input.addEventListener('change', function () {
[...document.querySelectorAll('#munics input')].forEach(a => a.value = '')
readXlsxFile(input.files[0]).then(function (rows) {
rows.forEach(row => {
val = values.filter(d => d.name.toLowerCase() == row[0].toLowerCase())[0]
if (val) {
val.value = +row[1]
let inp = document.getElementById(row[0].toLowerCase())
if (inp && row.length > 1) {
inp.value = Math.floor(+row[1])
}
}
});
drowMap()
})
})
</script>
<script>
document.getElementById('my_dataviz').setAttribute('width', document.body.clientWidth*0.7)
document.getElementById('my_dataviz').setAttribute('height', document.body.clientHeight)
document.getElementById('bg').setAttribute("style", "width: " + document.body.clientWidth*0.7 + "px; height:" + document.body.clientHeight + "px;")
// The svg
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
// Map and projection
var projection = d3.geoMercator()
.center([43.35, 42.35]) // GPS of location to zoom on
.scale(document.body.clientWidth*5.5) // This is like the zoom
.translate([width / 2, height / 2])
document.getElementById("download").onclick = function () {
html2canvas(document.querySelector("#my_dataviz"), {
allowTaint:false,
useCORS :true
}).then(canvas => canvas.toBlob(b => saveAs(b, 'geo-map.png')));
// var svgData = document.getElementById("my_dataviz").outerHTML;
// var svgBlob = new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
// var svgUrl = URL.createObjectURL(svgBlob);
// var downloadLink = document.createElement("a");
// downloadLink.href = svgUrl;
// downloadLink.download = "newesttree.svg";
// document.body.appendChild(downloadLink);
// downloadLink.click();
// document.body.removeChild(downloadLink);
}
var data
var drowMap = () => {
if (!data) {
d3.json("https://raw.githubusercontent.com/DatoJanez/geo-map-generator/master/munic_k.geojson", data_ => {
// d3.json("https://raw.githubusercontent.com/DatoJanez/rustavi-abonent-number/master/munic-and-city.geojson", data_ => {
data = data_
drowMap_()
})
} else {
drowMap_()
}
}
var drowMap_ = () => {
document.getElementsByTagName('svg')[0].innerHTML = ''
svg.append("g")
.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("stroke-width", 0.5)
.attr("opacity", 0.8)
.attr("stroke", "rgba(0,0,0,.4)")
.attr("fill", d => {
let name = d.properties.DISTRICT.toLowerCase()
let val = values.filter(a => a.name.toLowerCase() == name)[0]
// console.log(name, val);
if (!val || !val.value) return "white";
if (val.value <= 15) return "#c0392b";
if ((val.value > 15) && (val.value <= 30)) return "#e74c3c";
if ((val.value > 30) && (val.value <= 45)) return "#F4877B";
if ((val.value > 45) && (val.value <= 55)) return "#bdc3c7";
if ((val.value > 56) && (val.value <= 70)) return "#91CEF8";
if ((val.value > 70) && (val.value <= 85)) return "#3498db";
if (val.value > 85) return "#1c5c85";
return "white"
})
.attr("d", d3.geoPath()
.projection(projection)
)
// .style("stroke", "none")
}
function delay(fn, ms) {
let timer = 0
return function (...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
var values = []
let munics = ['Abasha', 'Adigeni', 'Akhalkalaki', 'Akhaltsikhe', 'Akhmeta', 'Ambrolauri', 'Aspindza', 'Axalgori', 'Bagdati', 'Batumi', 'Bolnisi', 'Borjomi', 'Chiatura', 'Chkhorotsku', 'Chokhatauri', 'Dedoflistskaro', 'Dmanisi', 'Duseti', 'Gagra', 'Gali', 'Gardabani', 'Gori', 'Gudauta', 'Gulripshi', 'Gurjaani', 'Java', 'Kareli', 'Kaspi', 'Kazbegi', 'Keda', 'Kharagauli', 'Khashuri', 'Khelvachauri', 'Khobi', 'Khoni', 'Khulo', 'Kobuleti', 'Kutaisi', 'Kvareli', 'Lagodekhi', 'Lanchkhuti', 'Lentekhi', 'Marneuli', 'Martvili', 'Mcxeta', 'Mestia', 'Ninotsminda', 'Ochamchire', 'Oni', 'Ozurgeti', 'Poti', 'Rustavi', 'Sachkhere', 'Sagarejo', 'Samtredia', 'Senaki', 'Shuakhevi', 'Signagi', 'Sokhumi', 'Tbilisi', 'Telavi', 'Terjola', 'Tetritskaro', 'Tianeti', 'Tkibuli', 'Tsageri', 'Tsalenjikha', 'Tsalka', 'Tskaltubo', 'Vani', 'Zestafoni', 'Zugdidi']
munics.forEach(munic => {
let cont = document.createElement('div')
let label = document.createElement('label')
label.innerHTML = munic
label.setAttribute("for", munic.toLowerCase())
let input = document.createElement('input')
input.setAttribute('id', munic.toLowerCase())
input.value = Math.floor(Math.random() * 100);
input.onkeyup = delay((e) => {
m = values.filter(a => a.name.toLowerCase() == e.target.getAttribute('id').toLowerCase())[0]
if (m) {
m.value = e.target.value
} else {
values.push({ name: e.target.getAttribute('id'), value: e.target.value })
}
drowMap()
}, 300)
// input.onkeyup()
cont.appendChild(label)
cont.appendChild(input)
values.push({ name: munic, value: input.value })
document.getElementById('munics').appendChild(cont)
})
drowMap()
// document.getElementsByTagName('textarea')[0].value = test_value
// document.getElementsByTagName('textarea')[0].onkeyup();
</script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script>
(function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c)},d.onerror=function(){console.error("could not download file")},d.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null},k.readAsDataURL(b)}else{var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m)},4E4)}});f.saveAs=g.saveAs=g,"undefined"!=typeof module&&(module.exports=g)});
</script>
</body>
</html>