0

i have a problem with my update data coordinates form leaflet popup. i just want to make edit form inside leaflet popup. if i click marker in a map it shown coordinate with input form, if the building is move i just adjust coordinate with input form and submit it to a database. but, that's the problem when i click on update button it shown no response. here the script i used:

var Sekolah = L.geoJson.ajax("template/lokasi/lokasi.php", {
    pointToLayer: function (feature, latlng) {
      return L.marker(latlng, {
        icon: marker,
        title: feature.properties.sekolah,
        riseOnHover: true
      });
    },
    onEachFeature: function (feature, layer) {
        var bujur = "<input type='text' class='form-control' name='bujur' id='bujur' value="+layer.feature.geometry.coordinates[0]+">";
        var lintang = "<input type='text' class='form-control' name='lintang' id='lintang' value="+layer.feature.geometry.coordinates[1]+">";
        var context = "<div class='form-horizontal form-lokasi'><div class='inp'><label>Bujur</label>"+bujur+"</div>&nbsp;"+
                        "<div class='inp'><label>Lintang</label>"+lintang+"</div></div>"+
                        "<button class='btn btn-warning lok' id='edit_lok' value="+layer.feature.properties.id_lokasi+"><span class='glyphicon glyphicon-pencil'></span></button>"+
                        "<button class='btn btn-danger lok' id='hapus_lok' value="+layer.feature.properties.id_lokasi+"><span class='glyphicon glyphicon-trash'></span></button>";

        layer.bindPopup(context, {
            maxWidth: 350
        });
    }
}).addTo(peta);

$('#edit_lok').on('click', function(){
    var id = $(this).val();
    var buj = $('#bujur').val();
    var lin = $('#lintang').val();

    var data = "&id="+id+"&bujur="+buj+"&lintang="+lin;

    $.ajax({
        url: 'template/lokasi/proses.php',
        type: 'post',
        data: data
    })
    .done(function(msg) {
        console.log(msg);
    })
    .fail(function() {
        console.log("error");
    });
});

i can't find any error in my script. hope there is an answer

  • is the DB updated? does your onclick event fire? if you expect the map to be updated with the new coordinates, do you reload the layer from DB? one more thing: although it's leaflet, there's no clear spatial component, making this question off-topic for GIS SE... – ThingumaBob Jun 5 '18 at 11:44
0

Here is an example of it working from a div not a popup. http://www.gistechsolutions.com/leaflet/DEMO/phpDemo/update.html the points are dragable, and you can see the coordinates change when you stop dragging it. Hitting save writes the data back using PHP to a mysql database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.