This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


The following commit(s) were added to refs/heads/main by this push:
     new a6d7edb8 Add building extrusions (#788)
a6d7edb8 is described below

commit a6d7edb8358b0607071fdcc4f3df3ce6b4b5ed70
Author: Bertil Chapuis <[email protected]>
AuthorDate: Sat Nov 11 01:18:16 2023 +0100

    Add building extrusions (#788)
    
    * Add building extrusions
    
    * Improve building style
    
    * Colors are disabled due to z-fighting
---
 .../org/apache/baremaps/server/TileResource.java   |  5 ++
 basemap/layers/building/extrusion.js               | 68 ++++++++++++++++++++++
 basemap/layers/building/shape.js                   |  7 +++
 basemap/layers/building/tileset.js                 | 46 +++++++++++++--
 basemap/layers/waterway/prepare.sql                |  1 +
 basemap/style.js                                   |  2 +
 basemap/tileset.js                                 |  2 +-
 7 files changed, 126 insertions(+), 5 deletions(-)

diff --git 
a/baremaps-server/src/main/java/org/apache/baremaps/server/TileResource.java 
b/baremaps-server/src/main/java/org/apache/baremaps/server/TileResource.java
index 4cc84227..bb074b94 100644
--- a/baremaps-server/src/main/java/org/apache/baremaps/server/TileResource.java
+++ b/baremaps-server/src/main/java/org/apache/baremaps/server/TileResource.java
@@ -29,6 +29,8 @@ import javax.ws.rs.core.Response;
 import org.apache.baremaps.tilestore.TileCoord;
 import org.apache.baremaps.tilestore.TileStore;
 import org.apache.baremaps.tilestore.TileStoreException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A resource that provides access to the tiles.
@@ -37,6 +39,8 @@ import org.apache.baremaps.tilestore.TileStoreException;
 @javax.ws.rs.Path("/")
 public class TileResource {
 
+  private static final Logger logger = 
LoggerFactory.getLogger(TileResource.class);
+
   public static final String TILE_ENCODING = "gzip";
 
   public static final String TILE_TYPE = "application/vnd.mapbox-vector-tile";
@@ -68,6 +72,7 @@ public class TileResource {
         return Response.status(204).build();
       }
     } catch (TileStoreException ex) {
+      logger.error("Error while reading tile.", ex);
       return Response.status(404).build();
     }
   }
diff --git a/basemap/layers/building/extrusion.js 
b/basemap/layers/building/extrusion.js
new file mode 100644
index 00000000..51081931
--- /dev/null
+++ b/basemap/layers/building/extrusion.js
@@ -0,0 +1,68 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ **/
+import theme from "../../theme.js";
+
+export default {
+    id: 'building-extrusion',
+    type: 'fill-extrusion',
+    source: 'baremaps',
+    'source-layer': 'building',
+    filter: ['!=', ['get', 'building'], 'no'],
+    layout: {
+        visibility: 'visible',
+    },
+    minzoom: 15,
+    paint: {
+        "fill-extrusion-base": [
+            'interpolate',
+            ['linear'],
+            ['zoom'],
+            15,
+            0,
+            16,
+            ['get', "extrusion:base"]
+        ],
+        "fill-extrusion-height": [
+            'interpolate',
+            ['linear'],
+            ['zoom'],
+            15,
+            0,
+            16,
+            ['get', "extrusion:height"]
+        ],
+        "fill-extrusion-opacity": [
+            'interpolate',
+            ['linear'],
+            ['zoom'],
+            15,
+            0,
+            16,
+            0.8
+        ],
+        "fill-extrusion-color": theme.buildingShapeFillColor,
+        // Having muliple colors for building parts results in z-fighting
+        // https://github.com/maplibre/maplibre-gl-js/issues/3157
+        // https://github.com/maplibre/maplibre-gl-js/issues/3187
+        // "fill-extrusion-color": [
+        //     "case",
+        //     ["has", "building:colour"],
+        //     ["get", "building:colour"],
+        //     theme.buildingShapeFillColor,
+        // ],
+    },
+}
diff --git a/basemap/layers/building/shape.js b/basemap/layers/building/shape.js
index d5f0116c..12a3f154 100644
--- a/basemap/layers/building/shape.js
+++ b/basemap/layers/building/shape.js
@@ -29,5 +29,12 @@ export default {
         'fill-antialias': false,
         'fill-color': theme.buildingShapeFillColor,
         'fill-outline-color': theme.buildingShapeFillOutlineColor,
+        'fill-opacity': [
+            'interpolate',
+            ['linear'],
+            ['zoom'],
+            13, 0,
+            13.5, 1
+        ]
     },
 }
