首页 > 解决方案 > 使用 react-leaflet 从 GeoJSON 显示不同类型对象的最有效方法

问题描述

这是我的 GeoJSON 示例,它将后端提供给前端。

{
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: { deviceType: 'mine' },
      geometry: {
        type: 'Point',
        coordinates: [-0.2197265625, 51.27050757321479],
      },
    },
    {
      type: 'Feature',
      properties: { deviceType: 'mine'},
      geometry: {
        type: 'Point',
        coordinates: [-0.2327265623, 51.27022757321422],
      },
    },
    {
      type: 'Feature',
      properties: { deviceType: 'favorite' },
      geometry: {
        type: 'Point',
        coordinates: [-0.263671875, 51.445448545784195],
      },
    },
    {
      type: 'Feature',
      properties: { deviceType: 'public' },
      geometry: {
        type: 'Point',
        coordinates: [0.10711669921875, 51.43346414054374],
      },
    },
}

我在两难中应该走哪条路:

目前我使用第二个选项,我首先映射特征并按“deviceType”键对它们进行分组,然后将 react-leaflet 中的 GeoJSON 层分配给它们,然后将其提供给 react-laeflet 地图。

这是我正在做的事情吗,如果源 json 变得非常大,我是否应该担心,任何其他建议如何正确地做到这一点。

谢谢,内纳德。

标签: geojsonreact-leaflet

解决方案


推荐阅读