Openlayers 3 Openlayers bbox策略

Openlayers 3 Openlayers bbox策略,openlayers-3,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(

我有一个数据源的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
    });
},
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
我工作很好,但是。。。当我平移/移动地图时,此加载程序将再次调用,并添加适合新框的其他功能。但是,由于一些新功能与旧功能完全相同,因此存在大量重复。 因此,我想在添加新功能之前,首先使用
this.clear()
清除所有功能,但当我添加此命令时,加载程序一直在运行,我有“无限循环”。你知道为什么吗?调用
this.clear()
后,如何禁用加载新功能

编辑:

我的功能响应如下所示:

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
    });
},
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
{“类型”:“功能集合”,“crs”:{“类型”:“名称”,“属性”: {“name”:“urn:ogc:def:crs:EPSG::3857”}, “功能”:[{“类型”:“功能”,“属性”:{“ogc_fid”:“2”, “名称”:“AL”},“几何体”:{“类型”:“多多边形”,“坐标”: [[…]]},{“类型”:“特征”,“属性”:{“ogc_fid”: “3”,“名称”:“B”},“几何体”:{“类型”:“多多边形”, “坐标”:[[…]]}}…..等等

我删除了坐标,因为坐标太多了

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

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
    });
},
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

总结讨论并回答初始问题:

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

{type: "Feature", id: "some-wfs.1234", properties: { "ogc_fid": 2, ...
有关ahocevar的原始注释,请参见

在GeoServer中,如果在图层中设置标识符,则可以实现这一点。
我想这与MapServer中的设置类似。

您的功能上有唯一的ID吗?如果您从地理服务器或任何服务器获取功能,请检查它们是否有唯一的ID,如果没有,请在服务器上创建唯一的ID,问题应该会消失。此外,使用url函数而不是加载程序进行排序。@pavlos我继承了此c由以前的开发人员编写的ode。将加载程序更改为url函数并不能解决问题。关于唯一ID:我已经更新了我的问题并添加了功能响应的示例。我在db中有一个唯一的列,名为
ogc_fid
。您是否能够将
ogc_fid
切换为仅
fid
?@pavlos要执行此操作,我必须更改很多js代码…也有隐藏的逻辑。但好吧,我会试试。谢谢你的回答。我会让你知道当我这样做:)只需在数据库中添加一个名为
fid
的新列,用
ogc_fid
填充它,然后在你的地理服务器上重新加载。祝你好运