Leaflet05波动的小图标(转载)

css代码:L.Icon.Pulse.css

.leaflet-pulsing-icon {
border-radius: 100%;
box-shadow: 1px 1px 8px 0 rgba(0,0,0,0.75);
}

.leaflet-pulsing-icon:after {
content: "";
border-radius: 100%;
height: 300%;
width: 300%;
position: absolute;
margin: -100% 0 0 -100%;

}

@keyframes pulsate {
0% {
transform: scale(0.1, 0.1);
opacity: 0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
50% {
opacity: 1;
-ms-filter: none;
filter: none;
}
100% {
transform: scale(1.2, 1.2);
opacity: 0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
}
js代码:L.Icon.Pulse.js
(function(window) {

L.Icon.Pulse = L.DivIcon.extend({

options: {
className: '',
iconSize: [12,12],
fillColor: 'red',
color: 'red',
animate: true,
heartbeat: 1,
},

initialize: function (options) {
L.setOptions(this,options);

// css

var uniqueClassName = 'lpi-'+ new Date().getTime()+'-'+Math.round(Math.random()*100000);

var before = ['font-weight:bold;">this.options.fillColor];
var after = [

'box-shadow: 0 0 6px 2px '+this.options.color,

'animation: pulsate ' + this.options.heartbeat + 's ease-out',
'animation-iteration-count: infinite',
'animation-delay: '+ (this.options.heartbeat + .1) + 's',
'position:absolute',
'left:0',
];

if (!this.options.animate){
after.push('animation: none');
after.push('box-shadow:none');
}

var css = [
'.'+uniqueClassName+'{'+before.join(';')+';}',
'.'+uniqueClassName+':after{'+after.join(';')+';}',
].join('');

var el = document.createElement('style');
if (el.styleSheet){
el.styleSheet.cssText = css;
} else {
el.appendChild(document.createTextNode(css));
}

document.getElementsByTagName('head')[0].appendChild(el);

// apply css class

this.options.className = this.options.className+' leaflet-pulsing-icon '+uniqueClassName;

// initialize icon

L.DivIcon.prototype.initialize.call(this, options);

}
});

L.icon.pulse = function (options) {
return new L.Icon.Pulse(options);
};


L.Marker.Pulse = L.Marker.extend({
initialize: function (latlng,options) {
options.icon = L.icon.pulse(options);
L.Marker.prototype.initialize.call(this, latlng, options);
}
});

L.marker.pulse = function (latlng,options) {
return new L.Marker.Pulse(latlng,options);
};

})(window);
页面引入
<link rel="stylesheet" href="Icon.Pulse/L.Icon.Pulse.css" />
<script src="Icon.Pulse/L.Icon.Pulse.js"></script>
var pulsingIcon = L.icon.pulse({iconSize:[20,20],color:'red'});
var marker = L.marker([41.509, 120],{icon: pulsingIcon}).addTo(map);

给一个连接:

https://blog.csdn.net/itas109/article/details/70054588

 

posted @ 2020-03-20 16:58  辛夷不改年年色  阅读(756)  评论(0)    收藏  举报