1. 程式人生 > >【資料視覺化】 D3+ArcGIS 遷徙圖實現

【資料視覺化】 D3+ArcGIS 遷徙圖實現

概述

用D3和ArcGIS結合做效果已經將近一年的時間,卻一直沒有時間整理部落格,將知識分享,終於,我的第一遍部落格將迎來了。

效果圖

效果圖

具體流程

1.svg疊合ArcGIS Server釋出的地圖服務疊加展示,在ArcGIS Server的地圖中有一個svg標籤可以供D3來繪製。

var poitMoveSvg = d3.select("#" + map.id + "_gc")

2.用svg的animateMotion標籤來建立path路徑,達到小圓圓的按照路徑移動效果

g.append("circle")
  .attr("r", 5)
   .attr("fill"
, colorArr[2]) .append('animateMotion') .attr('path', path) .attr('rotate', "auto") .attr('dur', "10s") .attr('repeatCount', "indefinite");

rotate:auto自動旋轉方向
dur:路徑執行完成時間
repeatCount:重複次數

3.svg的pauseAnimations與unpauseAnimations屬性控制斷點可以繼續運動,保證縮放和平移可以不出現間斷

/讓動畫時間停止
document.getElementById
("d3_svg").pauseAnimations() //開始動畫 document.getElementById("d3_svg").unpauseAnimations()

4.新增地圖縮放和平移事件,重新整理資料進行更新

if (zoomEvent_e == null) {
    zoomEvent_e = map.on("zoom-end", mig1);
}
if (zoomEvent_s == null) {
    zoomEvent_s = map.on("zoom-start", d3Clear);
}
if (panEvent_e == null) {
    panEvent_e =
map.on("pan-end", mig1); } if (panEvent_s == null) { panEvent_s = map.on("pan-start", d3Clear); }

5.點移動原始碼,僅供參考

/清除按鈕,清除事件
    function clearClick() {
        zoomEvent_s.remove()
        zoomEvent_e.remove()
        panEvent_s.remove()
        panEvent_e.remove()
        zoomEvent_s = null;
        zoomEvent_e = null;
        panEvent_s = null;
        panEvent_e = null;
        d3.selectAll("#pointMove").remove();
        d3.selectAll("#d3_svg").remove();
    }


    //----------------------------------分割--------------------------------------------
    //點移動
    var migData1 = [
        [{
            x: 110.85099,
            y: -74.25962166
        }, {
            x: 134.537944,
            y: -99.363874
        }],
        [{
            x: 30.98670782,
            y: -60.99922008
        }, {
            x: 30.98670782,
            y: -51.998
        }, {
            x: 84.678,
            y: -53.744
        }, {
            x: 85.101,
            y: -56.739
        }],
        [{
            x: 30.98670782,
            y: -60.99922008
        }, {
            x: 30.98670782,
            y: -50.998
        }, {
            x: 84.678,
            y: -52.744
        }, {
            x: 93.25,
            y: -40.759
        }]
    ];

    function d3Clear() {
        d3.selectAll("#pointMove").remove();
    }

    function play() {
        //        給svg標籤transform屬性,讓svg沒有偏移
        var poitMoveSvg = d3.select("#" + map.id + "_gc")
            .attr("class", "svgTransform")
            .append("svg")
            .attr("id", "d3_svg");
        mig1()

        function mig1() {
            d3.selectAll("#pointMove").remove();
            //讓動畫時間停止
            document.getElementById("d3_svg").pauseAnimations()
            if (zoomEvent_e == null) {
                zoomEvent_e = map.on("zoom-end", mig1);
            }
            if (zoomEvent_s == null) {
                zoomEvent_s = map.on("zoom-start", d3Clear);
            }
            if (panEvent_e == null) {
                panEvent_e = map.on("pan-end", mig1);
            }
            if (panEvent_s == null) {
                panEvent_s = map.on("pan-start", d3Clear);
            }
            //將資料變為螢幕座標
            for (var i = 0; i < migData1.length; i++) {
                screenData = [];
                for (var index = 0; index < migData1[i].length; index++) {
                    screenData.push(map.toScreen(migData1[i][index]));
                }

                g = d3.select("#d3_svg")
                    .append("g")
                    .attr("id", "pointMove");
                //迴圈軌跡每一點生成path
                var path = ''
                for (var j = 0; j < screenData.length; j++) {
                    path += j == 0 ? ('M' + screenData[j].x + ',' + screenData[j].y) : ('L' + screenData[j].x + ',' +
                        screenData[j].y)
                }
                g.append("path")
                    .attr("d", path)
                    .attr("stroke", colorArr[0]) //顏色
                    .attr("fill", "none")
                    .attr("stroke-width", "2");
                g.append("circle")
                    .attr("r", 5)
                    .attr("fill", colorArr[2])
                    .append('animateMotion')
                    .attr('path', path)
                    .attr('rotate', "auto")
                    .attr('dur', "10s")
                    .attr('repeatCount', "indefinite");
                //開始動
                document.getElementById("d3_svg").unpauseAnimations()
            }
        }
    }    

原文連結

型別 內容
qq 1004740957
公眾號 lzugis15
e-mail [email protected]
webgis群 1004740957
Android群 337469080
GIS資料視覺化群 458292378

LZUGIS

相關推薦

資料視覺 D3+ArcGIS 遷徙實現

