首页 > 解决方案 > GeoJSON 源的 OpenLayers 过滤器

问题描述

我在一个简单的 html/javascript/jquery 项目上使用 OpenLayers (v6.3.1) 和ol-ext扩展(处理动画集群)。

我成功地显示了来自 geojson 的数据,并将矢量源传递给集群源,然后添加到图层中。我现在的目标是向地图上显示的 geojson 字段添加/删除过滤器(通过用户交互)。

矢量/簇源和簇层的代码:

const clusterSource = new ol.source.Cluster({
    distance: 40,
    source: new ol.source.Vector({
        url: `${URL_PATH}`,
        format: new ol.format.GeoJSON(),
    })
});

const clusterLayer = new ol.layer.AnimatedCluster({
    name: 'Cluster',
    source: clusterSource,
    animationDuration: $("#animatecluster").prop('checked') ? 700 : 0,
    // Cluster style
    style: getStyle
});

我被困在过滤部分:我应该过滤特征数组并替换我的图层的源吗?或者有没有更简单的方法来使用 Openlayers?

谢谢你的帮助!

标签: javascriptopenlayersgeojsonopenlayers-6

解决方案


推荐阅读