在 Openlayers 中,可以根据缩放级别打开或关闭某些功能。尽管查看了文档,但我在 OpenLayers 3 中没有找到相同的功能。有谁知道如何做到这一点?这是我放置在地图上的功能ol.style.Text
是我只想在用户放大到特定缩放级别后才显示的内容。
var geoJsonObj = {
'type': 'Feature',
'geometry': JSON.parse(response.FieldList[key].Shape)
}
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geoJsonObj)
});
Fields[Field.FieldID] = new ol.layer.Vector({
projection: 'EPSG:4269',
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'yellow',
width: 1
}),
fill: new ol.style.Fill({
color: rcisWebMapUtilities.convertHex(response.FieldList[key].Shade, '0.5')
}),
text: new ol.style.Text({
textAlign: 'Center',
text: response.FieldList[key].Acres,
scale: 1
})
})
});
矢量层示例演示了如何使用样式函数来实现与分辨率相关的样式:http://openlayers.org/en/latest/examples/vector-layer.html http://openlayers.org/en/latest/examples/vector-layer.html
这是一个简化版本:
var layer = new ol.layer.Vector({
source: new ol.source.Vector(),
style: function(feature, resolution) {
var text = resolution < 5000 ? feature.get('name') : '';
return new ol.style.Style({
text: new ol.style.Text({
text: text,
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#f00',
width: 3
})
})
});
}
});
上面的层将渲染特征name
分辨率低于每像素 5000 个地图单位。
上面的矢量图层示例有一些额外的代码,可以在可能的情况下重用样式。如果您有大量功能,则可以通过为每个渲染帧创建新的样式实例来给垃圾收集器施加过大的压力。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)