From ccad39cf770cad54617d5bd73699fb2b8d65ee13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Fri, 4 Nov 2016 04:00:23 +0100 Subject: [PATCH] :art: supporting style based minzoom, adding sepertae admin_level_4 style --- src/Renderer.coffee | 21 ++++++++++------- src/Styler.coffee | 8 ++++++- src/Termap.coffee | 3 +-- styles/bright.json | 57 +++++++++++++++++++++++++-------------------- 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/Renderer.coffee b/src/Renderer.coffee index 08ed3b9..6519788 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -25,22 +25,22 @@ module.exports = class Renderer tileSize: 4096 projectSize: 256 - maxZoom: 14 + maxZoom: 4 #"poi_label", "water", drawOrder: [ "admin" + "building" - - "road" "water" - "road:structure=bridge" + "road" +# "road:structure=bridge" + "country_label" + "state_label" "place_label" "poi_label" "housenum_label" - "country_label" - "state_label" ] icons: @@ -69,6 +69,9 @@ module.exports = class Renderer margin: 5 cluster: true + place_label: cluster: true + state_label: cluster: true + isDrawing: false lastDrawAt: 0 @@ -139,7 +142,7 @@ module.exports = class Renderer position[1]>@height continue - tiles.push xyz: tile, position: position, scale: scale + tiles.push xyz: tile, zoom: zoom, position: position, scale: scale tiles @@ -194,7 +197,7 @@ module.exports = class Renderer continue if feature.data.id and drawn[feature.data.id] drawn[feature.data.id] = true - @_drawFeature short, feature, tile.scale, tile.xyz.z + @_drawFeature short, feature, tile.scale, tile.zoom @canvas.restore() @@ -232,7 +235,7 @@ module.exports = class Renderer feature.type = "LineString" if layer is "building" or layer is "road" # TODO: zoom level - unless style = @styler.getStyleFor layer, feature, 19-zoom + unless style = @styler.getStyleFor layer, feature, zoom return false toDraw = (@_scaleAndReduce points, scale for points in feature.points) diff --git a/src/Styler.coffee b/src/Styler.coffee index 3547b97..c7eea20 100644 --- a/src/Styler.coffee +++ b/src/Styler.coffee @@ -36,7 +36,7 @@ module.exports = class Styler return false unless @styleByLayer[layer] for style in @styleByLayer[layer] - if style.appliesTo(feature) and ((layer is "road") or (not style.minzoom) or style.minzoom <= zoom) + if style.appliesTo(feature) and ((not style.minzoom) or style.minzoom <= zoom) return style return false @@ -77,5 +77,11 @@ module.exports = class Styler return false for value in filter[2..] when feature.properties[filter[1]] is value true + when ">=" + (feature) -> feature.properties[filter[1]] >= filter[2] + + when "<=" + (feature) -> feature.properties[filter[1]] <= filter[2] + else -> true diff --git a/src/Termap.coffee b/src/Termap.coffee index db280f0..bd5a8a5 100644 --- a/src/Termap.coffee +++ b/src/Termap.coffee @@ -32,6 +32,7 @@ module.exports = class Termap mouseDragging: false tileSource: null + renderer: null zoom: 0 rotation: 0 @@ -59,11 +60,9 @@ module.exports = class Termap @_initKeyboard() @_initMouse() - console.log "loading tilesource" @_initTileSource() .then => - console.log "loaded" @_initRenderer() .then => diff --git a/styles/bright.json b/styles/bright.json index cde74d9..d669aab 100644 --- a/styles/bright.json +++ b/styles/bright.json @@ -6,8 +6,9 @@ "@country_label_2": "#ff0", "@country_label_3": "#ff0", "@country_label_4": "#ff0", - "@admin_level_2": "#f00", - "@admin_level_3": "#ccf" + "@admin_level_2": "#fff", + "@admin_level_3": "#aac", + "@admin_level_4": "#777" }, "layers": [ { @@ -281,14 +282,14 @@ "minzoom": 11 }, { - "type": "fill", + "type": "line", "id": "building", "paint": { "fill-color": { "base": 1, "stops": [ [ - 15.5, + 14.5, "#525652" ], [ @@ -299,7 +300,7 @@ } }, "source-layer": "building", - "minzoom": 15.5 + "minzoom": 14.5 }, { "type": "line", @@ -1425,26 +1426,10 @@ }, { "type": "line", - "id": "admin_level_3", + "id": "admin_level_4", "paint": { - "line-color": "@admin_level_3", - "line-width": { - "base": 1, - "stops": [ - [ - 4, - 0.4 - ], - [ - 5, - 1 - ], - [ - 12, - 3 - ] - ] - } + "line-color": "@admin_level_4", + "line-width": 1 }, "source-layer": "admin", "filter": [ @@ -1452,6 +1437,28 @@ [ ">=", "admin_level", + 4 + ], + [ + "==", + "maritime", + 0 + ] + ] + }, + { + "type": "line", + "id": "admin_level_3", + "paint": { + "line-color": "@admin_level_3", + "line-width": 1 + }, + "source-layer": "admin", + "filter": [ + "all", + [ + "==", + "admin_level", 3 ], [ @@ -1811,7 +1818,7 @@ "paint": { "text-color": "#444" }, - "minzoom": 17.5, + "minzoom": 16.5, "source-layer": "housenum_label" }, {