How to use the fastkml.styles.StyleUrl function in fastkml

To help you get started, we’ve selected a few fastkml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cleder / fastkml / fastkml / test_main.py View on Github external
def test_styleurl(self):
        f = kml.Document()
        f.styleUrl = '#somestyle'
        self.assertEqual(f.styleUrl, '#somestyle')
        self.assertTrue(isinstance(f._styleUrl, styles.StyleUrl))
        s = styles.StyleUrl(config.NS, url='#otherstyle')
        f.styleUrl = s
        self.assertTrue(isinstance(f._styleUrl, styles.StyleUrl))
        self.assertEqual(f.styleUrl, '#otherstyle')
        f2 = kml.Document()
        f2.from_string(f.to_string())
        self.assertEqual(f.to_string(), f2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
highlight
              #highlightState
            
          
          
        """
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertTrue(
            isinstance(list(list(k.features())[0].styles())[0], styles.StyleMap)
        )
        sm = list(list(list(k.features())[0].styles()))[0]
        self.assertTrue(isinstance(sm.normal, styles.StyleUrl))
        self.assertEqual(sm.normal.url, '#normalState')
        self.assertTrue(isinstance(sm.highlight, styles.StyleUrl))
        self.assertEqual(sm.highlight.url, '#highlightState')
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / styles.py View on Github external
def from_element(self, element):
        super(StyleMap, self).from_element(element)
        pairs = element.findall('%sPair' % self.ns)
        for pair in pairs:
            key = pair.find('%skey' % self.ns)
            style = pair.find('%sStyle' % self.ns)
            style_url = pair.find('%sstyleUrl' % self.ns)
            if key.text == "highlight":
                if style is not None:
                    highlight = Style(self.ns)
                    highlight.from_element(style)
                elif style_url is not None:
                    highlight = StyleUrl(self.ns)
                    highlight.from_element(style_url)
                else:
                    raise ValueError
                self.highlight = highlight
            elif key.text == "normal":
                if style is not None:
                    normal = Style(self.ns)
                    normal.from_element(style)
                elif style_url is not None:
                    normal = StyleUrl(self.ns)
                    normal.from_element(style_url)
                else:
                    raise ValueError
                self.normal = normal
            else:
                raise ValueError
github cleder / fastkml / fastkml / styles.py View on Github external
def etree_element(self):
        element = super(StyleMap, self).etree_element()
        if self.normal:
            if isinstance(self.normal, (Style, StyleUrl)):
                pair = etree.SubElement(element, "%sPair" % self.ns)
                key = etree.SubElement(pair, "%skey" % self.ns)
                key.text = 'normal'
                pair.append(self.normal.etree_element())
        if self.highlight:
            if isinstance(self.highlight, (Style, StyleUrl)):
                pair = etree.SubElement(element, "%sPair" % self.ns)
                key = etree.SubElement(pair, "%skey" % self.ns)
                key.text = 'highlight'
                pair.append(self.highlight.etree_element())
        return element
github cleder / fastkml / fastkml / kml.py View on Github external
def styleUrl(self):
        """ Returns the url only, not a full StyleUrl object.
            if you need the full StyleUrl object use _styleUrl """
        if isinstance(self._styleUrl, StyleUrl):
            return self._styleUrl.url
github cleder / fastkml / fastkml / kml.py View on Github external
def styleUrl(self, styleurl):
        """ you may pass a StyleUrl Object, a string or None """
        if isinstance(styleurl, StyleUrl):
            self._styleUrl = styleurl
        elif isinstance(styleurl, basestring):
            s = StyleUrl(self.ns, url=styleurl)
            self._styleUrl = s
        elif styleurl is None:
            self._styleUrl = None
        else:
            raise ValueError
github cleder / fastkml / fastkml / kml.py View on Github external
self.isopen = 1
            else:
                self.isopen = 0
        styles = element.findall('%sStyle' % self.ns)
        for style in styles:
            s = Style(self.ns)
            s.from_element(style)
            self.append_style(s)
        styles = element.findall('%sStyleMap' % self.ns)
        for style in styles:
            s = StyleMap(self.ns)
            s.from_element(style)
            self.append_style(s)
        style_url = element.find('%sstyleUrl' % self.ns)
        if style_url is not None:
            s = StyleUrl(self.ns)
            s.from_element(style_url)
            self._styleUrl = s
        snippet = element.find('%sSnippet' % self.ns)
        if snippet is not None:
            _snippet = {'text': snippet.text}
            if snippet.get('maxLines'):
                _snippet['maxLines'] = int(snippet.get('maxLines'))
            self.snippet = _snippet
        timespan = element.find('%sTimeSpan' % self.ns)
        if timespan is not None:
            s = TimeSpan(self.ns)
            s.from_element(timespan)
            self._time_span = s
        timestamp = element.find('%sTimeStamp' % self.ns)
        if timestamp is not None:
            s = TimeStamp(self.ns)
github cleder / fastkml / fastkml / styles.py View on Github external
if key.text == "highlight":
                if style is not None:
                    highlight = Style(self.ns)
                    highlight.from_element(style)
                elif style_url is not None:
                    highlight = StyleUrl(self.ns)
                    highlight.from_element(style_url)
                else:
                    raise ValueError
                self.highlight = highlight
            elif key.text == "normal":
                if style is not None:
                    normal = Style(self.ns)
                    normal.from_element(style)
                elif style_url is not None:
                    normal = StyleUrl(self.ns)
                    normal.from_element(style_url)
                else:
                    raise ValueError
                self.normal = normal
            else:
                raise ValueError