리플릿/JavaScript를 처음 접했고 레이어 컨트롤에서 특정 레이어가 선택된 경우에만 표시 할 범례를 표시하는 데 어려움을 겪고 있습니다. 나는 3 개의 레이어를 가지고 있는데, 그 중 하나는 전설이없고 다른 2 개의 레이어는 해당 전설이 있습니다. 나는 예를 건너 왔어요,하지만 그것이 작동되도록 할 수 없었던 :레이어 선택으로 범례 추가/제거
// Add and remove legend from layers
map.on('overlayadd', function (eventLayer) {
// Switch to the Permafrost legend...
if (eventLayer.name === 'Permafrost') {
this.removeControl(legend1);
legend2.addTo(this);
} else { // Or switch to the treeline legend...
this.removeControl(legend2);
legend1.addTo(this);
}});
나는 구체적인 예와 jsfiddle을 만들어 :
http://jsfiddle.net/gerlis/T8DHb/3/
모든 지침을 크게 감상 할 수있다.
귀하의 솔루션이 동작을 적용하기 위해 여러 가지 레이어를 선택하는 것으로 나타났습니다. 내가 실제로 원하는 것은 "위성"의 전설, "영구 동토 층"이있는 legend2 및 "Treeline"이있는 legend1이없는 것입니다. – user3498523
중첩 된 조건문을 시도했습니다 :'map.on ('baselayerchange', function (eventLayer) { if (eventLayer.name === 'Treeline') {map.removeControl (legend2);} if (eventLayer.name === '영구 동토 층') {map.removeControl (legend1); legend2.addTo (map);} – user3498523
좋아, 어떤 레이어에서 원하는 범례를 알지 못했습니다. ") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 기본 레이어를 두 번 선택해야하는 문제는 세 개의 기본 레이어를 모두지도에 추가하는 것과 관련이 있습니다. 기본적으로 PermaFrost 레이어 만지도에 추가됩니다 (http : //). jsfiddle.net/T8DHb/8/ –