Javascript 如何在Google Maps v3 api中绘制端点处带有箭头的虚线多段线?
我想画一条末端带有箭头的虚线多段线。问题是,strokeOpacity似乎要在图标数组中显示,但虚线的值必须为0,而绘制箭头的值必须为正值。有办法解决这个问题吗 下面是一个例子,说明了这一困境: 关键代码是javascript:Javascript 如何在Google Maps v3 api中绘制端点处带有箭头的虚线多段线?,javascript,google-maps,Javascript,Google Maps,我想画一条末端带有箭头的虚线多段线。问题是,strokeOpacity似乎要在图标数组中显示,但虚线的值必须为0,而绘制箭头的值必须为正值。有办法解决这个问题吗 下面是一个例子,说明了这一困境: 关键代码是javascript: // This example converts a polyline to a dashed line, by // setting the opacity of the polyline to 0, and drawing an opaque symbol // a
// This example converts a polyline to a dashed line, by
// setting the opacity of the polyline to 0, and drawing an opaque symbol
// at a regular interval on the polyline.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: 20.291, lng: 153.027},
mapTypeId: 'terrain'
});
// Define a symbol using SVG path notation, with an opacity of 1.
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4
};
var arrowSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
strokeColor: 'red'
}
// Create the polyline. If strokeOpacity is 0, the dashedLine shows.
// If strokeOpacity is 1, the arrow shows.
// How to show both?
var line = new google.maps.Polyline({
path: [{lat: 22.291, lng: 153.027}, {lat: 18.291, lng: 153.027}],
strokeOpacity: 0,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '20px',
strokeOpacity: 1
},
{
icon: arrowSymbol,
offset: '100%',
strokeOpacity: 1,
strokeColor: 'black'
}
],
map: map
});
}
在箭头符号上设置不透明度:
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
offset: '100%',
fillColor: "black",
fillOpacity: 1,
strokeOpacity: 1,
}
代码片段:
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:6,
中心:{
拉脱维亚:20.291,
液化天然气:153.027
},
mapTypeId:'地形'
});
变量lineSymbol={
路径:“M 0,-1 0,1”,
频闪不透明度:1,
比例:4
};
var line=新的google.maps.Polyline({
路径:[{
拉脱维亚:22.291,
液化天然气:153.027
}, {
拉脱维亚:18.291,
液化天然气:153.027
}],
笔划不透明度:0,
图标:[{
图标:lineSymbol,
偏移量:“0”,
重复:“20px”
}, {
图标:{
路径:google.maps.SymbolPath.FORWARD\u CLOSED\u箭头,
抵销:“100%”,
填充颜色:“黑色”,
不透明度:1,
频闪不透明度:1,
}
}],
地图:地图
});
}
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,
身体{
身高:100%;
保证金:0;
填充:0;
}
设置箭头符号的不透明度:
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
offset: '100%',
fillColor: "black",
fillOpacity: 1,
strokeOpacity: 1,
}
代码片段:
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:6,
中心:{
拉脱维亚:20.291,
液化天然气:153.027
},
mapTypeId:'地形'
});
变量lineSymbol={
路径:“M 0,-1 0,1”,
频闪不透明度:1,
比例:4
};
var line=新的google.maps.Polyline({
路径:[{
拉脱维亚:22.291,
液化天然气:153.027
}, {
拉脱维亚:18.291,
液化天然气:153.027
}],
笔划不透明度:0,
图标:[{
图标:lineSymbol,
偏移量:“0”,
重复:“20px”
}, {
图标:{
路径:google.maps.SymbolPath.FORWARD\u CLOSED\u箭头,
抵销:“100%”,
填充颜色:“黑色”,
不透明度:1,
频闪不透明度:1,
}
}],
地图:地图
});
}
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,
身体{
身高:100%;
保证金:0;
填充:0;
}
请提供一份说明您的问题的报告。请提供一份说明您的问题的报告。