本文实例为大家分享了Openlayers实现扩散的动态点的具体代码,供大家参考,具体内容如下
在openlayers中制作危险源标识可以需要动态扩散的点(有很多种方法 可以加入jpg动图,也可以写css动画) 这里提供一种思路用openlayer自带的方法写 并给予详细的方法注释供初学者学习 (所有jar包都是在线的代码可以复制过去直接用)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<!DOCTYPE html> < html > < head > < title >Icon Symbolizer</ title > < link rel = "stylesheet" href = "https://openlayers.org/en/v3.20.1/css/ol.css" 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" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" 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 > //水纹扩散 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(); //进行地图水波渲染 var listenerKey = map.on('postcompose', animate); function animate(event) { //获取几何图形 var vectorContext = event.vectorContext; //获取当前渲染帧状态 var frameState = event.frameState; //添加一个OpenLayers.Geometry几何对象 var flashGeom = feature.getGeometry().clone(); //渲染帧状已占时间 var elapsed = frameState.time - start; //已占比率 var elapsedRatio = elapsed / duration; // radius半径为5结束为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 ; ; } //请求地图渲染(在下一个动画帧处) map.render(); } } //数据源添加图层 source.on('addfeature', function(e) { flash(e.feature); }); addRandomFeature() </ script > </ body > </ html > |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_40482342/article/details/102493353