Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mapa = {
  2.     //dane inicjalizacyjne do googleMap
  3.     // blokowanie funkcjonalnosci
  4.     optionsMap: {
  5.         streetViewControl: false,
  6.         fullscreenControl: false,
  7.         fullscreenControlOptions: false,
  8.         mapTypeControl: false,
  9.         panControl: false,
  10.         minZoom: 11,
  11.         maxZoom: 20,
  12.     },
  13.     //dane inicjalizacyjne do rysowania tras
  14.     optionsBusLine: {
  15.         strokeColor: 'red',
  16.         strokeOpacity: 1.0,
  17.         strokeWeight: 3,
  18.     },
  19.     isready: false,
  20.     aktywnyPrzystanek: null,
  21.     //zmienna przechowujaca trase autobusu po jego edycji
  22.     busLineData: [],
  23.     map: null,
  24.     infowindow: null,
  25.     //obraz przystanku/ inicjowany w init
  26.     image: null,
  27.     //dla aktywnego przystanku
  28.     imageActive: null,
  29.     markerActive: null,
  30.     // Wsp. wszystkich przystankow
  31.     allBusStop: [],
  32.     // tablilica wsp do tworzenia markerow
  33.     locations: [],
  34.     // tablica zainicjowanych markerow
  35.     markersArray: [],
  36.     // trasa przejazdu
  37.     busLine: null,
  38.     // grupowanie Przystankow
  39.     markerCluster: null,
  40.     //dyrektywy rysowania lini tras
  41.     directionsDisplay: [],
  42.  
  43.     init: function () {
  44.         mapa.image = new google.maps.MarkerImage(
  45.             document.location.origin + "/web/mpk_sf3/web/assets/img/busstop.png",
  46.             new google.maps.Size(28, 50),
  47.             new google.maps.Point(0, 0)
  48.         );
  49.         mapa.imageActive = new google.maps.MarkerImage(
  50.             document.location.origin + "/web/mpk_sf3/web/assets/img/busstop-active.png",
  51.             new google.maps.Size(28, 50),
  52.             new google.maps.Point(0, 0)
  53.         );
  54.         mapa.initMap();
  55.     },
  56.  
  57.     clearOverlays: function () {
  58.         //czyszczenie mapy
  59.  
  60.         for (var i = 0; i < mapa.markersArray.length; i++) {
  61.             mapa.markersArray[i].setMap(null);
  62.         }
  63.         mapa.markersArray.length = 0;
  64.         google.maps.event.removeListener();
  65.  
  66.         if (mapa.markerCluster !== null) {
  67.             mapa.markerCluster.clearMarkers();
  68.         }
  69.         if (mapa.busLine !== null) {
  70.             mapa.busLine.setMap(null);
  71.         }
  72.         if (mapa.markerActive !== null) {
  73.             mapa.markerActive.setMap(null);
  74.         }
  75.         if (mapa.infowindow !== null) {
  76.             mapa.infowindow.close();
  77.         }
  78.  
  79.         for (let i = 0; i < mapa.directionsDisplay.length; i++) {
  80.             mapa.directionsDisplay[i].setMap(null);
  81.         }
  82.     },
  83.  
  84.     initMap: function () {
  85.         mapa.clearOverlays();
  86.         mapa.pokazWszystkiePrzystanki();
  87.     },
  88.  
  89.     setMarkerActive: function (marker) {
  90.         if (mapa.markerActive !== null) {
  91.             mapa.markerActive.setIcon(mapa.image);
  92.         }
  93.         mapa.map.setCenter(marker.getPosition());
  94.         mapa.map.setZoom(16);
  95.         marker.setIcon(mapa.imageActive);
  96.         mapa.markerActive = marker;
  97.     },
  98.  
  99.     wyswietlWszystkiePrzystanki: function () {
  100.         mapa.locations = mapa.allBusStop;
  101.         mapa.wyswietlPrzystankiZLocation();
  102.     },
  103.  
  104.     // Inicjowanie mapy z markerami wszystkich przystankow i listenerami po ich kliknieciu ( otwieraja rozklad na przystanku)
  105.     // przystanki musza byc zaladowane do mapa.location
  106.     // wyswietla przystanki i dodaje im listenerea po ktorego kliknieciu wyswietla rozklad na danym przystanku
  107.     wyswietlPrzystankiZLocation: function (bezClusterow) {
  108.         bezClusterow = bezClusterow || false;
  109.         mapa.clearOverlays();
  110.  
  111.         var clusterStyles = [
  112.             {
  113.                 url: document.location.origin + "/web/mpk_sf3/web/assets/img/busstop-group1.png",
  114.                 textColor: 'white',
  115.                 width: 22,
  116.                 height: 30
  117.             },
  118.             {
  119.                 url: document.location.origin + "/web/mpk_sf3/web/assets/img/busstop-group2.png",
  120.                 textColor: 'white',
  121.                 width: 28,
  122.                 height: 30
  123.             },
  124.             {
  125.                 url: document.location.origin + "/web/mpk_sf3/web/assets/img/busstop-group3.png",
  126.                 textColor: 'white',
  127.                 width: 34,
  128.                 height: 30
  129.             }];
  130.  
  131.         var clusterOptions = {
  132.             imagePath: document.location.origin + "/web/mpk_sf3/web/assets/img/busstop-group",
  133.             maxZoom: 15,
  134.             styles: clusterStyles
  135.         };
  136.  
  137.         $.each(mapa.locations, function (k, val) {
  138.             var latLng = new google.maps.LatLng(val[0], val[1]);
  139.             var marker = new google.maps.Marker({
  140.                 position: latLng,
  141.                 anchorPoint: google.maps.Point(0, 20),
  142.                 icon: mapa.image,
  143.                 title: val[3],
  144.                 optimized: true,
  145.                 przystanek: k,       // id przystanku, dodana wlasna wartosc
  146.                 map: mapa.map
  147.             });
  148.             mapa.markersArray.push(marker);
  149.  
  150.             google.maps.event.addListener(marker, 'click', function (mark, i) {
  151.                 mapa.setMarkerActive(marker);
  152.                 mapa.pokazPrzystanekZRozklademZAktualnaMapa(marker.przystanek);
  153.             });
  154.         });
  155.  
  156.         if (!bezClusterow) {
  157.             try {
  158.                 mapa.markerCluster = new MarkerClusterer(mapa.map, mapa.markersArray, clusterOptions);
  159.             } catch (err) {
  160.                 console.log("Błąd ładowania clusterów");
  161.             }
  162.         }
  163.     },
  164.  
  165.     wysrodkujPinezkiZLocation: function () {
  166.         var tempLenght = parseInt(Object.keys(mapa.locations).length / 2);
  167.         tempLenght = Object.keys(mapa.locations)[tempLenght];
  168.  
  169.         var uluru = {lat: parseFloat(mapa.locations[tempLenght][0]), lng: parseFloat(mapa.locations[tempLenght][1])};
  170.         mapa.map.setCenter(uluru);
  171.         mapa.map.setZoom(14);
  172.     },
  173.  
  174.     // uzupelnianie mapy o markery przystankow i trase przejazdu autobusu
  175.     // listener ustawiony na wysylanie ajax'a z idRozkladKierunekTrasa
  176.     wyswietlTrasePrzejazduZPrzystankami: function (tablicaPrzystankow, tablicaDrogi, aktualny) {
  177.         aktualny = aktualny || null;
  178.         mapa.locations = tablicaPrzystankow;
  179.         var aktualnyMarkerWsp = null;
  180.  
  181.         if (aktualny !== null) {
  182.             aktualnyMarkerWsp = new google.maps.LatLng(aktualny[0], aktualny[1]);
  183.         }
  184.         mapa.clearOverlays();
  185.         mapa.busLineData = null;
  186.  
  187.         if (aktualny === null) {
  188.             var tempLenght = parseInt(tablicaPrzystankow.length / 2);
  189.             var uluru = {
  190.                 lat: parseFloat(tablicaPrzystankow[tempLenght][0]),
  191.                 lng: parseFloat(tablicaPrzystankow[tempLenght][1])
  192.             };
  193.             mapa.map.setCenter(uluru);
  194.         } else {
  195.             mapa.map.setCenter(aktualnyMarkerWsp);
  196.         }
  197.         mapa.map.setZoom(16);
  198.  
  199.         $.each(tablicaPrzystankow, function (k, val) {
  200.             var latLng = new google.maps.LatLng(parseFloat(val[0]), parseFloat(val[1]));
  201.             var marker = new google.maps.Marker({
  202.                 position: latLng,
  203.                 icon: aktualnyMarkerWsp == null ?
  204.                     mapa.image :
  205.                     latLng.equals(aktualnyMarkerWsp) ?
  206.                         mapa.imageActive :
  207.                         mapa.image,
  208.                 title: val[3].toString(),
  209.                 optimized: true,
  210.                 idRozkladu: val[2].toString(),       // id rozkladu, dodana wlasna wartosc
  211.                 slug: val[4].toString(),
  212.                 map: mapa.map
  213.             });
  214.             if (latLng.equals(aktualnyMarkerWsp)) {
  215.                 mapa.markerActive = marker;
  216.             }
  217.             mapa.markersArray.push(marker);
  218.  
  219.             //sluchacz/ wyswietla rozklad po kliknieciu w marker
  220.             google.maps.event.addListener(marker, 'click', function (mark, i) {
  221.                 var location = window.location.href.split('?')[1];
  222.  
  223.                 location = location.split("&");
  224.                 var locationTemp = {};
  225.                 $.each(location, function (k, v) {
  226.                     var tempSplit = v.split("=");
  227.                     locationTemp[tempSplit[0]] = tempSplit[1];
  228.                 });
  229.                 location = locationTemp;
  230.  
  231.                 location["przystanek"] = this.get('slug');
  232.                 mapa.zmienUrl(location);
  233.                 mapa.setMarkerActive(marker);
  234.                 mapa.pokazRozkladNaPrzystankuPoIdRozkladu(this.get('idRozkladu'));
  235.  
  236.                 mapa.aktywujElementSidebar();
  237.                 var sidebar = document.getElementById("mainSidebarList").querySelectorAll('ul li');
  238.                 for (let i = 0; i < sidebar.length; i++) {
  239.                     if (sidebar[i].innerText == marker.title) {
  240.                         sidebar[i].classList.add("active");
  241.                         break;
  242.                     }
  243.                 }
  244.             });
  245.  
  246.         });
  247.  
  248.         //rysowanie trasy start
  249.         var points = mapa.getPoints(mapa.markerActive.idRozkladu);
  250.         if (points == false) {
  251.             var polyLines = [];
  252.             $.each(tablicaDrogi, function (k, val) {
  253.                 var line = {lat: parseFloat(val[0]), lng: parseFloat(val[1])};
  254.                 polyLines.push(line);
  255.             });
  256.         } else {
  257.             var polyLines = JSON.parse(points.punkty);
  258.         }
  259.  
  260.         var partsPolyLines = mapa.createPartsLine(polyLines);
  261.         for (let i = 0; i < partsPolyLines.length; i++) {
  262.             mapa.drawingRoutesLine(mapa.map, partsPolyLines[i]);
  263.         }
  264.     },
  265.  
  266.     otherRoute: function(){
  267.         mapa.clearOverlays();
  268.         var otherRoute = $('#trasa').val();
  269.         var points = mapa.getPoints(mapa.markerActive.idRozkladu, otherRoute);
  270.         var polyLines = JSON.parse(points.punkty);
  271.         var partsPolyLines = mapa.createPartsLine(polyLines);
  272.         for (let i = 0; i < partsPolyLines.length; i++) {
  273.             mapa.drawingRoutesLine(mapa.map, partsPolyLines[i]);
  274.         }
  275.     },
  276.  
  277.     // ustawianie pojedynczego przystanku na mapie i zwrocenie jego rozkladu
  278.     wyswietlPrzstanekZRozkladem: function (markerWsp, rozkladHTML) {
  279.         mapa.clearOverlays();
  280.         mapa.wstawNowyRozklad(rozkladHTML);
  281.         mapa.wyswietlWszystkiePrzystanki();
  282.  
  283.         var toActive = mapa.markersArray[markerWsp[2] - 1];
  284.         mapa.setMarkerActive(toActive);
  285.     },
  286.  
  287.     //Pobieranie trasy przejazdu autobusu
  288.     pokazTrasnePrzejazduZPrzystankami: function (linia, kierunek) {
  289.         if (linia !== "" && kierunek !== "") {
  290.             $.ajax({
  291.                 method: "GET",
  292.                 url: $('#urlLiniaTrasa').val(),
  293.                 data: {
  294.                     'linia': linia,
  295.                     'kierunek': kierunek,
  296.                     'mRozklad': $('#mRozklad :selected').val(),
  297.                 },
  298.                 success: function (json) {
  299.                     if (json.length == 1) {
  300.                         mapa.wyswietlTrasePrzejazduZPrzystankami(json[0], json[0]);
  301.                     } else {
  302.                         mapa.wyswietlTrasePrzejazduZPrzystankami(json[0], json[1]);
  303.                     }
  304.                     mapa.zmienUrl({'linia': linia, 'kierunek': kierunek});
  305.                 },
  306.                 error: function (data) {
  307.                     mapa.Status404Code(data);
  308.                 }
  309.             });
  310.         }
  311.     },
  312.  
  313.     // pobieranie wszystkich przystankow/ w wypadku gdy wyszukiwarka jest pusta
  314.     pokazWszystkiePrzystanki: function () {
  315.         $.ajax({
  316.             method: "get",
  317.             url: $("#urlAxPobierzWszyskiePrzystanki").val(),
  318.             data: {
  319.                 mRozklad: $('#mRozklad :selected').val()
  320.             },
  321.             success: function (data) {
  322.                 mapa.allBusStop = data;
  323.                 mapa.wyswietlWszystkiePrzystanki();
  324.                 mapa.isready = true;
  325.                 return true;
  326.             },
  327.             error: function (data) {
  328.                 mapa.Status404Code(data);
  329.             }, complete: function () {
  330.                 wyszukiwarkaMap.init();
  331.             }
  332.         });
  333.     },
  334.  
  335.     getPoints: function (id, otherRoute = null) {
  336.         var points;
  337.         var otherRoute = (otherRoute != null) ? otherRoute : null;
  338.         console.log($("#AxRozkladKierunekTrasa").val() + '?id=' + id + '&o=' + otherRoute);
  339.  
  340.         $.ajax({
  341.             method: "get",
  342.             async: false,
  343.             url: ($("#AxRozkladKierunekTrasa").val() + '?id=' + id + '&o=' + otherRoute),
  344.             success: function (data) {
  345.                 points = data.result;
  346.             },
  347.             error: function () {
  348.                 alert('Błąd');
  349.             }
  350.         });
  351.  
  352.         return points;
  353.     },
  354.  
  355.     // wyswietla rozklad na przystanku
  356.     pokazPrzystanekZRozkladem: function (id) {
  357.         $.ajax({
  358.             method: "GET",
  359.             url: $("#urlAxPobierzRozkladPrzystnku").val(),
  360.             data: {
  361.                 przystanek: id,
  362.                 mRozklad: $('#mRozklad :selected').val(),
  363.             },
  364.             success: function (html) {
  365.                 mapa.zmienUrl(html[1]);
  366.  
  367.                 if (html[3] != null) {
  368.                     mapa.wyswietlPrzstanekZRozkladem(html[2], html[0]);
  369.                     mapa.openInfoWindow(html[3]);
  370.                 } else {
  371.                     mapa.wstawNowyRozklad(html[0]);
  372.                     mapa.locations = html[2];
  373.                     mapa.wyswietlPrzystankiZLocation(true);
  374.                 }
  375.             },
  376.             error: function (data) {
  377.                 mapa.Status404Code(data);
  378.             }
  379.         });
  380.     },
  381.  
  382.     pokazPrzystanekZRozklademZAktualnaMapa: function (id) {
  383.         //po kliknieciu w marker przystanku
  384.         $.ajax({
  385.             method: "GET",
  386.             url: $("#urlAxPobierzRozkladPrzystnku").val(),
  387.             data: {
  388.                 przystanek: id,
  389.                 mRozklad: $('#mRozklad :selected').val()
  390.                 //nad chodzacy:$('#nad chodzacyRozklad').is(':selected'),
  391.             },
  392.             success: function (html) {
  393.                 mapa.wstawNowyRozklad(html[0]);
  394.                 mapa.zmienUrl(html[1]);
  395.                 mapa.openInfoWindow(html[3]);
  396.             },
  397.             error: function (data) {
  398.                 mapa.Status404Code(data);
  399.             }
  400.         });
  401.     },
  402.  
  403.     pokazRozkladNaPrzystankuPoIdRozkladu: function (idRozkladu) {
  404.         $.ajax({
  405.             method: "GET",
  406.             url: $("#urlPobierzRozkladPrzystankuDlaLiniPoIdRozkladu").val(),
  407.             data: {
  408.                 idRozkladu: idRozkladu,
  409.                 mRozklad: $('#mRozklad :selected').val(),
  410.             },
  411.             success: function (data) {
  412.                 // mapa.zmienUrl(data[2]);
  413.                 if (mapa.markersArray.length <= 1) {
  414.                     mapa.wyswietlPrzstanekZRozkladem(data[1], data[0]);
  415.                 } else {
  416.                     mapa.wstawNowyRozklad(data[0]);
  417.                 }
  418.                 mapa.openInfoWindow(data[3]);
  419.  
  420.             },
  421.             error: function (data) {
  422.                 mapa.Status404Code(data);
  423.             }
  424.         });
  425.     },
  426.     // przy wyszukani lini na przystanku wyswietla dla niej rozklad oraz marker na mapie
  427.  
  428.     pokazPrzystanekZRozklademDlaLini: function (przystanek, linia, kierunek) {
  429.         kierunek = kierunek || null;
  430.         $.ajax({
  431.             method: "GET",
  432.             url: $("#urlAxRozkladPrzystanekLiniaAction").val(),
  433.             data: {
  434.                 przystanek: przystanek,
  435.                 linia: linia,
  436.                 kierunek: kierunek,
  437.                 mRozklad: $('#mRozklad :selected').val(),
  438.             },
  439.             success: function (data) {
  440.                 mapa.wstawNowyRozklad(data[0]);
  441.                 mapa.zmienUrl(data[1]);
  442.                 mapa.usunSidebar();
  443.                 // w przypadku kiedy uzytkownik nie wybierze opcji (Pokaz rozklad na przystanku) z autocomplete i wyszuka po fragmencie wpisanego slowa
  444.                 // wyswietlamy przystanki
  445.                 if (data[3] == null) {
  446.                     mapa.locations = data[2];
  447.                     mapa.wyswietlPrzystankiZLocation(true);
  448.                 } else {
  449.                     mapa.wstawSideBar(data[4]);
  450.                     var tab = data[2];
  451.                     if (tab.length == 1) {
  452.                         mapa.wyswietlTrasePrzejazduZPrzystankami(tab[0], tab[0], data[3]);
  453.                     } else {
  454.                         mapa.wyswietlTrasePrzejazduZPrzystankami(tab[0], tab[1], data[3]);
  455.                     }
  456.                 }
  457.             },
  458.             error: function (data) {
  459.                 mapa.Status404Code(data);
  460.             }
  461.         });
  462.     },
  463.  
  464.     pokazTrasePrzejazduPoIdKieruneku: function (kierunek) {
  465.         kierunek = kierunek || null;
  466.         $.ajax({
  467.             method: "GET",
  468.             url: $("#urlAxRozkladPrzystanekLiniaAction").val(),
  469.             data: {
  470.                 przystanek: przystanek,
  471.                 linia: linia,
  472.                 kierunek: kierunek,
  473.                 mRozklad: $('#mRozklad :selected').val(),
  474.             },
  475.             success: function (data) {
  476.                 mapa.wstawNowyRozklad(data[0]);
  477.                 mapa.zmienUrl(data[1]);
  478.                 mapa.usunSidebar();
  479.                 // w przypadku kiedy uzytkownik nie wybierze opcji (Pokaz rozklad na przystanku) z autocomplete i wyszuka po fragmencie wpisanego slowa
  480.                 // wyswietlamy przystanki
  481.                 if (data[3] == null) {
  482.                     mapa.locations = data[2];
  483.                     mapa.wyswietlPrzystankiZLocation(true);
  484.                 } else {
  485.                     mapa.wstawSideBar(data[4]);
  486.                     var tab = data[2];
  487.                     if (tab.length == 1) {
  488.                         mapa.wyswietlTrasePrzejazduZPrzystankami(tab[0], tab[0], data[3]);
  489.                     } else {
  490.                         mapa.wyswietlTrasePrzejazduZPrzystankami(tab[0], tab[1], data[3]);
  491.                     }
  492.                 }
  493.             },
  494.             error: function (data) {
  495.                 mapa.Status404Code(data);
  496.             }
  497.         });
  498.     },
  499.     // wyswietla kierunki lini w postaci listy/ mapa pozostaje pusta
  500.     pokazLinieZTrasami: function (linia) {
  501.         $.ajax({
  502.             method: "GET",
  503.             url: $("#urlAxRozkladLiniaAction").val(),
  504.             data: {
  505.                 linia: linia,
  506.                 // mRozklad zmienione ze zmiennej nad chodzacy
  507.                 mRozklad: $('#mRozklad :selected').val()
  508.             },
  509.             success: function (html) {
  510.                 mapa.wstawNowyRozklad(html[0]);
  511.                 mapa.zmienUrl(html[1]);
  512.             },
  513.             error: function (data) {
  514.                 mapa.Status404Code(data);
  515.             },
  516.             complete: function () {
  517.                 mapa.usunSidebar();
  518.             }
  519.         });
  520.     },
  521.  
  522.     // po wyszukaniu samej ulicy wyswietla liste przystankow na niej i dodaje pinzeki na mapie
  523.     pokazPrzystankiNaUlicy: function (ulica) {
  524.         $.ajax({
  525.             method: "GET",
  526.             url: $("#urlAxUlicaAction").val(),
  527.             data: {
  528.                 ulica: ulica,
  529.                 mRozklad: $('#mRozklad :selected').val(),
  530.             },
  531.             success: function (html) {
  532.                 mapa.wstawNowyRozklad(html[0]);
  533.                 mapa.zmienUrl(html[1]);
  534.                 mapa.locations = html[2];
  535.                 mapa.wyswietlPrzystankiZLocation(true);
  536.                 mapa.wysrodkujPinezkiZLocation();
  537.  
  538.             },
  539.             error: function (data) {
  540.                 mapa.Status404Code(data);
  541.             },
  542.             complete: function () {
  543.                 mapa.usunSidebar();
  544.  
  545.             }
  546.         });
  547.  
  548.     },
  549.  
  550.     wstawNowyRozklad: function (html) {
  551.         var elRozklad = document.getElementById("rozklady");
  552.         $(elRozklad).empty();
  553.         $(elRozklad).html(html);
  554.         rozklad.pobierzPierwszyIntervalDoPelnejMinuty();
  555.     },
  556.  
  557.     wstawSideBar: function (html) {
  558.         var elSidebar = document.getElementById("kierunekSidebarDiv");
  559.         $(elSidebar).empty();
  560.         $(elSidebar).html(html);
  561.         $(elSidebar).removeClass('hidden');
  562.         $(elSidebar).addClass('col-sm-3 col-md-2');
  563.         $('.mapa-box').removeClass('col-md-5');
  564.         $('.mapa-box').removeClass('col-md-7');
  565.         $('.mapa-box').addClass('col-md-5');
  566.     },
  567.     usunSidebar: function () {
  568.         var elSidebar = document.getElementById("kierunekSidebarDiv");
  569.         $(elSidebar).empty();
  570.         $(elSidebar).removeClass('col-sm-3 col-md-2');
  571.         $(elSidebar).addClass("hidden");
  572.         $('.mapa-box').removeClass('col-md-5');
  573.         $('.mapa-box').removeClass('col-md-7');
  574.         $('.mapa-box').addClass('col-md-7');
  575.     },
  576.     aktywujElementSidebar: function (marker) {
  577.         var lista = $('#mainSidebarList');
  578.         var elementToActive = $(lista).find("li[class=\"active\"]");
  579.         $.each(elementToActive, function (k, val) {
  580.             $(val).removeClass("active");
  581.         });
  582.         elementToActive = $(lista).find("ul[class=\"active\"]");
  583.         $.each(elementToActive, function (k, val) {
  584.             $(val).removeClass("active");
  585.         });
  586.         if (marker != null) {
  587.             marker = $(marker).parent();
  588.             $(marker).addClass("active");
  589.             $(marker).parent().addClass("active");
  590.         }
  591.     },
  592.  
  593.     zmienUrl: function (dane) {
  594.         state = jQuery.param(dane);
  595.         window.history.pushState(state, window.title, window.location.href.split('?')[0] + '?' + state);
  596.     },
  597.  
  598.     Status404Code: function (data) {
  599.         if (data.status == 404) {
  600.             mapa.wstawNowyRozklad(data.responseJSON);
  601.         }
  602.     },
  603.  
  604.     openInfoWindow: function (content) {
  605.         if (mapa.infowindow != null) {
  606.             mapa.infowindow.close();
  607.         }
  608.         mapa.infowindow = new google.maps.InfoWindow({
  609.             content: content,
  610.             padding: 0,
  611.             borderRadius: 0,
  612.         });
  613.         mapa.infowindow.open(mapa.map, mapa.markerActive);
  614.     },
  615.  
  616.     //google ma limity w way pointach dlatego trase dzielimy na czesci
  617.     createPartsLine: function (line) {
  618.         const googleWayPointsLimit = 26;
  619.         let partsLineNumber = Math.floor(line.length / googleWayPointsLimit);
  620.         let partsLineNumberRest = line.length % googleWayPointsLimit;
  621.         let i = 0;
  622.         let lineParts = [];
  623.  
  624.         //pierwsza czesc normalnie od 1 do 26
  625.         lineParts.push(line.slice(i * googleWayPointsLimit, i * googleWayPointsLimit + googleWayPointsLimit));
  626.         i++;
  627.         if (line.length > googleWayPointsLimit) {
  628.             //kolejne czesci musza miec ostatni poprzedni punkt zeby sciezka byla polaczona
  629.             for (null; i < partsLineNumber; i++) {
  630.                 lineParts.push(line.slice(i * googleWayPointsLimit - 1, i * googleWayPointsLimit + googleWayPointsLimit));
  631.             }
  632.             //tutaj dodajemy reszte z dzielenia waypointow
  633.             if (partsLineNumberRest > 0) {
  634.                 lineParts.push(line.slice(i * googleWayPointsLimit - 1, i * googleWayPointsLimit + partsLineNumberRest));
  635.             }
  636.         }
  637.  
  638.         return lineParts;
  639.     },
  640.  
  641.     //rysowanie wszystkich czesci
  642.     drawingRoutesLine: function (map, partLine) {
  643.         directionsService = new google.maps.DirectionsService;
  644.         mapa.directionsDisplay[mapa.directionsDisplay.length] = new google.maps.DirectionsRenderer;
  645.         (mapa.directionsDisplay[mapa.directionsDisplay.length - 1]).setMap(map);
  646.         mapa.drawingPartLine(directionsService, mapa.directionsDisplay[mapa.directionsDisplay.length - 1], partLine);
  647.     },
  648.  
  649.     //rysowanie trasy lini
  650.     drawingPartLine: function (directionsService, directionsDisplay, line) {
  651.         if (line.length > 0) {
  652.             let waypoints = [];
  653.             for (let i = 0; i < line.length; i++) {
  654.                 waypoints.push({
  655.                     location: line[i],
  656.                     stopover: true
  657.                 });
  658.             }
  659.  
  660.             let start = waypoints[0].location;
  661.             let end = waypoints[waypoints.length - 1].location;
  662.             waypoints.shift();
  663.             waypoints.pop();
  664.  
  665.             directionsService.route({
  666.                 origin: start,
  667.                 destination: end,
  668.                 travelMode: 'DRIVING',
  669.                 waypoints: waypoints,
  670.                 optimizeWaypoints: true,
  671.             }, function (response, status) {
  672.                 if (status === 'OK') {
  673.                     directionsDisplay.setDirections(response);
  674.                 }
  675.             });
  676.         } else {
  677.             console.log('Brak punktów.');
  678.         }
  679.     }
  680. };
  681.  
  682. $(document).ready(function () {
  683.     var uluru = {lat: 51.247867, lng: 22.558816};
  684.     try {
  685.         mapa.map = new google.maps.Map(document.getElementById('map'), {
  686.             center: uluru,
  687.             zoom: 12,
  688.             options: mapa.optionsMap,
  689.         });
  690.     } catch (e) {
  691.         window.location.reload();
  692.     }
  693.  
  694.     mapa.init();
  695. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement