@@ -66,42 +66,40 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
66
66
renderModel ( model : IRenderMime . IMimeModel ) : Promise < void > {
67
67
const data = model . data [ this . _mimeType ] as any | GeoJSON . GeoJsonObject ;
68
68
// const metadata = model.metadata[this._mimeType] as any || {};
69
+ this . _map = new mapboxgl . Map ( {
70
+ container : this . node ,
71
+ style : 'mapbox://styles/mapbox/light-v9?optimize=true' ,
72
+ zoom : 10
73
+ } ) ;
69
74
return new Promise < void > ( ( resolve , reject ) => {
70
75
// Add GeoJSON layer to map
71
- if ( this . _map ) {
72
- const dataSource = this . _map . getSource ( 'geojson' ) as mapboxgl . GeoJSONSource ;
73
- dataSource . setData ( data ) ;
76
+ this . _map . on ( 'style.load' , ( ) => {
77
+ this . _map . addSource ( 'geojson' , {
78
+ type : 'geojson' ,
79
+ data
80
+ } ) ;
81
+ this . _map . addLayer ( {
82
+ id : 'geojson-points' ,
83
+ type : 'circle' ,
84
+ source : 'geojson' ,
85
+ paint : {
86
+ 'circle-color' : 'red' ,
87
+ 'circle-stroke-color' : 'white' ,
88
+ 'circle-stroke-width' : { stops : [ [ 0 , 0.1 ] , [ 18 , 3 ] ] , base : 1.2 } ,
89
+ 'circle-radius' : { stops : [ [ 15 , 3 ] , [ 18 , 5 ] ] , base : 1.2 }
90
+ }
91
+ } ) ;
92
+
74
93
this . update ( ) ;
75
- }
76
- resolve ( ) ;
94
+ resolve ( ) ;
95
+ } ) ;
77
96
} ) ;
78
97
}
79
98
80
99
/**
81
100
* A message handler invoked on an `'after-attach'` message.
82
101
*/
83
102
protected onAfterAttach ( msg : Message ) : void {
84
- this . _map = new mapboxgl . Map ( {
85
- container : this . node ,
86
- style : 'mapbox://styles/mapbox/light-v9?optimize=true'
87
- } ) ;
88
- this . _map . on ( 'style.load' , ( ) => {
89
- this . _map . addSource ( 'geojson' , {
90
- type : 'geojson' ,
91
- data : { 'type' :'FeatureCollection' , 'features' : [ ] }
92
- } ) ;
93
- this . _map . addLayer ( {
94
- id : 'geojson-points' ,
95
- type : 'circle' ,
96
- source : 'geojson' ,
97
- paint : {
98
- 'circle-color' : 'red' ,
99
- 'circle-stroke-color' : 'white' ,
100
- 'circle-stroke-width' : { stops : [ [ 0 , 0.1 ] , [ 18 , 3 ] ] , base : 1.2 } ,
101
- 'circle-radius' : { stops : [ [ 15 , 3 ] , [ 18 , 5 ] ] , base : 1.2 }
102
- }
103
- } )
104
- } ) ;
105
103
// If in a notebook context
106
104
// if (this.parent.hasClass('jp-OutputArea-child')) {
107
105
// // Disable scroll zoom by default to avoid conflicts with notebook scroll
@@ -115,7 +113,7 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
115
113
// this._map.scrollZoom.enable();
116
114
// });
117
115
// }
118
- this . update ( ) ;
116
+ // this.update();
119
117
}
120
118
121
119
/**
@@ -138,11 +136,13 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
138
136
protected onUpdateRequest ( msg : Message ) : void {
139
137
// Update map size after update
140
138
if ( this . _map && this . isVisible ) {
139
+ this . _map . fitBounds ( this . _map . getBounds ( ) ) ;
141
140
this . _map . resize ( ) ;
142
141
}
143
142
}
144
143
145
144
private _map : mapboxgl . Map ;
145
+ // private _geoJSONLayer: mapboxgl.GeoJSONSource;
146
146
private _mimeType : string ;
147
147
}
148
148
0 commit comments