亲宝软件园·资讯

展开

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

RNG_Never give up 人气:0
想了解Openlayers实现扩散的动态点(水纹效果)的相关内容吗,RNG_Never give up在本文为您仔细讲解Openlayers扩散的动态点的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:openlayers扩散动态点,openlayers水纹,openlayers动态点,下面大家一起来学习吧。

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

<!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>

加载全部内容

相关教程
猜你喜欢
用户评论