-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_MapView 01.cshtml
298 lines (265 loc) · 12.4 KB
/
_MapView 01.cshtml
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade;
@using ToSic.Sxc.Services;
@{
Kit.Page.Activate("turnOn");
//TODO: Use GoogleApiKey from App/System Settings instead of Header. Code below is from 2sxc Location Content App:
// They Google API key is in the App-Settings. See instructions: https://azing.org/2sxc/r/ApSwlItl
// The Preset-data is encrypted, so we must decrypt it to use
//var mapSettings = AsDynamic(Content.Presentation.GoogleMaps, Settings.GoogleMaps);
//var googleApikey = Kit.SecureData.Parse(mapSettings.ApiKey).Value;
var googleApikey = Header.ApiKey;
var googleMapDomId = "app-sexy-google-map-js-" + @CmsContext.Module.Id;
var gps = AsDynamic(Header.GPS);
var lat = gps.Latitude ?? 0;
var lng = gps.Longitude ?? 0;
var zoomLevel = Header.ZoomLevel ?? 13;
var tiltLevel = Header.Tilt ?? 45;
var mapType = Header.MapType ?? "roadmap";
var gestureHandling = Header.GestureHandling ?? "auto";
var markerMode = Header.MarkerMode ?? "CenterFocus";
}
<style>
#@googleMapDomId { height: 62%; width: 100%; }
.gm-style-mot { text-align:center; } // to center scroll message overlay
/*.gm-style-pbc { opacity: 0 !important; }*/ // to hide scroll message overlay
p { text-align: center !important;}
.streetViewFrame { width: 600px !important; }
.card img { height: auto; }
.btn-custom {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?key=@googleApikey&callback=initMap&v=weekly"
defer></script>
<script>
let map;
let bounds;
function initMap() {
bounds = new google.maps.LatLngBounds();
map = new google.maps.Map(document.getElementById('@googleMapDomId'), {
zoom: @zoomLevel,
minZoom: @zoomLevel - 2,
maxZoom: @zoomLevel + 2,
center: new google.maps.LatLng(@lat.ToString().Replace(',','.'), @lng.ToString().Replace(',','.')),
mapTypeId: '@mapType',
tilt: @tiltLevel,
options: {
gestureHandling: '@gestureHandling',
zoomControl: true
}
});
DrawMarkers();
}
window.initMap = initMap;
</script>
<div class="container mt-3" >
<div class="col-lg-12 sessao">
<h5>Unidades Senac</h5>
<h1><span class="sessao-negrito" @Edit.TagToolbar(Header)>@Header.MapName</span></h1>
<h3 class="descricao" @Edit.TagToolbar(Content.Presentation)>@Html.Raw(Header.Description)</h3>
</div>
<div class="row justify-content-center justify-content-around">
@foreach (var location in AsList(Data)) {
var gpsItem = AsDynamic(location.GPS);
var gpsLat = gpsItem != null && gpsItem.Latitude != null ? gpsItem.Latitude.ToString().Replace(',', '.') : "0";
var gpsLong = gpsItem != null && gpsItem.Longitude != null ? gpsItem.Longitude.ToString().Replace(',', '.') : "0";
var svFoV = location.FoV != null ? location.FoV.ToString() : "90";
var svHeading = location.Heading != null ? location.Heading.ToString() : "110";
var svPitch = location.Pitch != null ? location.Pitch.ToString() : "0";
var streetViewUrlStatic = "https://maps.googleapis.com/maps/api/streetview?size=600x300&location=" + gpsLat + "," + gpsLong + "&fov="+svFoV+"&heading="+svHeading+"&pitch="+svPitch+"&key=" + googleApikey;
<div class="col-xs-11 col-sm-11 col-md-6 col-lg-6 col-xl-4 col-xxl-4 mt-3" id="cards">
<div class="card mb-4" @Edit.TagToolbar(location) data-marker-index="@location.Index">
<img src="@streetViewUrlStatic" class="card-img-top" alt="@location.Title" style="height:auto;">
<div class="card-body">
<div class="card-title fw-bold mb-3" style="margin-top: -100px; margin-left: 0px; margin-right: 0px; padding: 0px; padding-top: 15px">
<a href="javascript:scrollToMap('cards');" class="btn btn-primary btn-custom"><img src="@location.Icon" style="height:32px;" /> @location.Title</a>
</div>
<div class="card-subtitle mb-2 text-muted" style="padding: 20px 20px 0px 20px;min-height:65px !important;">
@location.Street, @location.City<br>
<!-- @Html.Raw(location.Description) -->
</div>
</div>
</div>
</div>
}
</div>
</div>
<div>
<a name="@googleMapDomId"></a>
<div id="@googleMapDomId" @Edit.TagToolbar(Content)></div>
</div>
<script>
var lastInfoWindow = null;
var lastMarkerPosition = null;
var globalMarkers = [];
function scrollToMap(origin) {
const cardsElement = document.getElementById('cards');
const mapElement = document.getElementById('@googleMapDomId');
var y = 0;
if (window.innerWidth < 1200)
{
const yMapOffset = -90; // Ajuste para o posicionamento do mapa na tela
y = mapElement.getBoundingClientRect().top + window.pageYOffset + yMapOffset;
}
else if (origin == 'map')
{
const yMapOffset = -390; // Ajuste para o posicionamento do mapa na tela
y = mapElement.getBoundingClientRect().top + window.pageYOffset + yMapOffset;
}
else if (origin == 'cards')
{
const yCardOffset = -85; // Ajuste para o posicionamento do mapa na tela
y = cardsElement.getBoundingClientRect().top + window.pageYOffset + yCardOffset;
}
window.scrollTo({
top: y,
behavior: 'smooth'
});
}
function DrawMarkers()
{
var markers = [];
var customIcon = { url: '@Header.Icon' };
var markerMode = '@Header.MarkerMode';
if (customIcon.url.length === 0)
customIcon.url = 'https://icon-library.com/images/google-maps-bus-icon/google-maps-bus-icon-3.jpg';
@{
foreach (var location in AsList(Data)) {
var gpsItem = AsDynamic(location.GPS);
var gpsLat = gpsItem != null && gpsItem.Latitude !=null ? gpsItem.Latitude.ToString().Replace(',', '.') : "0";
var gpsLong = gpsItem != null && gpsItem.Longitude != null ? gpsItem.Longitude.ToString().Replace(',', '.') : "0";
var svFoV = location.FoV != null ? location.FoV.ToString() : "90";
var svHeading = location.Heading != null ? location.Heading.ToString() : "110";
var svPitch = location.Pitch != null ? location.Pitch.ToString() : "0";
var language = "pt-br";
var directionurl = gpsItem.Longitude > 0
// if we have coordinates, use them
? "https://www.google.com/maps/dir/" + Kit.Convert.ForCode(gpsLat) + "," + Kit.Convert.ForCode(gpsLong)
// otherwise use the address
: "https://maps.google.com/maps?daddr="
+ (location.Street + " " + location.ZipCode + " " + location.City + " " + location.Country)
.Replace(" ", "+")
+ "&saddr=&f=d&hl=" + language + "&ie=UTF8&z=16";
// var streetViewUrlStatic = "https://maps.googleapis.com/maps/api/streetview?size=600x300&location=" + gpsLat + "," + gpsLong + "&fov="+gpsItem.FoV+"&heading="+gpsItem.Heading+"&pitch="+gpsItem.Pitch+"&key=" + googleApikey; // unused yet
var streetViewUrl = "https://www.google.com/maps/embed/v1/streetview?";
var streetViewParams = "location=" + gpsLat + ',' + gpsLong + "&heading="+svHeading+"&pitch="+svPitch+ "&key="+ googleApikey;
var streetViewIframe = "<iframe src=\"" + streetViewUrl + streetViewParams + "\" class=\"streetViewFrame\" style=\"width: 30vw;height:15rem;\"></iframe>";
@:bounds.extend(new google.maps.LatLng(@gpsLat, @gpsLong));
@:markers.push({
@: marker: new google.maps.Marker({
@: position: new google.maps.LatLng(@gpsLat, @gpsLong),
@: map: map,
@: icon: customIcon.url,
@: title: '@Html.Raw(location.Title)'
@: }),
@: infoWindow: new google.maps.InfoWindow({
@: content: '<div><h6 class=fw-bold>@location.Title</h6><strong>@location.Street, @location.City</strong> <a href="@directionurl">obter direções</a><br><br>@Html.Raw(streetViewIframe)</div>'
@: }),
@: markerIcon: '@location.Icon'
@:});
//@:map.fitBounds(bounds); // uncomment if you want it to override your 'default' zoomlevel (min and max zoom level still apply)
@:scrollToMap('map');
}
}
for (var i = 0; i < markers.length; i++) {
(function () {
var marker = markers[i].marker;
var infoWindow = markers[i].infoWindow;
var isOpen = markers[i].isOpen;
var markerIcon = markers[i].markerIcon;
if (markerIcon.length === 0) markerIcon = customIcon.url;
// set the icon here because if i tried to pass newIcon on the marker it wont show!
var newIcon = {
url: markerIcon,
//scaledSize: new google.maps.Size(110, 142),
//origin: new google.maps.Point(0, 0),
//anchor: new google.maps.Point(55, 142)
scaledSize: new google.maps.Size(55, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(35, 71)
};
marker.setIcon(newIcon);
//alternate visibility / alternar a visibilidade apenas do marker clicado
if (markerMode == "ToggleVisibility") {
marker.addListener('click', function() {
if (isOpen) {
infoWindow.close();
isOpen = false;
} else {
infoWindow.open(map, marker);
isOpen = true;
}
});
}
else // if(markerMode == "CenterFocus") // 'default when not set'
{
// Para fechar os outros markers abertos e centralizar
marker.addListener('click', function() {
// Fecha o último infoWindow aberto (se houver)
if (lastInfoWindow != null) {
lastInfoWindow.close();
}
// Open infoWindow when clicked / Abre a janela de informação do marcador clicado
infoWindow.open(map, marker);
// Stores current marker position / Armazena a posição do marcador clicado
lastMarkerPosition = marker.getPosition();
// Stores current infoWindow / Armazena a janela de informação aberta atualmente
lastInfoWindow = infoWindow;
// Center the map on clicked position / Centraliza o mapa na posição do marcador clicado
map.panTo(lastMarkerPosition);
});
}
marker.isOpen = isOpen;
//Espera o infoWindow ser aberto
google.maps.event.addListener(infoWindow, 'domready', function() {
//selecione o div gm-style-iw-d que envolve o iframe
var iwOuter = $('.gm-style-iw-d');
//selecione o iframe dentro do div
var iwIframe = iwOuter.find('iframe');
//verifique se o tamanho do iframe é maior que o tamanho do div
if (iwIframe.height() > iwOuter.height()) {
//esconda o iframe
iwIframe.css({'display': 'none'});
}
});
})();
}
globalMarkers = markers;
}
// Function to activate the related marker when you click in a card
// Função para ativar o marcador correspondente no mapa ao clicar no card
function activateMarker(index) {
if (globalMarkers[index]) {
// Feche o último infoWindow aberto (se houver)
if (lastInfoWindow != null) {
lastInfoWindow.close();
}
// Open infoWindow when clicked / Abra a janela de informação do marcador clicado
globalMarkers[index].infoWindow.open(map, globalMarkers[index].marker);
// Stores current marker position / Armazene a posição do marcador clicado
lastMarkerPosition = globalMarkers[index].marker.getPosition();
// Stores current infoWindow / Armazene a janela de informação aberta atualmente
lastInfoWindow = globalMarkers[index].infoWindow;
// Center the map on clicked position / Centralize o mapa na posição do marcador clicado
map.panTo(lastMarkerPosition);
}
}
// Add click event on cards
document.querySelectorAll('.card').forEach(function (card, index) {
card.addEventListener('click', function () {
activateMarker(index);
scrollToMap('cards');
});
});
window.addEventListener('resize', function() {
// Remove todos os marcadores do mapa
for (let i = 0; i < globalMarkers.length; i++) {
globalMarkers[i].marker.setMap(null);
}
// chama novamente a função DrawMarkers para inserir os marcadores de volta no mapa
DrawMarkers();
});
</script>