-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
executable file
·180 lines (154 loc) · 5.27 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
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Poly Splitting | Demo page for Google Maps JavaScript API v3 polysplitting library</title>
<meta name="description" content="Demo for splitting google maps polygons">
<meta name="author" content="Trent Mentink">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- some basic styles for the demo -->
<style type="text/css">
html,
body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
}
#map {
height: 100%;
width: 100%;
}
#controls {
position: fixed;
top: 10px;
right: 10px;
z-index: 1000;
}
.button {
background-color: #fff;
border-top: 1px solid rgba(255, 255, 255, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 5px;
box-shadow: rgba(0,0,0,1) 0 1px 4px 0;
color: #333;
cursor: pointer;
font-size: 20px;
margin: 2.5px 0;
min-width: 150px;
padding: 8px;
text-align: center;
}
.button:hover {
background-color: #ebebeb;
box-shadow: inset 0 0 2px 2px rgba(0,0,0,.1), rgba(0,0,0,1) 0 1px 4px 0;
color: #000;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="controls">
<div id="btnSelection" class="button">Begin Selection</div>
<div id="btnSplit" class="button hidden">Split Polygons</div>
<div id="btnClear" class="button hidden">Clear All</div>
</div>
<!-- Google Maps API * including geometry library -->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry"></script>
<!-- Poly-Splitting Library -->
<script type="text/javascript" src="js/polysplitting.min.js"></script>
<!-- Demo JavaScript -->
<script type="text/javascript">
var map;
var coords = [{lat: 51.432674878507314, lng: -1.8486213684082031},{lat: 51.433390565845485, lng: -1.8473660945892334},{lat: 51.43307619989089, lng: -1.8458962440490723},{lat: 51.432066201014194, lng: -1.8454670906066895},{lat: 51.43133711510069, lng: -1.846604347229004},{lat: 51.43163811528248, lng: -1.8482029438018799}]
var demoPoly;
var selectionPoly;
var outerPoly;
var innerPoly;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 51.4323, lng: -1.8470 },
zoom: 17,
mapTypeId: google.maps.MapTypeId.SATELLITE
});
demoPoly = new google.maps.Polygon({
paths: coords,
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#0000FF",
fillOpacity: 0.25,
zIndex: 0
});
demoPoly.setMap(map);
} // <-- initMap()
initMap();
// get references to the buttons
var btnSelection = document.getElementById('btnSelection');
var btnSplit = document.getElementById('btnSplit');
var btnClear = document.getElementById('btnClear');
btnSelection.onclick=function(){
// toggle the buttons
btnSelection.className = "button hidden";
btnSplit.className = "button";
btnClear.className = "button";
// create selection box polygon and store it in variable
selectionPoly = demoPoly.initSelection('validate');
};
btnSplit.onclick=function(){
// get an array containing the result of the split
// index: 0 = outer polygon
// index: 1 = inner polygon
// returns null if the split fails
var splitPolys = demoPoly.split(selectionPoly);
// clear any previous splits
if (outerPoly != null) {
outerPoly.setMap(null);
innerPoly.setMap(null);
}
if (splitPolys != null) {
outerPoly = new google.maps.Polygon({
paths: splitPolys[0],
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#0000FF",
fillOpacity: 0.25,
zIndex: 2
});
outerPoly.setMap(map);
innerPoly = new google.maps.Polygon({
paths: splitPolys[1],
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.5,
zIndex: 2
});
innerPoly.setMap(map);
}
};
btnClear.onclick=function(){
// toggle the buttons
btnSelection.className = "button";
btnSplit.className = "button hidden";
btnClear.className = "button hidden";
// clear the selection poly
if (selectionPoly != null) {
selectionPoly.setMap(null);
}
// clear the split polygons
if (outerPoly != null) {
outerPoly.setMap(null);
innerPoly.setMap(null);
}
};
</script>
</body>
</html>