繁体   English   中英

在Leaflet中可视化带有属性的线串

[英]Visualizing Linestrings with properties in Leaflet

我想可视化以下发送到我的Leaflet / JavaScript应用程序的GeoJSON对象。 我如何可视化所有线串,显示每个线串的properties.name参数(例如,通过ToolTip)。

{ “特征”:[{ “类型”: “功能”, “属性”:{ “名称”: “0”}, “几何”:{ “类型”: “线段形式”, “坐标”:[[10.941445541381836, 52.438697814941406],[10.941454124450684,52.4387092590332],[10.941451263427734,52.43870544433594],[10.941445541381836,52.438697814941406],[10.941254806518555,52.440738677978516]]}},{ “类型”: “功能”, “属性”:{ “名称”:“0 “},” 几何 “:{” 类型 “:” 线段形式”, “坐标”:[[10.941445541381836,52.438697814941406],[10.941454124450684,52.4387092590332],[10.941451263427734,52.43870544433594],[10.941445541381836,52.438697814941406],[10.941254806518555,52.440738677978516] ]}}}

任何帮助将是巨大的!

谢谢

您没有正确使用GeoJSON。 如果您具有多个功能,则应使用功能集合: https : //geojson.org/geojson-spec.html

然后使用此网站来具有正确的格式: https : //jsonformatter.curiousconcept.com/

然后,如果您想添加工具提示,请参考本教程: http : //leafletjs.com/examples/geojson/

var geojsonFeature = {
   "type":"FeatureCollection",
   "features":[
      {
         "type":"Feature",
         "geometry":{
            "type":"LineString",
            "coordinates":[
               [
                  10.941445541381836,
                  52.438697814941406
               ],
               [
                  10.941454124450684,
                  52.4387092590332
               ],
               [
                  10.941451263427734,
                  52.43870544433594
               ],
               [
                  10.941445541381836,
                  52.438697814941406
               ],
               [
                  10.941254806518555,
                  52.440738677978516
               ]
            ]
         },
         "properties":{
            "name":"0"
         }
      },
      {
         "type":"Feature",
         "geometry":{
            "type":"LineString",
            "coordinates":[
               [
                  10.941445541381836,
                  52.438697814941406
               ],
               [
                  10.941454124450684,
                  52.4387092590332
               ],
               [
                  10.941451263427734,
                  52.43870544433594
               ],
               [
                  10.941445541381836,
                  52.438697814941406
               ],
               [
                  10.941254806518555,
                  52.440738677978516
               ]
            ]
        },
        "properties":{
           "name":"0"
        }
      }
   ]
};

function onEachFeature(feature, layer) {
    // This is where it loop through your features
    if (feature.properties) {
        // If there is a properties document we bind a tooltip with your property : name
        layer.bindTooltip(feature.properties.name);
    }
}

L.geoJSON(geojsonFeature, {
    onEachFeature: onEachFeature
}).addTo(map);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM