-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.js
83 lines (65 loc) · 2.12 KB
/
map.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
var shpfile, m ;
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
var selFile = files[0];
handleFile(selFile);
}
function handleFile(file){
var reader = new FileReader();
reader.onload = function(e) {
shpfile = new L.Shapefile(e.target.result,{isArrayBufer:true});
shpfile.on("data:loaded", function (e){
m.fitBounds(shpfile.getBounds());
});
shpfile.addTo(m);
};
reader.onerror = function(e) {
console.log(e);
};
reader.readAsArrayBuffer(file);
}
document.getElementById('file').addEventListener('change', handleFileSelect, false);
function init(){
m = L.map('map').setView([40, -80], 4);
var OpenStreetMap_BlackAndWhite = L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
OpenStreetMap_BlackAndWhite.addTo(m);
m.on('layeradd', function (e){
//console.dir(e);
});
//set up stuff
var dropbox = document.getElementById("map");
dropbox.addEventListener("dragenter", dragenter, false);
dropbox.addEventListener("dragover", dragover, false);
dropbox.addEventListener("drop", drop, false);
dropbox.addEventListener("dragleave", function() {
m.scrollWheelZoom.enable();
}, false);
function dragenter(e) {
e.stopPropagation();
e.preventDefault();
m.scrollWheelZoom.disable();
}
function dragover(e) {
e.stopPropagation();
e.preventDefault();
}
function drop(e) {
e.stopPropagation();
e.preventDefault();
m.scrollWheelZoom.enable();
var dt = e.dataTransfer;
var files = dt.files;
var i = 0;
var len = files.length;
if (!len) {
return
}
while (i < len) {
handleFile(files[i]);
i++;
}
}
}