diff options
author | Michael Straßburger <codepoet@cpan.org> | 2017-04-30 04:54:57 +0200 |
---|---|---|
committer | Michael Straßburger <codepoet@cpan.org> | 2017-04-30 04:54:57 +0200 |
commit | 80f3b5e35375688965a0746661c902bc432627e2 (patch) | |
tree | 20564d05fb546bac8796e8f05501b1bf215e5971 | |
parent | 8edd70c5bbce2f6fbf63df00feb0132702db0813 (diff) |
:art: optimizing telnet versiontelnetpoc
-rw-r--r-- | src/Renderer.coffee | 10 | ||||
-rw-r--r-- | src/Styler.coffee | 6 | ||||
-rw-r--r-- | src/Tile.coffee | 21 | ||||
-rw-r--r-- | src/TileSource.coffee | 10 | ||||
-rw-r--r-- | src/config.coffee | 4 |
5 files changed, 33 insertions, 18 deletions
diff --git a/src/Renderer.coffee b/src/Renderer.coffee index 51da171..d32db05 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -140,10 +140,7 @@ module.exports = class Renderer @_drawFeature tile, feature, layer.scale labels.sort (a, b) -> - if a.feature.properties.localrank - a.feature.properties.localrank-b.feature.properties.localrank - else - a.feature.properties.scalerank-b.feature.properties.scalerank + a.feature.sorty-b.feature.sort for label in labels @_drawFeature label.tile, label.feature, label.scale @@ -178,10 +175,7 @@ module.exports = class Renderer @canvas.polygon points, feature.color when "symbol" - text = feature.properties["name_"+config.language] or - feature.properties["name_en"] or - feature.properties["name"] or - feature.properties.house_num or + text = feature.label or genericSymbol = "◉" return false if @_seen[text] and not genericSymbol diff --git a/src/Styler.coffee b/src/Styler.coffee index b0f6711..f3f9015 100644 --- a/src/Styler.coffee +++ b/src/Styler.coffee @@ -42,12 +42,12 @@ module.exports = class Styler return false - _replaceConstants: (constants, tree) -> + _replaceConstants: (constants, tree, level=0) -> for id, node of tree switch typeof node when 'object' - continue if node.constructor.name.match /Stream/ - @_replaceConstants constants, node + continue if level>1 + @_replaceConstants constants, node, level+1 when 'string' if node.charAt(0) is '@' diff --git a/src/Tile.coffee b/src/Tile.coffee index 1702fb9..b948086 100644 --- a/src/Tile.coffee +++ b/src/Tile.coffee @@ -13,6 +13,7 @@ rbush = require 'rbush' x256 = require 'x256' earcut = require 'earcut' +config = require "./config" utils = require "./utils" class Tile @@ -74,22 +75,34 @@ class Tile # use feature.loadGeometry() again as soon as we got a 512 extent tileset geometries = feature.loadGeometry() #@_reduceGeometry feature, 8 + sort = feature.properties.localrank or feature.properties.scalerank + label = if feature.properties.$type is "Point" + feature.properties["name_"+config.language] or + feature.properties.name_en or + feature.properties.name or + feature.properties.house_num + else + undefined + if style.type is "fill" nodes.push @_addBoundaries true, - id: feature.id +# id: feature.id layer: name style: style - properties: feature.properties + label: label + sort: sort points: geometries color: colorCode else + for points in geometries nodes.push @_addBoundaries false, - id: feature.id +# id: feature.id layer: name style: style - properties: feature.properties + label: label + sort: sort points: points color: colorCode diff --git a/src/TileSource.coffee b/src/TileSource.coffee index b30485f..5cae1ee 100644 --- a/src/TileSource.coffee +++ b/src/TileSource.coffee @@ -25,6 +25,7 @@ catch module.exports = class TileSource cache: {} + cached: [] modes: MBTiles: 1 VectorTile: 2 @@ -67,6 +68,10 @@ module.exports = class TileSource if cached = @cache[[z,x,y].join("-")] return Promise.resolve cached + if @cached.length > 4 + for tile in @cached.splice 0, Math.abs(4-@cached.length) + delete @cache[tile] + switch @mode when @modes.MBTiles then @_getMBTile z, x, y when @modes.HTTP then @_getHTTP z, x, y @@ -93,7 +98,10 @@ module.exports = class TileSource resolve @_createTile z, x, y, buffer _createTile: (z, x, y, buffer) -> - tile = @cache[[z,x,y].join("-")] = new Tile @styler + name = [z,x,y].join("-") + @cached.push name + + tile = @cache[name] = new Tile @styler tile.load buffer _initPersistence: -> diff --git a/src/config.coffee b/src/config.coffee index 6cd6bc9..f0d0afd 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -3,7 +3,7 @@ module.exports = # TODO: adapt to osm2vectortiles successor openmaptiles v3) # mapscii.me hosts the last available version, 2016-06-20 - source: "http://mapscii.me/" + source: "http://mapscii.me:1337/" #source: __dirname+"/../mbtiles/regensburg.mbtiles" @@ -16,7 +16,7 @@ module.exports = simplifyPolylines: false # Downloaded files get persisted in ~/.mapscii - persistDownloadedTiles: true + persistDownloadedTiles: false tileRange: 14 projectSize: 256 |