@@ -13,15 +13,12 @@ import {
1313 IRenderMime
1414} from '@jupyterlab/rendermime-interfaces' ;
1515
16- import * as leaflet from 'leaflet ' ;
16+ import * as mapboxgl from 'mapbox-gl ' ;
1717
1818import 'leaflet/dist/leaflet.css' ;
1919
2020import '../style/index.css' ;
2121
22- import * as iconRetinaUrl from 'leaflet/dist/images/marker-icon-2x.png' ;
23- import * as iconUrl from 'leaflet/dist/images/marker-icon.png' ;
24- import * as shadowUrl from 'leaflet/dist/images/marker-shadow.png' ;
2522
2623/**
2724 * The CSS class to add to the GeoJSON Widget.
@@ -39,39 +36,7 @@ const CSS_ICON_CLASS = 'jp-MaterialIcon jp-GeoJSONIcon';
3936export
4037const MIME_TYPE = 'application/geo+json' ;
4138
42- /**
43- * Set base path for leaflet images.
44- */
45-
46- // https://github.com/Leaflet/Leaflet/issues/4968
47- // Marker file names are hard-coded in the leaflet source causing
48- // issues with webpack.
49- // This workaround allows webpack to inline all marker URLs.
50-
51- delete ( leaflet . Icon . Default . prototype as any ) [ '_getIconUrl' ] ;
52-
53- leaflet . Icon . Default . mergeOptions ( {
54- iconRetinaUrl : iconRetinaUrl ,
55- iconUrl : iconUrl ,
56- shadowUrl : shadowUrl
57- } ) ;
58-
59-
60- /**
61- * The url template that leaflet tile layers.
62- * See http://leafletjs.com/reference-1.0.3.html#tilelayer
63- */
64- const URL_TEMPLATE : string = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ;
65-
66- /**
67- * The options for leaflet tile layers.
68- * See http://leafletjs.com/reference-1.0.3.html#tilelayer
69- */
70- const LAYER_OPTIONS : leaflet . TileLayerOptions = {
71- attribution : 'Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors' ,
72- minZoom : 0 ,
73- maxZoom : 18
74- } ;
39+ mapboxgl . accessToken = 'pk.eyJ1IjoibWlja3QiLCJhIjoiLXJIRS1NbyJ9.EfVT76g4A5dyuApW_zuIFQ' ;
7540
7641
7742export
@@ -82,14 +47,7 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
8247 constructor ( options : IRenderMime . IRendererOptions ) {
8348 super ( ) ;
8449 this . addClass ( CSS_CLASS ) ;
85- this . _mimeType = options . mimeType ;
86- // Create leaflet map object
87- // trackResize option set to false as it is not needed to track
88- // window.resize events since we have individual phosphor resize
89- // events.
90- this . _map = leaflet . map ( this . node , {
91- trackResize : false
92- } ) ;
50+ this . _mimeType = options . mimeType ;
9351 }
9452
9553 /**
@@ -107,16 +65,20 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
10765 */
10866 renderModel ( model : IRenderMime . IMimeModel ) : Promise < void > {
10967 const data = model . data [ this . _mimeType ] as any | GeoJSON . GeoJsonObject ;
110- const metadata = model . metadata [ this . _mimeType ] as any || { } ;
68+ // const metadata = model.metadata[this._mimeType] as any || {};
11169 return new Promise < void > ( ( resolve , reject ) => {
112- // Add leaflet tile layer to map
113- leaflet . tileLayer (
114- metadata . url_template || URL_TEMPLATE ,
115- metadata . layer_options || LAYER_OPTIONS
116- ) . addTo ( this . _map ) ;
117- // Create GeoJSON layer from data and add to map
118- this . _geoJSONLayer = leaflet . geoJSON ( data ) . addTo ( this . _map ) ;
119- this . update ( ) ;
70+ // Add GeoJSON layer to map
71+ if ( this . _map ) {
72+ this . _map . addLayer ( {
73+ id : 'layer' ,
74+ type : 'symbol' ,
75+ source : {
76+ type : 'geojson' ,
77+ data
78+ }
79+ } ) ;
80+ this . update ( ) ;
81+ }
12082 resolve ( ) ;
12183 } ) ;
12284 }
@@ -125,16 +87,22 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
12587 * A message handler invoked on an `'after-attach'` message.
12688 */
12789 protected onAfterAttach ( msg : Message ) : void {
90+ this . _map = new mapboxgl . Map ( {
91+ container : this . node ,
92+ style : 'mapbox://styles/mapbox/light-v9' ,
93+ minZoom : 0 ,
94+ maxZoom : 18
95+ } ) ;
12896 if ( this . parent . hasClass ( 'jp-OutputArea-child' ) ) {
12997 // Disable scroll zoom by default to avoid conflicts with notebook scroll
130- this . _map . scrollWheelZoom . disable ( ) ;
98+ this . _map . scrollZoom . disable ( ) ;
13199 // Enable scroll zoom on map focus
132- this . _map . on ( 'blur' , ( event ) => {
133- this . _map . scrollWheelZoom . disable ( ) ;
100+ this . _map . on ( 'blur' , ( event : Event ) => {
101+ this . _map . scrollZoom . disable ( ) ;
134102 } ) ;
135103 // Disable scroll zoom on blur
136- this . _map . on ( 'focus' , ( event ) => {
137- this . _map . scrollWheelZoom . enable ( ) ;
104+ this . _map . on ( 'focus' , ( event : Event ) => {
105+ this . _map . scrollZoom . enable ( ) ;
138106 } ) ;
139107 }
140108 this . update ( ) ;
@@ -159,13 +127,12 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
159127 */
160128 protected onUpdateRequest ( msg : Message ) : void {
161129 // Update map size after update
162- if ( this . isVisible ) this . _map . invalidateSize ( ) ;
163- // Update map size after panel/window is resized
164- this . _map . fitBounds ( this . _geoJSONLayer . getBounds ( ) ) ;
130+ if ( this . _map && this . isVisible ) {
131+ this . _map . resize ( ) ;
132+ }
165133 }
166134
167- private _map : leaflet . Map ;
168- private _geoJSONLayer : leaflet . GeoJSON ;
135+ private _map : mapboxgl . Map ;
169136 private _mimeType : string ;
170137}
171138
0 commit comments