maps.js 26.8 KB
Newer Older
1
var map = L.map('map', { editable: true, zoomControl: false, drawControl: true }).setView([-4.117012285203445, 104.0673065185547], 10);
Manggar Mahardhika's avatar
Manggar Mahardhika committed
2 3 4

var pool = [];

5
var BaseMap = document.getElementById("BaseMap");
Manggar Mahardhika's avatar
Manggar Mahardhika committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
var OpenStreetMap = document.getElementById("OpenStreetMap");
var WorldImagery = document.getElementById("WorldImagery");
var BingSatellite = document.getElementById("BingSatellite");
var GoogleSatellite = document.getElementById("GoogleSatellite");

var BING_KEY = 'Anj9XBZaRShAMdbXJlZ16iqEVpjikY1eY_dzqGl451WYkSKV3l_FJaFgMbhwdbLz'

loaderPage(false);

function loaderPage(stat) {
    if (stat == true) {
        $('.page_loader').show();
    } else {
        $('.page_loader').hide();
    }
};

$("#sidebar").hide()
24
    //https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off
Manggar Mahardhika's avatar
Manggar Mahardhika committed
25 26 27 28 29 30 31

// maps = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', { id: 'mapbox/light-v9', tileSize: 512, zoomOffset: -1 }).addTo(map);
maps = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
    maxZoom: 22,
    minZoom: 3,
    // tileSize: 512, zoomOffset: -1 
}).addTo(map);
Manggar Mahardhika's avatar
Manggar Mahardhika committed
32

Manggar Mahardhika's avatar
Manggar Mahardhika committed
33 34 35 36 37 38 39 40 41 42 43
// BaseMap.onclick = function() {
//     map.removeLayer(maps)
//         //maps = L.tileLayer("https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off", {
//     maps = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw',{ 
//         id: 'mapbox/light-v9', 
//         tileSize: 512, 
//         zoomOffset: -1 
//     }).addTo(map);

// };

Manggar Mahardhika's avatar
Manggar Mahardhika committed
44
OpenStreetMap.onclick = function() {
45
    map.removeLayer(maps)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
46 47 48 49
    // maps = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', { 
    //     id: 'mapbox/light-v9', 
    //     tileSize: 512, zoomOffset: -1 
    // }).addTo(map);
50 51
        //maps = L.tileLayer("https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off", {
    maps = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
52 53 54
        maxZoom: 22,
        minZoom: 3,
    }).addTo(map);
55

Manggar Mahardhika's avatar
Manggar Mahardhika committed
56 57 58
};

WorldImagery.onclick = function() {
59 60
    map.removeLayer(maps)
        // https://{s}.tiles.wmflabs.org/osm-no-labels/{z}/{x}/{y}.png
Manggar Mahardhika's avatar
Manggar Mahardhika committed
61 62 63 64 65 66 67
    // maps = L.tileLayer("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", {
    //     maxZoom: 22,
    //     minZoom: 3,
    // }).addTo(map);
    maps = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', { 
        id: 'mapbox/light-v9', 
        tileSize: 512, zoomOffset: -1 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
68 69 70 71
    }).addTo(map);
};

BingSatellite.onclick = function() {
72
    map.removeLayer(maps)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
73
    maps = L.tileLayer.bing({ bingMapsKey: BING_KEY, maxNativeZoom: 22 }).addTo(map);
Muhamad's avatar
Muhamad committed
74 75 76 77
    setTimeout(function() {
        $('.leaflet-bottom.leaflet-right>.leaflet-control-attribution.leaflet-control').html(`Powered by <a href="https://khansia.co.id" target="_blank">Khansia</a> with <a href="https://leafletjs.com" target="_blank">Leaflet</a>`)
    }, 100);

Manggar Mahardhika's avatar
Manggar Mahardhika committed
78 79 80 81
};

GoogleSatellite.onclick = function() {

82
    map.removeLayer(maps)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
83
    maps = L.tileLayer('http://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off', {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
84 85 86 87 88 89 90 91 92 93 94 95 96
        maxZoom: 22,
        minZoom: 4,
    }).addTo(map);
};

$('#createPolygonTools').click(function() {
    polygonDrawer.enable();
});

var Marker = {};
var Poly = {};

