OpenLayers 6.15.1设置declutter:false后图标标签裁剪问题求解
OpenLayers 6.15.1点图层图标及标签被裁剪问题
我使用OpenLayers 6.15.1,需要在地图上展示一个点图层并设置declutter: false——因为不想让用户必须缩放才能发现存在更多要素。但最外侧的图标及其标签被裁剪了,该如何解决?
裁剪情况示例
- 图标下方裁剪:

- 图标右侧裁剪:

- 图标左上角裁剪:

我创建了一个可调试的示例,同时附上样式和图层代码:
样式代码
var size = 0; var placement = 'point'; var style_Civici = function(feature, resolution){ var context = { feature: feature, variables: {} }; var value = "" var labelText = ""; size = 0; var labelFont = "13.0px 'MS Shell Dlg 2', sans-serif"; var labelFill = "#e31a1c"; var bufferColor = "#ffffff"; var bufferWidth = 3.0; var textAlign = "left"; var offsetX = 8; var offsetY = 3; var placement = 'point'; if (feature.get("numcivico") !== null) { labelText = String(feature.get("numcivico")); } var style = [ new ol.style.Style({ image: new ol.style.Circle({radius: 4.0 + size, stroke: new ol.style.Stroke({color: 'rgba(35,35,35,1.0)', lineDash: null, lineCap: 'butt', lineJoin: 'miter', width: 0}), fill: new ol.style.Fill({color: 'rgba(227,26,28,0.9490196078431372)'})}), text: createTextStyle(feature, resolution, labelText, labelFont, labelFill, placement, bufferColor, bufferWidth) })]; return style; };
图层代码
var format_Civici = new ol.format.GeoJSON(); var features_Civici = format_Civici.readFeatures(json_Civici, {dataProjection: 'EPSG:4326', featureProjection: 'EPSG:25832'}); var jsonSource_Civici = new ol.source.Vector({ attributions: "<img src='styles/legend/Civici.png' /> <b>Civici</b>" }); jsonSource_Civici.addFeatures(features_Civici); var lyr_Civici = new ol.layer.Vector({ declutter: false, source:jsonSource_Civici, style: style_Civici, permalink: "Civici", popuplayertitle: "Civici", interactive: true, title: "<img src='styles/legend/Civici.png' /> Civici" }); var extent_Civici = jsonSource_Civici.getExtent(); lyr_Civici.setProperties('extent'); lyr_Civici.set('extent' , extent_Civici);
更新
删除图层中与extent相关的最后三行代码后,问题得以解决。请问如何在保留图层extent定义的同时,避免图标被裁剪?
内容的提问来源于stack exchange,提问作者andreaordonselli
相关产品推荐
相关产品推荐

