Openlayers实现扩散的动态点(水纹效果)

网络编程 2021-07-04 14:06www.168986.cn编程入门
这篇文章主要为大家详细介绍了Openlayers实现扩散的动态点,水纹效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Openlayers实现扩散的动态点的具体代码,供大家参考,具体内容如下

在openlayers中制作危险源标识可以需要动态扩散的点(有很多种方法 可以加入jpg动图,也可以写css动画) 这里提供一种思路用openlayer自带的方法写 并给予详细的方法注释供初学者学习 (所有jar包都是在线的代码可以复制过去直接用)

<!DOCTYPE html>
<html>
 <head>
  <title>Icon Symbolizer</title>
  <link rel="stylesheet" href="https://openlayers./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./en/v3.20.1/build/ol.js"></script>
  <script src="https://code.jquery./jquery-2.2.3.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn./bootstrap/3.3.6/css/bootstrap.min.css" rel="external nofollow" >
  <script src="https://maxcdn.bootstrapcdn./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://.google./maps/vt?lyrs=m@189&gl=&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('postpose', 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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by