Commit a0c716a0 authored by Ian Lee's avatar Ian Lee

Added support for phoneNumber

parent e0b744e6
......@@ -6,7 +6,7 @@ Changelog
-----------------
- back to development
- Add support for address
- Add support for address and phoneNumber
0.7 (2014/08/01)
----------------
......
......@@ -205,7 +205,7 @@ class _Feature(_BaseObject):
# You can use the <address> tag to specify the location of a point
# instead of using latitude and longitude coordinates.
# TODO phoneNumber = None
_phoneNumber = None
# A string value representing a telephone number.
# This element is used by Google Maps Mobile only.
......@@ -455,6 +455,20 @@ class _Feature(_BaseObject):
else:
raise ValueError
@property
def phoneNumber(self):
if self._phoneNumber:
return self._phoneNumber
@phoneNumber.setter
def phoneNumber(self, phoneNumber):
if isinstance(phoneNumber, basestring):
self._phoneNumber = phoneNumber
elif phoneNumber is None:
self._phoneNumber = None
else:
raise ValueError
def etree_element(self):
element = super(_Feature, self).etree_element()
if self.name:
......@@ -498,6 +512,9 @@ class _Feature(_BaseObject):
if self._address is not None:
address = etree.SubElement(element, '%saddress' % self.ns)
address.text = self._address
if self._phoneNumber is not None:
phoneNumber = etree.SubElement(element, '%sphoneNumber' % self.ns)
phoneNumber.text = self._phoneNumber
return element
def from_element(self, element):
......@@ -573,6 +590,9 @@ class _Feature(_BaseObject):
address = element.find('%saddress' % self.ns)
if address is not None:
self.address = address.text
phoneNumber = element.find('%sphoneNumber' % self.ns)
if phoneNumber is not None:
self.phoneNumber = phoneNumber.text
class _Container(_Feature):
......
......@@ -333,6 +333,13 @@ class BuildKmlTestCase(unittest.TestCase):
self.assertTrue(address in str(d.to_string()))
self.assertTrue('address>' in str(d.to_string()))
def test_phone_number(self):
phone = '+1 234 567 8901'
d = kml.Document()
d.phoneNumber = phone
self.assertTrue(phone in str(d.to_string()))
self.assertTrue('phoneNumber>' in str(d.to_string()))
class KmlFromStringTestCase(unittest.TestCase):
def test_document(self):
......@@ -834,6 +841,22 @@ class KmlFromStringTestCase(unittest.TestCase):
doc2.from_string(doc.to_string())
self.assertEqual(doc.to_string(), doc2.to_string())
def test_phone_number(self):
doc = kml.Document()
doc.from_string("""
<kml:Document xmlns:kml="http://www.opengis.net/kml/2.2" id="pm-id">
<kml:name>pm-name</kml:name>
<kml:description>pm-description</kml:description>
<kml:visibility>1</kml:visibility>
<kml:phoneNumber>+1 234 567 8901</kml:phoneNumber>
</kml:Document>
""")
doc2 = kml.Document()
doc2.from_string(doc.to_string())
self.assertEqual(doc.to_string(), doc2.to_string())
class StyleTestCase(unittest.TestCase):
def test_styleurl(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment