Leaflet 单张标记拖动移动地图

Leaflet 单张标记拖动移动地图,leaflet,openstreetmap,marker,drag,Leaflet,Openstreetmap,Marker,Drag,我正在使用传单处理OSM。我在我的目标标记上启用拖动:true,因为我需要它可以拖动,但在拖动标记的同时,我的地图也会移动。有没有办法我只能移动标记 $(document).ready(function() { homepg(); }); var cab_map = null; function homepg() { var str = ''; var markers = new L.Marke

我正在使用传单处理OSM。我在我的目标标记上启用拖动:true,因为我需要它可以拖动,但在拖动标记的同时,我的地图也会移动。有没有办法我只能移动标记

    $(document).ready(function()
    {   
        homepg();
    });
    var cab_map = null;
    function homepg()
    {
        var str = '';
        var markers = new L.MarkerClusterGroup();
        var lat = '19.068246';
        var lng = '72.850638';
        cab_map = ddmap.init('mapdivcab',[lat,lng],14);
        ddmap.getDirection(13.039680,77.580214,13.040850,77.625532,cab_map,'lmenu');
    }

 getDirection: function(flat,flon,tlat,tlon,map,mapdv)
{
    this.dirMap = map;
    this.mapDiv = mapdv;
    this.sourceLatLng = new L.LatLng(flat,flon);
    this.targetLatLng = new L.LatLng(tlat,tlon);

    if(this.fScript) 
        head.removeChild(fScript);
    fScript = document.createElement('script');
    fScript.setAttribute("type","text/javascript");
    fScript.setAttribute("src", ddmap.serverUrl+"jsonp=ddmap.updateAddressFrom/nearbylocation/"+flat.toFixed(6).replace('.','')+"/"+flon.toFixed(6).replace('.','')+"/1?json_callback=%jsonp");
    document.getElementsByTagName("head")[0].appendChild(fScript);

    if(this.tScript) 
        head.removeChild(tScript);
    tScript = document.createElement('script');
    tScript.setAttribute("type","text/javascript");
    tScript.setAttribute("src", ddmap.serverUrl+"jsonp=ddmap.updateAddressTo/nearbylocation/"+tlat.toFixed(6).replace('.','')+"/"+tlon.toFixed(6).replace('.','')+"/1?json_callback=%jsonp");
    document.getElementsByTagName("head")[0].appendChild(tScript);

    if(this.currentScript) 
        head.removeChild(currentScript);
    currentScript = document.createElement('script');
    currentScript.setAttribute("type","text/javascript");
    currentScript.setAttribute("src", "viaroute?z=13&output=json&jsonp=ddmap.showRoute&loc="+flat+","+flon+"&loc="+tlat+","+tlon+"&instructions=true");
    document.getElementsByTagName("head")[0].appendChild(currentScript);
}
    showRoute: function(response) {
    var geometry = this._decode(response.route_geometry, 6);
    var route = new L.Polyline( [], {dashArray:""} );
    route.setLatLngs( geometry );
    var sIcon = L.icon({iconUrl:this.imageHost+"/images/marker-source.png",iconAnchor:[10,30],shadowUrl: this.imageHost+'/images/marker-shadow.png'});
    var tIcon = L.icon({iconUrl:this.imageHost+"/images/marker-target.png",iconAnchor:[10,30],shadowUrl: this.imageHost+'/images/marker-shadow.png'});
    mrkrSrc = L.marker(this.sourceLatLng, {icon: sIcon});
    mrkrTgt = L.marker(this.targetLatLng, {icon: tIcon,draggable:'true'});
    if(this.mainLayer)
        this.dirMap.removeLayer(this.mainLayer);

    this.mainLayer = L.layerGroup([mrkrSrc, mrkrTgt])
    .addLayer(route)
    .addTo(this.dirMap);
    var bounds = new L.LatLngBounds(this.sourceLatLng, this.targetLatLng);
    this.dirMap.fitBounds(bounds);
    this.showRouteDesc(response,geometry);

    //
        mrkrTgt.on('drag', function(event){
            var marker = event.target;
            var dst = marker.getLatLng();
            var src = mrkrSrc.getLatLng();         
            ddmap.getroute(src.lat,src.lng,dst.lat,dst.lng,cab_map,'lmenu');//instead of calling getDriection i m calling this function
    });
//这个函数与getDirection相同,但我删除了一些代码,认为这不是必需的,它使“拖动事件”变得粗糙和耗时

getroute: function(flat,flon,tlat,tlon,map,mapdv)
{
    this.dirMap = map;
    this.mapDiv = mapdv;
    this.sourceLatLng = new L.LatLng(flat,flon);
    this.targetLatLng = new L.LatLng(tlat,tlon);    
    if(this.currentScript) 
        head.removeChild(currentScript);
    currentScript = document.createElement('script');
    currentScript.setAttribute("type","text/javascript");
    currentScript.setAttribute("src", "viaroute?z=13&output=json&jsonp=ddmap.showRoute&loc="+flat+","+flon+"&loc="+tlat+","+tlon+"&instructions=true");
    document.getElementsByTagName("head")[0].appendChild(currentScript);
}

你能发布一些代码让其他人看到你到目前为止尝试了什么吗?如果你创建了一个案例,那就太好了。你能发布一些代码让其他人看到你到目前为止尝试了什么吗?如果你创建了一个案例,那就太好了