From bc2d050581dad76cfe26fd480ba9f08034cf413b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Thu, 29 Sep 2016 23:27:58 +0200 Subject: [PATCH] :art: respecting style.minzoom --- README.md | 4 +++- src/LabelBuffer.coffee | 8 +++----- src/Renderer.coffee | 5 +---- src/Styler.coffee | 3 ++- src/Termap.coffee | 7 ++++++- styles/bright.json | 4 +++- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2b60d8e..42c78cd 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,9 @@ No web browser around? No worries - discover the planet in your console! * [`sphericalmercator`](https://github.com/mapbox/node-sphericalmercator) for [EPSG:3857](http://spatialreference.org/ref/sr-org/6864/) <> [WGS84](http://spatialreference.org/ref/epsg/wgs-84/) conversions ### TODOs -* [ ] mouse hover of POIs (maybe even polygons?) +* [ ] mouse hover + * [x] of POIs/labels + * [ ] maybe even polygons/-lines? * [ ] termap-server - telnet and ssh access * [ ] cli linking * [ ] mapping of view to tiles to show diff --git a/src/LabelBuffer.coffee b/src/LabelBuffer.coffee index 2f78cda..fec3a1f 100644 --- a/src/LabelBuffer.coffee +++ b/src/LabelBuffer.coffee @@ -3,13 +3,12 @@ by Michael Strassburger Using 2D spatial indexing to avoid overlapping labels and markers - Future: to detect collision on mouse interaction + and to find labels underneath a mouse cursor's position ### rbush = require 'rbush' module.exports = class LabelBuffer - treeWithMargin: null tree: null margin: 5 @@ -20,7 +19,6 @@ module.exports = class LabelBuffer clear: -> @tree.clear() - project: (x, y) -> [Math.floor(x/2), Math.floor(y/4)] @@ -42,6 +40,6 @@ module.exports = class LabelBuffer _calculateArea: (text, x, y, margin = 0) -> minX: x-margin - minY: y-margin/4 + minY: y-margin/2 maxX: x+margin+text.length - maxY: y+margin/4 + maxY: y+margin/2 diff --git a/src/Renderer.coffee b/src/Renderer.coffee index 15a905b..a797a54 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -54,11 +54,8 @@ module.exports = class Renderer layers: housenum_label: - minZoom: 1.5 margin: 3 - building: minZoom: 3.8 poi_label: - minZoom: 3 margin: 5 cluster: true @@ -135,7 +132,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, 14 + unless style = @styler.getStyleFor layer, feature, 19-@zoom return false toDraw = (@_scaleAndReduce points, scale for points in feature.points) diff --git a/src/Styler.coffee b/src/Styler.coffee index 32147cb..b804697 100644 --- a/src/Styler.coffee +++ b/src/Styler.coffee @@ -34,7 +34,8 @@ module.exports = class Styler return false unless @styleByLayer[layer] for style in @styleByLayer[layer] - return style if style.appliesTo feature + if style.appliesTo(feature) and ((layer is "road") or (not style.minzoom) or style.minzoom <= zoom) + return style false diff --git a/src/Termap.coffee b/src/Termap.coffee index 35aaad1..fdb6019 100644 --- a/src/Termap.coffee +++ b/src/Termap.coffee @@ -146,7 +146,12 @@ module.exports = class Termap _getFooter: -> features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2) - "features: ["+features.map((f) -> f.feature.id).join(", ")+"] "+ + "features: ["+features.map((f) -> + JSON.stringify + name: f.feature.properties.name + type: f.feature.properties.type + rank: f.feature.properties.scalerank + ).join(", ")+"] "+ "#{@mousePosition.x} #{@mousePosition.y}" #"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}] zoom: #{utils.digits @zoom, 2}" #"bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(', ')}]" diff --git a/styles/bright.json b/styles/bright.json index 2d5505e..312d94f 100644 --- a/styles/bright.json +++ b/styles/bright.json @@ -289,7 +289,8 @@ ] } }, - "source-layer": "building" + "source-layer": "building", + "minzoom": 15.5 }, { "type": "line", @@ -1801,6 +1802,7 @@ "paint": { "text-color": "#444" }, + "minzoom": 17.5, "source-layer": "housenum_label" }, {