作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在这段代码中用虚线更改黑线,或者如何设置 line: 的 opacity:0
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 20.291, lng: 153.027},
zoom: 6,
mapTypeId: 'terrain'
});
var lineSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#393'
};
property.
var line = new google.maps.Polyline({
path: [{lat: 22.291, lng: 153.027}, {lat: 18.291, lng: 153.027}],
icons: [{
icon: lineSymbol,
offset: '100%'
}],
map: map
});
animateCircle(line);
}
// Use the DOM setInterval() function to change the offset of the symbol
// at fixed intervals.
function animateCircle(line) {
var count = 0;
window.setInterval(function() {
count = (count + 1) % 200;
var icons = line.get('icons');
icons[0].offset = (count / 2) + '%';
line.set('icons', icons);
}, 20);
}
</script>
这是谷歌地图的引用: google maps sample
如何用虚线更改该线
最佳答案
将 lineSymbol
的 linesOpacity
设置为 1(或大于 0)。
var lineSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#393',
strokeOpacity: 1
};
代码片段:
// This example adds an animated symbol to a polyline.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: 20.291,
lng: 153.027
},
zoom: 6,
mapTypeId: 'terrain'
});
// Define the symbol, using one of the predefined paths ('CIRCLE')
// supplied by the Google Maps JavaScript API.
var lineSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#393',
strokeOpacity: 1,
};
// Define a symbol using SVG path notation, with an opacity of 1.
var dashedLineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4
};
// Create the polyline and add the symbol to it via the 'icons' property.
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: '100%'
}, {
icon: dashedLineSymbol,
offset: '0',
repeat: '20px'
}],
map: map
});
animateCircle(line);
}
// Use the DOM setInterval() function to change the offset of the symbol
// at fixed intervals.
function animateCircle(line) {
var count = 0;
window.setInterval(function() {
count = (count + 1) % 200;
var icons = line.get('icons');
icons[0].offset = (count / 2) + '%';
line.set('icons', icons);
}, 20);
}
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>
关于javascript - 谷歌地图 :adds an animated symbol to a polyline with dotted line set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407614/
我是一名优秀的程序员,十分优秀!