@@ -7,18 +7,10 @@ import { Message } from '@lumino/messaging';
7
7
8
8
import { IRenderMime } from '@jupyterlab/rendermime-interfaces' ;
9
9
10
- import { defaultSanitizer } from '@jupyterlab/apputils' ;
11
-
12
- import leaflet from 'leaflet' ;
13
-
14
- import 'leaflet/dist/leaflet.css' ;
10
+ import { view } from 'geoverview' ;
15
11
16
12
import '../style/index.css' ;
17
13
18
- import iconRetinaUrl from 'leaflet/dist/images/marker-icon-2x.png' ;
19
- import iconUrl from 'leaflet/dist/images/marker-icon.png' ;
20
- import shadowUrl from 'leaflet/dist/images/marker-shadow.png' ;
21
-
22
14
/**
23
15
* The CSS class to add to the GeoJSON Widget.
24
16
*/
@@ -34,40 +26,6 @@ const CSS_ICON_CLASS = 'jp-MaterialIcon jp-GeoJSONIcon';
34
26
*/
35
27
export const MIME_TYPE = 'application/geo+json' ;
36
28
37
- /**
38
- * Set base path for leaflet images.
39
- */
40
-
41
- // https://github.com/Leaflet/Leaflet/issues/4968
42
- // Marker file names are hard-coded in the leaflet source causing
43
- // issues with webpack.
44
- // This workaround allows webpack to inline all marker URLs.
45
-
46
- delete ( leaflet . Icon . Default . prototype as any ) [ '_getIconUrl' ] ;
47
-
48
- leaflet . Icon . Default . mergeOptions ( {
49
- iconRetinaUrl : iconRetinaUrl ,
50
- iconUrl : iconUrl ,
51
- shadowUrl : shadowUrl ,
52
- } ) ;
53
-
54
- /**
55
- * The url template that leaflet tile layers.
56
- * See http://leafletjs.com/reference-1.0.3.html#tilelayer
57
- */
58
- const URL_TEMPLATE = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ;
59
-
60
- /**
61
- * The options for leaflet tile layers.
62
- * See http://leafletjs.com/reference-1.0.3.html#tilelayer
63
- */
64
- const LAYER_OPTIONS : leaflet . TileLayerOptions = {
65
- attribution :
66
- 'Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors' ,
67
- minZoom : 0 ,
68
- maxZoom : 18 ,
69
- } ;
70
-
71
29
export class RenderedGeoJSON extends Widget implements IRenderMime . IRenderer {
72
30
/**
73
31
* Create a new widget for rendering GeoJSON.
@@ -76,59 +34,24 @@ export class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
76
34
super ( ) ;
77
35
this . addClass ( CSS_CLASS ) ;
78
36
this . _mimeType = options . mimeType ;
79
- // Create leaflet map object
80
- // trackResize option set to false as it is not needed to track
81
- // window.resize events since we have individual phosphor resize
82
- // events.
83
- this . _map = leaflet . map ( this . node , {
84
- trackResize : false ,
85
- } ) ;
86
37
}
87
38
88
39
/**
89
40
* Dispose of the widget.
90
41
*/
91
42
dispose ( ) : void {
92
- // Dispose of leaflet map
93
- this . _map . remove ( ) ;
94
- this . _map = null ;
95
43
super . dispose ( ) ;
96
44
}
97
45
98
46
/**
99
47
* Render GeoJSON into this widget's node.
100
48
*/
101
49
renderModel ( model : IRenderMime . IMimeModel ) : Promise < void > {
102
- const data = model . data [ this . _mimeType ] as any | GeoJSON . GeoJsonObject ;
103
- const metadata = ( model . metadata [ this . _mimeType ] as any ) || { } ;
50
+ const data = model . data [ this . _mimeType ] as any ;
104
51
return new Promise < void > ( ( resolve , reject ) => {
105
- // Add leaflet tile layer to map
106
- leaflet
107
- . tileLayer (
108
- metadata . url_template || URL_TEMPLATE ,
109
- metadata . layer_options || LAYER_OPTIONS
110
- )
111
- . addTo ( this . _map ) ;
112
- // Create GeoJSON layer from data and add to map
113
- this . _geoJSONLayer = leaflet
114
- . geoJSON ( data , {
115
- onEachFeature : function ( feature , layer ) {
116
- if ( feature . properties ) {
117
- let popupContent = '<table>' ;
118
- for ( const p in feature . properties ) {
119
- popupContent +=
120
- '<tr><td>' +
121
- p +
122
- ':</td><td><b>' +
123
- feature . properties [ p ] +
124
- '</b></td></tr>' ;
125
- }
126
- popupContent += '</table>' ;
127
- layer . bindPopup ( defaultSanitizer . sanitize ( popupContent ) ) ;
128
- }
129
- } ,
130
- } )
131
- . addTo ( this . _map ) ;
52
+ const map = view ( data ) ;
53
+ this . node . appendChild ( map . next ( ) . value ) ;
54
+ map . next ( ) ;
132
55
this . update ( ) ;
133
56
resolve ( ) ;
134
57
} ) ;
@@ -138,18 +61,6 @@ export class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
138
61
* A message handler invoked on an `'after-attach'` message.
139
62
*/
140
63
protected onAfterAttach ( msg : Message ) : void {
141
- if ( this . parent . hasClass ( 'jp-OutputArea-child' ) ) {
142
- // Disable scroll zoom by default to avoid conflicts with notebook scroll
143
- this . _map . scrollWheelZoom . disable ( ) ;
144
- // Enable scroll zoom on map focus
145
- this . _map . on ( 'blur' , ( event ) => {
146
- this . _map . scrollWheelZoom . disable ( ) ;
147
- } ) ;
148
- // Disable scroll zoom on blur
149
- this . _map . on ( 'focus' , ( event ) => {
150
- this . _map . scrollWheelZoom . enable ( ) ;
151
- } ) ;
152
- }
153
64
this . update ( ) ;
154
65
}
155
66
@@ -173,14 +84,9 @@ export class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
173
84
protected onUpdateRequest ( msg : Message ) : void {
174
85
// Update map size after update
175
86
if ( this . isVisible ) {
176
- this . _map . invalidateSize ( ) ;
177
87
}
178
- // Update map size after panel/window is resized
179
- this . _map . fitBounds ( this . _geoJSONLayer . getBounds ( ) ) ;
180
88
}
181
89
182
- private _map : leaflet . Map ;
183
- private _geoJSONLayer : leaflet . GeoJSON ;
184
90
private _mimeType : string ;
185
91
}
186
92
0 commit comments