';
}
//
if(coordinates.length == 2){
lat = coordinates[0];
lng = coordinates[1];
} else {
console.log("As coordenadas do asset " + markerInfo.name + " ["+markerInfo.coords+"] nao estao no formato correcto. Devem estar no formato: -8.824206, 13.236721");
return;
}
var position = new google.maps.LatLng(lat, lng);
var markerDesktop = new google.maps.Marker({
position: position,
icon: image.url,
clickable: true,
title: markerInfo.name,
prop: markerInfo,
array: -1,
info: infoDesktop
});
google.maps.event.addListener(markerDesktop, 'click', function() {
if(infowindowD.getPosition() != 'undefined'){
var oldPosition = infowindowD.getPosition();
infowindowD.setContent(markerDesktop.info);
infowindowD.open(map,markerDesktop);
var newPosition = infowindowD.getPosition();
if(oldPosition == newPosition){
infowindowD.close();
infowindowD = new google.maps.InfoWindow();
}
} else {
infowindowD.setContent(markerDesktop.info);
infowindowD.open(map,markerDesktop);
}
});
if(markerInfo.type == 'A') {
markerDesktop.array = 'markersADesktop['+markersADesktop.length+']';
markersADesktop.push(markerDesktop);
}
if(markerInfo.type == 'E') {
markerDesktop.array = 'markersEDesktop['+markersEDesktop.length+']';
markersEDesktop.push(markerDesktop);
}
if(markerInfo.type == 'C') {
markerDesktop.array = 'markersCDesktop['+markersEDesktop.length+']';
markersCDesktop.push(markerDesktop);
}
if(markerInfo.type == 'CE'){
markerDesktop.array = 'markersCEDesktop['+markersCEDesktop.length+']';
markersCEDesktop.push(markerDesktop);
}
if(markerInfo.type == 'PRE') {
markerDesktop.array = 'markersPREDesktop['+markersPREDesktop.length+']';
markersPREDesktop.push(markerDesktop);
}
if(markerInfo.type == 'POS') {
markerDesktop.array = 'markersPOSDesktop['+markersPOSDesktop.length+']';
markersPOSDesktop.push(markerDesktop);
}
if(markerInfo.type == 'PREPOS') {
markerDesktop.array = 'markersPREPOSDesktop['+markersPREPOSDesktop.length+']';
markersPREPOSDesktop.push(markerDesktop);
}
var markerMobile = new google.maps.Marker({
position: position,
icon: image.url,
clickable: true,
title: markerInfo.name,
prop: markerInfo,
array: -1,
info: infoMobile,
});
google.maps.event.addListener(markerMobile, 'click', function() {
if(infowindowM.getPosition() != 'undefined'){
var oldPosition = infowindowM.getPosition();
infowindowM.setContent(markerMobile.info);
infowindowM.open(mapMini,markerMobile);
var newPosition = infowindowM.getPosition();
if(oldPosition == newPosition){
infowindowM.close();
infowindowM = new google.maps.InfoWindow();
}
} else {
infowindowM.setContent(markerMobile.info);
infowindowM.open(mapMini,markerMobile);
}
});
if(markerInfo.type == 'A') {
markerMobile.array = 'markersAMobile['+markersAMobile.length+']';
markersAMobile.push(markerMobile);
}
if(markerInfo.type == 'E') {
markerMobile.array = 'markersEMobile['+markersEMobile.length+']';
markersEMobile.push(markerMobile);
}
if(markerInfo.type == 'C') {
markerMobile.array = 'markersCMobile['+markersCMobile.length+']';
markersCMobile.push(markerMobile);
}
if(markerInfo.type == 'CE'){
markerMobile.array = 'markersCEMobile['+markersCEMobile.length+']';
markersCEMobile.push(markerMobile);
}
if(markerInfo.type == 'PRE') {
markerMobile.array = 'markersPREMobile['+markersPREMobile.length+']';
markersPREMobile.push(markerMobile);
}
if(markerInfo.type == 'POS') {
markerMobile.array = 'markersPOSMobile['+markersPOSMobile.length+']';
markersPOSMobile.push(markerMobile);
}
if(markerInfo.type == 'PREPOS') {
markerMobile.array = 'markersPREPOSMobile['+markersPREPOSMobile.length+']';
markersPREPOSMobile.push(markerMobile);
}
}
/* Coloca os markers criados pelas Queries no mapa. */
function addMarkersToMap(){
allMarkersM = [];
allMarkersD = [];
/* Valida checkboxes na página Lojas */
var x = document.getElementById("Px");
if(x!=null){
if(document.getElementById("Px").checked || document.getElementById("Ex").checked) {
addMarker("CE");
} else { removeMarker("CE"); }
if(document.getElementById("Ax").checked){
addMarker("A");
} else { removeMarker("A"); }
if(document.getElementById("Px").checked) {
addMarker("C");
} else { removeMarker("C"); }
if(document.getElementById("Ex").checked) {
addMarker("E");
} else { removeMarker("E"); }
if(!document.getElementById("Px").checked && !document.getElementById("Ex").checked && !document.getElementById("Ax").checked){
document.getElementById("store-left-bot").innerHTML = '';
document.getElementById("store-left-mobile").innerHTML = '';
}
}
/* Valida checkboxes na página Roaming */
var y = document.getElementById("Prex");
if(y!=null){
if(document.getElementById("Prex").checked || document.getElementById("Posx").checked){
addMarker("PREPOS");
} else { removeMarker("PREPOS"); }
if(document.getElementById("Prex").checked){
addMarker("PRE");
} else { removeMarker("PRE"); }
if(document.getElementById("Posx").checked){
addMarker("POS");
} else { removeMarker("POS"); }
if(!document.getElementById("Prex").checked && !document.getElementById("Posx").checked){
document.getElementById("store-left-bot").innerHTML = '';
document.getElementById("store-left-mobile").innerHTML = '';
}
}
google.maps.event.trigger(map, 'idle');
google.maps.event.trigger(mapMini, 'idle');
}
/* Add a marker to the map and push to the array. */
function addMarker(type) {
var markers;
if(type == 'A') { markers = markersADesktop; }
if(type == 'E') { markers = markersEDesktop; }
if(type == 'C') { markers = markersCDesktop; }
if(type == 'CE'){ markers = markersCEDesktop; }
if(type == 'PRE') { markers = markersPREDesktop; }
if(type == 'POS') { markers = markersPOSDesktop; }
if(type == 'PREPOS') { markers = markersPREPOSDesktop; }
// To add the marker to the map, call setMap();
for(marker in markers){
allMarkersD.push(markers[marker]);
markers[marker].setMap(map);
}
var markers = [];
if(type == 'A') { markers = markersAMobile; }
if(type == 'E') { markers = markersEMobile; }
if(type == 'C') { markers = markersCMobile; }
if(type == 'CE'){ markers = markersCEMobile; }
if(type == 'PRE') { markers = markersPREMobile; }
if(type == 'POS') { markers = markersPOSMobile; }
if(type == 'PREPOS') { markers = markersPREPOSMobile; }
// To add the marker to the map, call setMap();
for(marker in markers){
allMarkersM.push(markers[marker]);
markers[marker].setMap(mapMini);
}
}
function removeMarker(type){
var markers;
if(type == 'A') { markers = markersADesktop; }
if(type == 'E') { markers = markersEDesktop; }
if(type == 'C') { markers = markersCDesktop; }
if(type == 'CE'){ markers = markersCEDesktop; }
if(type == 'PRE') { markers = markersPREDesktop; }
if(type == 'POS') { markers = markersPOSDesktop; }
if(type == 'PREPOS') { markers = markersPREPOSDesktop; }
for(marker in markers){ markers[marker].setMap(null); }
if(type == 'A') { markers = markersAMobile; }
if(type == 'E') { markers = markersEMobile; }
if(type == 'C') { markers = markersCMobile; }
if(type == 'CE'){ markers = markersCEMobile; }
if(type == 'PRE') { markers = markersPREMobile; }
if(type == 'POS') { markers = markersPOSMobile; }
if(type == 'PREPOS') { markers = markersPREPOSMobile; }
for(marker in markers){ markers[marker].setMap(null); }
}
function isDesktop(){
var wid_mapMini = $("#map-canvas-lojas-mini").width();
if(wid_mapMini == 100){
return true;
}
return false;
}
function activeMap(){
var wid_mapMini = $("#map-canvas-lojas-mini").width();
if(wid_mapMini == 100){
/*console.log("mapa activo: MAXI");*/
return map;
}
//console.log("mapa activo: mini");
return mapMini;
}
function autocompleteCall(autocomplete,restricted){
infowindowM.close();
infowindowD.close();
var result = autocomplete.getPlace();
if(typeof result == 'undefined' || typeof result.address_components == 'undefined') {
// The user pressed enter in the input without selecting a result from the list
autocompleteService = new google.maps.places.AutocompleteService();
if(restricted == "1"){
autocompleteService.getPlacePredictions(
{
'input': document.getElementById("texto").value,
'offset': document.getElementById("texto").value.length,
// repeat the options for my AutoComplete
'componentRestrictions': {'country': 'AO'}
},
function listentoresult(list, status) {
if(list == null || list.length == 0) {
// There are no suggestions available. The user saw an empty list and hit enter.
} else {
// Here's the first result that the user saw in the list.
placesService = new google.maps.places.PlacesService(document.getElementById('texto'));
placesService.getDetails(
{'reference': list[0].reference},
function detailsresult(detailsResult, placesServiceStatus) {
// Here's the first result in the AutoComplete
activeMap().setCenter(detailsResult.geometry.location);
try {
activeMap().fitBounds(detailsResult.geometry.viewport);
} catch (err) {
activeMap().setZoom(15);
}
}
);
}
}
);}
else {
autocompleteService.getPlacePredictions(
{
'input': document.getElementById("texto").value,
'offset': document.getElementById("texto").value.length,
// repeat the options for my AutoComplete
},
function listentoresult(list, status) {
if(list == null || list.length == 0) {
// There are no suggestions available. The user saw an empty list and hit enter.
} else {
// Here's the first result that the user saw in the list.
placesService = new google.maps.places.PlacesService(document.getElementById('texto'));
placesService.getDetails(
{'reference': list[0].reference},
function detailsresult(detailsResult, placesServiceStatus) {
// Here's the first result in the AutoComplete
activeMap().setCenter(detailsResult.geometry.location);
try {
activeMap().fitBounds(detailsResult.geometry.viewport);
} catch (err) {
activeMap().setZoom(6);
}
}
);
}
}
);}
} else {
// The user selected a result from the list, we can proceed and use it right away
activeMap().setCenter(result.geometry.location);
try {
activeMap().fitBounds(result.geometry.viewport);
} catch (err) {
activeMap().setZoom(15);
}
}
}
/* Clicou em Pesquisar na Página Lojas, autocomplete com restrição a Angola*/
function clicked(){
var autocomplete = new google.maps.places.Autocomplete(document.getElementById('texto'));
var restricted = "1";
autocompleteCall(autocomplete,restricted);
}
/* Clicou em Pesquisar na Página Roaming, autocomplete sem restrição*/
function clickedRoam(){
var autocomplete = new google.maps.places.Autocomplete(document.getElementById('texto'));
var restricted = "0";
autocompleteCall(autocomplete,restricted);
}
/* Clicou em Perto de Mim */
function nearMe(){
//console.log("near-me");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getClientPosition,error);
} else {
alert("Geolocation is not supported by this browser.");
}
document.getElementById("near-me").blur();
}
function getClientPosition(position){
activeMap().setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var marker = new google.maps.Marker({
position: myLatlng,
title:"A minha posição"
});
// To add the marker to the map, call setMap();
marker.setMap(activeMap());
}
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
$("#near-me").removeClass("btn-blue").addClass("disabled");
document.getElementById("near-me").setAttribute('onclick',"return false;");
}
function GetLocation(address,callback) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (locations, status) {
var pos = {};
if (status == google.maps.GeocoderStatus.OK) {
pos = ParseLocation(locations[0].geometry.location);
activeMap().setCenter(locations[0].geometry.location);
try {
activeMap().fitBounds(locations[0].geometry.viewport);
} catch (err) {
activeMap().setZoom(15);// VER
}
}
else{
console.log('...GetLocation Error: ' + status);
pos = {lat: -8.8220369, lng: 13.2437445};
}
}
);
}
function ParseLocation(location) {
var coordinates = {lat : location.lat().toString().substr(0, 12),
lng : location.lng().toString().substr(0, 12)};
return coordinates;
}
function changedProvincia(j, thhis){
var municipio = document.getElementById("dropdown-municipio");
var texto1 = document.getElementById("text-provincia");
var labelProvincia = document.getElementById("dropdownMenu1");
var labelMunicipio = document.getElementById("dropdownMenu2");
labelMunicipio.innerHTML = 'Município
';
if(j == -1) {
// Desactivar este botao
labelProvincia.innerHTML = 'Província
';
municipio.innerHTML = '';
texto1.value = "";
} else {
labelProvincia.innerHTML = thhis.textContent +'
';
municipio.innerHTML = '
 ';
for(i in municipality[j]){
texto1.value = thhis.textContent;
municipio.innerHTML += '
'+municipality[j][i]+'';
}
changeMapCenter(texto1.value,'');
}
}
function changedContinente(j, thhis){
var pais = document.getElementById("dropdown-pais");
var texto1 = document.getElementById("text-continente");
var labelContinente = document.getElementById("dropdownMenu1");
var labelPais = document.getElementById("dropdownMenu2");
labelPais.innerHTML = 'País
';
if(j == -1) {
// Desactivar este botao
labelContinente.innerHTML = 'Continente
';
pais.innerHTML = '';
texto1.value = "";
} else {
labelContinente.innerHTML = thhis.textContent +'
';
pais.innerHTML = '
 ';
for(i in country[j]){
texto1.value = thhis.textContent;
pais.innerHTML += '
'+country[j][i]+'';
}
changeMapCenterRoam(texto1.value,'');
}
}
function changedMunicipio(i,thhis){
var labelMunicipio = document.getElementById("dropdownMenu2");
var texto2 = '';
if(i == -1) {
labelMunicipio.innerHTML = 'Município
';
texto2 = "";
} else {
texto2 = thhis.textContent;
labelMunicipio.innerHTML = thhis.textContent +'
';
}
changeMapCenter(document.getElementById("text-provincia").value,texto2);
}
function changedPais(i,thhis){
var labelPais = document.getElementById("dropdownMenu2");
var texto2 = '';
if(i == -1) {
labelPais.innerHTML = 'País
';
texto2 = "";
} else {
texto2 = thhis.textContent;
labelPais.innerHTML = thhis.textContent +'
';
}
changeMapCenterRoam(document.getElementById("text-continente").value,texto2);
}
function showStore(store,url) { // mostra a loja em modo desktop
var iframe = document.getElementById("store-frame");
if( url == undefined || $("#"+store).hasClass("active")){
$(".detalhe-loja").addClass("goaway");
$(".desktop .loja").removeClass("active");
setTimeout(function () {
iframe.setAttribute('src','');
$("#detalhe-da-loja").html('
');
}, 500);
return;
}
if(!$("#"+store).hasClass("active")) {
$("#detalhe-da-loja").html('
');
$(".desktop .loja").removeClass("active");
$("#"+store).addClass("active");
if(iframe != null){
iframe.setAttribute('src',url);
$(".detalhe-loja").removeClass("goaway");
}
}
}
function showBubble(coords,marker,thhis){
var lat = coords.split(",")[0];
var lng = coords.split(",")[1];
if(!isDesktop()){ // show map again
$(".horario").slideDown();
$(".mobile .loja").removeClass("active");
$(thhis).addClass("active");
$('html,body').animate({
scrollTop: $("#map-canvas-lojas-mini").offset().top},
'slow');
for(marker in markersCEMobile){
if(isEqual(markersCEMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowM.setContent(markersCEMobile[marker].info); infowindowM.open(mapMini,markersCEMobile[marker]);
return;
}
}
for(marker in markersEMobile){
if(isEqual(markersEMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersEMobile[marker].title);
infowindowM.setContent(markersEMobile[marker].info); infowindowM.open(mapMini,markersEMobile[marker]);
return;
}
}
for(marker in markersCMobile){
if(isEqual(markersCMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCMobile[marker].title);
infowindowM.setContent(markersCMobile[marker].info); infowindowM.open(mapMini,markersCMobile[marker]);
return;
}
}
for(marker in markersAMobile){
if(isEqual(markersAMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersAMobile[marker].title);
infowindowM.setContent(markersAMobile[marker].info); infowindowM.open(mapMini,markersAMobile[marker]);
return;
}
}
for(marker in markersPREPOSMobile){
if(isEqual(markersPREPOSMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowM.setContent(markersPREPOSMobile[marker].info); infowindowM.open(mapMini,markersPREPOSMobile[marker]);
return;
}
}
for(marker in markersPOSMobile){
if(isEqual(markersPOSMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowM.setContent(markersPOSMobile[marker].info); infowindowM.open(mapMini,markersPOSMobile[marker]);
return;
}
}
for(marker in markersPREMobile){
if(isEqual(markersPREMobile[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowM.setContent(markersPREMobile[marker].info); infowindowM.open(mapMini,markersPREMobile[marker]);
return;
}
}
} else {
var iframe = document.getElementById("store-frame");
$(".detalhe-loja").addClass("goaway");
$(".desktop .loja").removeClass("active");
setTimeout(function () {
iframe.setAttribute('src','');
$("#detalhe-da-loja").html('
');
}, 500);
for(marker in markersCEDesktop){
if(isEqual(markersCEDesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEDesktop[marker].title);
infowindowD.setContent(markersCEDesktop[marker].info); infowindowD.open(map,markersCEDesktop[marker]);
return;
}
}
for(marker in markersEDesktop){
if(isEqual(markersEDesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersEDesktop[marker].title);
infowindowD.setContent(markersEDesktop[marker].info); infowindowD.open(map,markersEDesktop[marker]);
return;
}
}
for(marker in markersCDesktop){
if(isEqual(markersCDesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCDesktop[marker].title);
infowindowD.setContent(markersCDesktop[marker].info); infowindowD.open(map,markersCDesktop[marker]);
return;
}
}
for(marker in markersADesktop){
if(isEqual(markersADesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersADesktop[marker].title);
infowindowD.setContent(markersADesktop[marker].info); infowindowD.open(map,markersADesktop[marker]);
return;
}
}
for(marker in markersPREPOSDesktop){
if(isEqual(markersPREPOSDesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowD.setContent(markersPREPOSDesktop[marker].info); infowindowD.open(map,markersPREPOSDesktop[marker]);
return;
}
}
for(marker in markersPOSDesktop){
if(isEqual(markersPOSDesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowD.setContent(markersPOSDesktop[marker].info); infowindowD.open(map,markersPOSDesktop[marker]);
return;
}
}
for(marker in markersPREDesktop){
if(isEqual(markersPREDesktop[marker].prop.coords,coords)){
//console.log("o marker achado é o "+markersCEMobile[marker].title);
infowindowD.setContent(markersPREDesktop[marker].info); infowindowD.open(map,markersPREDesktop[marker]);
return;
}
}
}
}
function addStoreInfoToLeftBar(marker,id,coords){
var maindiv = document.getElementById("store-left-bot");
var detail = "";
var country_code = "";
if(marker.prop.pre != null || typeof marker.prop.pre != "undefined" || marker.prop.pos != null || typeof marker.prop.pos != "undefined"){
country_code = '
('+ marker.prop.country +')';
if(marker.prop.pos != ''){
var servicearray = marker.prop.pos.split(",");
var servicelist = '
Pós-Pago
';
for(i=0;i'+ servicearray[i] +'';
}
servicelist += '
';
//detail += servicelist;
}
if(marker.prop.pre != ''){
var servicearray = marker.prop.pre.split(",");
var servicelist = '
Pré-Pago
';
for(i=0;i'+ servicearray[i] +'';
}
servicelist += '
';
//detail += servicelist;
}
} else { detail += '
'+marker.prop.address+'
' ;}
var div =
'
'+
'
'+ marker.title + country_code +'
'+detail+'
';
maindiv.innerHTML += div;
}
function addStoreInfoToLeftBarMobile(marker){
var mobilediv = document.getElementById("store-left-mobile");
var mobileinner2 = '';
var country_code = '';
if(marker.prop.pre != null || typeof marker.prop.pre != "undefined" || marker.prop.pos != null || typeof marker.prop.pos != "undefined"){
country_code = '
('+ marker.prop.country +')';
if(marker.prop.pos != ''){
var servicearray = marker.prop.pos.split(",");
var servicelist = '
Pós-Pago
';
for(i=0;i'+ servicearray[i] +'';
}
servicelist += '
';
//mobileinner2 += servicelist;
}
if(marker.prop.pre != ''){
var servicearray = marker.prop.pre.split(",");
var servicelist = '
Pré-Pago
';
for(i=0;i'+ servicearray[i] +'';
}
servicelist += '
';
//mobileinner2 += servicelist;
}
}else{
mobileinner2 += '
'+ marker.prop.address +'
';
}
var mobileinner = '
'+
'
'+ marker.title + country_code+'
';
mobileinner += mobileinner2;
mobileinner += '
';
if(!isEqual(marker.prop.hour,'')){
mobileinner += '
HORÁRIO DE FUNCIONAMENTO
'+
'
'+marker.prop.hour+'
';
}
if(!isEqual(marker.prop.tel,'')){
mobileinner += '
';
}
mobileinner += '
';
mobilediv.innerHTML += mobileinner;
}
function showStoreMobile(store,url) { // mostra a loja em modo mobile
var iframe = document.getElementById("store-frame");
iframe.setAttribute('src',url);
$(".lojas-sidebar, .lojas-lista, .detalhe-loja-mobile").toggle();
$('html,body').animate({
scrollTop: $(".close-button").offset().top - 20},
'slow');
}
function closeMobileDetail(){
$("#detalhe-da-loja-mobile").html('
Voltar
');
$(".lojas-sidebar, .lojas-lista, .detalhe-loja-mobile").toggle();
$('html,body').animate({
scrollTop: $("#map-canvas-lojas-mini").offset().top - 20},
'slow');
}
/* Open new tab with google maps directions */
function navigateToGoogleMaps(){
//console.log("A tentar centrar o mapa PERTO DE MIM");
if (parent.navigator.geolocation) {
parent.navigator.geolocation.getCurrentPosition(goToStore,directionsError);
} else {
console.error("Geolocation is not supported by this browser.");
}
}
function goToStore(position){
var myLocation = "";
if(position != null && typeof position != "undefined") {
myLocation = position.coords.latitude + "," + position.coords.longitude;
}
var url = "https://www.google.pt/maps/dir/";
url += myLocation + ""; // FROM: coordinates from computer location
url += "/";
url += document.getElementById('coords').value;// TO: coordinates from store
url += "/";
var win = window.open(url,"GoogleMaps",'scrollbars=1,height=650,width=1050');
win.focus();
}
function directionsError(err){
console.warn('ERROR(' + err.code + '): ' + err.message);
goToStore();
}