2017-12-17 27 views
0

지도에 새 아이콘을 추가하면 사용자 정의 아이콘을 사용할 수있는 속성이 추가됩니다. 그렇다면 나는 geoJson을 저장하지만, 저장된 geojson을 볼 때 나는 그 장소가 잘못된 곳으로 설정되어있는 것을 보았다.지도 업데이트 속성이 지오메트리로 변경됩니다.

{ 
    "type": "Feature", 
    "properties": { 
     "iconSet": 2 
    }, 
    "geometry": { 
     "type": "Point", 
     "coordinates": [9.672668, 44.934964] 
    } 
} 

그냥이 내 코드를 완료 :

{ 
    "type": "Feature", 
    "properties": {}, 
    "geometry": { 
     "properties": { 
      "iconSet": 2 
     }, 
     "geometry": { 
      "type": "Point", 
      "coordinates": [9.672668, 44.934964] 
     } 
    } 

이 내가해야 할 것입니다 :

function updtateMarker(t, layer) { 

    // t is the value I need to save in property "iconSet" 
    // layer is the layer ID 

    var marker = featureGroup._layers[layer]; 
    console.log("### updtate Marker ###"); 

    // if marker already exists it works good 
    if (marker.feature && marker.feature.properties && marker.feature.properties.iconSet) { 

     marker.feature.properties.iconSet = t; 
     marker.setIcon(arrayIcon[t]); // update icon on Map 

    } else { 

     // Marker is new, it doesn't exist 

     // update marker icon on Map 
     marker.setIcon(runnaloIcon[t]); 

     marker.feature = {properties: {iconSet: t}}; 
     // ***** THIS IS WRONG: why? ****** 
     // this will be saved in "geometry" !??! 

    } 

} 

이 일 잘못 geojson입니다 :

코드입니다 절약 부분입니다

var data = featureGroup.toGeoJSON(); 
var convertedData = JSON.stringify(data); 

도움 주셔서 감사합니다.

답변

0

새 마커를 만들 때 대신에 새 마커를 만들 때 속성을 추가하여 고정했습니다.

map.on('draw:created', function (event) { 

    // Each time a featuree is created, it's added to the over arching feature group 

    if (event.layerType == "marker") { 

     var layer = event.layer; 

     // set the first property 
     feature = layer.feature = layer.feature || {}; 
     feature.type = feature.type || "Feature"; 
     var props = feature.properties = feature.properties || {}; 
     props.iconSet = 1; // default value 

    } 

})