-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.html
138 lines (106 loc) · 4.44 KB
/
Example.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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Google Map Custom Shape Example</title>
<script src="https://maps.googleapis.com/maps/api/js?key=&sensor=false&libraries=geometry"></script>
<script src="googlemapsCustomShape.js"></script>
<style type="text/css">
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
padding: 0;
}
#map-canvas {
float: inherit;
height: 100%;
}
#map-controls {
margin: 20px;
float: left;
}
</style>
</head>
<body>
<div id="map-controls">
Radius1:
<input type="text" id="txtRadius1" value="30000" /><br />
Radius2:
<input type="text" id="txtRadius2" value="80000" /><br />
Center:
<input type="text" id="txtCenter" value="33.588, 73.026" /><br />
Shape:
<select id="ddlShapeType">
<option title="Circle" value="circle" selected="selected">Circle</option>
<option title="Ellipse" value="ellipse">Ellipse</option>
<option title="Star" value="star">Star</option>
<option title="Diamond" value="diamond">Diamond</option>
<option title="Rectangle" value="rectangle">Rectangle</option>
</select>
<input type="button" id="btnDraw" value="Draw" onclick="gmapsExample.drawCustomShapes();" />
<input type="button" id="btnClear" value="Clear" onclick="gmapsExample.clearOverlays();" />
</div>
<div id="map-canvas" />
<script type="text/javascript">
//custom namespace Instead of Global namespace
var gmapsExample = {};
//Markers array to track added markers on the top
//will be used to remove them later on
gmapsExample.markerArray = [];
gmapsExample.strokeColor = "#000000";
gmapsExample.fillColor = "#ffff00";
gmapsExample.drawCustomShapes = function () {
var radius1 = document.getElementById("txtRadius1").value;
var radius2 = document.getElementById("txtRadius2").value;
var centerCordinates = document.getElementById("txtCenter").value;
var centerLatLong = new google.maps.LatLng(
centerCordinates.split(",")[0],
centerCordinates.split(",")[1]
);
var ddlShapeType = document.getElementById("ddlShapeType");
var shape;
switch (ddlShapeType[ddlShapeType.selectedIndex].value) {
case "ellipse":
shape = gmapsCustomShapes.Polygon.Ellipse(centerLatLong, radius1, radius2, 0,
gmapsExample.strokeColor, 2, 1, gmapsExample.fillColor, 0.5);
break;
case "star":
shape = gmapsCustomShapes.Polygon.Star(centerLatLong, radius1, radius2, 7, 0,
gmapsExample.strokeColor, 2, 1, gmapsExample.fillColor, 0.5);
break;
case "rectangle":
break;
case "diamond":
shape = gmapsCustomShapes.Polygon.RegularPoly(centerLatLong, radius1, 4, 0,
gmapsExample.strokeColor, 2, 1, gmapsExample.fillColor, 0.5);
break;
default: //Circle
shape = gmapsCustomShapes.Polygon.Circle(centerLatLong, radius1, "#000000", 2, 1, "#ffff00", 0.5);
break;
}
shape.setMap(gmapsExample.map);
gmapsExample.markerArray.push(shape);
}
gmapsExample.clearOverlays = function () {
for (var i = 0; i < gmapsExample.markerArray.length; i++) {
gmapsExample.markerArray[i].setMap(null);
}
gmapsExample.markerArray = [];
}
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(33.588, 73.026),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
gmapsExample.map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>