Skip to content

Commit 3b3f932

Browse files
author
Stefan Kuethe
committed
Add MapTiler Geocoding control
1 parent 66587e5 commit 3b3f932

File tree

9 files changed

+275
-85
lines changed

9 files changed

+275
-85
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
# OpenLayers for Python
22

3+
[![Release](https://img.shields.io/github/v/release/eoda-dev/py-openlayers)](https://img.shields.io/github/v/release/eoda-dev/py-openlayers)
4+
[![pypi](https://img.shields.io/pypi/v/openlayers.svg)](https://pypi.python.org/pypi/openlayers)
5+
[![License](https://img.shields.io/github/license/eoda-dev/py-openlayers)](https://img.shields.io/github/license/eoda-dev/py-openlayers)
6+
[![OpenLayers JS](https://img.shields.io/badge/OpenLayers-v10.5.0-blue.svg)](https://github.com/openlayers/openlayers/releases//tag/v10.5.0)
7+
38
## Installation
49

510
```bash
611
uv init
712

813
uv add "git+https://github.com/eoda-dev/py-openlayers@main"
914
```
15+
16+
## Quickstart
17+
18+
```python
19+
import openlayers as ol
20+
21+
# Jupyter or Marimo
22+
ol.MapWidget()
23+
24+
# Standalone
25+
m = ol.Map()
26+
m.save()
27+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import openlayers as ol
2+
3+
ctrl = ol.MapTilerGeocodingControl(
4+
collapsed=True,
5+
country="de",
6+
limit=2
7+
)
8+
9+
m = ol.Map()
10+
m.add_control(ctrl)
11+
m.save()
12+
13+
# print(ctrl.model_dump())

src/openlayers/controls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ZoomControl,
1313
RotateControl,
1414
ZoomToExtentControl,
15+
MapTilerGeocodingControl,
1516
DrawControl,
1617
)
1718

@@ -22,5 +23,6 @@
2223
"ScaleLineControl",
2324
"ZoomSliderControl",
2425
"MousePositionControl",
26+
"MapTilerGeocodingControl",
2527
"DrawControl",
2628
]

src/openlayers/js/openlayers.standalone.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openlayers/js/openlayers.standalone.js

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

src/openlayers/models/controls.py

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

3+
import os
4+
35
from typing import Literal, Union
46
from uuid import uuid4
57

6-
from pydantic import Field, field_validator
8+
from pydantic import Field, field_validator, ConfigDict
79

810
from .core import OLBaseModel
911
from .layers import LayerT, TileLayer
@@ -60,6 +62,16 @@ class ZoomToExtentControl(Control):
6062
) = None
6163

6264

65+
# --- MapTiler
66+
class MapTilerGeocodingControl(Control):
67+
api_key: str = Field(os.getenv("MAPTILER_API_TOKEN"), serialization_alias="apiKey", validate_default=True)
68+
collapsed: bool | None = False
69+
country: str | None = None
70+
limit: int | None = 5
71+
marker_on_selected: bool | None = Field(True, serialization_alias="markerOnSelected")
72+
placeholder: str | None = "Search"
73+
74+
6375
# --- Custom controls
6476
class InfoBox(Control):
6577
html: str

srcjs/ipywidget-ts/controls.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ import Rotate from 'ol/control/Rotate';
88
import Attribution from 'ol/control/Attribution.js';
99
import ZoomToExtent from 'ol/control/ZoomToExtent.js';
1010

11+
import { GeocodingControl } from "@maptiler/geocoding-control/openlayers";
12+
1113
import { InfoBox } from './custom-controls/info-box';
1214
import { DrawControl } from './custom-controls/draw';
1315

16+
// MapTiler Geocoding css
17+
import "@maptiler/geocoding-control/style.css";
18+
19+
const olSearchStyle = document.createElement("style");
20+
olSearchStyle.innerText = ".ol-search {position: absolute; top: .5em; right: .5em;}";
21+
document.head.appendChild(olSearchStyle);
22+
// ---
23+
1424
const zoom = new Zoom();
1525
zoom.setProperties({ id: "zoom", type: "ZoomControl" });
1626

@@ -33,7 +43,8 @@ const controlCatalog: ControlCatalog = {
3343
AttributionControl: Attribution,
3444
InfoBox: InfoBox,
3545
DrawControl: DrawControl,
36-
ZoomToExtentControl: ZoomToExtent
46+
ZoomToExtentControl: ZoomToExtent,
47+
MapTilerGeocodingControl: GeocodingControl
3748
};
3849

3950
export { controlCatalog, defaultControls };

srcjs/package-lock.json

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

srcjs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"vite": "^6.2.4"
2424
},
2525
"dependencies": {
26+
"@maptiler/geocoding-control": "^2.1.6",
2627
"mustache": "^4.2.0",
2728
"ol": "^10.5.0",
2829
"ol-pmtiles": "^2.0.2"

0 commit comments

Comments
 (0)