diff --git a/basemap/layers/building/tileset.js 
b/basemap/layers/building/tileset.js
index 66c9bf1f..e7fabd2f 100644
--- a/basemap/layers/building/tileset.js
+++ b/basemap/layers/building/tileset.js
@@ -21,14 +21,52 @@ export default {
         {
             minzoom: 13,
             maxzoom: 20,
-            sql:
-                "SELECT id, tags, geom FROM osm_ways WHERE tags ? 'building'",
+            sql: `
+                SELECT
+                    id,
+                    tags
+                        || jsonb_build_object('extrusion:base', (CASE
+                            WHEN tags ? 'building:min_height'
+                                THEN (tags ->> 'building:min_height')::real
+                            WHEN tags ->> 'building:min_level' ~ '^[0-9.]+$'
+                                THEN (tags ->> 'building:min_level')::real * 3
+                            ELSE 0 END))
+                        || jsonb_build_object('extrusion:height', (CASE
+                            WHEN tags ? 'height'
+                               THEN (SUBSTRING(tags ->> 'height' FROM 
'^[0-9]+'))::real
+                            WHEN tags ? 'building:height'
+                               THEN (tags ->> 'building:height')::real
+                            WHEN tags ->> 'building:levels' ~ '^[0-9.]+$'
+                               THEN (tags ->> 'building:levels')::real * 3
+                            ELSE 6 END)) as tags,
+                    geom
+                FROM osm_ways
+                WHERE (tags ? 'building' OR tags ? 'building:part') AND ((NOT 
tags ? 'layer') OR (tags ->> 'layer')::real >= 0)`,
         },
         {
             minzoom: 13,
             maxzoom: 20,
-            sql:
-                "SELECT id, tags, geom FROM osm_relations WHERE tags ? 
'building'",
+            sql: `
+                SELECT
+                    id,
+                    tags
+                        || jsonb_build_object('extrusion:base', (CASE
+                            WHEN tags ? 'building:min_height'
+                                THEN (tags ->> 'building:min_height')::real
+                            WHEN tags ->> 'building:min_level' ~ '^[0-9.]+$'
+                                THEN (tags ->> 'building:min_level')::real * 3
+                            ELSE 0 END))
+                        || jsonb_build_object('extrusion:height', (CASE
+                            WHEN tags ? 'height'
+                                THEN (SUBSTRING(tags ->> 'height' FROM 
'^[0-9]+'))::real
+                            WHEN tags ? 'building:height'
+                                THEN (tags ->> 'building:height')::real
+                            WHEN tags ->> 'building:levels' ~ '^[0-9.]+$'
+                                THEN (tags ->> 'building:levels')::real * 3
+                            ELSE 6 END)) as tags,
+                    geom
+                FROM osm_relations
+                WHERE (tags ? 'building' OR tags ? 'building:part') AND ((NOT 
tags ? 'layer') OR (tags ->> 'layer')::real >= 0)`,
         },
     ],
 }
diff --git a/basemap/layers/waterway/prepare.sql 
b/basemap/layers/waterway/prepare.sql
index 5a588d90..54c8928a 100644
--- a/basemap/layers/waterway/prepare.sql
+++ b/basemap/layers/waterway/prepare.sql
@@ -23,6 +23,7 @@ WITH
                 geom AS geom
         FROM osm_linestring
         WHERE tags ->> 'waterway' IN ('river', 'stream', 'canal', 'drain', 
'ditch')
+        AND NOT tags ? 'intermittent'
     ),
     -- Cluster the linestrings
     clustered AS (
diff --git a/basemap/style.js b/basemap/style.js
index 448ff763..ab23bca4 100644
--- a/basemap/style.js
+++ b/basemap/style.js
@@ -53,6 +53,7 @@ import highway_label from './layers/highway/highway_label.js';
 import ocean_overlay from './layers/ocean/overlay.js';
 import route_line from "./layers/route/style.js"
 import building_shape from "./layers/building/shape.js";
+import building_extrusion from "./layers/building/extrusion.js";
 import building_number from "./layers/building/number.js";
 import man_made_bridge from "./layers/man_made/bridge.js";
 import man_made_pier_line from "./layers/man_made/pier_line.js";
@@ -121,6 +122,7 @@ export default {
         natural_trunk,
         boundary_line,
         waterway_label,
+        building_extrusion,
         icon,
         point_label,
         country_label,
diff --git a/basemap/tileset.js b/basemap/tileset.js
index 611d8e1a..31d5520c 100644
--- a/basemap/tileset.js
+++ b/basemap/tileset.js
@@ -64,6 +64,6 @@ export default {
     power,
     railway,
     route,
-    //waterway,
+    waterway,
   ]
 }

Reply via email to