Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <!DOCTYPE html>
  3.  
  4. <html>
  5. <head>
  6.     <meta charset="utf-8" />
  7.     <meta name="format-detection" content="telephone=no" />
  8.     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
  9.     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
  10.     <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  11.     <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
  12.     <script src="gmap/gmap3.js"></script>
  13.     <script src="http://maps.google.com/maps/api/js?sensor=false&language=pl"></script>
  14.     <script src="gmap3/gmap3.min.js"></script>
  15.     <title>Hello World</title>
  16.     <script>
  17.         var kolory = "#000000";
  18.         var tab = []; // tablica z lokalizacjami
  19.  
  20.        
  21.         $(document).on("pageinit", function () {
  22.             var x, y, z;
  23.             y = 0;
  24.             x = 0;
  25.             z = 5;
  26.             var idmark = 1;
  27.             var licz = 0;
  28.             $("#mark").on("click", ".centr", function () {
  29.                 var index = $(this).parents('li').index();
  30.                 $('#mapDiv').gmap3({
  31.                     map: {
  32.                         options: {
  33.                             center: [tab[index].szer, tab[index].dl],
  34.                             zoom: tab[index].prz,
  35.                             disableDefaultUI: true
  36.                         },
  37.                     },
  38.                     marker: {
  39.                         latLng: [tab[index].lat, tab[index].lng],
  40.                         id: [tab[index].id]
  41.                     }
  42.                 });
  43.  
  44.             });
  45.  
  46.             $("#popupek").on("click", ".kol", function () {
  47.                 var index = $(this).index();
  48.                // alert(index);
  49.                 index = parseInt(index);
  50.                 if (index == 0)
  51.                     kolory = "#FF0000";
  52.                 else if (index == 1)
  53.                     kolory = "#000000";
  54.                 else if (index == 2)
  55.                     kolory = "#0000FF";
  56.                 else if (index == 3)
  57.                     kolory = "#FF7F50";
  58.                 else if (index == 4)
  59.                     kolory = "#006400";
  60.                 else if (index == 5)
  61.                     kolory = "#228B22";
  62.                 else if (index == 6)
  63.                     kolory = "#FFFFF0";
  64.                 else if (index == 7)
  65.                     kolory = "#BA55D3";
  66.                 else if (index == 8)
  67.                     kolory = "#FF4500";
  68.             });
  69.  
  70.             $("#zapisz").click(function () {
  71.                 localStorage.setItem("markery", JSON.stringify(tab));
  72.             });
  73.             $("#wczytaj").click(function () {
  74.                 if (localStorage.getItem("markery") != null && localStorage.getItem("markery") != undefined) {
  75.                     tab = JSON.parse(localStorage.getItem("markery"));
  76.                     for (var i = 0; i < tab.length; i++) {
  77.                         $("#mark").append("<li><a class='centr'>Marker " + idmark + "</a><a class='del' data-icon='delete' id='" + tab[i].id + "'></a></li>");
  78.                         $("#mapDiv").gmap3({
  79.                             marker: {
  80.                                 options: {
  81.                                     draggable: false,
  82.                                 },
  83.                                 id: tab[i].id,
  84.                                 latLng: [tab[i].szer, tab[i].dl],
  85.                                 zoom: tab[i].prz
  86.                             }
  87.                         });
  88.                         idmark++;
  89.                     }
  90.                     $("#mark").listview('refresh');
  91.  
  92.                 }
  93.             });
  94.             function zmiana() {
  95.  
  96.                 x = $("#input1").val();
  97.                 y = $("#input2").val();
  98.                 z = $("#input3").val();
  99.                 $("#mapDiv").gmap3({
  100.                     map: {
  101.                         options: {
  102.                             center: [parseInt(x), parseInt(y)],
  103.                             zoom: parseInt(z)
  104.  
  105.  
  106.                         }
  107.                     }
  108.                 })
  109.             }
  110.  
  111.             $(".inp").change(function () { zmiana() });
  112.             $("#mapDiv").width("100%");
  113.             $("#mapDiv").height("500px");
  114.             $("#mapDiv").gmap3();
  115.  
  116.             $("#mapDiv").gmap3({
  117.                 map: {
  118.                     options: {
  119.                         center: [x, y],
  120.                         zoom: 5,
  121.                         disableDefaultUI: true
  122.  
  123.                     },
  124.                     events: {
  125.                         click: function (map, event) {
  126.                             var x = event.latLng.lat();
  127.                             var y = event.latLng.lng();
  128.                             var z = map.getZoom();
  129.  
  130.                             $("#mark").append("<li><a class='centr'>Marker " + idmark + "</a><a class='del' data-icon='delete' id='mark" + idmark + "'></a></li>");
  131.                             $("#mark").listview('refresh');
  132.                             $("#mapDiv").gmap3({
  133.                                 marker: {
  134.                                     options: {
  135.                                         draggable: false,
  136.                                     },
  137.                                     id: "mark" + idmark,
  138.                                     latLng: [x, y],
  139.                                     zoom: parseInt(z)
  140.                                 }
  141.  
  142.                             });
  143.                             idmark += 1;
  144.  
  145.                             tab.push({ szer: x, dl: y, prz: z, id: "mark" + idmark });     // dodanie pierwszego obiektu na początek tablicy
  146.                             // alert(tab[licz].szer);
  147.                             licz += 1;
  148.  
  149.                         }
  150.                     }
  151.                 }
  152.             });
  153.  
  154.             /*   $("#mapDiv").gmap3({
  155.                    map: {
  156.  
  157.                        events: {
  158.                            click: function (map, event) {
  159.                                console.log(event.latLng.lat());
  160.                                console.log(event.latLng.lng());
  161.                                console.log(map.getZoom());
  162.                                console.log(map.getCenter());
  163.                                 $("#input1").change(functio
  164.                                  $("#input2").change(functio
  165.                            }
  166.                        }
  167.                    }
  168.                })*/
  169.  
  170.             $("#mark").on("click", ".del", function () {
  171.                 var markers = $("#mapDiv").gmap3({
  172.                     get: {
  173.                         name: 'marker',
  174.                         all: true
  175.                     }
  176.                 });
  177.  
  178.                 var w = $(this).prop("id");
  179.                 var index = $(this).parents('li').index();
  180.                 tab.splice(index, 1);
  181.                 $("#mapDiv").gmap3({
  182.                     clear: {
  183.                         id: w
  184.                     }
  185.                 });
  186.                 $(this).parent().remove();
  187.  
  188.             });
  189.  
  190.             $("#rysujtrase").click(function () {
  191.                 var markerArray = [];
  192.                 //pobranie wszystkich markerow z mapy
  193.                 var markers = $("#mapDiv").gmap3({
  194.                     get: {
  195.                         name: 'marker',
  196.                         all: true
  197.                     }
  198.                 });
  199.  
  200.                 //dla kazdego markera do tablicy wrzucasz jego pozycje latLng
  201.                 for (var i = 0; i < markers.length; i++) {
  202.                     markerArray.push(markers[i].getPosition());
  203.                 }
  204.                 $("#mapDiv").gmap3({
  205.                     polyline: {
  206.                         options: {
  207.                             strokeColor: kolory,
  208.                             strokeOpacity: 0.8,
  209.                             strokeWeight: 2,
  210.                             path: markerArray
  211.                         }
  212.                     }
  213.                 })
  214.             });
  215.             ////////////////////////////////////////////////////////////////////
  216.  
  217.             $("#wyslij").click(function () {
  218.                 // loader
  219.                 imie = prompt("Podaj imie:");
  220.                 ostatnia_data = new Date().toLocaleTimeString()
  221.  
  222.                 $.mobile.showPageLoadingMsg();
  223.  
  224.                 //upraszczam to co wysylam
  225.                 var sendTab = [];
  226.                 sendTab.push(imie);
  227.                 sendTab.push(ostatnia_data);
  228.                 sendTab.push(kolory);
  229.                 for (var i = 0; i < tab.length; i++) {
  230.                     sendTab.push([tab[i].szer, tab[i].dl, tab[i].prz]);
  231.                 }
  232.                 //alert(JSON.stringify(sendTab));
  233.                 var sendObj = {
  234.                     trasa: JSON.stringify(sendTab)
  235.                 }
  236.                 //jak wysylamy - AJAX
  237.                 $.ajax({
  238.                     type: "POST",
  239.                     url: "ZapisPliku.aspx",
  240.                     data: sendObj,
  241.                     dataType: "text",
  242.                     success: function (response) {
  243.                         $.mobile.hidePageLoadingMsg();
  244.                         alert(response);
  245.                     },
  246.                     error: function (xhr) {
  247.                         alert(xhr.responseText);
  248.                     }
  249.                 })
  250.             });
  251.  
  252.  
  253.  
  254.  
  255.             ////////////////////////////////////////////////////////////////////
  256.  
  257.  
  258.             $("#pobierz").click(function () {
  259.                 $.ajax({
  260.                     type: "POST",
  261.                     url: "ReadTrips.aspx",
  262.                     dataType: "text",
  263.                     success: onSuccess,
  264.                     error: function (xhr) {
  265.                         alert(xhr.responseText);
  266.                     }
  267.                 });
  268.                 function onSuccess(response) {
  269.  
  270.                     //czytam wszystko z serwera
  271.                     alert(response)
  272.                   //  var allTripsOnServer = JSON.parse(response);
  273.                    // alert(allTripsOnServer.length)
  274.  
  275.                     //jedna wycieczka - numer 0 w pliku txt
  276.  
  277.                     //var firstTrip = allTripsOnServer[0];
  278.                     // usuwam z tablicy imie, kolor i datę aby czytac tylko dane geolokacyjne wycieczki
  279.                     // uwaga  - ta metoda modyfikuje tablicę!
  280.                    // firstTrip.splice(0, 3);
  281.  
  282.                     //rysuję pierwsza wycieczkę:
  283.  
  284.                   /*  $("#mapa").gmap3({
  285.                         marker: {
  286.                             values: firstTrip
  287.                         },
  288.                         polyline: {
  289.                             options: {
  290.                                 strokeColor: "#ff0000",
  291.                                 strokeOpacity: 0.5,
  292.                                 strokeWeight: 4,
  293.                                 path: firstTrip
  294.                             }
  295.                         },
  296.                         autofit: {} // focus na wycieczkę - przybliżenie
  297.  
  298.                     })*/
  299.  
  300.                 }
  301.  
  302.             });
  303.  
  304.  
  305.  
  306.  
  307.             ///////////////////////////////////////////////////////////////////////
  308.         });
  309.  
  310.  
  311.  
  312.  
  313.     </script>
  314.     <style>
  315.         #h1 {
  316.             text-align: center;
  317.             margin: 0 auto;
  318.             float: left;
  319.         }
  320.  
  321.         .ui-content {
  322.             padding: 0px;
  323.         }
  324.  
  325.         #popupek {
  326.             width: 290px;
  327.             height: 300px;
  328.             margin: 0auto;
  329.         }
  330.  
  331.         #kol2 {
  332.             width: 50px;
  333.             height: 50px;
  334.             background: black;
  335.             margin: 20px;
  336.             float: left;
  337.         }
  338.  
  339.         #kol1 {
  340.             width: 50px;
  341.             height: 50px;
  342.             background: red;
  343.             margin: 20px;
  344.             float: left;
  345.         }
  346.  
  347.         #kol3 {
  348.             width: 50px;
  349.             height: 50px;
  350.             background: blue;
  351.             margin: 20px;
  352.             float: left;
  353.         }
  354.  
  355.         #kol4 {
  356.             width: 50px;
  357.             height: 50px;
  358.             background: #FF7F50;
  359.             margin: 20px;
  360.             float: left;
  361.         }
  362.  
  363.         #kol5 {
  364.             width: 50px;
  365.             height: 50px;
  366.             background: #006400;
  367.             margin: 20px;
  368.             float: left;
  369.         }
  370.  
  371.         #kol6 {
  372.             width: 50px;
  373.             height: 50px;
  374.             background: #228B22;
  375.             margin: 20px;
  376.             float: left;
  377.         }
  378.  
  379.         #kol7 {
  380.             width: 50px;
  381.             height: 50px;
  382.             background: #FFFFF0;
  383.             margin: 20px;
  384.             float: left;
  385.         }
  386.  
  387.         #kol8 {
  388.             width: 50px;
  389.             height: 50px;
  390.             background: #BA55D3;
  391.             margin: 20px;
  392.             float: left;
  393.         }
  394.  
  395.         #kol9 {
  396.             width: 50px;
  397.             height: 50px;
  398.             background: #FF4500;
  399.             margin: 20px;
  400.             float: left;
  401.         }
  402.         #startowa img {
  403.             width:100%;
  404.             margin:0auto;
  405.         }
  406.     </style>
  407. </head>
  408. <body>
  409.     <div id="calosc" data-role="page">
  410.         <div data-role="header">
  411.             <h1>mapa GOOGLE</h1>
  412.             <a href="#mypanel"><img src="lista.png" id="lista" /></a>
  413.             <a href="#popupek" data-rel="popup"><img src="lista.png" /></a>
  414.         </div>
  415.         <div data-role="content">
  416.             <div id="mapDiv">
  417.             </div>
  418.  
  419.  
  420.         </div>
  421.         <div data-role="panel" id="mypanel">
  422.             <ul data-role="listview" id="mark"></ul>
  423.             <br />
  424.             <input type="range" id="input1" class="inp" value="0" min="-90" max="90" step="1" />
  425.             <input type="range" id="input2" class="inp" value="0" min="-180" max="180" step="1" />
  426.             <input type="range" id="input3" class="inp" value="5" min="1" max="15" step="1" />
  427.             <button id="rysujtrase">Rysuj Trasę</button>
  428.             <button id="zapisz">Zapamiętaj dane</button>
  429.             <button id="wczytaj">Wczytaj dane</button>
  430.             <button id="wyslij">Wyślij na serwer</button>
  431.             <button id="pobierz">Wczytaj z serwera</button>
  432.         </div>
  433.         <div id="popupek" data-role="popup">
  434.             <div id="kol1" class="kol"></div>
  435.             <div id="kol2" class="kol"></div>
  436.             <div id="kol3" class="kol"></div>
  437.             <div id="kol4" class="kol"></div>
  438.             <div id="kol5" class="kol"></div>
  439.             <div id="kol6" class="kol"></div>
  440.             <div id="kol7" class="kol"></div>
  441.             <div id="kol8" class="kol"></div>
  442.             <div id="kol9" class="kol"></div>
  443.         </div>
  444.     </div>
  445.     <div id="startowa" data-role="page">
  446.         <img src="sitemap.png" />
  447.         <input type="text" value="Wpisz imie" />
  448.         <button id="startbt">Wyslij</button>
  449.     </div>
  450.  
  451.  
  452.  
  453.  
  454.     <script type="text/javascript" src="cordova.js"></script>
  455. </body>
  456. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement