/* MAP */
$(document).ready(function () {
});
function setMapHeader(item_type, place_id, lat, lon) {
/*
var userLat = $("#LocIP_lat").val();
var userLon = $("#LocIP_lon").val();
*/
/*
//FUNCION OK - DINAMICA
mapHeader = new google.maps.Map(document.getElementById('mapHeader'), {
center: {lat: parseFloat($("#mapHeader").attr("lat")), lng: parseFloat($("#mapHeader").attr("lon"))},
zoom: 10,
disableDefaultUI: true
});
var marker = new google.maps.Marker({
position: {lat: parseFloat($("#mapHeader").attr("lat")), lng: parseFloat($("#mapHeader").attr("lon"))},
maps: mapHeader,
title: ''
});
*/
$("#fullMap > .fa-times").off('click touch');
$("#fullMap > .fa-times").on('click', function () {
//$("#fullMap").modal('hide');
$('#fullMap').removeClass("in");
$('.modal-backdrop').hide();
$('body').removeClass('modal-open');
$('body').css('padding-right', '');
$('#fullMap').hide();
});
$(".item-maps, #mapHeaderUI").off('click touch');
$(".item-maps, #mapHeaderUI").on('click touch', function (e) {
e.preventDefault();
$("#fullMap").modal('show');
/*
var setMap_type = $('body.item');
if (setMap_type.length) {
setMap_Full(place_id, lat, lon);
} else {
raymiSetMap(lat, lon);
}
*/
var setMap_type = $('body.raymi');
if (setMap_type.length) {
raymiSetMap(lat, lon);
} else {
setMap_Full(place_id, lat, lon);
}
/*
//ACTIVAR
// alert('TIPO: '+item_type);
if (item_type == 'raymi') {
raymiSetMap(lat, lon);
} else {
setMap_Full(place_id, lat, lon, key);
}
*/
});
}
function setMap_Full(place_id, lat, lon) {
let zoom = 16;
let html;
// var markers='color:blue%7Clabel:S%7C'+center;
if (place_id != '') {
html = '';
$('#fullMap .content').html(html);
} else {
$('#fullMap').css('display', 'block');
mapFull = new google.maps.Map(document.getElementById('fullMapContent'), {
// center: {lat: parseFloat($("#mapHeader").attr("lat")), lng: parseFloat($("#mapHeader").attr("lon"))},
center: {lat: parseFloat(lat), lng: parseFloat(lon)},
zoom: zoom,
});
var marker = new google.maps.Marker({
position: {lat: parseFloat(lat), lng: parseFloat(lon)},
map: mapFull,
title: ''
});
}
}
function raymiSetMap(lat, lon) {
// alert('ingresa en setMAP RAYMI');
windows = [];
objects = [];
markers = [];
// alert('RAYMI MAP');
// $('#fullMap .content').html('RAYMI');
$('#fullMap .content').html('');
$('#fullMap').css('display', 'block');
mapFull = new google.maps.Map(document.getElementById('fullMapContent'), {
// center: {lat: parseFloat($("#mapHeader").attr("lat")), lng: parseFloat($("#mapHeader").attr("lon"))},
center: {lat: parseFloat(lat), lng: parseFloat(lon)},
zoom: 8,
});
//Creates a sidebar button
$('#fullMap .content').after('
');
var map_side = document.getElementById('map-side');
var ms_child = '';
//Creates a infowindow object.
var infoWnd = new google.maps.InfoWindow();
var markerSize = {x: 20, y: 79};
google.maps.Marker.prototype.setLabel = function (label) {
this.label = new MarkerLabel({
map: this.map,
marker: this,
text: label
});
this.label.bindTo('position', this, 'position');
};
var MarkerLabel = function (options) {
this.setValues(options);
this.span = document.createElement('span');
this.span.className = 'maps-marker-label';
};
MarkerLabel.prototype = $.extend(new google.maps.OverlayView(), {
onAdd: function () {
this.getPanes().overlayImage.appendChild(this.span);
var self = this;
this.listeners = [
google.maps.event.addListener(this, 'position_changed', function () {
self.draw();
})];
},
draw: function () {
var text = String(this.get('text'));
var position = this.getProjection().fromLatLngToDivPixel(this.get('position'));
this.span.innerHTML = text;
// this.span.style.left = (position.x - (markerSize.x / 2)) - (text.length * 3) + 10 + 'px';
this.span.style.left = (position.x - (markerSize.x / 2)) + 'px';
this.span.style.top = (position.y - markerSize.y + 40) + 'px';
}
});
var bounds = new google.maps.LatLngBounds();
//$(".raymi-list .item .distance").each(function(){
$(".items-collection .item .distance").each(function () {
if (parseFloat($(this).data("lat"))) {
$this = $(this);
var pos = Number($(this).data("pos"));
objects.push($(this).html());
var myPlace = new google.maps.LatLng(parseFloat($(this).data("lat")), parseFloat($(this).data("lon")));
bounds.extend(myPlace);
var title = '';
if ($this.parent().parent().find('.card-title').text().trim() != '') {
title = $this.parent().parent().find('.card-title').text().trim();
} else {
}
/*
if($this.parent().find(".font-size-tyni").text().trim()!=""){
$h5 = $this.parent().find(".font-size-tyni").text().trim();
}
$link=$this.parent().parent().parent().parent().attr('href');
if (typeof $link === "undefined") {
$link=$this.parent().parent().parent().parent().parent().attr('href');
}
*/
var contentString = pos + '.- ' + title; //ARREGLAR
/*
var infoWnd = new google.maps.InfoWindow({
content: contentString
});
*/
// var item_category = $(this).closest('.searchItem').data('category');
var marker = new google.maps.Marker({
position: myPlace,
map: mapFull,
// label: labels[labelIndex++ % labels.length]
label: pos
//pos
// icon: '/common/images/map_'+item_category+'.png'
});
//The infoWindow is opened when the sidebar button is clicked
marker.addListener('click', function () {
infoWnd.setContent(contentString);
infoWnd.open(mapFull, marker);
});
/*
//The infoWindow is opened when the sidebar button is clicked
google.maps.event.addListener(marker, "click", function(){
infoWnd.setContent("" + title + "");
infoWnd.open(maps, marker);
});
*/
$(this).attr("position", objects.length - 1);
markers.push(marker);
ms_child = document.createElement("li");
ms_child.innerHTML = '' + pos + '.- ' + title;
ms_child.setAttribute('title', title);
map_side.appendChild(ms_child);
//Trigger a click event to marker when the button is clicked.
google.maps.event.addDomListener(ms_child, "click", function () {
google.maps.event.trigger(marker, "click");
$('#maps-side li').removeClass('active');
$(this).addClass('active');
// alert('clic');
});
}
});
mapFull.fitBounds(bounds);
var input = document.getElementById('map-side');
mapFull.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
/*
$("body").append('
');
$(".bgFullScreen:last").click(function(){
$(".bgFullScreen:last,.fullmap").toggleClass("hidden");
});
*/
/*
$("body").append('
');
$(".bgFullScreen:last").click(function(){
$(".bgFullScreen:last,.fullmap").toggleClass("hidden");
});
*/
}