Skip to content

Commit

Permalink
feat: export and render building:part
Browse files Browse the repository at this point in the history
  • Loading branch information
c84c committed Feb 29, 2024
1 parent 07e878f commit 9eb2e38
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 83 deletions.
72 changes: 42 additions & 30 deletions resources/process-openmaptiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,29 @@ end
-- Process way tags

function way_function()
local route = Find("route")
local highway = Find("highway")
local waterway = Find("waterway")
local water = Find("water")
local building = Find("building")
local natural = Find("natural")
local historic = Find("historic")
local landuse = Find("landuse")
local leisure = Find("leisure")
local amenity = Find("amenity")
local aeroway = Find("aeroway")
local railway = Find("railway")
local service = Find("service")
local sport = Find("sport")
local shop = Find("shop")
local tourism = Find("tourism")
local man_made = Find("man_made")
local boundary = Find("boundary")
local isClosed = IsClosed()
local housenumber = Find("addr:housenumber")
local write_name = false
local construction = Find("construction")
local route = Find("route")
local highway = Find("highway")
local waterway = Find("waterway")
local water = Find("water")
local building = Find("building")
local building_part = Find("building:part")
local natural = Find("natural")
local historic = Find("historic")
local landuse = Find("landuse")
local leisure = Find("leisure")
local amenity = Find("amenity")
local aeroway = Find("aeroway")
local railway = Find("railway")
local service = Find("service")
local sport = Find("sport")
local shop = Find("shop")
local tourism = Find("tourism")
local man_made = Find("man_made")
local boundary = Find("boundary")
local isClosed = IsClosed()
local housenumber = Find("addr:housenumber")
local write_name = false
local construction = Find("construction")

-- Miscellaneous preprocessing
if Find("disused") == "yes" then return end
Expand Down Expand Up @@ -568,7 +569,7 @@ function way_function()
end

-- Set 'building' and associated
if building~="" then
if building~="" or building_part~="" then
Layer("building", true)
SetBuildingHeightAttributes()
SetMinZoomByArea()
Expand Down Expand Up @@ -773,17 +774,28 @@ end

function SetBuildingHeightAttributes()
local height = tonumber(Find("height"), 10)
local minHeight = tonumber(Find("min_height"), 10)
local levels = tonumber(Find("building:levels"), 10)
local minLevel = tonumber(Find("building:min_level"), 10)
local buildingHeight = tonumber(Find("building:height"), 10)
local finalHeight = height or buildingHeight

local minHeight = tonumber(Find("min_height"), 10)
local buildingMinHeight = tonumber(Find("building:min_height"), 10)
local finalMinHeight = minHeight or buildingMinHeight

local levels = tonumber(Find("levels"), 10)
local buildingLevels = tonumber(Find("building:levels"), 10)
local finalLevels = levels or buildingLevels

local minLevel = tonumber(Find("min_level"), 10)
local buildingMinLevel = tonumber(Find("building:min_level"), 10)
local finalMinLevel = minLevel or buildingMinLevel

local renderHeight = BUILDING_FLOOR_HEIGHT
if height or levels then
renderHeight = height or (levels * BUILDING_FLOOR_HEIGHT)
if finalHeight or finalLevels then
renderHeight = finalHeight or (finalLevels * BUILDING_FLOOR_HEIGHT)
end
local renderMinHeight = 0
if minHeight or minLevel then
renderMinHeight = minHeight or (minLevel * BUILDING_FLOOR_HEIGHT)
if finalMinHeight or finalMinLevel then
renderMinHeight = finalMinHeight or (finalMinLevel * BUILDING_FLOOR_HEIGHT)
end

-- Fix upside-down buildings
Expand Down
114 changes: 69 additions & 45 deletions server/static/index.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,78 @@
<!DOCTYPE html>
<html>

<head>
<meta charset='utf-8' />
<title>Tilemaker example server</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css' rel='stylesheet' />
<script src='http://mapbox-gl-inspect.lukasmartinelli.ch/dist/mapbox-gl-inspect.min.js'></script>
<link href='http://mapbox-gl-inspect.lukasmartinelli.ch/dist/mapbox-gl-inspect.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
#refresh { position: absolute; top: 15px; left: 15px; background-color: white; padding: 5px;
border: 1px solid black; font-family: Avenir; cursor: pointer; }
</style>
<meta charset='utf-8' />
<title>Tilemaker example server</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css' rel='stylesheet' />
<script src='http://mapbox-gl-inspect.lukasmartinelli.ch/dist/mapbox-gl-inspect.min.js'></script>
<link href='http://mapbox-gl-inspect.lukasmartinelli.ch/dist/mapbox-gl-inspect.css' rel='stylesheet' />
<style>
body {
margin: 0;
padding: 0;
}

