Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for line offset parameter #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified cascadenik-compile.py
100644 → 100755
Empty file.
11 changes: 7 additions & 4 deletions cascadenik/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def get_line_rules(declarations):
This function is wise to line-<foo>, inline-<foo>, and outline-<foo> properties,
and will generate multiple LineSymbolizers if necessary.
"""
property_map = {'line-color': 'stroke', 'line-width': 'stroke-width',
property_map = {'line-color': 'stroke', 'line-width': 'stroke-width', 'line-offset': 'offset',
'line-opacity': 'stroke-opacity', 'line-join': 'stroke-linejoin',
'line-cap': 'stroke-linecap', 'line-dasharray': 'stroke-dasharray',
'line-meta-output': 'meta-output', 'line-meta-writer': 'meta-writer'}
Expand All @@ -926,34 +926,37 @@ def get_line_rules(declarations):
width = values.has_key('line-width') and values['line-width'].value
color = values.has_key('line-color') and values['line-color'].value

offset = values.has_key('line-offset') and values['line-offset'].value or None
opacity = values.has_key('line-opacity') and values['line-opacity'].value or None
join = values.has_key('line-join') and values['line-join'].value or None
cap = values.has_key('line-cap') and values['line-cap'].value or None
dashes = values.has_key('line-dasharray') and values['line-dasharray'].value or None

line_symbolizer = color and width and output.LineSymbolizer(color, width, opacity, join, cap, dashes) or False
line_symbolizer = color and width and output.LineSymbolizer(color, width, opacity, join, cap, dashes, offset) or False

width = values.has_key('inline-width') and values['inline-width'].value
color = values.has_key('inline-color') and values['inline-color'].value

offset = values.has_key('line-offset') and values['line-offset'].value or None
opacity = values.has_key('inline-opacity') and values['inline-opacity'].value or None
join = values.has_key('inline-join') and values['inline-join'].value or None
cap = values.has_key('inline-cap') and values['inline-cap'].value or None
dashes = values.has_key('inline-dasharray') and values['inline-dasharray'].value or None

inline_symbolizer = color and width and output.LineSymbolizer(color, width, opacity, join, cap, dashes) or False
inline_symbolizer = color and width and output.LineSymbolizer(color, width, opacity, join, cap, dashes, offset) or False

# outline requires regular line to have a meaningful width
width = values.has_key('outline-width') and values.has_key('line-width') \
and values['line-width'].value + values['outline-width'].value * 2
color = values.has_key('outline-color') and values['outline-color'].value

offset = values.has_key('line-offset') and values['line-offset'].value or None
opacity = values.has_key('outline-opacity') and values['outline-opacity'].value or None
join = values.has_key('outline-join') and values['outline-join'].value or None
cap = values.has_key('outline-cap') and values['outline-cap'].value or None
dashes = values.has_key('outline-dasharray') and values['outline-dasharray'].value or None

outline_symbolizer = color and width and output.LineSymbolizer(color, width, opacity, join, cap, dashes) or False
outline_symbolizer = color and width and output.LineSymbolizer(color, width, opacity, join, cap, dashes, offset) or False

if outline_symbolizer or line_symbolizer or inline_symbolizer:
rules.append(make_rule(filter, outline_symbolizer, line_symbolizer, inline_symbolizer))
Expand Down
6 changes: 5 additions & 1 deletion cascadenik/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,22 @@ def to_mapnik(self):
return sym

class LineSymbolizer:
def __init__(self, color, width, opacity=None, join=None, cap=None, dashes=None):
def __init__(self, color, width, opacity=None, join=None, cap=None, dashes=None, offset=None):
assert color.__class__ is style.color
assert type(width) in (int, float)
assert opacity is None or type(opacity) in (int, float)
assert join is None or isinstance(join, basestring)
assert cap is None or isinstance(cap, basestring)
assert dashes is None or dashes.__class__ is style.numbers
assert offset is None or type(offset) in (int, float)

self.color = color
self.width = width
self.opacity = opacity
self.join = safe_str(join)
self.cap = safe_str(cap)
self.dashes = dashes
self.offset = offset

def __repr__(self):
return 'Line(%s, %s)' % (self.color, self.width)
Expand All @@ -258,6 +260,8 @@ def to_mapnik(self):
stroke.add_dash(length, gap)

sym = mapnik.LineSymbolizer(stroke)
if self.offset != None:
sym.offset = self.offset

return sym

Expand Down
3 changes: 3 additions & 0 deletions cascadenik/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def __eq__(self, other):
# 0.0 - n (default 1.0)
'line-width': float,

# 0.0 - n (default 1.0)
'line-offset': float,

# 0.0 - 1.0 (default 1.0)
'line-opacity': float,

Expand Down