Skip to content

Commit

Permalink
Merge pull request #20 from jericks/issue5
Browse files Browse the repository at this point in the history
Fix issue #5, allow for specifying size in Icon
  • Loading branch information
Justin Deoliveira committed Aug 7, 2012
2 parents 6d7655a + 8f93bf1 commit ff66884
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions geoscript/style/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from geoscript.util import toURL
from geoscript.style import util
from geoscript.style.symbolizer import Symbolizer
from geoscript.style.expression import Expression
from org.geotools.styling import PointSymbolizer, PolygonSymbolizer

class Icon(Symbolizer):
Expand All @@ -14,14 +15,15 @@ class Icon(Symbolizer):
>>> icon = Icon('tests/work/colorblocks.png', 'image/png')
>>> icon = Icon('http://v2.suite.opengeo.org/geoserver/styles/smileyface.png', 'image/png')
"""
def __init__(self, url, format=None):
def __init__(self, url, format=None, size=None):
Symbolizer.__init__(self)
self.url = toURL(url)

if not format:
format = mimetypes.guess_type(url)[0]

self.format = format
self.size = Expression(size) if size else None

def _prepare(self, rule):
syms = util.symbolizers(rule, PointSymbolizer)
Expand All @@ -32,6 +34,8 @@ def _apply(self, sym):
Symbolizer._apply(self, sym)
eg = self.factory.createExternalGraphic(self.url, self.format)
g = util.graphic(sym)
if self.size:
g.size = self.size.expr
g.setMarks([])
if g:
g.graphicalSymbols().add(eg)
Expand Down

0 comments on commit ff66884

Please sign in to comment.