gpt4 book ai didi

leaflet - 单击传单中的脉动圆圈

转载 作者:行者123 更新时间:2023-12-01 21:59:25 24 4
gpt4 key购买 nike

我有一张传单 map 。我使用圆圈作为标记,因为我内置了一些缩放功能,并且我希望圆圈的半径在缩放过程中具有动画效果。不过,我也希望圆圈在被点击时“跳动”。我在网上看到很多关于脉动传单标记的文档,但没有关于脉动圆圈的文档。这里有一个简单的解决方案吗?

j查询:

var map = L.map('map').setView([40.449620, -79.939990], 13);

L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}{r}.{ext}', {
maxZoom: 19,
ext: 'png',
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'//,
}).addTo(map);

map.on('click', function(e) {
var currentZoom = map.getZoom();
if (currentZoom == 13) {
map.flyTo(e.latlng, 15, { //zoom in on click
animate: true,
duration: 1,
easeLinearity: 1
});
}
});
$.post('php/get-buildings.php', function(output){
var obj = jQuery.parseJSON( output );

var color;

customCircle = L.Circle.extend({
options: {
//some more options here
}
});

for (var i=0; i<obj.length; i++) {

if (obj[i].there_2017 == 'No') {
color = '#000';
} else {
color = '#1565C0';
}
//var circle = L.circle([obj[i].lat,obj[i].lng], {
var circle = new customCircle([obj[i].lat,obj[i].lng], {
color: '#000',
weight: 0.5,
fillColor: color,
fillOpacity: 1,
borderWidth: 2,
radius: 40,
//some more properties
}).addTo(map).on("click", circleClick);

function circleClick(e) {
var clickedCircle = e.target;
clickedCircle.setStyle({'weight': '3'}); want to animate this
}

}//end for
});

最佳答案

拥有脉动圆圈标记的解决方案是使用 divIcon并使用 CSS 创建您喜欢的脉动标记。

js代码:

    const generatePulsatingMarker = function (radius, color) {
const cssStyle = `
width: ${radius}px;
height: ${radius}px;
background: ${color};
color: ${color};
box-shadow: 0 0 0 ${color};
`
return L.divIcon({
html: `<span style="${cssStyle}" class="pulse"/>`,
// empty class name to prevent the default leaflet-div-icon to apply
className: ''
})
}

const pulsatingIcon = generatePulsatingMarker(10, 'red');
L.marker([51.497, -0.09], {icon: pulsatingIcon}).addTo(map);

和 CSS 脉动标记:

    .pulse {
display: block;
border-radius: 50%;
cursor: pointer;
animation: pulse 2s infinite;
}

@keyframes pulse {
0% {
-moz-box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.4);
box-shadow: 0 0 0 0;
}
70% {
-moz-box-shadow: 0 0 0 10px rgba(0, 0, 0, 0);
box-shadow: 0 0 0 10px rgba(0, 0, 0, 0);
}
100% {
-moz-box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
}

fiddle 示例 here

此外,如果您希望标记仅在单击时发出脉冲,请在单击事件上添加相应的“脉冲”css 类。

关于leaflet - 单击传单中的脉动圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54240788/

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