2013-04-23 4 views
2

전단지와 함께 Geojson 레이어를 표시하고 있습니다. 기본 마커 아이콘 크기를 변경하고 싶습니다.전단지 : geojson 레이어의 마커 아이콘 크기

Uncaught TypeError: Cannot read property 'popupAnchor' of undefined 

모든 단서 : 페이지를로드 할 때

$.ajax({ 
     type: "GET", 
     url: "data.json", 
     dataType: 'json', 
     success: function (response) { 
      geojsonLayer = L.geoJson(response, { 
       pointToLayer: function(featuer, latlng) { 
        var smallIcon = L.Icon.extend({ 
         options: { 
          'iconSize': [10, 10] 
         } 
        }); 
        var myIcon = new smallIcon(); 
        return L.marker(latlng, {icon: smallIcon}); 
       }, 
       onEachFeature: onEachFeature 
      }).addTo(map); 
     } 
    }); 

그러나, 내가 자바 스크립트 오류가 있어요 : 여기

내가 해낸 코드?

+0

당신은 아약스없이 시도? –

+0

아니요. 내가 어떻게 할 수 있는지 잘 모르겠다. –

답변

3

L.Icon 클래스를 확장 할 때 아이콘에 사용 된 이미지 파일에 대한 링크 인 IconUrl을 지정해야한다고 생각합니다. 문서보기 : http://leafletjs.com/reference.html#icon

smallIcon 생성자가 필요한 모든 옵션을 만족하지 않으므로 myIcon이 정의되지 않습니다.

이 시도 :

var myIcon = L.icon({ 
    iconUrl: 'leaflet/images/marker-icon.png', 
    iconSize: [10,10], 
    iconAnchor: [22, 94], 
    popupAnchor: [-3, -76], 
    shadowUrl: 'leaflet/images/marker-shadow.png', 
    shadowSize: [68, 95], 
    shadowAnchor: [22, 94] 
}); 

L.marker(latlng, {icon: myIcon}).addTo(map); 
+2

또는'L.Icon' 대신'L.Icon.Default'를 확장하십시오. – flup

+0

감사합니다. geohacker의 솔루션이 실제로 작동합니다. 그러나 iconURL (CDN의 리플릿을 사용하고 있음)을 재정의하고 싶지 않기 때문에 L.Icon.Default를 확장하는 것이 좋은 방법이었습니다. 건배! –

관련 문제