Skip to content

Commit de73bf3

Browse files
committed
Update mapbox-gl implementation
1 parent ac06df9 commit de73bf3

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

packages/geojson-extension/src/index.tsx

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,8 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
6969
return new Promise<void>((resolve, reject) => {
7070
// Add GeoJSON layer to map
7171
if (this._map) {
72-
this._map.addLayer({
73-
id: 'layer',
74-
type: 'symbol',
75-
source: {
76-
type: 'geojson',
77-
data
78-
}
79-
});
72+
const dataSource = this._map.getSource('geojson') as mapboxgl.GeoJSONSource;
73+
dataSource.setData(data);
8074
this.update();
8175
}
8276
resolve();
@@ -89,22 +83,38 @@ class RenderedGeoJSON extends Widget implements IRenderMime.IRenderer {
8983
protected onAfterAttach(msg: Message): void {
9084
this._map = new mapboxgl.Map({
9185
container: this.node,
92-
style: 'mapbox://styles/mapbox/light-v9',
93-
minZoom: 0,
94-
maxZoom: 18
86+
style: 'mapbox://styles/mapbox/light-v9?optimize=true'
9587
});
96-
if (this.parent.hasClass('jp-OutputArea-child')) {
97-
// Disable scroll zoom by default to avoid conflicts with notebook scroll
98-
this._map.scrollZoom.disable();
99-
// Enable scroll zoom on map focus
100-
this._map.on('blur', (event: Event) => {
101-
this._map.scrollZoom.disable();
102-
});
103-
// Disable scroll zoom on blur
104-
this._map.on('focus', (event: Event) => {
105-
this._map.scrollZoom.enable();
106-
});
107-
}
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+
// If in a notebook context
106+
// if (this.parent.hasClass('jp-OutputArea-child')) {
107+
// // Disable scroll zoom by default to avoid conflicts with notebook scroll
108+
// this._map.scrollZoom.disable();
109+
// // Enable scroll zoom on map focus
110+
// this._map.on('blur', (event: Event) => {
111+
// this._map.scrollZoom.disable();
112+
// });
113+
// // Disable scroll zoom on blur
114+
// this._map.on('focus', (event: Event) => {
115+
// this._map.scrollZoom.enable();
116+
// });
117+
// }
108118
this.update();
109119
}
110120

0 commit comments

Comments
 (0)