var request = new XMLHttpRequest();
Manggar Mahardhika's avatar
Manggar Mahardhika committed
97
request.open("GET", "../static/batas.json", false);
Manggar Mahardhika's avatar
Manggar Mahardhika committed
98
request.send(null)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
99
var batas = JSON.parse(request.responseText);
100
// console.log(batas);
Manggar Mahardhika's avatar
Manggar Mahardhika committed
101

Manggar Mahardhika's avatar
Manggar Mahardhika committed
102
var geo_batas = L.geoJson(batas, {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
103 104
    style: function(feature) {
        return {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
105 106 107 108 109
            color: "#000000",
            weight: 1,
            opacity: 1,
            fillcolor: "#FFFFFF",
            fillOpacity: 0.1
Manggar Mahardhika's avatar
Manggar Mahardhika committed
110 111 112 113 114 115 116
        };
    },
    onEachFeature: function(feature, layer) {
        layer.on({
            mouseover: function(e) {
                var layer = e.target;
                layer.setStyle({
Manggar Mahardhika's avatar
Manggar Mahardhika committed
117
                    weight: 1,
Manggar Mahardhika's avatar
Manggar Mahardhika committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
                    Color: "#067800",
                    fillColor: "#067800",

                });
                if (!L.Browser.ie && !L.Browser.opera) {
                    layer.bringToFront();
                }

            },
            mouseout: function(e) {
                geo_batas.resetStyle(e.target);
            }

        });
    }
}).addTo(map);

map.on(L.Draw.Event.CREATED, function(e) {
    var layer = e.layer;

    $("#coordinateZone").empty();

    var type = e.layerType;
    var layer = e.layer;

    var shape = layer.toGeoJSON();
    let geoShape = shape.geometry.coordinates[0];

    let kordinat = "";
    for (j in geoShape) {

        kordinat += geoShape[j][0] + ' ' + geoShape[j][1];

        if (j <= (geoShape.length - 2)) {
            kordinat += ', ';
        }
    }

    window.thisBaseDrawPolygonLayer = layer;

    $("#coordinateZone").val(JSON.stringify(kordinat));
});

polygon_options = {
    showArea: false,
    shapeOptions: {
        stroke: true,
        color: '#6e83f0',
        weight: 4,
        opacity: 0.5,
        fill: true,
        fillColor: null, //same as color by default
        fillOpacity: 0.2,
        clickable: true
    }
}

var polygonDrawer = new L.Draw.Polygon(map, polygon_options);

polygonDrawer.on("click", function(event) {
    shapecoords.innerHTML = event.latlng.toString();
    map.fire("click", event); // Trigger a map click as well.

});

map.on('draw:created', function(e) {
    var type = e.layerType,
        layer = e.layer;

    // Do whatever you want with the layer.
    // e.type will be the type of layer that has been draw (polyline, marker, polygon, rectangle, circle)
    // E.g. add it to the map
    var lay = layer.addTo(map);
    Poly = lay;
    $("#PolygonModal").modal({
        backdrop: 'static',
        keyboard: false
    });
});

function cheakDFeas(e) {

    $('#latM').val();
    $('#lonM').val();

    $("#PointModal").modal();
    // Add marker to map at click location; add popup window
    var newMarker = new L.marker(e.latlng).addTo(map);
    Marker = newMarker;

    $('#latM').val(e.latlng.lat);
    $('#lonM').val(e.latlng.lng);

}

$('#createRadius').click(function() {
    map.on('click', cheakDFeas);
})

$("#closeP").click(function() {
    map.removeLayer(Poly);

});

$("#closeR").click(function() {
    map.removeLayer(Marker);
    map.off('click', cheakDFeas);
});

var results = L.layerGroup().addTo(map);

// listen for the results event and add every result to the map

$('#GetAddress').click(function() {
    $("#AddressModal").modal("show");
});

$("#id_provinsi ").change(function() {
    var prov_val = $(this).val();

    $.ajax({
        url: 'ajax/administrasi/',
        data: {
            'prov_val': prov_val
        },
        dataType: 'json',
        success: function(data) {
            var data_all_kab = []
            for (var i = 0; i < data['kab_res'].length; i++) {
                var data_k = data['kab_res'][i];
                var data_kab = `<option value="` +
                    data_k +
                    `">` +
                    data_k +
                    `</option>`;
                data_all_kab.push(data_kab)
            };
            $('#id_kab').html(`<option>Select Kabupaten</option>` + data_all_kab);

            $('#polypro').val(data['nama_pro']);

        }
    });
});

