Leaflet how to take individual values ​in GeoJSON?

自古美人都是妖i 提交于 2021-02-11 15:31:22

问题


I would like to do this in the Leaflet! I have a GeoJSON file with these data:

"type": "Feature",
"geometry": {
"type": "MultiPoint",
"coordinates": [
  [
    -123.77252789,
    44.37857221
  ],
  [
    -123.77317087,
    44.37864694
  ],
  [
    -123.77383407,
    44.37875853
     ]
     ]
   },
    "properties": {
       "title" : "tillicum",
       "path_options" : { "color" : "red" },

       "time": [
         1580403952000,
         1580403990000,
         1580404202000
          ],
            "speed": [
               85,
               88,
               90
               ],
            "altitude": [
                29,
                50,
                69
           ],
             "heading": [
                 0,
                 0,
                 0
           ],
             "horizontal_accuracy": [
                 87,
                 79,
                 59
           ],
             "vertical_accuracy": [
                  0,
                  0,
                  0
           ],
             "raw": []
           },
             "bbox": [
           [
              -124.09386637,
               44.34348063
           ],
           [
              -124.09386637,
               44.56531305
           ],
           [
              -123.26148271,
               44.56531305
           ],
           [
              -123.26148271,
               44.34348063
           ]
    ]
 };

I would like to take the altitude properties and, based on their numerical value, assign the radius to a hypothetical circle in the function:

pointToLayer: function (featureData, latlng) {


 return new L.CircleMarker(latlng, result);
}

I would only need to know how to take these values ​​and assign them to radius.

i'm trying with:

pointToLayer : function(featureData, latlng){
                    if (featureData.properties.altitude) {
      radius = featureData.properties.altitude;
                } 
            return new L.CircleMarker(latlng, featureData.properties.altitude);
        }

回答1:


You have to use the radius property:

var i = 0;
L.geoJSON(json,{
    pointToLayer: function (feature, latlng) {
        var marker = L.circleMarker(latlng, {radius: feature.properties.altitude[i]});
        i++;
        return marker;
    }
}).addTo(map);

https://jsfiddle.net/falkedesign/dkheswg1/



来源:https://stackoverflow.com/questions/60031554/leaflet-how-to-take-individual-values-in-geojson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!