[javascript] asdsa
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- @{ ViewBag.Title = "Index"; }
- <input type="hidden" id="hd_path" value="@ViewBag.pathParent" />
- <h3>Tambah Lokasi Baru</h3>
- <hr />
- <br />
- <html>
- <head>
- <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
- <style>
- </style>
- </head>
- <body>
- <div class="row" id="form">
- <div class="col-md-12">
- <div class="form-horizontal">
- <div class="form-group">
- <label class="col-md-2">Nama Lokasi</label>
- <div class="col-md-4">
- <input type="text" id="tx_namalokasi" name="tx_namalokasi" class="form-control" data-bind="value: location_name" />
- </div>
- </div>
- </div>
- <div class="form-horizontal">
- <div class="form-group">
- <div class="col-md-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- Tentukan titik koordinat untuk menentukan area lokasi : <span style="font-size:9px">(*klik pada peta untuk setting titik koordinat)</span>
- </div>
- <div class="panel-body">
- <div class="form-group">
- <div class="col-md-12">
- <input id="pac-input" class="controls" type="text" placeholder="Search Box">
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-12">
- <div id="map" style="width: 100%;height: 400px;background-color: grey;"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="form-horizontal">
- <div class="form-group">
- <div class="col-md-4">
- <div class="btn-group" role="group" aria-label="Third group">
- <button id="btn_save" class="btn btn-primary"><i class="glyphicon glyphicon-save"> </i>Simpan</button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
- <script>
- var map;
- var arr_marker = [];
- function initMap() {
- // Initialize the map
- map = L.map('map').setView([-6.198138, 106.915365], 15);
- // Add a base map layer
- L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
- attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
- }).addTo(map);
- // Add click event to the map
- map.on('click', function (e) {
- placeMarker(e.latlng);
- addMarker({ "latitude": e.latlng.lat, "longtitude": e.latlng.lng });
- });
- }
- function placeMarker(latlng) {
- var marker = L.marker(latlng).addTo(map);
- marker.on('click', function (e) {
- map.removeLayer(marker);
- deleteMarker({ "latitude": e.latlng.lat, "longtitude": e.latlng.lng });
- });
- }
- function deleteMarker(latLng) {
- var lat = latLng.latitude;
- var lng = latLng.longtitude;
- for (var i = 0; i < arr_marker.length; i++) {
- if (arr_marker[i].latitude == lat && arr_marker[i].longtitude == lng) {
- arr_marker.splice(i, 1);
- }
- }
- }
- function addMarker(latLng) {
- arr_marker.push(latLng);
- }
- // This initializes the map once the document is fully loaded
- document.addEventListener('DOMContentLoaded', function () {
- initMap();
- });
- $(document).ready(function () {
- $("#btn_save").click(function () {
- console.log(arr_marker)
- save();
- })
- kendo.bind($("#form"), viewModel);
- })
- function save() {
- //console.log(JSON.stringify(viewModel));
- viewModel.set("latLng", arr_marker);
- $.ajax({
- type: "POST",
- url: $("#hd_path").val() + "/SetLocation/AjaxInsertLocation",
- contentType: "application/json",
- data: JSON.stringify(viewModel),
- success: function (response) {
- if (response.status) {
- alert(response.remark)
- } else {
- alert(response.error)
- }
- location.reload();
- },
- error: function (jqXHR, textStatus, errorThrown) {
- }
- });
- }
- var viewModel = kendo.observable({
- location_id: "",
- location_name: "",
- latLng: [],
- });</script>
- </body>
- </html>
Editor
You can edit this paste and save as new: