Skip to content

Commit 5895d09

Browse files
committed
More updates
1 parent 987d92b commit 5895d09

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

packages/geojson-extension/src/index.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,40 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
6666
renderModel(model: IRenderMime.IMimeModel): Promise<void> {
6767
const data = model.data[this._mimeType] as any | GeoJSON.GeoJsonObject;
6868
// 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+
});
6974
return new Promise<void>((resolve, reject) => {
7075
// 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+
7493
this.update();
75-
}
76-
resolve();
94+
resolve();
95+
});
7796
});
7897
}
7998

8099
/**
81100
* A message handler invoked on an `'after-attach'` message.
82101
*/
83102
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-
});
105103
// If in a notebook context
106104
// if (this.parent.hasClass('jp-OutputArea-child')) {
107105
// // Disable scroll zoom by default to avoid conflicts with notebook scroll
@@ -115,7 +113,7 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
115113
// this._map.scrollZoom.enable();
116114
// });
117115
// }
118-
this.update();
116+
// this.update();
119117
}
120118

121119
/**
@@ -138,11 +136,13 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
138136
protected onUpdateRequest(msg: Message): void {
139137
// Update map size after update
140138
if (this._map && this.isVisible) {
139+
this._map.fitBounds(this._map.getBounds());
141140
this._map.resize();
142141
}
143142
}
144143

145144
private _map: mapboxgl.Map;
145+
// private _geoJSONLayer: mapboxgl.GeoJSONSource;
146146
private _mimeType: string;
147147
}
148148

0 commit comments

Comments
 (0)