我将值传递给函数addPolyline(props)以动态更改路径值和颜色
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4,
strokeWeight: 2,
};
function addPolyline(props){
flightPath = new google.maps.Polyline({
path: props.flightPath,
geodesic: true,
strokeColor: props.color,
strokeOpacity: 0,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '20px'
}]
});
}
addPolyline({
flightPath: flightPlanCoordinates,
color: "#f9a61e"
});
但是我如何更改lineSymbol内部的不透明度,但在addPolyline中作为图标键的一部分调用。
答案 0 :(得分:1)
您只需使用props
初始化lineSymbol中的值即可传递所需的值
function addPolyline(props){
lineSymbol.strokeOpacity = props.symbolOpacity;
flightPath = new google.maps.Polyline({
...
或者,如果您不想修改全局lineSymbol
function addPolyline(props){
var symbol = Object.assign({}, lineSymbol)
symbol.strokeOpacity = props.symbolOpacity;
flightPath = new google.maps.Polyline({
...
icons: [{
icon: symbol,
并使用
调用addPolyline({
flightPath: flightPlanCoordinates,
color: "#f9a61e",
symbolOpacity: 0.8
});