Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit 6330ec4

Browse files
committed
Temporary work on single map endpoint
1 parent 03f1613 commit 6330ec4

File tree

5 files changed

+27
-36
lines changed

5 files changed

+27
-36
lines changed

.idea/sqldialects.xml

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

macrostrat_tileserver/single_map/__init__.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,22 @@
1414
__here__ = Path(__file__).parent
1515

1616

17-
@router.get("/{compilation}/{z}/{x}/{y}")
17+
@router.get("/{slug}/{z}/{x}/{y}")
1818
async def get_tile(
19-
request: Request,
20-
compilation: MapCompilation,
21-
z: int,
22-
x: int,
23-
y: int,
24-
lithology: List[str] = Query(None)
19+
request: Request,
20+
slug: str,
21+
z: int,
22+
x: int,
23+
y: int,
2524
):
2625
"""Get a tile from the tileserver."""
2726
pool = request.app.state.pool
2827

29-
mapsize, linesize = scales_for_zoom(z)
30-
31-
compilation_name = compilation.value
32-
3328
params = dict(
3429
z=z,
3530
x=x,
3631
y=y,
37-
mapsize=mapsize,
38-
linesize=linesize,
32+
slug=slug,
3933
)
4034

4135
async with pool.acquire() as con:
@@ -44,16 +38,14 @@ async def get_tile(
4438
"units",
4539
compilation=V(compilation_name + ".polygons"),
4640
lithology=lithology,
47-
**params
41+
**params,
4842
)
4943
lines_ = await run_layer_query(
50-
con,
51-
"lines",
52-
compilation=V(compilation_name + ".lines"),
53-
**params
44+
con, "lines", compilation=V(compilation_name + ".lines"), **params
5445
)
5546
return VectorTileResponse(units_, lines_)
5647

48+
5749
def build_lithology_clause(lithology: List[str]):
5850
"""Build a WHERE clause to filter by lithology."""
5951
if lithology is None or len(lithology) == 0:
@@ -72,7 +64,7 @@ def build_lithology_clause(lithology: List[str]):
7264

7365

7466
async def run_layer_query(con, layer_name, **params):
75-
query = get_layer_sql( __here__ / "queries", layer_name)
67+
query = get_layer_sql(__here__ / "queries", layer_name)
7668
if ":where_lithology" in query:
7769
lith_clause = build_lithology_clause(params.get("lithology"))
7870
query = query.replace(":where_lithology", lith_clause)

macrostrat_tileserver/single_map/queries/lines.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ SELECT
77
coalesce(l.type, '') AS "type",
88
tile_layers.tile_geom(l.geom, :envelope) AS geom
99
FROM maps.lines l
10-
WHERE l.source_id = :source_id
10+
JOIN maps.sources s ON l.source_id = s.source_id
11+
WHERE s.slug = :slug
1112
AND ST_Intersects(geom, ST_Transform(:envelope, 4326))

macrostrat_tileserver/single_map/queries/points.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
certainty,
88
comments,
99
tile_layers.tile_geom(geom, :envelope) AS geom
10-
FROM maps.points
11-
WHERE source_id = :source_id
10+
FROM maps.points p
11+
JOIN maps.sources s
12+
WHERE p.source_id = s.source_id
1213
AND ST_Intersects(geom, ST_Transform(:envelope, 4326))
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
WITH mvt_features AS (
2-
SELECT
3-
map_id,
4-
source_id,
5-
geom
6-
FROM maps.polygons
7-
WHERE source_id = :source_id
8-
AND ST_Intersects(geom, ST_Transform(:envelope, 4326))
9-
)
101
SELECT
11-
z.map_id,
12-
z.source_id,
2+
p.map_id,
3+
p.source_id,
134
l.*, -- map legend info
145
tile_layers.tile_geom(z.geom, :envelope) AS geom
15-
FROM mvt_features z
16-
LEFT JOIN maps.map_legend ON z.map_id = map_legend.map_id
6+
FROM maps.polygons p
7+
JOIN maps.sources s
8+
ON p.source_id = s.source_id
9+
LEFT JOIN maps.map_legend ml
10+
ON p.map_id = ml.map_id
1711
LEFT JOIN tile_layers.map_legend_info AS l
18-
ON l.legend_id = map_legend.legend_id;
12+
ON l.legend_id = ml.legend_id
13+
WHERE s.slug = :slug
14+
AND ST_Intersects(geom, ST_Transform(:envelope, 4326))

0 commit comments

Comments
 (0)