Search code examples
google-earth

google earth combine balloon information


I'm creating a kml file that has image references in each placemark. I'm wanting to be able to do two things. First, combine the placemarks as the user zooms. Second, to be able to combine the images into the same combined placemark. I'm looking to replicate the same type of behavior that the Panoramio placemarks and pictures display.

I have not found an example of the code needed to do either of these behaviors. Combining placemarks on zoom or the combining of information inside of the balloons.


Solution

  • CC12,

    The exact functionality you're looking for doesn't actually exist, at least not in the way you're thinking. When you zoom in or out, the photos you see are not being merged or torn apart, instead what you're seeing is the effect of regions that have been assigned to the individual objects. There is merging going on, but that happens on the back end when the photos are uploaded to Google. Your point in the comment to this question, however, is well taken, when you copy an object from the map, the region KML does not come with it. To replicate that function, you would have to add the regions yourself: https://developers.google.com/kml/documentation/regions

    To replicate the stylistic aspects of the panorama layers, of course, is just a matter of selecting a panorama image of your choosing (on the map) followed by Right-click > Copy and then pasting the output into your favorite text editor. The following is an example:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
    <Document>
        <name>KmlFile</name>
        <Style id="pano_cluster1h">
            <IconStyle>
                <scale>0.7</scale>
                <Icon>
                    <href>http://kh.google.com:80/flatfile?lf-0-icons/panoramio_cluster_n2.png</href>
                    <gx:w>32</gx:w>
                    <gx:h>32</gx:h>
                </Icon>
            </IconStyle>
            <LabelStyle>
            </LabelStyle>
            <BalloonStyle>
                <text>$[description]</text>
            </BalloonStyle>
            <LineStyle>
                <color>ff000000</color>
                <width>0</width>
                <gx:labelVisibility>1</gx:labelVisibility>
            </LineStyle>
            <PolyStyle>
                <color>ff000000</color>
            </PolyStyle>
        </Style>
        <StyleMap id="1052802">
            <Pair>
                <key>normal</key>
                <styleUrl>#pano_cluster1n</styleUrl>
            </Pair>
            <Pair>
                <key>highlight</key>
                <styleUrl>#pano_cluster1h</styleUrl>
            </Pair>
        </StyleMap>
        <Style id="pano_cluster1n">
            <IconStyle>
                <scale>0.5</scale>
                <Icon>
                    <href>http://kh.google.com:80/flatfile?lf-0-icons/panoramio_cluster_n2.png</href>
                    <gx:w>32</gx:w>
                    <gx:h>32</gx:h>
                </Icon>
            </IconStyle>
            <LabelStyle>
                <scale>0</scale>
            </LabelStyle>
            <BalloonStyle>
                <text>$[description]</text>
            </BalloonStyle>
            <LineStyle>
                <color>ff000000</color>
                <width>0</width>
                <gx:labelVisibility>1</gx:labelVisibility>
            </LineStyle>
            <PolyStyle>
                <color>ff000000</color>
            </PolyStyle>
        </Style>
        <Placemark>
            <name>Zabriskie Point. Death Valley, California</name>
            <description><![CDATA[<html><head><link rel="stylesheet" type="text/css"href="http://mw2.google.com/mw-earth-vectordb/panoramio_clusters/pcb.css"/><script type="text/javascript" src="http://mw2.google.com/mw-earth-vectordb/panoramio_clusters/pcb1.js"></script></head><body onload="loadPhotos(21262,'000145',8,36.420188,-116.812217,'n')"><div id="display-panel" style="position:absolute;border:none;height:578px;width:680px"></div><div id="hint">USA</div></body></html>]]></description>
            <styleUrl>#1052802</styleUrl>
            <Point>
                <coordinates>-116.812217,36.420188,0</coordinates>
            </Point>
        </Placemark>
    </Document>
    </kml>
    

    In addition, the following is a little Python script I wrote a while back to help set regions for placemarks in GE. It's set up right now for points and to run on windows but it's easy enough to adapt for whatever. It works like this: You copy the placemark from GE, when you run the script it asks the user for an integer which will set the vanishing point for your region. The script pulls the KML from your clipboard, extracts the cords, generates the correct region data for kml, and puts the result back into your clipboard. You can then just paste your placemark back onto the map with the correct region data attached. Please keep in mind that I've only written this for personal use, so the code is a little messy, but it works just great (I use it almost every day). Here you go:

    import win32clipboard
    import wx
    import win32com.client, time
    
    win32clipboard.OpenClipboard()
    strClip = win32clipboard.GetClipboardData()
    win32clipboard.CloseClipboard()
    
    NakedRegion = "<Style><ListStyle><listItemType>checkHideChildren</listItemType><ItemIcon></ItemIcon></ListStyle></Style><Region><LatLonAltBox><north></north><south></south><east></east><west></west><minAltitude>0</minAltitude><maxAltitude>0</maxAltitude></LatLonAltBox><Lod><minLodPixels>10</minLodPixels><maxLodPixels>1024</maxLodPixels></Lod></Region>"
    
    StartC = strClip.find("<coordinates>") + 13
    EndC = strClip.find("</coordinates>")
    
    StartIcon = strClip.find("<Icon>") + 6
    EndIcon = strClip.find("</Icon>")
    TheIcon = strClip[StartIcon:EndIcon]
    
    StartName = strClip.find("<name>",600) + 6
    EndName = strClip.find("</name>",600)
    TheName = strClip[StartName:EndName]
    
    TheCords = strClip[StartC:EndC]
    TheLatLon = TheCords.split(',')
    TheLat = float(TheLatLon[1])
    TheLon = float(TheLatLon[0])
    
    def ask(parent=None, message='Set Region to...'):
            app = wx.App()
            dlg = wx.TextEntryDialog(parent,message)
            dlg.ShowModal()
            result = dlg.GetValue()
            dlg.Destroy()
            app.MainLoop() 
            return result
    n = ask(message = 'Integer...')
    TheEnhancement = 0.00001 * (2**float(n))
    TNorth = TheLat + TheEnhancement
    TSouth = TheLat - TheEnhancement
    TEast = TheLon + TheEnhancement
    TWest = TheLon - TheEnhancement
    
    NakedRegion = NakedRegion.replace("<north>", "<north>" + str(TNorth))
    NakedRegion = NakedRegion.replace("<south>", "<south>" + str(TSouth))
    NakedRegion = NakedRegion.replace("<east>", "<east>" + str(TEast))
    NakedRegion = NakedRegion.replace("<west>", "<west>" + str(TWest))
    
    strClip = strClip.replace("<name>KmlFile", "<name>" + str(TheName))
    strClip = strClip.replace("<Placemark>", NakedRegion + "<Placemark>")
    strClip = strClip.replace("<ItemIcon>", "<ItemIcon>" + str(TheIcon))
    strClip = strClip.replace("<visibility>0</visibility>", "<visibility>1</visibility>" + str(TheIcon))
    
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(strClip)
    win32clipboard.CloseClipboard()