$("#id_kab").change(function() {
    var kab_val = $(this).val();
    var nama_pro = $('#polypro').val();
    loaderPage(true);

    $.ajax({
        url: 'ajax/kabupaten/',
        data: {
            'kab_val': kab_val,
            'prov_val': nama_pro
        },
        dataType: 'json',
        success: function(data) {
            loaderPage(false);
            var data_all_kab = []
            for (var i = 0; i < data['nama_kec'].length; i++) {
                var data_k = data['nama_kec'][i];
                var data_kab = `<option value="` +
                    data_k +
                    `">` +
                    data_k +
                    `</option>`;
                data_all_kab.push(data_kab)
            };
            $('#id_kec').html(`<option>Select Kecamatan</option>` + data_all_kab);

            $('#polykab').val(data['nama_kab']);
            $('#polypro').val(data['nama_pro']);

        }
    });
});

Muhamad's avatar
Muhamad committed
296 297
// var geocodeService = L.esri.Geocoding.geocodeService();
// var geocoderNominatim = new L.Control.Geocoder.Nominatim();
Manggar Mahardhika's avatar
Manggar Mahardhika committed
298

Muhamad's avatar
Muhamad committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
// var geo_build_gen = L.geoJson(null, {
//     style: function(feature) {
//         if (feature.properties.f4 == 'osm') {
//             return {
//                 color: "#00ff00",
//                 weight: 1,
//                 opacity: 2,
//                 zIndex: 1000
//             };

//         }
//         if (feature.properties.f4 == 'gen') {
//             return {
//                 color: "#ff0008",
//                 weight: 1,
//                 opacity: 2,
//                 zIndex: 1000
//             };
//         }
//         if (feature.properties.f4 == 'new') {
//             return {
//                 color: "#0400ed",
//                 weight: 1,
//                 opacity: 2,
//                 zIndex: 1000
//             };
//         }

//     },

//     onEachFeature: function(feature, layer) {
//         if (feature.properties) {

//             var lattitud, longitud;
//             if (feature.geometry.type == 'MultiPolygon') {
//                 lattitud = feature.geometry.coordinates[0][0][0][1];
//                 longitud = feature.geometry.coordinates[0][0][0][0];

//             } else {
//                 lattitud = feature.geometry.coordinates[0][0][1];
//                 longitud = feature.geometry.coordinates[0][0][0];
//             };

//             layer.on({
//                 click: function(e) {
//                     $('#id_poly').val(feature.properties.f1);
//                     $('#id_poly_delete').val(feature.properties.f1);
//                 }
//             });

//             $("#list-polygon tbody").append(`
//             <tr class="feature-row" id="` + L.stamp(layer) + `" lat="` + lattitud + `" lng="` + longitud + `">
//                 <td class="feature-name">
//                     ` + feature.properties.f2 + `
//                 </td>
//             </tr>`);
//             pool.push({
//                 name: feature.properties.f2,
//                 id: L.stamp(layer),
//                 lat: lattitud,
//                 lng: longitud
//             });

//         }
//         layer.on({
//             mouseover: function(e) {
//                 var layer = e.target;
//                 layer.setStyle({
//                     weight: 1,
//                     Color: "#067800",
//                     fillColor: "#067800",

//                 });
//                 if (!L.Browser.ie && !L.Browser.opera) {
//                     layer.bringToFront();
//                 }
//             },
//             mouseout: function(e) {
//                 geo_build_gen.resetStyle(e.target);
//             }
//         });
//         var content = `
//         <div class="tabbable">
//         <ul class="nav nav-tabs nav-tabs-bottom nav-justified">
//             <li class="active text-primary" id="feature-title"><a href="#left-tab1-feas-upl" data-toggle="tab" id="info">Information</a></li>
//             <li><a href="#right-tab2-feas-upl" data-toggle="tab" id="edit">Edit Buildings</a></li>
//         </ul>

//         <div class="tab-content">

