地圖js部分

<script type="text/javascript">
var tcount = {{$sort}}+1; //表格行數
var land = [];
var total = {{$need->area_measure}}; //總面積

//處理地塊信息
var need_id = $("input[name='id']").val();
$.post("{{ route('admin.need.land') }}", {need_id: need_id}, function (result) {
    land = result;
    $("input[name='coordinate']").val(JSON.stringify(land));
});


//點擊確認保存
$('.btn-confirm').click(function() {

    //清除地圖上的覆蓋物
    map.clearMap();
    init();

    var spot = JSON.parse($('#spot').val());
    var spotArr = [];
    for (var i = 0; i < spot.length; i++) {
        spotArr.push({ 'latitude': spot[i].lat, 'longitude': spot[i].lng });
    }
    // console.info(JSON.stringify(spotArr));
    // console.info(rst);

    //點擊保存,添加一條記錄
    var tpl='<tr id="s'+ tcount +'"><td>地塊'+ tcount +'</td><td>'+rst+'畝</td><td onclick="deltab('+tcount+')"><button type="button" class="layui-btn layui-btn-xs layui-btn-normal">刪除</button></td></tr>';
    $("#tbody").append(tpl);

    //計算總面積
    total  = parseFloat(total)+parseFloat(rst);
    total  = total.toFixed(2);
    $("input[name='area_measure']").val(total);

    //數據打包
    land.push({'sort':tcount, 'area': rst, 'coordinate': JSON.stringify(spotArr)});
    $("input[name='coordinate']").val(JSON.stringify(land));
    tcount++;
});

//刪除表格
function deltab(x){
    //更新數組
    for ( i = 0; i < land.length; i++) {
        if (land[i].sort == x){
            land.splice(i,1)
        }
    }
    $("input[name='coordinate']").val(JSON.stringify(land));

    //更新面積
    var area = parseFloat($("#s"+x).find("td").eq(1).text());
    total  = parseFloat(total)-area;
    total  = total.toFixed(2);
    $("input[name='area_measure']").val(total);
    $("#s"+x).remove();
}
</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章