-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
151 lines (133 loc) · 4.82 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0;">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>UtiliSync</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<link rel="stylesheet" href="css/leaflet-draw.css">
<style>
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
}
div#button-holder {
position: absolute;
width:100%;
top:0px;
z-index: 400;
}
</style>
</head>
<body>
<div id="map">
<div id="button-holder">
<button id="drawPolygon">Draw Polygon</button>
<button id="drawPolyLine">Draw PolyLine</button>
<button id="drawPath">Draw Freehand</button>
<button id="stopDraw">Stop Drawing</button>
<button id="getData">Get Coordinate Array</button>
</div>
</div>
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
<script src="js/vendor/esri-leaflet.js"></script>
<script>
var map = L.map('map').setView([40.606389, -112.009011], 15);
// Add ArcGIS Online Basemap
L.esri.basemapLayer("Streets").addTo(map);
function touchHandler(event)
{
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
case "touchmove": type = "mousemove"; break;
case "touchend": type = "mouseup"; break;
default: return;
}
//initMouseEvent(type, canBubble, cancelable, view, clickCount,
// screenX, screenY, clientX, clientY, ctrlKey,
// altKey, shiftKey, metaKey, button, relatedTarget);
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
function init()
{
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
}
init();
var drawPolygonButton = document.getElementById('drawPolygon');
var stopDrawButton = document.getElementById('stopDraw');
var getDataButton = document.getElementById('getData');
var drawPath = document.getElementById('drawPath');
var drawPolyLine = document.getElementById('drawPolyLine');
var currentPolygon = {}; //Empty object to be used later;
var currentPolyLine = {};
var currentPath = {};
drawPath.addEventListener('mousedown', function() {
currentPath = new L.Polyline([]).addTo(map);
map.dragging.disable();
map.on('mousedown', function drawPoly() {
console.log("mousedown just happened.");
map.on('mousemove', addLatLngToPath);
map.on('dblClick', function() {
map.off('mousedown', drawPoly);
map.off('mousemove', addLatLngToPath);
});
});
});
drawPolyLine.addEventListener('mousedown', function() {
currentPolyLine = new L.Polyline([]).addTo(map);
map.on('mousedown', addLatLngToPolyLine);
})
drawPolygonButton.addEventListener('mousedown', function(e){
e.stopPropagation();
map.dragging.disable();
currentPolygon = new L.polygon([]).addTo(map);
map.on('mousedown', addLatLngToPolygon); //Listen for clicks on map.
}, true);
stopDraw.addEventListener('mousedown', function(){
map.off('mousedown', addLatLngToPolyLine);
map.off('mousedown', addLatLngToPolygon); //Stop listening for clicks on map.
map.off('mousedown'); //Stop listenting for clicks
map.off('mousemove'); //Stop listenting for drags
map.dragging.enable();
});
getDataButton.addEventListener('mousedown', function(){
var data = simplifyLatLngs(currentPath.getLatLngs());
console.log(data);
//SEND DATA USING AJAX
});
function addLatLngToPolygon(e){
currentPolygon.addLatLng(e.latlng);
}
function addLatLngToPolyLine(e) {
currentPolyLine.addLatLng(e.latlng);
}
function addLatLngToPath(e) {
console.log("dragging and adding points");
currentPath.addLatLng(e.latlng);
}
function simplifyLatLngs(latlngs){
var x = []; //blank array
for(var i=0;i<latlngs.length;i++){
x.push([latlngs[i].lat,latlngs[i].lng]);
}
return x;
}
</script>
</body>
</html>