gpt4 book ai didi

javascript - 矢量特征渲染

转载 作者:行者123 更新时间:2023-12-02 20:12:51 25 4
gpt4 key购买 nike

在 OpenLayers 中,我有一个 LineFeature 对象。

我更改对象的样式(例如 my_line.style.StrokeColor="Black")。

但是在我放大/缩小(即重新渲染)之前,屏幕上的颜色不会改变。

如何判断需要重新渲染的矢量特征?

最佳答案

更改样式后,尝试在包含该要素的矢量图层上调用 redraw() 方法。

更新:如果不想重绘整个图层,您可以尝试drawFeature()方法。如果您查看它的代码,您可能会更好地了解它是如何工作的:

/**
* APIMethod: drawFeature
* Draw (or redraw) a feature on the layer. If the optional style argument
* is included, this style will be used. If no style is included, the
* feature's style will be used. If the feature doesn't have a style,
* the layer's style will be used.
*
* This function is not designed to be used when adding features to
* the layer (use addFeatures instead). It is meant to be used when
* the style of a feature has changed, or in some other way needs to
* visually updated *after* it has already been added to a layer. You
* must add the feature to the layer for most layer-related events to
* happen.
*
* Parameters:
* feature - {<OpenLayers.Feature.Vector>}
* style - {String | Object} Named render intent or full symbolizer object.
*/
drawFeature: function(feature, style) {
// don't try to draw the feature with the renderer if the layer is not
// drawn itself
if (!this.drawn) {
return;
}
if (typeof style != "object") {
if(!style && feature.state === OpenLayers.State.DELETE) {
style = "delete";
}
var renderIntent = style || feature.renderIntent;
style = feature.style || this.style;
if (!style) {
style = this.styleMap.createSymbolizer(feature, renderIntent);
}
}

var drawn = this.renderer.drawFeature(feature, style);
//TODO remove the check for null when we get rid of Renderer.SVG
if (drawn === false || drawn === null) {
this.unrenderedFeatures[feature.id] = feature;
} else {
delete this.unrenderedFeatures[feature.id];
};
}

关于javascript - 矢量特征渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6750519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com