//             <div class="tab-pane active" id="left-tab1-feas-upl" style="padding-bottom: 17px;">
//                 <div style="width: 350px; margin-left:10px;">
//                     <table>
//                         <tr>
//                             <th>Id</th>
//                             <td>:&nbsp` + feature.properties.f1 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Name</th>
//                             <td>:&nbsp` + feature.properties.f2 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Information</th>
//                             <td>:&nbsp` + feature.properties.f3 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Kelurahan</th>
//                             <td>:&nbsp` + feature.administrasi.f1 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Kecamatan</th>
//                             <td>:&nbsp` + feature.administrasi.f2 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Kab/Kota</th>
//                             <td>:&nbsp` + feature.administrasi.f3 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Provinsi</th>
//                             <td>:&nbsp` + feature.administrasi.f4 + `</td>
//                         </tr>

//                     </table>
//                 </div><br>
//                 <input id='delet-pol' class="btn btn-warning" type="submit" value="DELETE">

//             </div>
//             <div class="tab-pane" id="right-tab2-feas-upl" style="padding-bottom: 17px;">
//                 <div id="map-edit" style="width:500px;height: 250px;">
//                 </div><br>
//                 <input id='buttonsaveedit' class="btn btn-primary" type="submit" value="Save">
//             </div>
//             <input type="text" name="coordinateZoneedit" class="hidden" id="coordinateZoneedit" value="">
//             <input class="hidden" type="text" name='id-poly' id="id-poly" value="` + feature.properties.f1 + `">
//             <input class="hidden" type="text" name='sumber' id="sumber" value="gen">

//         </div>

//     </div>`;
//         layer.bindPopup(content);

//     }
// }).addTo(map);

// var geo_build_osm = L.geoJson(null, {
//     style: function(feature) {
//         if (feature.properties.f4 == 'osm') {
//             return {
//                 color: "#00ff00",
//                 weight: 1,
//                 opacity: 2,
//                 zIndex: 1000
//             };

//         }
//         if (feature.properties.f4 == 'gen') {
//             return {
//                 color: "#ff0008",
//                 weight: 1,
//                 opacity: 2,
//                 zIndex: 1000
//             };
//         }
//     },

//     onEachFeature: function(feature, layer) {
//         if (feature.properties) {
//             var lattitud, longitud;
//             if (feature.geometry.type == 'MultiPolygon') {
//                 lattitud = feature.geometry.coordinates[0][0][0][1];
//                 longitud = feature.geometry.coordinates[0][0][0][0];

//             } else {
//                 lattitud = feature.geometry.coordinates[0][0][1];
//                 longitud = feature.geometry.coordinates[0][0][0];
//             };

//             layer.on({
//                 click: function(e) {
//                     $('#id_poly').val(feature.properties.f1);
//                     $('#id_poly_delete').val(feature.properties.f1);
//                 }
//             });
//             pool.push({
//                 name: feature.properties.f2,
//                 id: L.stamp(layer),
//                 lat: lattitud,
//                 lng: longitud
//             });

//         }
//         layer.on({
//             mouseover: function(e) {
//                 var layer = e.target;
//                 layer.setStyle({
//                     weight: 1,
//                     Color: "#067800",
//                     fillColor: "#067800",

//                 });
//                 if (!L.Browser.ie && !L.Browser.opera) {
//                     layer.bringToFront();
//                 }
//             },
//             mouseout: function(e) {
//                 geo_build_osm.resetStyle(e.target);
//             }
//         });
//         var content = `<div class="tabbable">
//         <ul class="nav nav-tabs nav-tabs-bottom nav-justified">
//             <li class="active text-primary" id="feature-title"><a href="#left-tab1-feas-upl" data-toggle="tab" id="info">Information</a></li>
//             <li><a href="#right-tab2-feas-upl" data-toggle="tab" id="edit">Edit Buildings</a></li>
//         </ul>

//         <div class="tab-content">

//             <div class="tab-pane active" id="left-tab1-feas-upl" style="padding-bottom: 17px;">
//                 <div style="width: 350px; margin-left:10px;">
//                     <table>
//                         <tr>
//                             <th>Id</th>
//                             <td>:&nbsp` + feature.properties.f1 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Name</th>
//                             <td>:&nbsp` + feature.properties.f2 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Information</th>
//                             <td>:&nbsp` + feature.properties.f3 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Kelurahan</th>
//                             <td>:&nbsp` + feature.administrasi.f1 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Kecamatan</th>
//                             <td>:&nbsp` + feature.administrasi.f2 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Kab/Kota</th>
//                             <td>:&nbsp` + feature.administrasi.f3 + `</td>
//                         </tr>
//                         <tr>
//                             <th>Provinsi</th>
//                             <td>:&nbsp` + feature.administrasi.f4 + `</td>
//                         </tr>

