首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Leaflet中可视化具有属性的线串

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

Stack Overflow用户
提问于 2017-08-18 22:39:53
回答 1查看 476关注 0票数 0

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

{“功能”:[{“类型”:“功能”,“属性”:{“名称”:“0”},“几何”:{“类型”:“LineString”,"coordinates":[10.941445541381836,52.438697814941406,10.941454124450684,52.4387092590332,10.941451263427734,52.43870544433594,10.941445541381836,52.438697814941406,10.941254806518555,52.440738677978516]}},{“类型”:“功能”,“属性”:{“名称”:“0”},“几何”:{“类型”:“LineString”,"coordinates":[10.941445541381836,52.438697814941406,10.941454124450684,52.4387092590332,10.941451263427734,52.43870544433594,10.941445541381836,52.438697814941406,10.941254806518555,52.440738677978516]}}}

任何帮助都是最好的!

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-08-21 16:31:38

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

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

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

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45759314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档