我有一个 Mapbox 圆形图层,我需要更改圆形的半径,但 setPaintProperty 方法似乎不起作用。该图层最初显示:
map.addLayer({
"id": "circleCurrentGpsCircle",
"type": "circle",
"source": "source_circleCurrentGpsCircle",
"paint": {
"circle-radius": {
stops: [
[0, 0],
[22, metersToPixelsAtMaxZoom(gpsAccuracyWidth, currentLatitude)]
],
base: 2
},
"circle-color": self.props.senData.gpsCircleShading ? "#FFFF00" : "transparent",
"circle-opacity": 0.3,
"circle-stroke-width": 3,
"circle-stroke-color": "#FFFF00"
}
});
然后我调用以下命令来更改圆的半径:
var radiusData = {
stops: [
[0, 0],
[22, metersToPixelsAtMaxZoom(gpsAccuracyWidth, currentLatitude)]
],
base: 2
};
this.map.getLayer('circleCurrentGpsCircle').setPaintProperty('circle-radius', radiusData);
但圆圈并没有改变。我在控制台中没有收到任何错误。
最佳答案
通常,人们会在 map
对象本身而不是图层上调用 setPaintProperty
:
this.map.setPaintProperty('circleCurrentGpsCircle', '圆半径', radiusData);
我从未注意到返回的图层对象上的 setPaintProperty()
方法,但在我的简短测试中,它似乎对我也不起作用。
(实际上,经过一些进一步的测试,似乎通过该函数设置的值确实被记录在某处,并且当您稍后调用 map.setPaintProperty()
时,所有这些值现在都会显示出来。但这对你没有帮助 - 只需将行更改为我上面提供的内容即可。)
关于javascript - 圆半径的 Mapbox setPaintProperty 未更新图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57152742/