99 < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no " />
1010 < meta name ="description " content ="This sample creates a WebGL trips layer in Manhattan, NY using Deck.gl 3D framework for Azure Maps. " />
1111 < meta name ="keywords " content ="3D, Microsoft maps, map, gis, API, SDK, thematic, choropleth, heatmap, heat map, animation, animate, animations, county, population, data-driven, data driven styling, temporal, temporal analysis " />
12- < meta name ="author " content ="Microsoft Azure Maps " /> < meta name ="version " content ="1.0 " />
12+ < meta name ="author " content ="Microsoft Azure Maps " />
13+ < meta name ="version " content ="1.0 " />
1314 < meta name ="screenshot " content ="screenshot.gif " />
1415
1516 <!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
1617 < link href ="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css " rel ="stylesheet " />
1718 < script src ="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js "> </ script >
1819
1920 <!-- deck.gl is a WebGL-powered framework for visual exploratory data analysis of large datasets. -->
20- < script src ="https://unpkg.com/deck.gl@^8 /dist.min.js "> </ script >
21+ < script src ="https://unpkg.com/deck.gl@latest /dist.min.js "> </ script >
2122
2223 < script >
23- var map ;
24+ var map , deckOverlay ;
25+
26+ //Define animation options.
27+ const loopLength = 1800 ; // unit corresponds to the timestamp in source data
28+ let animationSpeed = 5 ;
29+ let time = 500 ;
30+ let shouldRotate = true ;
31+ let rotation = 0 ;
32+
33+ //Initialize the trip layer options.
34+ let tripLayerOptions = {
35+ id : "trips" ,
36+ data : "/3d-layer/newyork/trips-v7.json" ,
37+ getPath : ( d ) => d . path ,
38+ getTimestamps : ( d ) => d . timestamps ,
39+ getColor : ( d ) => ( d . vendor === 0 ? [ 250 , 250 , 93 ] : [ 50 , 230 , 50 ] ) ,
40+ opacity : 0.3 ,
41+ widthMinPixels : 2 ,
42+ trailLength : 180 ,
43+ currentTime : time ,
44+ shadowEnabled : false
45+ } ;
2446
2547 function GetMap ( ) {
2648 map = new atlas . Map ( "map" , {
3052 style : "grayscale_dark" ,
3153 antialias : true ,
3254
33- // Add authentication details for connecting to Azure Maps.
55+ //Add your Azure Maps subscription client ID to the map SDK. Get an Azure Maps client ID at https://azure.com/maps
3456 authOptions : {
35- // Use Azure Active Directory authentication.
57+ //Use Azure Active Directory authentication.
3658 authType : 'anonymous' ,
37- clientId : 'e6b6ab59-eb5d-4d25-aa57-581135b927f0' , // Your Azure Maps client id for accessing your Azure Maps account.
59+ clientId : 'e6b6ab59-eb5d-4d25-aa57-581135b927f0' , //Your Azure Maps client id for accessing your Azure Maps account.
3860 getToken : function ( resolve , reject , map ) {
39- // URL to your authentication service that retrieves an Azure Active Directory Token.
61+ //URL to your authentication service that retrieves an Azure Active Directory Token.
4062 var tokenServiceUrl = "https://samples.azuremaps.com/api/GetAzureMapsToken" ;
4163
4264 fetch ( tokenServiceUrl ) . then ( r => r . text ( ) ) . then ( token => resolve ( token ) ) ;
4365 }
4466
45- // Use an Azure Maps key. Get an Azure Maps key at https://azuremaps .com/. NOTE: The primary key should be used as the key.
67+ //Alternatively, use an Azure Maps key. Get an Azure Maps key at https://azure .com/maps . NOTE: The primary key should be used as the key.
4668 //authType: 'subscriptionKey',
4769 //subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
4870 }
4971 } ) ;
5072
5173 // Wait until the map resources are ready
5274 map . events . add ( "ready" , function ( ) {
75+ //Add the overlay to the map.
76+ deckOverlay = new DeckGLOverlay ( {
77+ layers : [
78+ new deck . TripsLayer ( tripLayerOptions )
79+ ]
80+ } ) ;
81+
82+ // Add the overlay to the map
83+ map . controls . add ( deckOverlay ) ;
5384
5485 animate ( ) ;
5586
70101 } ) ;
71102 }
72103
73- const loopLength = 1800 ; // unit corresponds to the timestamp in source data
74-
75- let trailColor0 = [ 250 , 250 , 93 ] ;
76- let trailColor1 = [ 50 , 230 , 50 ] ;
77- let animationSpeed = 5 ;
78- let trailLength = 180 ;
79- let time = 500 ;
80- let shouldRotate = true ;
81- let rotation = 0 ;
82-
83104 const animate = ( ) => {
84105 time = ( time + animationSpeed ) % loopLength ;
85- //remove("trips");
86- map . layers . add (
87- new DeckGLLayer ( {
88- id : "trips" ,
89- type : deck . TripsLayer ,
90- data : "/3d-layer/newyork/trips-v7.json" ,
91- getPath : ( d ) => d . path ,
92- getTimestamps : ( d ) => d . timestamps ,
93- getColor : ( d ) => ( d . vendor === 0 ? trailColor0 : trailColor1 ) ,
94- opacity : 0.3 ,
95- widthMinPixels : 2 ,
96- rounded : true ,
97- trailLength,
98- currentTime : time ,
99- shadowEnabled : false
100- } )
101- ) ;
106+
107+ //Update the time of the trips layer.
108+ tripLayerOptions . currentTime = time ;
109+
110+ //Update the properties of the deck overlay.
111+ deckOverlay . setProps ( {
112+ layers : [
113+ new deck . TripsLayer ( tripLayerOptions )
114+ ]
115+ } ) ;
116+
102117 if ( shouldRotate ) {
103118 map [ "map" ] . rotateTo ( ( rotation ++ / 5 ) % 360 , { duration : 0 } ) ;
104119 }
114129 shouldRotate = ! shouldRotate ;
115130 }
116131
117- // A custom implementation of WebGLLayer
118- class DeckGLLayer extends atlas . layer . WebGLLayer {
132+ // A custom control for adding DeckGL to Azure Maps.
133+ class DeckGLOverlay {
119134 constructor ( options ) {
120- super ( options . id ) ;
121- // Create an instance of deck.gl MapboxLayer what is compatible with Azure Maps
122- // https://deck.gl/docs/api-reference/mapbox/mapbox-layer
123- this . _mbLayer = new deck . MapboxLayer ( options ) ;
124-
125- // Create a renderer
126- const renderer = {
127- renderingMode : "3d" ,
128- onAdd : ( map , gl ) => {
129- this . _mbLayer . onAdd ?. ( map [ "map" ] , gl ) ;
130- } ,
131- onRemove : ( map , gl ) => {
132- this . _mbLayer . onRemove ?. ( map [ "map" ] , gl ) ;
133- } ,
134- prerender : ( gl , matrix ) => {
135- this . _mbLayer . prerender ?. ( gl , matrix ) ;
136- } ,
137- render : ( gl , matrix ) => {
138- this . _mbLayer . render ( gl , matrix ) ;
139- }
140- } ;
141- this . setOptions ( { renderer } ) ;
135+ this . id = options . id ;
136+
137+ // Create an instance of deck.gl MapboxOverlay what is compatible with Azure Maps
138+ // https://deck.gl/docs/api-reference/mapbox/mapbox-overlay
139+ this . _mbOverlay = new deck . MapboxOverlay ( options ) ;
140+ }
141+
142+ onAdd ( map , options ) {
143+ this . map = map ;
144+ return this . _mbOverlay . onAdd ( map [ "map" ] ) ;
145+ }
146+
147+ onRemove ( ) {
148+ this . _mbOverlay . onRemove ( ) ;
149+ }
150+
151+ getCanvas ( ) {
152+ this . _mbOverlay . getCanvas ( ) ;
153+ }
154+
155+ getId ( ) {
156+ return this . id ;
157+ }
158+
159+ pickObject ( params ) {
160+ return this . _mbOverlay . pickObject ( params ) ;
161+ }
162+
163+ pickMultipleObjects ( params ) {
164+ return this . _mbOverlay . pickMultipleObjects ( params ) ;
165+ }
166+
167+ pickObjects ( params ) {
168+ return this . _mbOverlay . pickObjects ( ) ;
169+ }
170+
171+ setProps ( props ) {
172+ this . _mbOverlay . setProps ( props ) ;
173+ }
174+
175+ finalize ( ) {
176+ this . _mbOverlay . finalize ( ) ;
142177 }
143178 }
179+
144180 </ script >
145181</ head >
146182< body onload ="GetMap() ">
173209
174210 < fieldset style ="width:calc(100% - 30px);min-width:290px;margin-top:10px; ">
175211 < legend > Yellow Cab vs Green Cab Trips in Manhattan</ legend >
176- This sample creates a WebGL trips layer in Manhattan, NY using < a href ="https://deck.gl/ "> Deck.gl</ a > 3D framework for Azure Maps.
212+ This sample creates a WebGL trips layer in Manhattan, NY using
213+ < a href ="https://deck.gl/ "> Deck.gl</ a > 3D framework for Azure Maps.
177214 Trips are taken from June 16, 2016 21:00 to 21:30
178- Trip data source: < a href ="http://www.nyc.gov/html/tlc/html/about/trip_record_data.shtml "> NYC Taxi & Limousine Commission Trip Records</ a > .
215+ Trip data source:
216+ < a href ="http://www.nyc.gov/html/tlc/html/about/trip_record_data.shtml "> NYC Taxi & Limousine Commission Trip Records</ a > .
217+ < br />
218+ < br />
219+ If using an older version of deck.gl, you can find an older version of this sample
220+ < a href ="https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/978458eef14881df9cc7316d2fdbb67b9cb09653/Samples/3D-layer/newyork/newyork.html " target ="_blank "> here</ a > .
179221 </ fieldset >
180222</ body >
181223</ html >
0 commit comments