Skip to content

Vector type added #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions examples/VectorLayer.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "81807477-4f95-4e56-9c00-40894b6f03ea",
"metadata": {},
"source": [
"# Vector Layer"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b18cdb9c-e8d6-450e-b86d-0767936ee2cf",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "23ee42c538dc4ed6bed767395fbb51b0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[-77.15, 34.56], zoom=9.5)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipyopenlayers import Map, Vector ,RasterTileLayer\n",
"import os\n",
"import json\n",
"\n",
"m = Map(center=[-77.15, 34.56], zoom=9.5)\n",
"layer= RasterTileLayer()\n",
"m.add_layer(layer)\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2cf558fc",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "23ee42c538dc4ed6bed767395fbb51b0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[-77.15, 34.56], zoom=9.5)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vidget = Vector(\n",
" data = { 'geom':[-77.04, 34.66 ] },\n",
" visible=True,\n",
" style = { 'pointFillColor': 'rgba(255,0,255,1)',\n",
" 'image' : { 'height' : 40,\n",
" 'width' : 30,\n",
" 'src' : 'https://openlayers.org/en/latest/examples/data/icon.png'\n",
" } }\n",
")\n",
"m.add_layer(vidget)\n",
"\n",
"# Display the map\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d76847b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
43 changes: 31 additions & 12 deletions ipyopenlayers/openlayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TileLayer(Layer):
min_zoom = Int(0).tag(sync=True)
max_zoom = Int(18).tag(sync=True)
source_format = Dict().tag(sync=True)

class GeoTIFFTileLayer(Layer):
"""GeoTIFFTileLayer class for WebGL-based GeoTIFF raster tiles.

Expand Down Expand Up @@ -87,7 +87,7 @@ class VectorTileLayer(TileLayer):

_view_name = Unicode('VectorTileLayerView').tag(sync=True)
_model_name = Unicode('VectorTileLayerModel').tag(sync=True)
style = Dict({}).tag(sync=True)
style = Dict({}).tag(sync=True)

class GeoJSON(Layer):
"""GeoJSON class for GeoJSON data layers.
Expand All @@ -108,6 +108,25 @@ class GeoJSON(Layer):
style = Dict({}).tag(sync=True)
visible = Bool(True).tag(sync=True)

class Vector(Layer):
"""Vector class for Vector data layers.

Attributes
----------
data: dict
The Vector data for the layer.
style: dict
Style options for the Vector data.
visible: bool, default True
Whether the layer is visible or not.
"""

_view_name = Unicode('OpenLayersVectorView').tag(sync=True)
_model_name = Unicode('OpenLayersVectorModel').tag(sync=True)
data = Dict({}).tag(sync=True)
style = Dict({}).tag(sync=True)
visible = Bool(True).tag(sync=True)


class HeatmapLayer(Layer):
"""HeatmapLayer class for heatmap visualization.
Expand All @@ -128,15 +147,15 @@ class HeatmapLayer(Layer):
radius = Int(8).tag(sync=True)


class BaseOverlay(DOMWidget):
class BaseOverlay(DOMWidget):
"""Base class for overlays on the map.

Attributes
----------
position: list of float, default [0, 0]
The position of the overlay on the map (it's center).
"""

_model_module = Unicode(module_name).tag(sync=True)
_model_module_version = Unicode(module_version).tag(sync=True)
_view_module = Unicode(module_name).tag(sync=True)
Expand All @@ -146,7 +165,7 @@ class BaseOverlay(DOMWidget):
class ImageOverlay (BaseOverlay):
"""ImageOverlay class.

Image layer from a local or remote image file.
Image layer from a local or remote image file.

Attributes
----------
Expand All @@ -162,7 +181,7 @@ class ImageOverlay (BaseOverlay):
class VideoOverlay (BaseOverlay):
"""VideoOverlay class.

Video layer from a local or remote video file.
Video layer from a local or remote video file.

Attributes
----------
Expand Down Expand Up @@ -201,13 +220,13 @@ class BaseControl(DOMWidget):
_model_module_version = Unicode(module_version).tag(sync=True)
_view_module = Unicode(module_name).tag(sync=True)
_view_module_version = Unicode(module_version).tag(sync=True)

class ZoomSlider(BaseControl):
"""ZoomSlider class for adding a zoom slider control to the map.
"""
_view_name = Unicode('ZoomSliderView').tag(sync=True)
_model_name = Unicode('ZoomSliderModel').tag(sync=True)

class FullScreen(BaseControl):
"""FullScreen class, with Control as parent class.

Expand Down Expand Up @@ -250,7 +269,7 @@ class Map(DOMWidget):
The current center of the map.
zoom: float, default 0
The current zoom value of the map."""

_model_name = Unicode('MapModel').tag(sync=True)
_model_module = Unicode(module_name).tag(sync=True)
_model_module_version = Unicode(module_version).tag(sync=True)
Expand Down Expand Up @@ -288,7 +307,7 @@ def __init__(self, center=None, zoom=None, **kwargs):
def __repr__(self):
"""Return a string representation of the Map instance."""
return f"Map(center={self.center}, zoom={self.zoom})"

def add_layer(self, layer):
"""Add a layer on the map.

Expand Down Expand Up @@ -318,7 +337,7 @@ def remove_layer(self, layer):
The layer to remove.
"""
self.layers = [x for x in self.layers if x != layer]

def remove_overlay(self, overlay):
"""Remove an overlay from the map.

Expand Down Expand Up @@ -348,7 +367,7 @@ def remove_control(self, control):
The control to remove.
"""
self.controls = [x for x in self.controls if x != control]


def clear_layers(self):
"""Remove all layers from the map.
Expand Down
Loading
Loading