Skip to content

Commit

Permalink
Fix bug when loading geojson layers in notebook and update notebook t…
Browse files Browse the repository at this point in the history
…est (#305)

* Assign IDs to features when creating

* Update notebook test

* Update Playwright Snapshots

* Upload geojson file in test

* Update Playwright Snapshots

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
gjmooney and github-actions[bot] authored Jan 10, 2025
1 parent 86abebb commit 96cef85
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion packages/base/src/mainview/mainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { IObservableMap, ObservableMap } from '@jupyterlab/observables';
import { User } from '@jupyterlab/services';
import { JSONValue, UUID } from '@lumino/coreutils';
import { Collection, MapBrowserEvent, Map as OlMap, View } from 'ol';
import { Collection, MapBrowserEvent, Map as OlMap, View, getUid } from 'ol';
import { ScaleLine } from 'ol/control';
import { GeoJSON, MVT } from 'ol/format';
import { DragAndDrop, Select } from 'ol/interaction';
Expand Down Expand Up @@ -489,6 +489,10 @@ export class MainView extends React.Component<IProps, IStates> {

const featureCollection = new Collection(featureArray);

featureCollection.forEach(feature => {
feature.setId(getUid(feature));
});

newSource = new VectorSource({
features: featureCollection
});
Expand Down
6 changes: 6 additions & 0 deletions ui-tests/tests/notebook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect, IJupyterLabPageFixture, test } from '@jupyterlab/galata';
import * as path from 'path';
const klaw = require('klaw-sync');

const FILENAME = 'eq.json';

const testCellOutputs = async (
page: IJupyterLabPageFixture,
tmpPath: string,
Expand Down Expand Up @@ -65,6 +67,10 @@ test.describe('Notebook API Visual Regression', () => {
path.resolve(__dirname, './notebooks'),
tmpPath
);
await page.contents.uploadFile(
path.resolve(__dirname, `./gis-files/${FILENAME}`),
`/${tmpPath}/${FILENAME}`
);
await page.filebrowser.openDirectory(tmpPath);
});

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions ui-tests/tests/notebooks/Notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"metadata": {},
"outputs": [],
"source": [
"doc = GISDocument(latitude=40.775, longitude=-73.973, zoom=13)\n",
"doc = GISDocument(latitude=20.718, longitude=129.940, zoom=4)\n",
"\n",
"doc.add_raster_layer(\n",
" url=\"https://tile.openstreetmap.org/{z}/{x}/{y}.png\",\n",
Expand All @@ -46,7 +46,7 @@
"metadata": {},
"outputs": [],
"source": [
"doc = GISDocument(latitude=40.775, longitude=-73.973, zoom=13)\n",
"doc = GISDocument(latitude=20.718, longitude=129.940, zoom=4)\n",
"\n",
"doc.add_raster_layer(\n",
" url=\"https://tile.openstreetmap.org/{z}/{x}/{y}.png\",\n",
Expand All @@ -55,12 +55,7 @@
" opacity=0.6,\n",
")\n",
"\n",
"doc.add_vectortile_layer(\n",
" url=\"https://planetarycomputer.microsoft.com/api/data/v1/vector/collections/ms-buildings/tilesets/global-footprints/tiles/{z}/{x}/{y}\",\n",
" source_layer=\"bingmlbuildings\",\n",
" max_zoom=13,\n",
" min_zoom=13,\n",
")\n",
"doc.add_geojson_layer(path=\"./eq.json\")\n",
"\n",
"doc"
]
Expand All @@ -82,7 +77,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 96cef85

Please sign in to comment.