Skip to content

Commit 334633e

Browse files
committed
Import sources and refactor tooltip
1 parent 5f988a6 commit 334633e

File tree

6 files changed

+115
-23
lines changed

6 files changed

+115
-23
lines changed

maplibre/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
except ImportError as e:
3131
print(e)
3232

33+
from .sources import *
34+
3335
__version__ = importlib.metadata.version(__package__)
3436

3537
__all__ = ["Map", "MapOptions", "Layer", "LayerType", "ControlPosition"]

maplibre/anywidget.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def add_call(self, method_name: str, *args) -> None:
104104
# Initial calls
105105
self.calls = self.calls + [call]
106106

107+
"""
107108
def _add_call(self, method_name: str, *args) -> None:
108109
call = [method_name, args]
109110
if not self._rendered:
@@ -115,3 +116,7 @@ def _add_call(self, method_name: str, *args) -> None:
115116
return
116117
117118
self.send({"calls": [call], "msg": "custom call"})
119+
"""
120+
121+
def add_tooltip(self, layer_id, template = None) -> None:
122+
return self.add_call("addTooltip", layer_id, template)

maplibre/sources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,5 @@ def to_source(self, **kwargs) -> GeoJSONSource:
204204

205205
def to_sources_dict(self, **kwargs) -> dict:
206206
return {self.source_id: self.to_source(**kwargs)}
207+
208+
__all__ = ["GeoJSONSource", "RasterSource", "RasterDEMSource"]

maplibre/srcjs/maplibre.anywidget.js

Lines changed: 31 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

marimo/icons.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import marimo
2+
3+
__generated_with = "0.10.17"
4+
app = marimo.App(width="medium")
5+
6+
7+
@app.cell
8+
def _():
9+
import marimo as mo
10+
import maplibre as mlb
11+
return mlb, mo
12+
13+
14+
@app.cell
15+
def _(mlb):
16+
m = mlb.MapWidget()
17+
return (m,)
18+
19+
20+
@app.cell
21+
def _():
22+
image_url = "https://maplibre.org/maplibre-gl-js/docs/assets/custom_marker.png"
23+
image_id = "custom-marker"
24+
return image_id, image_url
25+
26+
27+
@app.cell
28+
def _(image_id, image_url, m):
29+
m.add_call("addImage", image_id, image_url)
30+
return
31+
32+
33+
@app.cell
34+
def _():
35+
data_url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson"
36+
return (data_url,)
37+
38+
39+
@app.cell
40+
def _(data_url, image_id, mlb):
41+
vector = mlb.Layer(
42+
id="icons",
43+
type=mlb.LayerType.SYMBOL,
44+
source=mlb.GeoJSONSource(data=data_url),
45+
layout={"icon-image": image_id, "icon-overlap": "always"},
46+
)
47+
return (vector,)
48+
49+
50+
@app.cell
51+
def _(m, vector):
52+
m.add_layer(vector)
53+
return
54+
55+
56+
@app.cell
57+
def _(m):
58+
m
59+
return
60+
61+
62+
@app.cell
63+
def _(m):
64+
m.add_tooltip("icons", "{{ place }}, {{ mag }}")
65+
return
66+
67+
68+
@app.cell
69+
def _():
70+
return
71+
72+
73+
if __name__ == "__main__":
74+
app.run()

tests/test_sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from geopandas import GeoDataFrame, read_file
4-
from maplibre.sources import *
4+
from maplibre.sources import GeoJSONSource, SimpleFeatures, VectorTileSource
55

66

77
def test_geojson_source():

0 commit comments

Comments
 (0)