在一個WebGIS系統中每每要實現圖形的切換,好比業務圖層的切換,以及底圖的切換等等,能夠經過控制圖層的可見性來實現。好比經過設置圖層的opacity 、visible來控制,前幾天有網友聊天的時候提了一個這樣的需求若是在地圖切換的時候添加一個過渡效果,以致於變化的效果不顯得生硬。寫面說一下個人實現思路。
先看一下效果吧 Demo連接 css
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" > <style> html, body, #map { width: 100%; height: 100%; margin: 0; padding: 0; overflow-y:hidden; background-color: #DBD7D0;; font-family: "Trebuchet MS"; } </style> <title> </title> </head> <body> <div id="map"> <button id="switchbasemap" style="position: absolute;z-index: 1;left: 100px;top: 20px;height: 30px;">切換底圖</button> </div> </body> <script src="http://js.arcgis.com/3.7/"></script> <script src="app.js"></script> </html>
關鍵代碼以下(具體代碼請下載完整的代碼 地址:http://codepen.io/kunkun/share/zip/xsiub )html
basefx.animateProperty({ node: colorfullbasemapdiv, duration:1000, properties: { opacity: 0 }, onEnd:function(){ colorfullbasemapdiv.style.display="none"; graybasemapdiv.style.display="block"; basefx.animateProperty({ duration:1000, node: graybasemapdiv, properties: { opacity: 1 } }).play(); } }).play();
總結:經過控制包裹圖層的div來實現效果的漸變,經過這種方式還能夠給地圖添加一個濾鏡的功能,經過獲取map的div 設置相應的CSS 熟悉便可。根據這種思想的指導,在之後開發中,若是碰到API不支持的工功能,能夠試試這種這種控制原生的html來解決。
node