Skip to content

Implement the ability to set "id" for most elements #19

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

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
7 changes: 5 additions & 2 deletions simplekml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class Kmlable(object):
_compiling = False
_namespaces = ['xmlns="http://www.opengis.net/kml/2.2"', 'xmlns:gx="http://www.google.com/kml/ext/2.2"']

def __init__(self):
self._id = str(Kmlable._globalid)
def __init__(self, id=None):
if not id:
self._id = str(Kmlable._globalid)
else:
self._id = id
Kmlable._globalid += 1
try:
from collections import OrderedDict
Expand Down
3 changes: 2 additions & 1 deletion simplekml/featgeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Feature(Kmlable):

def __init__(self,
name=None,
id=None,
visibility=None,
open=None,
atomauthor=None,
Expand All @@ -57,7 +58,7 @@ def __init__(self,
region=None,
extendeddata=None,
gxballoonvisibility=None):
super(Feature, self).__init__()
super(Feature, self).__init__(id=id)
self._kml['name'] = name
self._kml['visibility'] = visibility
self._kml['open'] = open
Expand Down
4 changes: 2 additions & 2 deletions simplekml/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class Schema(Kmlable):
The arguments are the same as the properties.
"""

def __init__(self, name=None):
super(Schema, self).__init__()
def __init__(self, name=None, id=None):
super(Schema, self).__init__(id=id)
self._kml['name'] = name
self.simplefields = []
self.gxsimplearrayfields = []
Expand Down
14 changes: 8 additions & 6 deletions simplekml/styleselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class StyleSelector(Kmlable):
There are no arguments.
"""

def __init__(self):
super(StyleSelector, self).__init__()
def __init__(self, id=None):
super(StyleSelector, self).__init__(id=id)

@property
def id(self):
Expand Down Expand Up @@ -57,8 +57,9 @@ def __init__(self,
linestyle=None,
polystyle=None,
balloonstyle=None,
liststyle=None):
super(Style, self).__init__()
liststyle=None,
id=None):
super(Style, self).__init__(id=id)
self._kml["IconStyle_"] = iconstyle
self._kml["LabelStyle_"] = labelstyle
self._kml["LineStyle_"] = linestyle
Expand Down Expand Up @@ -158,8 +159,9 @@ class StyleMap(StyleSelector):
"""
def __init__(self,
normalstyle=None,
highlightstyle=None):
super(StyleMap, self).__init__()
highlightstyle=None,
id=None):
super(StyleMap, self).__init__(id=id)
self._pairnormal = None
self._pairhighlight = None
self.normalstyle = normalstyle
Expand Down
14 changes: 8 additions & 6 deletions simplekml/substyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class ColorStyle(Kmlable):
Not to be used directly.
"""

def __init__(self, color=None, colormode=ColorMode.normal):
super(ColorStyle, self).__init__()
def __init__(self, color=None, colormode=ColorMode.normal, id=None):
super(ColorStyle, self).__init__(id=id)
self._kml["color"] = color
self._kml["colorMode"] = colormode

Expand Down Expand Up @@ -305,8 +305,9 @@ def __init__(self,
bgcolor=None,
textcolor=None,
text=None,
displaymode=DisplayMode.default):
super(BalloonStyle, self).__init__()
displaymode=DisplayMode.default,
id=None):
super(BalloonStyle, self).__init__(id=id)
self._kml["bgColor"] = bgcolor
self._kml["textColor"] = textcolor
self._kml["text"] = text
Expand Down Expand Up @@ -373,8 +374,9 @@ class ListStyle(Kmlable):
def __init__(self,
listitemtype=ListItemType.check,
bgcolor=None,
itemicon=None):
super(ListStyle, self).__init__()
itemicon=None,
id=None):
super(ListStyle, self).__init__(id=id)
self._kml["listItemType"] = listitemtype
self._kml["bgColor"] = bgcolor
self._kml["ItemIcon"] = itemicon
Expand Down