概述 用D3和ArcGIS結合做效果已經將近一年的時間,卻一直沒有時間整理部落格,將知識分享,終於,我的第一遍部落格將迎來了。 效果圖 具體流程 1.svg疊合ArcGIS Server釋出的地圖服務疊加展示,在ArcGIS Server的地

資料視覺25個即時改進資料視覺設計的技巧

資料視覺化不是關於顯示資料; 它是以更容易理解的方式顯示資料 - 這就是真正的價值所在。如果你想真正“看到”我們的意思,請看一下這個快速視訊: 視訊地址:https://vimeo.com/29684853 不幸的是,很多人認為將幾張圖表放在一起意味著您正在進行資料視覺

資料視覺地理資訊視覺應用

1 地球與生存環境         人類長期以來對地球和周遭自然環境進行觀測來研究和了解自己生存的自然空間,科學家們也通過建立數學模型來模擬環境的變化。這些觀測和模擬得到的資料通常包含了地理空間中的位置資訊,因此自然需要用到地理資訊視覺化來呈現資料,最常見的是與氣象相關的資

資料視覺可放縮可拖拽畫布的力導向

效果: 拖拽並縮小後: 1、確認主次 以力導向圖為藍本 2、增加縮放控制變數 var transform = d3.zoomIdentity; 3、響應放縮事件 d3.select(canvas) .call(

資料視覺echarts繪製帶有點選事件的圖表

<script type="text/javascript"> //基於準備好的dom,初始化echarts例項 var myChart = echart

資訊視覺使用D3實現的中科院院士姓氏首字母分佈視覺

   Figure 1: The overview of the visualization. Figure 2: the distribution of the first letter in one aca

推薦好輪子Echarts資料視覺圖表外掛 相容ie6、7、8

前幾天在網上找一些圖表外掛,無意間發現的一個外掛,開源來自百度商業前端資料視覺化團隊。簡單的貼一些他的簡介:官網:http://echarts.baidu.com/echarts2/index.html介紹ppt:http://echarts.baidu.com/echart

python 資料視覺pyecharts的使用

Echarts是百度出的很有名 也很叼。 Echarts 是百度開源的一個數據視覺化 JS 庫。主要用於資料視覺化。 pyecharts 是一個用於生成 Echarts 圖表的類庫。實際上就是 Echarts 與 Python 的對接。 安裝:

coco資料視覺檢視影象和mask

import os import sys import cv2 import numpy as np import imgaug # Download and install the Python COCO tools from https://github.com/w

資訊視覺網路輿情監控系統創意視覺設計

 Figure 1: An overview of my visualization design. Figure 2: The mouseover event of the picture on the curve.

互動式資料視覺D3.js(四)形狀生成器

形狀生成器 線段生成器 var linePath = d3.line() - 使用預設的設定構造一個 line 生成器。 linePath.x() - 如果指定了 x 則將 x 訪問器設定為指定的函式或數值並返回當前 line 生成器。如果沒有指定 x 則返回當前 x 訪問器,預設為: functi

演算法視覺第一章 Java GUI程式設計基礎

1.1 使用JFrame import javax.swing.*; import java.awt.*; public class Main { public static void main(String[] args) { EventQu

資料視覺D3.js

資料視覺化 資料視覺化是如何把資料更好的展現出來的一個課題,在大資料出現後,它變得更為重要和迫切。 以前使用excel進行柱狀圖、餅狀圖、折線圖等是最常用的資料視覺化手段之一,而在WEB端,使用流行的extjs、fusioncharts、jfreechart

python 視覺pyecharts + Django 使用指南

本指南按照 Django 官方教程,通過完成一個 Django 小專案來說明如何在 Django 中使用 pyecharts。如果對 Django 還不太熟悉的開發者,可仔細閱讀官方提供的最新文件。 Step 0: 使用新的 virtualenv 環境 建議

資料視覺:淺談熱力如何在前端實現

作者 個推開發工程師甄鑫 當我們需要用更直觀有效的形式來展現各類大資料資訊時,熱力圖無疑是一種很好的方式。作為一種密度圖,熱力圖一般使用具備顯著顏色差異的方式來呈現資料效果,熱力圖中亮色一般代表事件發生頻率較高或事物分佈密度較大,暗色則反之。 值得一提的是,熱力圖最終效果常常優於

資料視覺-Matplotlib繪製簡單拆線

要檢視使用matplotlib可製作的各種圖表,請訪問 http://matplotlib.org/ 的示例畫廊。單擊畫廊中的圖表,就可檢視用於生成圖表的程式碼。 import matplotlib.pyplot as plt squares = [1, 4

資料視覺--全球分佈散點

//返回隨機顏色 function getColor() { var colors = ['#00F5FF','#00E5EE','#00FFFF','#00C5CD']; var index

Echarts資料視覺series-bar柱形詳解,開發全解+完美註釋

全棧工程師開發手冊 (作者:欒鵬) Echarts資料視覺化series-bar柱形圖詳解全解: mytextStyle={ color:"#333", //文字顏色 fontSty

D3.js資料視覺系列教程(三十)--力導向之帶文字

(1)連結陣列var links = [ {source: "Microsoft", target: "Amazon", type: "licensing" ,weight:1,color:1}, {source: "Microsoft", target:

D3.js資料視覺系列教程(十六)--更新、過度和動畫

//(1) 準備資料集 var dataset = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ]; //(2) 設定SVG的高寬 var w=600; va