1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < title > Show some timezones on a map</ title >
5
+ < meta property ="og:description " content ="Show some timezones on a map " />
6
+ < meta charset ='utf-8 '>
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 ">
8
+ < link rel ='
stylesheet '
href ='
https://unpkg.com/[email protected] /dist/maplibre-gl.css '
/>
9
+ < script src ='
https://unpkg.com/[email protected] /dist/maplibre-gl.js '
> </ script >
10
+ < style >
11
+ body { margin : 0 ; padding : 0 ; }
12
+ html , body , # map { height : 100% ; }
13
+ .maplibregl-popup {
14
+ background-color : transparent;
15
+ box-shadow : none;
16
+ }
17
+ .maplibregl-popup-content {
18
+ background-color : transparent;
19
+ color : # 000 ;
20
+ box-shadow : none;
21
+ padding : 0 ;
22
+ }
23
+ .maplibregl-popup-tip {
24
+ display : none;
25
+ }
26
+ </ style >
27
+ </ head >
28
+ < body >
29
+ < div id ="map "> </ div >
30
+
31
+ < script >
32
+ const map = new maplibregl . Map ( {
33
+ container : 'map' ,
34
+ style : 'https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json' ,
35
+ center : [ 170 , 32 ] ,
36
+ zoom : 1
37
+ } ) ;
38
+
39
+ map . on ( 'load' , function ( ) {
40
+ const laPopup = new maplibregl . Popup ( { offset : 25 , closeOnClick : false , closeButton : false } )
41
+ . setLngLat ( [ - 118.2437 , 34.0522 ] )
42
+ . setText ( '🇺🇸 Loading...' )
43
+ . addTo ( map ) ;
44
+
45
+ const tokyoPopup = new maplibregl . Popup ( { offset : 25 , closeOnClick : false , closeButton : false } )
46
+ . setLngLat ( [ 139.6917 , 35.6895 ] )
47
+ . setText ( '🇯🇵 Loading...' )
48
+ . addTo ( map ) ;
49
+
50
+ // Update the labels every second.
51
+ setInterval ( ( ) => {
52
+ let laTime = new Intl . DateTimeFormat ( 'en-US' , { timeZone : 'America/Los_Angeles' , timeStyle : 'medium' } ) . format ( new Date ( ) ) ;
53
+ let tokyoTime = new Intl . DateTimeFormat ( 'en-US' , { timeZone : 'Asia/Tokyo' , timeStyle : 'medium' } ) . format ( new Date ( ) ) ;
54
+
55
+ laPopup . setText ( '🇺🇸 ' + laTime ) ;
56
+ tokyoPopup . setText ( '🇯🇵 ' + tokyoTime ) ;
57
+ } , 1000 ) ;
58
+ } ) ;
59
+ </ script >
60
+ </ body >
61
+ </ html >
0 commit comments