📐 adding hole support to polygon triangulation

This commit is contained in:
Michael Straßburger 2016-11-08 18:32:10 +01:00
parent 73a56dce9d
commit f2cbeb465e
3 changed files with 32 additions and 21 deletions

View File

@ -44,19 +44,14 @@ module.exports = class Canvas
background: (x, y, color) ->
@buffer.setBackground x, y, color
polygon: (polylines, color) ->
polygon: (rings, color) ->
vertices = []
holes = []
xs = {}
ys = {}
#
# for points in polylines
# if vertices.length
# continue
# holes.push vertices.length/2
polylines.push polylines[0]
for point in polylines
for ring in rings
if vertices.length
holes.push vertices.length/2
for point in ring
vertices = vertices.concat point
try

View File

@ -14,6 +14,8 @@ Styler = require './Styler'
Tile = require './Tile'
utils = require './utils'
simplify = require 'simplify-js'
module.exports = class Renderer
cache: {}
config:
@ -210,16 +212,17 @@ module.exports = class Renderer
if feature.style.minzoom and tile.zoom < feature.style.minzoom
return false
points = @_scaleAndReduce tile, feature, feature.points
switch feature.style.type
when "line"
width = feature.style.paint['line-width']
width = width.stops[0][1] if width instanceof Object
points = @_scaleAndReduce tile, feature, feature.points
@canvas.polyline points, feature.color, width if points.length
when "fill"
points = (@_scaleAndReduce tile, feature, p, false for p in feature.points)
@canvas.polygon points, feature.color
# if points.length is 3
# @canvas._filledTriangle points[0], points[1], points[2], feature.color
@ -281,7 +284,13 @@ module.exports = class Renderer
outside = null
scaled.push [lastX, lastY]
scaled.push [x, y]
scaled.push [x, y] #x: x, y: y
if scaled.length < 2
if feature.style.type isnt "symbol"
return []
# else
# scaled = ([point.x, point.y] for point in simplify scaled, 2, false)
if filter
if scaled.length is 2
@ -291,7 +300,4 @@ module.exports = class Renderer
@_seen[ka] = @_seen[kb] = true
if scaled.length < 2 and feature.style.type isnt "symbol"
return []
scaled

View File

@ -74,8 +74,18 @@ class Tile
# use feature.loadGeometry() again as soon as we got a 512 extent tileset
geometries = feature.loadGeometry() #@_reduceGeometry feature, 8
for points in (if style.type is "fill" then [geometries[0]] else geometries)
nodes.push @_addBoundaries
if style.type is "fill"
nodes.push @_addBoundaries true,
id: feature.id
layer: name
style: style
properties: feature.properties
points: geometries
color: colorCode
else
for points in geometries
nodes.push @_addBoundaries false,
id: feature.id
layer: name
style: style
@ -91,13 +101,13 @@ class Tile
@layers = layers
_addBoundaries: (data) ->
_addBoundaries: (deep, data) ->
minX = Infinity
maxX = -Infinity
minY = Infinity
maxY = -Infinity
for p in data.points
for p in (if deep then data.points[0] else data.points)
minX = p.x if p.x < minX
maxX = p.x if p.x > maxX
minY = p.y if p.y < minY