如何在拖动标记后更新弹出窗口?

时间:2017-02-23 14:13:57

标签: javascript leaflet openstreetmap

我有一个传单地图,我使用Control Geocoder来搜索一些位置,然后我在2个输入字段上添加坐标,同时我为搜索结果添加了一个弹出窗口,问题是当标记被移动时弹出窗口没有用新地方更新,怎么办呢?

Mmap = L.map('Modalmap').setView([8.7144, 125.7481],8);
    L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright"></a>',
        subdomains: ['a','b','c']
    }).addTo(Mmap);
var geocoder = L.Control.geocoder({
        defaultMarkGeocode: false,
        draggable:true
    })
    .on('markgeocode', function(e) {
        var box = e.geocode.center;
        var name=e.geocode.name;
        document.getElementById("Latitude").value = box.lat;
        document.getElementById("Longitude").value = box.lng;
        MarkLayer=L.marker([box.lat,box.lng],{draggable:true}).addTo(Mmap). 
        on('dragend', onDragEnd). 
        bindPopup(e.geocode.name). 
        openPopup(); 
        displayLatLng(box); 

        group = new L.featureGroup([MarkLayer]);

        Mmap.fitBounds(group.getBounds());
    }).addTo(Mmap); 

    function onDragEnd(event) 
    {
        var latlng = event.target.getLatLng();

        displayLatLng(latlng);
    }

    function displayLatLng(latlng) {
        document.getElementById("Latitude").value = latlng.lat;
        document.getElementById("Longitude").value = latlng.lng;
    }

0 个答案:

没有答案
相关问题