-
Notifications
You must be signed in to change notification settings - Fork 4
/
map.js
162 lines (146 loc) · 4.2 KB
/
map.js
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
let map;
const center = { lat: 12.9692, lng: 79.1559 };
const styles = [
{ elementType: "geometry", stylers: [{ color: "#efe6be" }] },
{ elementType: "labels.icon", stylers: [{ visibility: "off" }] },
{
elementType: "labels.text.fill",
stylers: [{ color: "#f5f5f5" }, { weight: 1.5 }],
},
{
elementType: "labels.text.stroke",
stylers: [{ color: "#9e9e9e" }, { weight: 1.5 }],
},
{
featureType: "administrative.land_parcel",
stylers: [{ visibility: "off" }],
},
{
featureType: "administrative.land_parcel",
elementType: "labels.text.fill",
stylers: [{ color: "#bdbdbd" }],
},
{
featureType: "administrative.neighborhood",
stylers: [{ visibility: "off" }],
},
{
featureType: "poi",
elementType: "geometry",
stylers: [{ color: "#c44135" }],
},
{
featureType: "poi.park",
elementType: "geometry",
stylers: [{ color: "#328829" }],
},
{
featureType: "poi.sports_complex",
elementType: "geometry",
stylers: [{ color: "#2ca37b" }],
},
{
featureType: "road",
elementType: "geometry",
stylers: [{ color: "#e4b083" }],
},
{
featureType: "road",
elementType: "labels",
stylers: [{ visibility: "off" }],
},
{
featureType: "water",
elementType: "geometry",
stylers: [{ color: "#32cbb1" }],
},
{
featureType: "water",
elementType: "labels.text",
stylers: [{ visibility: "off" }],
},
{
featureType: "water",
elementType: "labels.text.fill",
stylers: [{ color: "#9e9e9e" }],
},
];
function initMap() {
const localContextMapView = new google.maps.localContext.LocalContextMapView({
element: document.getElementById("map"),
placeTypePreferences: [
{ type: "bakery", weight: 1 },
{ type: "park", weight: 2 },
{ type: "restaurant", weight: 3 },
{ type: "shopping_mall", weight: 1 },
{ type: "tourist_attraction", weight: 3 },
],
maxPlaceCount: 18,
directionsOptions: { origin: center },
});
map = localContextMapView.map;
// Trigger hidePlaceDetailsView() with a click event handler on the inner map.
map.addListener("click", () => {
localContextMapView.hidePlaceDetailsView();
});
// Merge map styles.
const mergedStyles = map.get("styles").concat(styles);
map.setOptions({
center: center,
zoom: 14,
styles: mergedStyles,
});
// Add a marker at the center point
new google.maps.Marker({
position: center,
map: map,
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAdUlEQVR4AWMYOWAU/AfhYWMBCxA3A/FlIN4MxN7I6gjg80DcD8QC+CzIxqIxH6aOSHwfYQmmBZexuQymjgTcj8uCz1gUHybDgvO4LFiMRXE4GRb8x2UBDxCXQ8PxPdSrLNSxAD+g3ALCeNQCKoHhZcHAg1EAAM3cyWj3TGxhAAAAAElFTkSuQmCC",
zIndex: 30,
});
}
// Standard google maps function
function initialize() {
var myLatlng = new google.maps.LatLng(40.779502, -73.967857);
var myOptions = {
zoom: 12,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
TestMarker();
}
// Function for adding a marker to the page.
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map
});
}
// Testing the addMarker function
function TestMarker() {
CentralPark = new google.maps.LatLng(37.7699298, -122.4469157);
addMarker(CentralPark);
}
window.initMap = initMap;
// [START maps_add_map]
// Initialize and add the map
function initMap() {
// [START maps_add_map_instantiate_map]
// The location of Uluru
const uluru = { lat: 12.9692, lng: 79.1559 };
// The map, centered at Uluru
const map = new google.maps.Map(document.getElementById("map"), {
zoom:14,
center: uluru,
});
// [END maps_add_map_instantiate_map]
// [START maps_add_map_instantiate_marker]
// The marker, positioned at Uluru
const marker = new google.maps.Marker({
position: uluru,
map: map,
});
// [END maps_add_map_instantiate_marker]
}
window.initMap = initMap;
// [END maps_add_map]