//                     </table>
//                 </div><br>
//                 <input id='delet-pol' class="btn btn-warning" type="submit" value="DELETE">
//             </div>
//             <div class="tab-pane" id="right-tab2-feas-upl" style="padding-bottom: 17px;">
//                 <div id="map-edit" style="width:500px;height: 250px;">
//                 </div><br>
//                 <input id='buttonsaveedit' class="btn btn-primary" type="submit" value="Save">
//             </div>
//             <input type="text" name="coordinateZoneedit" class="hidden" id="coordinateZoneedit" value="">
//             <input class="hidden" type="text" name='id-poly' id="id-poly" value="` + feature.properties.f1 + `">
//             <input class="hidden" type="text" name='sumber' id="sumber" value="osm">

//         </div>

//     </div>`;
//         layer.bindPopup(content);
//     }
// }).addTo(map);
Manggar Mahardhika's avatar
Manggar Mahardhika committed
566 567 568 569 570 571

// $("#edit").click(function() {
//     alert("cel")

// });

572 573 574 575 576 577
$.ajaxSetup({
    headers: {
        'Csrf-Token': $('meta[name="csrf-token"]').attr('content')
    }
});

Manggar Mahardhika's avatar
Manggar Mahardhika committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
jQuery(document).ajaxSend(function(event, xhr, settings) {
    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }

    function sameOrigin(url) {
        // url could be relative or scheme relative or absolute
        var host = document.location.host; // host + port
        var protocol = document.location.protocol;
        var sr_origin = '//' + host;
        var origin = protocol + sr_origin;
        // Allow absolute or scheme relative URLs to same origin
        return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
            (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
            // or any other URL that isn't scheme relative or absolute i.e relative.
            !(/^(\/\/|http:|https:).*/.test(url));
    }

    function safeMethod(method) {
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
    }

    if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
        xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
    }
});

Muhamad's avatar
Muhamad committed
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
// map.on('contextmenu', function(e) {
//     $("#map-create").remove();

//     // document.getElementsByClassName('leaflet-popup-content').style.width = "550px";
//     var popup = L.popup()
//         .setLatLng(e.latlng)
//         .setContent(`
//         <div id="map-create" style="height: 250px;">
//         <input type="button" id="create" value="Create" style="z-index: 1000;position:relative;">
//         </div>
//         <br>

//         <label class="control-label col-lg-2 label-12">Name</label>
//         <input type="text" class="form-control" name="name_create" id="name_create" value=""><br>
//         <label class="control-label col-lg-2 label-12">Information</label>
//         <input type="text" class="form-control" name="info_create" id="info_create" value=""><br>
//         <div class="row">
//         <div class="col-md-2">
635

Muhamad's avatar
Muhamad committed
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
//         </div>
//         <div class="col-md-7">
//         </div>
//         <div class="col-md-3">
//             <input type="button" class="btn btn-primary" id="create_save" value="SAVE" style="margin-right:30px;">
//         </div>
//         </div>
//         <input type="text" name="poly_create" class="hidden" id="poly_create" value="">
//         `)
//         .openOn(map);

//     map.openPopup(popup);

//     var map_create = L.map('map-create', {
//         editable: true,
//         zoomControl: false,
//         drawControl: true
//     }).setView([e.latlng.lat, e.latlng.lng], 20.5);

//     map_created = L.tileLayer('https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}', {
//         maxZoom: 22,
//         minZoom: 4,
//     }).addTo(map_create);

//     map_create.invalidateSize();

//     $('#create').click(function() {

//         polygonDraweredit.enable();
//     });

//     var Marker = {};
//     var Poly = {};

//     map_create.on(L.Draw.Event.CREATED, function(e) {
//         var layer = e.layer;

//         $("#poly_create").empty();

//         var type = e.layerType;
//         var layer = e.layer;

//         var shape = layer.toGeoJSON();
//         let geoShape = shape.geometry.coordinates[0];

//         let kordinat = "";
//         for (j in geoShape) {

//             kordinat += geoShape[j][0] + ' ' + geoShape[j][1];

