带孔的 GeoJson LineString 特征集合

GeoJson LineString Feature Collection with holes

我有一长串代表资产移动的坐标(由 GPS 传感器发送)。

我正在使用 leaflet 渲染 GeoJSON,如果我将 LineString 渲染为单个特征,它工作正常,但如果我将它分解为多个特征(在 FeatureCollection 内 - 应用不同的动态颜色)我开始看到特征之间的“漏洞”。

我很确定这是因为我收到的数据中实际上存在一个“漏洞”。但为什么它作为单个 LineString 功能工作?有办法解决这个问题吗?

这是 GeoJSON(非常大的对象)的摘录

对象的 866 个特征中有 3 个

{
          "type":"Feature",
          "properties":{
             "type":"traffic",
             "color":"#ffa600"
          },
          "geometry":{
             "type":"LineString",
             "coordinates":[
                [
                   7.583125,
                   45.0485616
                ],
                [
                   7.5830532999999996,
                   45.0485816
                ],
                [
                   7.58299,
                   45.0486133
                ],
                [
                   7.582893299999999,
                   45.0486066
                ],
                [
                   7.5828682999999995,
                   45.04859
                ]
             ]
          }
       },

link 到 bin

https://jsbin.com/nexijajake/edit?html,output

具有单一特征的示例

https://jsbin.com/guqihajalu/1/edit?html,output

其实渲染也没什么问题。您的 data 数组(在您的 jsbin link 中)是一个不相互连接的线串数组。您有这样的模式(假设每一行都是一个线串):

[pointA-pointB-pointC]

[pointD-pointE-pointF]

为了使您的线连续,每个线串的最后一个点应作为第一个点存在于下一个线串中:

[pointA-pointB-pointC]

[pointC-pointD-pointE-pointF]

这样,你的线就会连续。

例如,以下示例(取自您的 jsbin)有一个间隙:

const data = [
   {
      "type":"Feature",
      "properties":{
         "type":"traffic",
         "color":"#ffa600"
      },
      "geometry":{
         "type":"LineString",
         "coordinates":[
            [
               7.583125,
               45.0485616
            ],
            [
               7.5830532999999996,
               45.0485816
            ],
            [
               7.58299,
               45.0486133
            ],
            [
               7.582893299999999,
               45.0486066
            ],
            [
               7.5828682999999995,
               45.04859
            ]
         ]
      }
   },
   {
      "type":"Feature",
      "properties":{
         "type":"normal",
         "color":"#07e36a"
      },
      "geometry":{
         "type":"LineString",
         "coordinates":[
            [
               7.582795,
               45.0485149
            ],
            [
               7.582624999999999,
               45.0483233
            ],
            [
               7.581984899999999,
               45.047521599999996
            ]
         ]
      }
   }
];

间隙固定(第二个线串的第一个点是第一个线串的最后一个点):

const data = [
   {
      "type":"Feature",
      "properties":{
         "type":"traffic",
         "color":"#ffa600"
      },
      "geometry":{
         "type":"LineString",
         "coordinates":[
            [
               7.583125,
               45.0485616
            ],
            [
               7.5830532999999996,
               45.0485816
            ],
            [
               7.58299,
               45.0486133
            ],
            [
               7.582893299999999,
               45.0486066
            ],
            [
               7.5828682999999995,
               45.04859
            ]
         ]
      }
   },
   {
      "type":"Feature",
      "properties":{
         "type":"normal",
         "color":"#07e36a"
      },
      "geometry":{
         "type":"LineString",
         "coordinates":[
            //the first point here is the last of previous linestring
            [
               7.5828682999999995,
               45.04859
            ],
            [
               7.582795,
               45.0485149
            ],
            [
               7.582624999999999,
               45.0483233
            ],
            [
               7.581984899999999,
               45.047521599999996
            ]
         ]
      }
   }
];