geojson - 使用 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],
},
},
}
我在两难中应该走哪条路:
在后端将响应拆分为多个 GeoJSON 对象,然后在前端我可以以标准方式处理每个实例(不太喜欢这种解决方案)
发送单个 GeoJSON 对象,其中包含我的功能的所有变体以及前端地图槽功能并将它们分组
目前我使用第二个选项,我首先映射特征并按“deviceType”键对它们进行分组,然后将 react-leaflet 中的 GeoJSON 层分配给它们,然后将其提供给 react-laeflet 地图。
这是我正在做的事情吗,如果源 json 变得非常大,我是否应该担心,任何其他建议如何正确地做到这一点。
谢谢,内纳德。
解决方案
推荐阅读
- android - 为什么按意图添加联系人不起作用?
- html - 如何使用 Bootstrap 4 和 Angular 6 在鼠标单击表格的选定行时突出显示?
- node.js - Heroku 你可以在一台测功机上同时运行多少个听众?
- php - 从 mysql db 中查询特殊字符
- c# - 对象引用 Null - 将 jQuery 数组传递给 C# 列表
- java - 实现没有用户角色的 Spring Security
- ios - 有没有办法在 Swift 中阻止特定应用程序的设备
- python - create an adjacency matrix in python
- inno-setup - 运行后安装可能存在错误?
- javascript - How to replace characters at the beginning and at the end of a word?