Skip to content

Commit

Permalink
Update GeoTIFF layer source property (#30)
Browse files Browse the repository at this point in the history
* changed url

* Update Playwright Snapshots

* Delete examples/.config.ini

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: martinRenou <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent ed26819 commit b1e59e4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 39 deletions.
31 changes: 16 additions & 15 deletions examples/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -18,21 +18,21 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "47a42e9446f44146a853ebba1de8b8c8",
"model_id": "2f268e1adb234ab19da2eecccc7167c0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[5.314329221346643, 16.3625002926901], zoom=9.0)"
]
},
"execution_count": 26,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -64,26 +64,27 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"geo_tiff_layer = GeoTIFFTileLayer(\n",
" sources=[\n",
" {'url': 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/36/Q/WD/2020/7/S2A_36QWD_20200701_0_L2A/TCI.tif'}\n",
" ]\n",
")\n",
"geo_tiff_layer = GeoTIFFTileLayer(url= 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/36/Q/WD/2020/7/S2A_36QWD_20200701_0_L2A/TCI.tif')\n",
"m.add_layer(geo_tiff_layer)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"m.remove_layer(geo_tiff_layer)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
4 changes: 1 addition & 3 deletions ipyopenlayers/Map.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GeoJSON(Layer):
class GeoTIFFTileLayer(Layer):
_model_name = Unicode('GeoTIFFTileLayerModel').tag(sync=True)
_view_name = Unicode('GeoTIFFTileLayerView').tag(sync=True)
sources = List(Dict).tag(sync=True)
url = Unicode('').tag(sync=True)

class HeatmapLayer(Layer):
_view_name = Unicode('HeatmapLayerView').tag(sync=True)
Expand All @@ -52,8 +52,6 @@ class HeatmapLayer(Layer):
radius = Int(8).tag(sync=True)




class BaseOverlay(DOMWidget):

_model_module = Unicode(module_name).tag(sync=True)
Expand Down
33 changes: 15 additions & 18 deletions src/geotifflayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class GeoTIFFTileLayerModel extends LayerModel {
_view_name: GeoTIFFTileLayerModel.view_name,
_view_module: GeoTIFFTileLayerModel.view_module,
_view_module_version: GeoTIFFTileLayerModel.view_module_version,
source: [],
url: '',
};
}

Expand All @@ -37,33 +37,30 @@ export class GeoTIFFTileLayerView extends LayerView {
render() {
super.render();
this.sourcesChanged();
this.model.on('change:sources', this.sourcesChanged, this);
this.model.on('change:url', this.sourcesChanged, this);
}

create_obj() {
const sources = this.model.get('sources').map((source: any) => ({
url: source.url,
}));
const url = this.model.get('url');

this.obj = this.tileLayer = new WebGLTileLayer({
source: new GeoTIFF({
sources: sources,
}),
});
if (url) {
this.obj = new WebGLTileLayer({
source: new GeoTIFF({
sources: [{ url: url }],
}),
});
}
}

sourcesChanged() {
const newSources = this.model.get('sources').map((source: any) => ({
url: source.url,
}));
const newUrl = this.model.get('url');

if (newSources) {
if (newUrl) {
const newSource = new GeoTIFF({
sources: newSources,
sources: [{ url: newUrl }],
});
this.tileLayer.setSource(newSource);
this.obj.setSource(newSource);
}
}

tileLayer: WebGLTileLayer;
obj: WebGLTileLayer;
}
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.
5 changes: 2 additions & 3 deletions ui-tests/tests/notebooks/map_update.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"outputs": [],
"source": [
"from ipyopenlayers import (\n",
" Map, TileLayer, ImageOverlay, VideoOverlay, PopupOverlay,\n",
" ZoomSlider, FullScreen, ScaleLine, MousePosition\n",
" Map, RasterTileLayer\n",
")\n",
"\n",
"m = Map(center=[0.0, 0.0], zoom=2)\n",
Expand All @@ -31,7 +30,7 @@
},
"outputs": [],
"source": [
"layer = TileLayer()\n",
"layer = RasterTileLayer()\n",
"m.add_layer(layer)"
]
}
Expand Down

0 comments on commit b1e59e4

Please sign in to comment.