Changeset 3287 for DPPP/kml


Ignore:
Timestamp:
30/01/08 11:18:03 (12 years ago)
Author:
mkochan
Message:

Made prototype use KMLDocument as a module.

Location:
DPPP/kml/csml2kml/python/prototypes
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/prototypes/buildPointSeriesWithReferencedPlotsUsingGeoServerOO.py

    r3285 r3287  
    66import urllib 
    77 
    8 class KMLDocument: 
    9  
    10     def __init__(self, name, basicBalloonTemplate): 
    11  
    12         self.name = name 
    13  
    14         basicIcon = 'http://maps.google.com/mapfiles/kml/shapes/target.png' 
    15         basicStyle = KMLStyle('basic_style', basicIcon, basicBalloonTemplate) 
    16         self.styles = [basicStyle] 
    17  
    18         self.documentElement = Element('Document') 
    19         SubElement(self.documentElement, 'name').text = name 
    20         SubElement(self.documentElement, 'open').text = '0' 
    21  
    22         for style in self.styles: 
    23             self.documentElement.append(style.build()) 
    24  
    25     def append(self, element): 
    26         '''Append directly to the <Document> element''' 
    27         self.documentElement.append(element) 
    28  
    29     def save(self, outputFilename): 
    30  
    31         # Auxiliary function, indents XML 
    32         def _indentXML(elem, level=0): 
    33             i = "\n" + level * "  " 
    34             if len(elem): 
    35                 if not elem.text or not elem.text.strip(): 
    36                     elem.text = i + "  " 
    37                 for child in elem: 
    38                     _indentXML(child, level+1) 
    39                 if not child.tail or not child.tail.strip(): 
    40                     child.tail = i 
    41                 if not elem.tail or not elem.tail.strip(): 
    42                     elem.tail = i 
    43             else: 
    44                 if level and (not elem.tail or not elem.tail.strip()): 
    45                     elem.tail = i 
    46  
    47         # Attach the Document element as a subelement of a root 'kml' element 
    48         kmlElement=Element('kml', xmlns='http://earth.google.com/kml/2.2') 
    49         kmlElement.append(self.documentElement) 
    50         _indentXML(kmlElement) 
    51  
    52         # Write the KML document to a file 
    53         t = ElementTree(kmlElement)        
    54         f = open(outputFilename, 'w') 
    55         t.write(f) 
    56         f.close() 
    57  
    58 class KMLStyle: 
    59  
    60     def __init__(self, id, iconURL, balloonTemplate): 
    61         self.id = id 
    62         self.iconURL = iconURL 
    63         self.balloonTemplate = balloonTemplate 
    64  
    65     def build(self): 
    66  
    67         styleElement = Element('Style') 
    68         styleElement.set('id', self.id) 
    69  
    70         # Build the IconStyle element (for assigning an icon to station placemarks) 
    71         iconStyleElement = SubElement(styleElement, 'IconStyle') 
    72         SubElement(iconStyleElement, 'scale').text = '1.2' 
    73         iconElement = SubElement(iconStyleElement, 'Icon') 
    74         SubElement(iconElement, 'href').text = self.iconURL 
    75  
    76         # Build the BalloonStyle element -- an HTML template for the balloons 
    77         ballonStyleElement = SubElement(styleElement, 'BalloonStyle') 
    78         SubElement(ballonStyleElement, 'text').text = self.balloonTemplate 
    79  
    80         return styleElement 
     8from KMLDocument import KMLDocument, KMLStyle, getBasicKMLStyle 
    819 
    8210# -------------------------------------------------------------------------------------------------------------------------- 
     
    14270 
    14371balloonTemplate = '<img src="http://bond.badc.rl.ac.uk:8089/csmlGrapher/plot?feature_id=$[feature_id]">' 
    144 kmlDocument = KMLDocument('MIDAS stations (example)', balloonTemplate) 
     72basicKmlStyle = getBasicKMLStyle(balloonTemplate) 
     73kmlDocument = KMLDocument('MIDAS stations (example)', basicKmlStyle) 
    14574 
    14675for (gml_id, name, lon, lat) in parseGMLStationsCollection(textGml): 
Note: See TracChangeset for help on using the changeset viewer.