//             if (j <= (geoShape.length - 2)) {
//                 kordinat += ', ';
//             }
//         }

//         window.thisBaseDrawPolygonLayer = layer;

//         $("#poly_create").val(JSON.stringify(kordinat));
//     });

//     polygon_options = {
//         showArea: false,
//         shapeOptions: {
//             stroke: true,
//             color: '#6e83f0',
//             weight: 1.5,
//             opacity: 2,
//             fill: true,
//             fillColor: null, //same as color by default
//             fillOpacity: 0.3,
//             clickable: true
//         }
//     }

//     var polygonDraweredit = new L.Draw.Polygon(map_create, polygon_options);

//     polygonDraweredit.on("click", function(event) {
//         shapecoords.innerHTML = event.latlng.toString();
//         map_create.fire("click", event); // Trigger a map click as well.
//     });

//     map_create.on('draw:created', function(e) {
//         var type = e.layerType,
//             layer = e.layer;

//         var lay = layer.addTo(map_create);
//         Poly = lay;
//     });
Manggar Mahardhika's avatar
Manggar Mahardhika committed
724

Muhamad's avatar
Muhamad committed
725
// });
Manggar Mahardhika's avatar
Manggar Mahardhika committed
726 727


Muhamad's avatar
Muhamad committed
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
// $(document).on("click", "#create_save", function(e) {
//     var polygin = $('#poly_create').val();
//     var name_poly = $('#name_create').val();
//     var info_poly = $('#info_create').val();
//     loaderPage(true);

//     $.ajax({
//         url: "api/v1/create/",
//         data: {
//             'polygon': polygin,
//             'name': name_poly,
//             'info': info_poly
//         },
//         dataType: 'json',

//         success: function(data) {
//             map.closePopup();
//             loaderPage(false);
//         }
//     });
// });
Manggar Mahardhika's avatar
Manggar Mahardhika committed
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842

$(document).on("click", "#info", function() {
    document.getElementsByClassName('leaflet-popup-content')[0].style.width = "301px";
    document.getElementsByClassName('leaflet-popup')[0].style.left = "-171px";
});


var geo_jln = L.geoJson(null, {
    style: function(feature) {
        return {
            color: "#fcba03",
            weight: 5,
            opacity: 2,
            fillcolor: "#fcba03",
            fillOpacity: 0
        };
    },
    onEachFeature: function(feature, layer) {
        layer.on({
            mouseover: function(e) {
                var layer = e.target;
                layer.setStyle({
                    weight: 5,
                    Color: "#067800",
                    fillColor: "#067800",

                });
                if (!L.Browser.ie && !L.Browser.opera) {
                    layer.bringToFront();
                }

            },
            mouseout: function(e) {
                geo_jln.resetStyle(e.target);
            }

        });
        var popupContent = feature.properties.f2;
        layer.bindTooltip(popupContent);
        layer.bindPopup(popupContent);
    }
}).addTo(map);

function geo_json_jln(data) {
    geo_jln.addData(data)
}

function geo_json_build_osm(data) {
    geo_build_osm.addData(data)
}

function geo_json_build_gen(data) {
    geo_build_gen.addData(data)
}


$("#id_kec").change(function() {
    var kec_val = $(this).val();
    var kab_val = $('#polykab').val();
    var pro_val = $('#polypro').val();
    loaderPage(true);
    $.ajax({
        url: 'ajax/kecamatan/',
        data: {
            'kec_val': kec_val,
            'kab_val': kab_val,
            'pro_val': pro_val
        },
        dataType: 'json',
        success: function(data) {
            loaderPage(false);
            var data_all_kab = []
            for (var i = 0; i < data['nama_desa'].length; i++) {
                var data_k = data['nama_desa'][i];
                var data_kab = `<option value="` +
                    data_k +
                    `">` +
                    data_k +
                    `</option>`;
                data_all_kab.push(data_kab)
            };
            $('#id_desa').html(`<option>Select Desa/Kelurahan</option>` + data_all_kab);

            $('#polykab').val(data['nama_kab']);
            $('#polypro').val(data['nama_pro']);
            $('#polykec').val(data['nama_kec']);

        }
    });
});

$(document).on('click', 'li', function() {
    $('#provinsi').val($(this).text());
    $('#provinsiList').fadeOut();
843
});