在 Leaflet 中按经纬度过滤 GeoJSON
Filtering GeoJSON by lat-long in Leaflet
我正在 leaflet 中摄取一个大型 geoJSON 文件,其中包含大约 19,000 个特征(点)。这会导致地图上出现大量混乱并且难以管理。
目标是使用地理定位来标记我的位置,围绕它画一个 5 纳米的圆,并且只显示位于该几何图形内的 geoJSON 特征。
我的项目的精简版是:
https://jsfiddle.net/blintster/d2ucock2/3/
我已经找到了我的位置并绘制了圆圈,但我无法解析位置上的 geoJSON 功能。理想情况下,输出的功能如下:https://esri.github.io/esri-leaflet/examples/spatial-queries.html 但是,该方法似乎仅适用于 L.esri.FeatureLayer,这是本地导入的 geoJSON。
所讨论的 geoJSON 层位于 [airports] 是 19,000 个条目的下方:
var allairportsLayer = L.geoJson([airports], {
filter: airportFilter,
onEachFeature: function(feature, layer) {
layer.bindPopup(feature.properties.Type + " - " + feature.properties.FacilityName + "<br>Contact Info: " + feature.properties.Manager + "<br> Phone: " + feature.properties.ManagerPhone);
}
}).addTo(map);
function airportFilter(feature) {
if (feature.properties.State === "MD") return true
};
我能够通过使用按州过滤的方法稍微对结果进行配对,但这只允许我确定一个属性是否满足指定的标准。
我也尝试过以下方法:https://www.mapbox.com/mapbox.js/example/v1.0.0/marker-radius-search/
没有运气。
有谁知道我可以尝试解析数据的任何其他方法,以便它只显示位于几何图形中的点?
However, that method only seems to apply to L.esri.FeatureLayer and this is a locally imported geoJSON.
esri-leaflet 搭载 ArcGIS Server 和 ArcGIS Online 服务,后者提供支持空间查询的后端托管数据库。
显然 Esri 不是唯一的选择,但您的用例是一个完美的例子,说明了 不获取您不获取的整个数据集是有益的不打算展示。
您可以创建一个 arcgis developer account and then sign into arcgis.com 来免费上传您的 .geojson 文件作为新的托管服务。
您可以找到另一个提供类似功能的托管服务
您可以 运行 您自己的服务器,安装您自己的 PostGIS 数据库并自己连接空间网络查询。
您可以在页面加载时继续下载所有 19,000 个功能,并且:
a) 简化您的搜索并测试是否相关 L.latLngBounds.contains()
每个点。
b) 使用类似 turf to test the relationship with an actual circle. (one caveat worth mentioning here is that leaflet doesn't include any built in methods for generating actual L.circle
geometry so you'd need more custom logic for that too. i wrote something similar here 的东西,欢迎您使用。
我正在 leaflet 中摄取一个大型 geoJSON 文件,其中包含大约 19,000 个特征(点)。这会导致地图上出现大量混乱并且难以管理。
目标是使用地理定位来标记我的位置,围绕它画一个 5 纳米的圆,并且只显示位于该几何图形内的 geoJSON 特征。
我的项目的精简版是: https://jsfiddle.net/blintster/d2ucock2/3/
我已经找到了我的位置并绘制了圆圈,但我无法解析位置上的 geoJSON 功能。理想情况下,输出的功能如下:https://esri.github.io/esri-leaflet/examples/spatial-queries.html 但是,该方法似乎仅适用于 L.esri.FeatureLayer,这是本地导入的 geoJSON。
所讨论的 geoJSON 层位于 [airports] 是 19,000 个条目的下方:
var allairportsLayer = L.geoJson([airports], {
filter: airportFilter,
onEachFeature: function(feature, layer) {
layer.bindPopup(feature.properties.Type + " - " + feature.properties.FacilityName + "<br>Contact Info: " + feature.properties.Manager + "<br> Phone: " + feature.properties.ManagerPhone);
}
}).addTo(map);
function airportFilter(feature) {
if (feature.properties.State === "MD") return true
};
我能够通过使用按州过滤的方法稍微对结果进行配对,但这只允许我确定一个属性是否满足指定的标准。
我也尝试过以下方法:https://www.mapbox.com/mapbox.js/example/v1.0.0/marker-radius-search/ 没有运气。
有谁知道我可以尝试解析数据的任何其他方法,以便它只显示位于几何图形中的点?
However, that method only seems to apply to L.esri.FeatureLayer and this is a locally imported geoJSON.
esri-leaflet 搭载 ArcGIS Server 和 ArcGIS Online 服务,后者提供支持空间查询的后端托管数据库。
显然 Esri 不是唯一的选择,但您的用例是一个完美的例子,说明了 不获取您不获取的整个数据集是有益的不打算展示。
您可以创建一个 arcgis developer account and then sign into arcgis.com 来免费上传您的 .geojson 文件作为新的托管服务。
您可以找到另一个提供类似功能的托管服务
您可以 运行 您自己的服务器,安装您自己的 PostGIS 数据库并自己连接空间网络查询。
您可以在页面加载时继续下载所有 19,000 个功能,并且:
a) 简化您的搜索并测试是否相关
L.latLngBounds.contains()
每个点。b) 使用类似 turf to test the relationship with an actual circle. (one caveat worth mentioning here is that leaflet doesn't include any built in methods for generating actual
L.circle
geometry so you'd need more custom logic for that too. i wrote something similar here 的东西,欢迎您使用。