2017-09-26 4 views
1

私はやや一般的なコーディングとリーフレットの初心者です。私は小さな問題に遭遇しました。ドラッグ可能なユーザーにマーカーを提出させるために、このコードがあります。このコードでマーカのスタイルを追加する場所を入力してください(リーフレット)

var currentMarker; 
map.on("click", function (event) { 
if (currentMarker) { 
    currentMarker._icon.style.transition = "transform 0.3s ease-out"; 
    currentMarker._shadow.style.transition = "transform 0.3s ease-out";   
    currentMarker.setLatLng(event.latlng); 

    setTimeout(function() { 
     currentMarker._icon.style.transition = null; 
     currentMarker._shadow.style.transition = null; 
    }, 300); 
    return; 
} 

currentMarker = L.marker(event.latlng, { 
    draggable: true 
}).addTo(map).on("click", function() { 
    event.originalEvent.stopPropagation(); 
}).bindPopup("HI").openPopup(); 
}); 

document.getElementById("done").addEventListener("click", function() { 
currentMarker = null; 
}); 

私はすでにマップ上に配置したマーカーのスタイルを設定するために素晴らしいマーカーのリーフレットプラグインも使用しています。私は、これらのオプションを使用してジェネリックマーカーをスタイルするために、上記のコードにこのコードを入れるべき場所について助けを求めています。私が言ったように私は初心者です、私はおそらくそれが実際に可能である場合にどうするかを見下ろすていても

icon: L.AwesomeMarkers.icon({ 
    icon: '#fix', 
    markerColor: 'darkpurple', 
    iconColor: '#F8FAEE',   
})  

私は、異なるスポットのトンを試してみました。ご協力いただきありがとうございます。

答えて

1

ようこそ!

iconあなたdraggable: trueオプションのように、L.marker工場のオプションです。

L.marker(event.latlng, { 
    draggable: true, 
    icon: L.AwesomeMarkers.icon({ /* … */ }) 
}).addTo(map) 

Markers With Custom Iconsリーフレットのチュートリアルだけでなく、あなたのコードのためのインスピレーションを得ることができ、そこからオンライン demoにリンク Leaflet.awesome-markersプラグインのホーム・ページを参照してください。

関連する問題