Openlayers bbox策略

时间:2016-07-06 11:05:41

标签: openlayers-3

我有一个数据源的bbox策略。代码如下所示:

bbox: function newBboxFeatureSource(url, typename) {
    return new ol.source.Vector({
        loader: function (extent) {
            let u = `${url}&TYPENAME=${typename}&bbox=${extent.join(",")}`;

            $.ajax(u).then((response) => {
                this.addFeatures(
                    geoJsonFormat.readFeatures(response)
                );
            });
        },
        strategy: ol.loadingstrategy.bbox
    });
},

我工作得很好但是...当我平移/移动地图时,此加载器再次调用并添加适合新框的其他功能。但是有很多重复,因为一些新功能与旧功能相同。 所以我想在添加新功能之前首先使用this.clear()清除所有功能,但是当我添加此命令时, loader 一直在运行,我有"不定式循环"。你知道为什么吗?如何在调用this.clear()后禁用加载新功能?

编辑:

我对功能的回答如下:

  

{" type":" FeatureCollection"," crs":{" type":" name", "属性&#34 ;:   {" name":" urn:ogc:def:crs:EPSG :: 3857" },                                                                                    "功能":[{"类型":"功能","属性":{" ogc_fid":&# 34; 2&#34 ;,   "姓名":" AL" }," geometry":{" type":" MultiPolygon" ,"坐标":   [[[...]]]}},{"类型":"功能","属性":{" ogc_fid":   " 3","名称":" B" }," geometry":{" type":" MultiPolygon" ,   "坐标":[[[...]]]}} .....等等

我删除了坐标,因为它们太多了。

我的功能由mapserver生成,并在.map文件中配置,如下所示:

LAYER
    NAME "postcode_area_boundaries"
    METADATA
        "wfs_title"                 "Postcode area boundaries"
        "wfs_srs"                   "EPSG:3857"
        "wfs_enable_request"        "*"
        "wfs_getfeature_formatlist" "json"
        "wfs_geomtype"              "multipolygon"
        "wfs_typename"              "postcode_area_boundaries"
        "wms_context_fid"           "id"
        "wfs_featureid"             "id"
        "gml_featureid"             "id"
        "gml_include_items"         "id,postarea,wkb_geometry"
        "gml_postarea_alias"        "name"
        "ows_featureid"             "id"
        "tinyows_table"             "postcode_area_boundaries"
        "tinyows_retrievable"       "1"
        "tinyows_include_items"     "id,postarea,wkb_geometry"
    END
    TYPE POLYGON
    STATUS ON
    CONNECTIONTYPE POSTGIS
    CONNECTION "..."
    DATA "wkb_geometry FROM postcode_area_boundaries USING UNIQUE id"
    DUMP TRUE
END

1 个答案:

答案 0 :(得分:1)

总结讨论并回答最初的问题:

服务器发送的功能需要一个名为id的属性,该属性必须是唯一的,并且对于每个请求的功能都必须相同。

{type: "Feature", id: "some-wfs.1234", properties: { "ogc_fid": 2, ...

有关ahocevar的原始评论,请参阅this GitHub Issue

在GeoServer中,如果在图层中设置标识符,则可以实现此目的。 我想在MapServer中有类似的设置。