forked from deawx/google-maps-polygon-splitting
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
executable file
·110 lines (92 loc) · 4.04 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
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Poly Intersecting | Demo page for Google Maps JavaScript API v3 polyintersect library</title>
<meta name="description" content="Demo for validate self-intersecting google maps polygons">
<meta name="author" content="techievickyr">
<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%;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- 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/polyintersect.min.js"></script>
<!-- Demo JavaScript -->
<script type="text/javascript">
var map, poly, coords = [{lat: 45, lng: -100}, {lat: 45.5, lng: -99.5}, {lat: 46, lng: -100}, {lat: 46, lng: -101}, {lat: 45, lng: -101}]
var initialize = function () {
function getDeleteButton() {
return $("img[src$='img/remove.png']");
}
function validateUpdated(index) {
var path = this, btnDelete = getDeleteButton();
if (!(poly.validate(index))) {
if(btnDelete.length === 0)
{
var undoimg = $("img[src$='https://maps.gstatic.com/mapfiles/undo_poly.png']");
undoimg.parent().css('height', '21px !important');
undoimg.parent().parent().append('<div style="overflow: hidden; position: absolute; width: 30px; height: 27px;top:21px;"><img src="img/remove.png" class="deletePoly" style="height:auto; width:auto; position: absolute; left:0;"/></div>');
// now get that button back again!
btnDelete = getDeleteButton();
btnDelete.hover(function() { $(this).css('left', '-30px'); return false;},
function() { $(this).css('left', '0px'); return false;});
btnDelete.mousedown(function() { $(this).css('left', '-60px'); return false;});
}
// if we've already attached a handler, remove it
if(path.btnDeleteClickHandler)
btnDelete.unbind('click', path.btnDeleteClickHandler);
// now add a handler for removing the passed in index
path.btnDeleteClickHandler = function() {
path.removeAt(index);
return false;
};
btnDelete.click(path.btnDeleteClickHandler);
}else {
// if we've already attached a handler, remove it
if(btnDelete.length !== 0 && path.btnDeleteClickHandler)
{
btnDelete.unbind('click', path.btnDeleteClickHandler);
btnDelete.remove();
}
}
}
map = new google.maps.Map(document.getElementById("map"), {
center: {lat: 45.5, lng: -100.5},
zoom: 8,
});
poly = new google.maps.Polygon({
paths: coords,
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#0000FF",
fillOpacity: 0.25,
zIndex: 0,
map: map
});
poly.setEditable(true);
google.maps.event.addListener(poly.getPath(), 'set_at', validateUpdated);
google.maps.event.addListener(poly.getPath(), 'insert_at', validateUpdated);
};
</script>
</head>
<body onload="initialize()">
<div id="map"></div>
</body>
</html>