繁体   English   中英

如何在使用Mapbox LeafLet拖动标记时获取标记拖动事件

[英]How to get marker drag event on dragging marker with mapbox LeafLet

我已经创建了自定义创建标记按钮,并在地图上添加了onClick。

我可以拖动该地图,但拖动时会得到LatLng。 我想对标记拖动事件进行延迟。下面是我创建标记的代码。

this.map.on('draw:created', function(e) {
        e.layer.options.draggable = true;
        this.drawnItems.addLayer(e.layer);
        this.props.markerCoordinates(e.layer._latlng);
        this.mapState = MAP_STATE.NONE;
        mapSearch.searchByLocation(e.layer._latlng, this.getLocation);
        this.setState({
            drawActiveClass: 'polygonAction clearfix',
        });
    }.bind(this));

    drawMarker: function() {
    if(this.mapState === MAP_STATE.DRAW) {
        return;
    }
    this.drawnItems.clearLayers();
    this.mapState = MAP_STATE.DRAW;
    this.drawHandler = new L.Draw.Marker(this.map,this.drawControl.options.draw.marker);
    this.drawHandler.enable();
    this.setState({
        drawActiveClass: 'polygonAction clearfix active',
        createMarkerErrorClass: 'hide'
    });
}

render: function() {
     <li className={this.state.drawActiveClass} ref="drawMarker" onClick={this.drawMarker}>
          <span className="drawAction">{this.props.drawAction}</span>
     </li>
}

创建标记时,我将其拖动。 但是如何为其添加拖动事件。

我刚刚在创建的事件中添加了dragend事件列表器。

  this.map.on('draw:created', function(e) {
        e.layer.options.draggable = true;
        e.layer.on('dragend',function(e) {
            mapSearch.searchByLocation(e.target.getLatLng(),this.getLocation);
        }.bind(this));
        this.drawnItems.addLayer(e.layer);
        this.props.markerCoordinates(e.layer._latlng);
        this.mapState = MAP_STATE.NONE;
        mapSearch.searchByLocation(e.layer._latlng, this.getLocation);
        this.setState({
            drawActiveClass: 'polygonAction clearfix',
        });
    }.bind(this));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM