2016-05-06 9 views
0

Ich habe benutzerdefinierte create Marker-Schaltfläche erstellt und onClick, dass ich Marker auf der Karte hinzufügen.So erhalten Sie Marker-Drag-Ereignis beim Ziehen Marker mit Mapbox LeafLet

Ich kann diese Karte ziehen, aber ich bekomme viel LatLng beim Ziehen. Ich möchte latlng marker drag event.Below ist mein Code zum Erstellen von Marker.

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> 
} 

Auf Marker erstellen, ich mache es ziehbar. Aber wie Drag-Ereignis dafür hinzuzufügen.

Antwort

0

Ich habe gerade dragend Event Listner innerhalb erstellt Ereignis hinzugefügt.

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)); 
Verwandte Themen