我试图在选择具有 ol.style.Style 样式的点几何时不查询,其中在某些情况下配置 ol.style.Icon,在其他情况下配置 ol.style.FontSymbol
ol.style.Icon 示例https://www.opengis.it/ente/demo/styles/StruttureSensibili_style.js
ol.style.FontSymbol 示例https://www.opengis.it/a_opengis/opengis_fontsymbol.js
我写了这段代码,怎么不行?
// Function to check if a feature has FontSymbol or Icon style
function hasFontSymbolOrIconStyle(feature) {
var styles = feature.getStyle();
if (Array.isArray(styles)) {
return styles.some(function(style) {
var image = style.getImage();
return (
(style instanceof ol.style.Style &&
(image instanceof ol.style.FontSymbol ||
image instanceof ol.style.Icon)) ||
image instanceof ol.style.FontSymbol ||
image instanceof ol.style.Icon
);
});
}
return false;
}
// Feature Popup Select interaction
var popupselect = new ol.interaction.Select({
hitTolerance: 5,
multi: true,
condition: ol.events.condition.singleClick,
style: function(feature, resolution) {
if (hasFontSymbolOrIconStyle(feature)) {
// Return null to use the default style for point geometries with FontSymbol or Icon style
return null;
} else {
// Apply the highlightPopupStyle for other geometries
return highlightPopupStyle;
}
}
});
map.addInteraction(popupselect);