Openlayers 3 openlayers 3 featureKey存在于FeatureChangeKey中
我有一个Openlayers 3 openlayers 3 featureKey存在于FeatureChangeKey中,openlayers-3,Openlayers 3,我有一个ol.interaction。选择ol.source.Vector作用于ol.layer.Vector中的ol.source.Vector。我可以很好地选择和取消选择各个国家。我正在使用dragbox选择多个国家/地区。如果我选择“倍增选定国家”之外的任何位置,则当前选定的将取消选中。好极了 但是,问题是,如果我在倍数中选择了当前选定的国家/地区,我会得到断言Error:Assertion failed:featureKey存在于FeatureChangeKey中 这是我的矢量层: _c
ol.interaction。选择ol.source.Vector
作用于ol.layer.Vector
中的ol.source.Vector。我可以很好地选择和取消选择各个国家。我正在使用dragbox选择多个国家/地区。如果我选择“倍增选定国家”之外的任何位置,则当前选定的将取消选中。好极了
但是,问题是,如果我在倍数中选择了当前选定的国家/地区,我会得到断言Error:Assertion failed:featureKey存在于FeatureChangeKey中
这是我的矢量层:
_countrySelectSource = new ol.source.Vector({
url: 'vendor/openlayers/geojson/countries.json',
format: new ol.format.GeoJSON()
});
var countryLayer = new ol.layer.Vector({
title: 'Country Select',
visible: true,
type: 'interactive-layers',
source: _countrySelectSource
});
我将countryLayer添加到地图中,\u map
然后,我创建一个_CountrySelect对象,允许我在与我的国家选择相关的交互上设置active(true | false)
_CountrySelect = {
init : function(){
this.select = new ol.interaction.Select();
_map.addInteraction(this.select);
this.dragbox = new ol.interaction.DragBox({
condition: ol.events.condition.platformModifierKeyOnly
});
_map.addInteraction(this.dragbox);
this.setEvents();
},
setEvents: function(){
var selectedFeatures = this.select.getFeatures();
var infoBox = document.getElementById('info');
var selfDragbox = this.dragbox;
selfDragbox.on('boxend', function() {
// features that intersect the box are added to the collection of
// selected features, and their names are displayed in the "info"
// div
var extent = selfDragbox.getGeometry().getExtent();
_countrySelectSource.forEachFeatureIntersectingExtent(extent, function(feature) {
selectedFeatures.push(feature);
_countryCodes.push(feature.getId());
});
infoBox.innerHTML = _countryCodes.join(', ');
});
// clear selection when drawing a new box and when clicking on the map
selfDragbox.on('boxstart', function() {
selectedFeatures.clear();
infoBox.innerHTML = ' ';
});
_map.on('singleclick', function(event) {
selectedFeatures.clear();
_countryCodes = [];
_map.forEachFeatureAtPixel(event.pixel,function(feature){
selectedFeatures.push(feature);
var id = feature.getId();
var index = _countryCodes.indexOf(id);
if ( index === -1 ) {
_countryCodes.push(feature.getId());
}
});
infoBox.innerHTML = _countryCodes.join(', ');
});
},
setActive: function(active){
this.select.setActive(active);
this.dragbox.setActive(active);
}
};
_CountrySelect.init();
我不确定这是否是OL3或我的代码的问题。也许有件事我没有处理?可能是ol.interaction.DragBox(在DragBox上研究没有运气)。让我知道我能提供什么进一步的信息 看看它是否有帮助。@JonatasWalker,我在谷歌搜索这类断言错误时也发现了这一点。然而,我不认为我的问题是相同的。至少,我从那个问题上看不出任何线索。@westandy你能解决这个问题吗?我目前也面临着这个问题之王,在互联网上找不到任何帮助……不过,我发现了我的问题:我的功能列表中有两个相同的id。@Shimrod-我仍然没有找到解决这个问题的方法。如果你认为你的解决方案解决了这个问题,请把它写出来。看看它是否有帮助。@JonatasWalker,我在谷歌搜索这种类型的断言错误时也发现了这一点。然而,我不认为我的问题是相同的。至少,我从那个问题上看不出任何线索。@westandy你能解决这个问题吗?我目前也面临着这个问题之王,在互联网上找不到任何帮助……不过,我发现了我的问题:我的功能列表中有两个相同的id。@Shimrod-我仍然没有找到解决这个问题的方法。如果你认为你的解决方案解决了这个问题,请写出来。