1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > 纽约出租车上车点热力图</ title >
6+ < link rel ="stylesheet " href ="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css ">
7+ < link rel ="stylesheet " href ="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css ">
8+ < style >
9+ # loading {
10+ position : absolute;
11+ top : 50% ;
12+ left : 50% ;
13+ z-index : 800 ;
14+ margin-left : -130px ;
15+ text-align : center;
16+ margin-top : -50px ;
17+ width : 290px ;
18+ padding : 10px ;
19+ background : rgba (0 , 0 , 0 , 0.5 );
20+ color : whitesmoke;
21+ font-size : 16px ;
22+ }
23+ </ style >
24+ </ head >
25+ < body style =" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0; ">
26+ < div id ="map " style ="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd "> </ div >
27+ < div id ="loading "> 纽约出租车145万上车点数据加载中...</ div >
28+
29+ < script type ="text/javascript " src ="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js "> </ script >
30+ < script type ="text/javascript " src ="http://cdn.bootcss.com/leaflet.heat/0.2.0/leaflet-heat.js "> </ script >
31+ < script type ="text/javascript " src ="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js "> </ script >
32+ < script type ="text/javascript " src ="http://cdn.bootcss.com/PapaParse/4.3.2/papaparse.min.js "> </ script >
33+ < script type ="text/javascript " src ="../../dist/iclient9-leaflet.js "> </ script >
34+ < script type ="text/javascript ">
35+
36+ var token = "pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw" ,
37+ mbUrl = "https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=" + token ;
38+
39+ var map = L . map ( 'map' , {
40+ maxZoom : 20 ,
41+ center : [ 40.68 , - 73.92 ] ,
42+ zoom : 12 ,
43+ } ) ;
44+
45+ var attribution = '数据来源<a target="_blank" href="http://www.nyc.gov/html/tlc/html/about/trip_record_data.shtml">NYC Taxi(纽约出租车上车点)</a>|' +
46+ 'Imagery © <a href="http://mapbox.com">Mapbox</a>' ;
47+ L . tileLayer ( mbUrl , { id : 'mapbox.light' , attribution : attribution } ) . addTo ( map ) ;
48+
49+ loadHeatMap ( ) ;
50+
51+ function loadHeatMap ( ) {
52+ //145万个点
53+ var radius = 30 , opacity = 0.5 ;
54+ var length = 0 ; //需要截取示例数据的长度,0表示全部
55+ $ . get ( './data/nyc-taxi.csv' , function ( csvstr ) {
56+ var result = Papa . parse ( csvstr , { skipEmptyLines : true , header : true } ) ;
57+ $ ( "#loading" ) . hide ( ) ;
58+
59+ var heatPoints = processData ( result , length ) ;
60+ resultLayer = L . heatLayer ( heatPoints , {
61+ radius : radius ,
62+ minOpacity : opacity
63+ } ) . addTo ( map ) ;
64+ } ) ;
65+ }
66+
67+ function processData ( result , length ) {
68+ var data = result . data ;
69+ var len = ( length < 1 || length > data . lenth || length == null ) ? data . length : length ;
70+ data = data . slice ( 0 , len ) ;
71+ return data ;
72+ }
73+ </ script >
74+ </ body >
75+ </ html >
0 commit comments