#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}

#refresh {
position: absolute;
top: 15px;
left: 15px;
background-color: white;
padding: 5px;
border: 1px solid black;
font-family: Avenir;
cursor: pointer;
}
</style>
</head>

<body>

<div id='map'></div>
<!-- <div id='refresh' onclick='reload()'>Reload</div> -->
<script>
var map;

fetch("/metadata")
.then(response => response.json())
.then(data => {
var styleURL = window.location.protocol+'//'+window.location.host+'/style.json';
var bounds = data['bounds'].split(',');
map = new mapboxgl.Map({
container: 'map', // container id
style: styleURL, // stylesheet location
center: [(Number(bounds[0])+Number(bounds[2]))/2,
(Number(bounds[1])+Number(bounds[3]))/2], // starting position [lng, lat]
zoom: 13 // starting zoom
});
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new mapboxgl.AttributionControl({ compact: false, customAttribution:
"Style © <a href='http://openmaptiles.org/'>OpenMapTiles</a> | "+
"Data © <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap contributors</a>" }));

// -- Comment the following lines out to remove debug UI --
map.showTileBoundaries=true;
map.addControl(new MapboxInspect({
showInspectButton: false,
showMapPopup: true
}));
// -- --
}
)
</script>
<div id='map'></div>
<!-- <div id='refresh' onclick='reload()'>Reload</div> -->
<script>
var map;

fetch("/metadata")
.then(response => response.json())
.then(data => {
var styleURL = window.location.protocol + '//' + window.location.host + '/style.json';
var bounds = data['bounds'].split(',');
map = new mapboxgl.Map({
container: 'map', // container id
style: styleURL, // stylesheet location
center: [(Number(bounds[0]) + Number(bounds[2])) / 2,
(Number(bounds[1]) + Number(bounds[3])) / 2], // starting position [lng, lat]
zoom: 13, // starting zoom
pitch: 60, // pitch in degrees
});
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new mapboxgl.AttributionControl({
compact: false, customAttribution:
"Style © <a href='http://openmaptiles.org/'>OpenMapTiles</a> | " +
"Data © <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap contributors</a>"
}));

// -- Comment the following lines out to remove debug UI --
map.showTileBoundaries = true;
map.addControl(new MapboxInspect({
showInspectButton: false,
showMapPopup: true
}));
// -- --
}
);
</script>

</body>

</html>
22 changes: 14 additions & 8 deletions server/static/style.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,23 +366,29 @@
"metadata": {"mapbox:group": "1444849364238.8171"},
"source": "openmaptiles",
"source-layer": "building",
"minzoom": 13,
"maxzoom": 21,
"layout": {
"visibility": "visible"
},
"paint": {
"fill-antialias": true,
"fill-color": {"base": 1, "stops": [[15.5, "#f2eae2"], [16, "#dfdbd7"]]}
"fill-color": "rgba(203, 198, 198, 1)",
"fill-outline-color": {"base": 1, "stops": [[13,"rgba(131, 123, 123, 0.32)"], [14,"rgba(157, 3, 5, 1)"]]}
}
},
{
"id": "building-top",
"type": "fill",
"id": "building-3d",
"type": "fill-extrusion",
"metadata": {"mapbox:group": "1444849364238.8171"},
"source": "openmaptiles",
"source-layer": "building",
"minzoom": 14,
"layout": {"visibility": "visible"},
"paint": {
"fill-color": "#f2eae2",
"fill-opacity": {"base": 1, "stops": [[13, 0], [16, 1]]},
"fill-outline-color": "#dfdbd7",
"fill-translate": {"base": 1, "stops": [[14, [0, 0]], [16, [-2, -2]]]}
"fill-extrusion-color": "rgba(203, 198, 198, 1)",
"fill-extrusion-height": {"property": "render_height","type": "identity"},
"fill-extrusion-base": {"property": "render_min_height","type": "identity"},
"fill-extrusion-opacity": 0.9
}
},
{
Expand Down

0 comments on commit 9eb2e38

Please sign in to comment.