Openlayers實(shí)現(xiàn)擴(kuò)散的動(dòng)態(tài)點(diǎn)(水紋效果)
本文實(shí)例為大家分享了Openlayers實(shí)現(xiàn)擴(kuò)散的動(dòng)態(tài)點(diǎn)的具體代碼,供大家參考,具體內(nèi)容如下
在openlayers中制作危險(xiǎn)源標(biāo)識(shí)可以需要?jiǎng)討B(tài)擴(kuò)散的點(diǎn)(有很多種方法 可以加入jpg動(dòng)圖,也可以寫css動(dòng)畫) 這里提供一種思路用openlayer自帶的方法寫 并給予詳細(xì)的方法注釋供初學(xué)者學(xué)習(xí) (所有jar包都是在線的代碼可以復(fù)制過去直接用)
<!DOCTYPE html>
<html>
<head>
<title>Icon Symbolizer</title>
<link rel="stylesheet" rel="external nofollow" type="text/css">
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<link rel="stylesheet" rel="external nofollow" >
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
#map {
position: relative;
}
#popup {
cursor: pointer;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<div id="styleType">
</div>
<script>
//水紋擴(kuò)散
var bingMap = new ol.layer.Tile({
source :new ol.source.XYZ({
crossOrigin: 'anonymous',
url:'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}'
})
});
var map = new ol.Map({
layers: [bingMap],
target: 'map',
view: new ol.View({
center: ol.proj.transform([112.91, 28.21], 'EPSG:4326', 'EPSG:3857'),
zoom: 5
})
});
var source = new ol.source.Vector({
wrapX: false
});
var vector = new ol.layer.Vector({
source: source
});
map.addLayer(vector);
function addRandomFeature() {
var geom = new ol.geom.Point(ol.proj.fromLonLat([112.91, 28.21]));
var feature = new ol.Feature(geom);
source.addFeature(feature);
}
var duration = 1000;
function flash(feature) {
var start = new Date().getTime();
//進(jìn)行地圖水波渲染
var listenerKey = map.on('postcompose', animate);
function animate(event) {
//獲取幾何圖形
var vectorContext = event.vectorContext;
//獲取當(dāng)前渲染幀狀態(tài)
var frameState = event.frameState;
//添加一個(gè)OpenLayers.Geometry幾何對(duì)象
var flashGeom = feature.getGeometry().clone();
//渲染幀狀已占時(shí)間
var elapsed = frameState.time - start;
//已占比率
var elapsedRatio = elapsed / duration;
// radius半徑為5結(jié)束為30
var radius = ol.easing.easeOut(elapsedRatio) * 25 + 5;
//不透漸變消失
var opacity = ol.easing.easeOut(1 - elapsedRatio);
//Circle樣式
var style = new ol.style.Style({
image: new ol.style.Circle({
radius: radius,
stroke: new ol.style.Stroke({
color: 'rgba(255, 0, 0, ' + opacity + ')',
width: 1 + opacity
})
})
});
//給幾何圖形添加樣式
vectorContext.setStyle(style);
//將幾何體渲染到畫布中
vectorContext.drawGeometry(flashGeom);
if (elapsed > duration) {
start = frameState.time ;
;
}
//請(qǐng)求地圖渲染(在下一個(gè)動(dòng)畫幀處)
map.render();
}
}
//數(shù)據(jù)源添加圖層
source.on('addfeature', function(e) {
flash(e.feature);
});
addRandomFeature()
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS+CSS模擬可以無刷新顯示內(nèi)容的留言板實(shí)例
這篇文章主要介紹了JS+CSS模擬可以無刷新顯示內(nèi)容的留言板,涉及javascript操作dom元素、鼠標(biāo)事件及css樣式的技巧,需要的朋友可以參考下2015-03-03
JS腳本實(shí)現(xiàn)定時(shí)到網(wǎng)站上簽到/簽退功能
這篇文章主要介紹了JS腳本實(shí)現(xiàn)定時(shí)到網(wǎng)站上簽到/簽退功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
el-date-picker 如何限制選擇六個(gè)月內(nèi)的日期
這篇文章主要介紹了el-date-picker 如何限制選擇六個(gè)月內(nèi)的日期,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-07-07
詳解javascript腳本何時(shí)會(huì)被執(zhí)行
這篇文章主要介紹了詳解javascript腳本何時(shí)會(huì)被執(zhí)行,幫助大家更好的理解和使用JavaScript,感興趣的朋友可以了解下2021-02-02
js+html+css實(shí)現(xiàn)簡(jiǎn)單電子時(shí)鐘
這篇文章主要為大家詳細(xì)介紹了js+html+css實(shí)現(xiàn)簡(jiǎn)單電子時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
通過函數(shù)作用域和塊級(jí)作用域看javascript的作用域鏈
這篇文章給大家分享了通過函數(shù)作用域和塊級(jí)作用域看javascript的作用域鏈的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友參考學(xué)習(xí)下。2018-08-08
JavaScript數(shù)據(jù)結(jié)構(gòu)之雙向鏈表定義與使用方法示例
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)之雙向鏈表定義與使用方法,簡(jiǎn)單介紹了雙向鏈表的原理,并結(jié)合實(shí)例形式分析了雙向鏈表的定義與使用方法,需要的朋友可以參考下2017-10-10

