Files
SIG/GPS/AF/JS/AF.js
JORGE LUIS CAUDILLO ESPARZA c35cf91883 Commit inicial Ventas Productivo
2019-08-14 16:40:54 -07:00

414 lines
12 KiB
JavaScript

// #region R A S T R E O
var mapRastreo;
var visible = false;
var lastOpenedInfoWindow;
var markers = [];
function initMapRastreo() {
mapRastreo = new google.maps.Map(document.getElementById('mapRastreo'), {
center: { lat: 29.0730, lng: -110.9559 },
zoom: 7
});
}
function CreaMarcadorWatch(coords, nomEquipo, ContentString, imagen) {
if (typeof imagen === 'undefined') { imagen = image; }
var markerIcon = {
url: imagen,
labelOrigin: new google.maps.Point(26, 43)
};
var myLatLng = new google.maps.LatLng({ lat: coords.lat, lng: coords.lng });
var label;
if (visible) {
label = {
text: nomEquipo,
fontSize: "12px",
color: 'black',
fontWeight: 'bolder'
}
} else {
label = null;
}
var marker = new google.maps.Marker({
position: myLatLng,
title: nomEquipo,
map: mapRastreo,
icon: markerIcon
});
var infowindow = new google.maps.InfoWindow({
content: ContentString
});
marker.addListener('click', function () {
closeLastOpenedInfoWindow();
GetDirecciones(coords, infowindow, marker);
infowindow.open(mapRastreo, marker);
lastOpenedInfoWindow = infowindow;
});
marker.Nombre = nomEquipo
marker.setLabel(label)
markers.push(marker);
mapRastreo.setCenter(myLatLng);
}
function creaPolylineRastreo(coords, color, info, lastcoord, nomequipo, Imagen, valueEquipo, Continuo) {
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
strokeWeight: 1,
strokeOpacity: 1,
scale: 3,
fillOpacity: 0.6
};
var polyline = new google.maps.Polyline({
path: coords,
strokeColor: color,
strokeOpacity: 0.6,
strokeWeight: 6,
fillOpacity: 0.35,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '80px'
}]
});
polyline.setMap(mapRastreo);
polylines.push(polyline);
if (coordspoly.length <= 0 && typeof (Continuo) === "undefined") {
FitBoundsToCoordsWatch(coords);
} else {
coordspoly.push(coords[coords.length - 1]);
}
if (lastcoord != "") {
CreaMarcadorWatch(lastcoord, nomequipo, info, Imagen);
}
}
function FitBoundsToCoordsWatch(pCoords) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < pCoords.length; i++) {
bounds.extend(pCoords[i]);
}
mapRastreo.fitBounds(bounds)
}
function DeleteMarkersRastreo() {
for (var i = 0; i < markersHistorico.length; i++) {
markers[i].setMap(null);
}
markers = [];
}
// #endregion
// #region H I S T O R I C O
var mapHistorico;
var markersHistorico = [];
var polylines = [];
var coordspoly = [];
function initMapHistorico() {
mapHistorico = new google.maps.Map(document.getElementById('mapHistorico'), {
center: { lat: 29.0730, lng: -110.9559 },
zoom: 7
});
}
var marker2;
function CreaMarcadorHistorico(coords, nomEquipo, ContentString, click, imagen, indice) {
var Circle = new google.maps.Circle({
strokeColor: '#b2dbff',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#b2dbff',
fillOpacity: 0.35,
map: mapHistorico,
center: coords,
radius: 10
});
var infowindow2 = new google.maps.InfoWindow({
content: ContentString
});
Circle.addListener('click', function () {
if (typeof marker2 != 'undefined') { marker2.setMap(null); }
marker2 = new google.maps.Marker({
position: coords,
title: nomEquipo,
map: mapHistorico,
icon: imagen
});
marker2.addListener('click', function () {
if ($("#HdnOpcion").val() != "Play") {
GetDirecciones(coords, infowindow2, Circle, indice)
}
closeLastOpenedInfoWindow();
infowindow2.open(mapHistorico, marker2);
lastOpenedInfoWindow = infowindow2;
});
google.maps.event.trigger(marker2, 'click')
infowindow2.open(mapHistorico, marker2);
lastOpenedInfoWindow = infowindow2;
});
if (click === 1) {
google.maps.event.trigger(Circle, 'click', {})
}
coordspoly.push(coords);
}
function creaPolyline(coords, color, info, lastcoord, nomequipo, Imagen, valueEquipo, Continuo) {
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
strokeWeight: 1,
strokeOpacity: 1,
scale: 3,
fillOpacity: 0.6
};
var polyline = new google.maps.Polyline({
path: coords,
strokeColor: color,
strokeOpacity: 0.6,
strokeWeight: 6,
fillOpacity: 0.35,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '80px'
}]
});
polyline.setMap(mapHistorico);
polylines.push(polyline);
if (coordspoly.length <= 0 && typeof (Continuo) === "undefined") {
FitBoundsToCoords(coords);
} else {
coordspoly.push(coords[coords.length - 1]);
}
if (lastcoord != "") {
CreaMarcador(lastcoord, nomequipo, info, Imagen);
}
}
function CreaMarcador(coords, nomEquipo, ContentString, imagen) {
if (typeof imagen === 'undefined') { imagen = image; }
var markerIcon = {
url: imagen,
labelOrigin: new google.maps.Point(26, 43)
};
var marker = new google.maps.Marker({
position: coords,
title: nomEquipo,
map: mapHistorico,
icon: markerIcon
});
var infowindow = new google.maps.InfoWindow({
content: ContentString
});
marker.addListener('click', function () {
closeLastOpenedInfoWindow();
GetDirecciones(coords, infowindow, marker)
infowindow.open(mapHistorico, marker);
lastOpenedInfoWindow = infowindow;
});
marker.Nombre = nomEquipo
markersHistorico.push(marker);
if (markersHistorico.length > 1 && coordspoly.length < 1) {
fitBoundsToVisibleMarkers()
} else if (markersHistorico.length === 1 && coordspoly.length < 1) {
mapHistorico.setZoom(15);
mapHistorico.setCenter(coords);
}
mapHistorico.setCenter(coords);
}
function FitBoundsToCoords(pCoords) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < pCoords.length; i++) {
bounds.extend(pCoords[i]);
}
mapHistorico.fitBounds(bounds)
}
function fitBoundsToVisibleMarkers() {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markersHistorico.length; i++) {
if (markersHistorico[i].getVisible()) {
bounds.extend(markersHistorico[i].getPosition());
}
}
mapHistorico.fitBounds(bounds);
}
function DeleteMarkersHistorico() {
for (var i = 0; i < markersHistorico.length; i++) {
markersHistorico[i].setMap(null);
}
markersHistorico = [];
for (var i = 0; i < polylines.length; i++) {
polylines[i].setMap(null);
}
polylines = [];
coordspoly = [];
}
// #endregion
function closeLastOpenedInfoWindow() {
if (lastOpenedInfoWindow) {
lastOpenedInfoWindow.close();
}
}
function GetDirecciones(posicion, infowindow, marker) {
var lat = posicion.lat
var lng = posicion.lng
$.getJSON('http://adsistemasof.sytes.net/nominatim/reverse.php?format=jsonv2&lat=' + lat + '&lon=' + lng, function (data) {
if (typeof (data.error) === 'undefined') {
marker.formatted_address = data.display_name;
var contenido = infowindow.getContent();
if (contenido.indexOf("direccion") >= 0) {
var html = $($.parseHTML(contenido));
var dir = html.filter(".direccion");;
dir.text("Dirección: " + data.display_name);
var htmlstring = "";
for (var i = 0; i < html.length; i++) {
htmlstring = htmlstring.concat(html[i].outerHTML);
}
infowindow.setContent(htmlstring);
} else {
infowindow.setContent(contenido + "<div class='direccion' style='margin-left:5px'>" + "Dirección: " + data.display_name + "</div>");
}
} else {
marker.formatted_address = "Dirección no encontrada";
if (contenido.indexOf("direccion") >= 0) {
var html = $($.parseHTML(contenido));
var dir = html.filter(".direccion");;
dir.text("Dirección no encontrada");
var htmlstring = "";
for (var i = 0; i < html.length; i++) {
htmlstring = htmlstring.concat(html[i].outerHTML);
}
infowindow.setContent(htmlstring);
} else {
infowindow.setContent(infowindow.getContent() + "<div style='margin-left:5px'> Dirección: No Encontrada </div>");
}
}
});
}
function CargaGraficaCombustible() {
var data = [];
var Gcolor = $('#ChkEncendido').is(':checked') ? "lineColor" : null;
eval($("#HdfVGrafica").val());
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginRight": 40,
"marginLeft": 40,
"autoMarginOffset": 20,
"dataDateFormat": "YYYY-MM-DD HH:NN:SS",
"valueAxes": [{
"id": "v1",
"axisAlpha": 0,
"position": "left",
"ignoreAxisWidth": true
}],
"balloon": {
"borderThickness": 1,
"shadowAlpha": 0
},
"graphs": [{
"id": "g1",
"balloon": {
"drop": true,
"adjustBorderColor": false,
"color": "#ffffff",
"type": "smoothedLine"
},
"fillAlphas": 0.2,
"bullet": "round",
"bulletBorderAlpha": 1,
"bulletColor": "#FFFFFF",
"bulletSize": 5,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "red line",
//"useLineColorForBulletBorder": true,
"valueField": "value",
"lineColorField": Gcolor,
"fillColorsField": Gcolor,
"balloonText": "<span style='font-size:18px;'>[[value]]</span>"
}],
"chartScrollbar": {},
"chartCursor": {
"valueLineEnabled": true,
"valueLineBalloonEnabled": true,
"cursorAlpha": 0,
"zoomable": false,
"valueZoomable": true,
"valueLineAlpha": 0.5
},
"categoryField": "date",
"categoryAxis": {
"parseDates": false,
"dashLength": 1,
"minorGridEnabled": true,
},
"export": {
"enabled": true,
"menu": []
},
"dataProvider": data
});
}
//GEOREFERENCIAS
var mapGeo;
function initMapGeo() {
mapGeo = new google.maps.Map(document.getElementById('mapGeo'), {
center: { lat: 29.0730, lng: -110.9559 },
zoom: 7
});
}
var polygons = [];
function creaPoligono(coords, color) {
var polygon = new google.maps.Polygon({
paths: coords,
strokeColor: color,
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: color,
fillOpacity: 0.35
});
polygon.setMap(mapGeo);
polygons.push(polygon);
//map.setCenter(coords[0]);
}
var markersGeo = [];
function CreaMarcadorGeo(coords, nomEquipo, ContentString, imagen) {
if (typeof imagen === 'undefined') { imagen = image; }
var marker = new google.maps.Marker({
position: coords,
title: nomEquipo,
map: mapGeo,
icon: imagen
});
var infowindow = new google.maps.InfoWindow({
content: ContentString
});
marker.addListener('click', function () {
closeLastOpenedInfoWindow();
GetDirecciones(coords, infowindow, marker);
infowindow.open(mapGeo, marker);
lastOpenedInfoWindow = infowindow;
});
markersGeo.push(marker);
//map.setCenter(coords);
fitBoundsToVisibleMarkersGeo()
}
function fitBoundsToVisibleMarkersGeo() {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markersGeo.length; i++) {
if (markersGeo[i].getVisible()) {
bounds.extend(markersGeo[i].getPosition());
}
}
mapGeo.fitBounds(bounds);
}