🎨 optimizing telnet version

This commit is contained in:
Michael Straßburger 2017-04-30 04:54:57 +02:00
parent 8edd70c5bb
commit 80f3b5e353
5 changed files with 33 additions and 18 deletions

View File

@ -140,10 +140,7 @@ module.exports = class Renderer
@_drawFeature tile, feature, layer.scale @_drawFeature tile, feature, layer.scale
labels.sort (a, b) -> labels.sort (a, b) ->
if a.feature.properties.localrank a.feature.sorty-b.feature.sort
a.feature.properties.localrank-b.feature.properties.localrank
else
a.feature.properties.scalerank-b.feature.properties.scalerank
for label in labels for label in labels
@_drawFeature label.tile, label.feature, label.scale @_drawFeature label.tile, label.feature, label.scale
@ -178,10 +175,7 @@ module.exports = class Renderer
@canvas.polygon points, feature.color @canvas.polygon points, feature.color
when "symbol" when "symbol"
text = feature.properties["name_"+config.language] or text = feature.label or
feature.properties["name_en"] or
feature.properties["name"] or
feature.properties.house_num or
genericSymbol = "" genericSymbol = ""
return false if @_seen[text] and not genericSymbol return false if @_seen[text] and not genericSymbol

View File

@ -42,12 +42,12 @@ module.exports = class Styler
return false return false
_replaceConstants: (constants, tree) -> _replaceConstants: (constants, tree, level=0) ->
for id, node of tree for id, node of tree
switch typeof node switch typeof node
when 'object' when 'object'
continue if node.constructor.name.match /Stream/ continue if level>1
@_replaceConstants constants, node @_replaceConstants constants, node, level+1
when 'string' when 'string'
if node.charAt(0) is '@' if node.charAt(0) is '@'

View File

@ -13,6 +13,7 @@ rbush = require 'rbush'
x256 = require 'x256' x256 = require 'x256'
earcut = require 'earcut' earcut = require 'earcut'
config = require "./config"
utils = require "./utils" utils = require "./utils"
class Tile class Tile
@ -74,22 +75,34 @@ class Tile
# use feature.loadGeometry() again as soon as we got a 512 extent tileset # use feature.loadGeometry() again as soon as we got a 512 extent tileset
geometries = feature.loadGeometry() #@_reduceGeometry feature, 8 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" if style.type is "fill"
nodes.push @_addBoundaries true, nodes.push @_addBoundaries true,
id: feature.id # id: feature.id
layer: name layer: name
style: style style: style
properties: feature.properties label: label
sort: sort
points: geometries points: geometries
color: colorCode color: colorCode
else else
for points in geometries for points in geometries
nodes.push @_addBoundaries false, nodes.push @_addBoundaries false,
id: feature.id # id: feature.id
layer: name layer: name
style: style style: style
properties: feature.properties label: label
sort: sort
points: points points: points
color: colorCode color: colorCode

View File

@ -25,6 +25,7 @@ catch
module.exports = class TileSource module.exports = class TileSource
cache: {} cache: {}
cached: []
modes: modes:
MBTiles: 1 MBTiles: 1
VectorTile: 2 VectorTile: 2
@ -67,6 +68,10 @@ module.exports = class TileSource
if cached = @cache[[z,x,y].join("-")] if cached = @cache[[z,x,y].join("-")]
return Promise.resolve cached return Promise.resolve cached
if @cached.length > 4
for tile in @cached.splice 0, Math.abs(4-@cached.length)
delete @cache[tile]
switch @mode switch @mode
when @modes.MBTiles then @_getMBTile z, x, y when @modes.MBTiles then @_getMBTile z, x, y
when @modes.HTTP then @_getHTTP 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 resolve @_createTile z, x, y, buffer
_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 tile.load buffer
_initPersistence: -> _initPersistence: ->

View File

@ -3,7 +3,7 @@ module.exports =
# TODO: adapt to osm2vectortiles successor openmaptiles v3) # TODO: adapt to osm2vectortiles successor openmaptiles v3)
# mapscii.me hosts the last available version, 2016-06-20 # mapscii.me hosts the last available version, 2016-06-20
source: "http://mapscii.me/" source: "http://mapscii.me:1337/"
#source: __dirname+"/../mbtiles/regensburg.mbtiles" #source: __dirname+"/../mbtiles/regensburg.mbtiles"
@ -16,7 +16,7 @@ module.exports =
simplifyPolylines: false simplifyPolylines: false
# Downloaded files get persisted in ~/.mapscii # Downloaded files get persisted in ~/.mapscii
persistDownloadedTiles: true persistDownloadedTiles: false
tileRange: 14 tileRange: 14
projectSize: 256 projectSize: 256