-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
207 lines (176 loc) · 4.83 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<meta charset="utf-8">
<title>Angular</title>
<style>
#legend {
background: white;
padding: 10px;
border: 2px solid black;
}
#legend img {
vertical-align: middle;
}
#panel {
margin: 20px;
}
</style>
</head>
<body>
<div id="panel">
<input id="address">
<input id="search" type="button" value="Искать">
</div>
<div id="map_canvas" style="width: 500px; height: 500px"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script>
google.maps.event.addDomListener(window, 'load', init);
function init() {
var myLatlng = new google.maps.LatLng(53.865953999999995, 27.6115002);
var myOpts = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOpts);
map.setOptions({ styles: styles });
var styles = [
{
featureType: "road",
elementType: "geometry.stroke",
stylers: [{ color: "#000000" }, { weight: 1.2 }]
}, {
featureType: "road.highway",
elementType: "geometry",
stylers: [{ color: "#46C34D" }, { weight: 1.2 }]
}, {
featureType: "road.highway.controlled_access",
elementType: "geometry",
stylers: [{ color: "#FF6A0A" }, { weight: 1.2 }]
}, {
featureType: "road",
elementType: "labels.text",
stylers: [{ saturation: -100 }, { invert_lightness: true }]
}, {
featureType: "landscape",
elementType: "geometry",
stylers: [
{ hue: "#ffff00" },
{ gamma: 1.4 },
{ saturation: 82 },
{ lightness: 96 }
]
}, {
featureType: "poi",
elementType: "geometry",
stylers: [
{ visibility: "off" }
]
}, {
featureType: "poi.school",
elementType: "geometry",
stylers: [
{ visibility: "on" },
{ hue: "#fff700" },
{ lightness: -15 },
{ saturation: 99 }
]
}, {
featureType: "poi.school",
elementType: "labels.icon",
stylers: [
{ hue: "##770303" },
{ saturation: 100 },
{ weight: 5 }
]
}
];
var iconBase = "https://maps.google.com/mapfiles/kml/shapes/";
var icons = {
parking: {
name: "Parking",
icon: iconBase + "parking_lot_maps.png"
},
library: {
name: "Library",
icon: iconBase + "library_maps.png"
},
info: {
name: "Info",
icon: iconBase + "info-i_maps.png"
}
};
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
title: feature.title || "",
map: map
});
google.maps.event.addListener(marker, "click", function() {
infoWindow.open(map, marker);
});
}
addMarker({
position: myLatlng,
type: "info",
title: "There I live"
})
var contentStr = `<div id="content">Here are details of marker</div>`;
var infoWindow = new google.maps.InfoWindow({
content: contentStr
});
var legend = document.createElement("div");
var legendTitle = document.createElement("h3");
legendTitle.textContent = "My first legend!";
legend.appendChild(legendTitle);
legend.id = "legend";
map.controls[google.maps.ControlPosition.RIGHT_TOP].push(legend);
for (var key in icons) {
var type = icons[key];
var name = type.name;
var icon = type.icon;
var div = document.createElement("div");
div.innerHTML = `<img src="${icon}"> ${name}`;
legend.appendChild(div);
}
var geoCoder = new google.maps.Geocoder();
document.getElementById("search").onclick = codeAddress;
function codeAddress() {
var address = document.getElementById("address").value;
geoCoder.geocode({ "address" : address }, function(results, status) {
console.log(map);
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status)
}
});
}
//map.data.loadGeoJson("https://storage.googleapis.com/maps-devrel/google.json");
var styleOptions = {
fillColor: "green",
strokeColor: "orange",
strokeOpacity: 0.2,
strokeWeight: 2
};
map.data.loadGeoJson("info.json");
map.data.setStyle(styleOptions);
//var kmlUrl = "http://localhost:5555/westcampus.kml";
var kmlUrl = "https://www.dropbox.com/s/xye8ziiwheg7rfy/westcampus.kml";
var remoteKmlUrl = 'https://developers.google.com/maps/tutorials/kml/westcampus.kml';
var kmlOptions = {
suppressInfoWindow: true,
preserveViewport: false,
map: map
};
var kmlLayer = new google.maps.KmlLayer(remoteKmlUrl, kmlOptions);
}
</script>
</body>
</html>