开发者

Google Earth KML Not Properly Rendering Balloon Style

开发者 https://www.devze.com 2023-03-03 03:45 出处:网络
This issue has been plaguing me for about 2 days Google isn\'t helping me figure this one out. Basically, the code below should be defining the text within the balloon. Unfortunately, it\'s not workin

This issue has been plaguing me for about 2 days Google isn't helping me figure this one out. Basically, the code below should be defining the text within the balloon. Unfortunately, it's not working that way. We're ending up with what seems to be the fallback if GE can't handle the style defined in the KML.

Here's one (of many) ways I've tried injecting the KML straight into the GE plugin for rendering.

var kmlString = '' +
'<?xml version="1.0" encoding="UTF-8"?>' +
'<kml xmlns="http://www.opengis.net/kml/2.2">' +
'  <Document>' +
'    <Style id="sitegeom">' +
'      <BalloonStyle>' +
'       <text>' +
'           <![CDATA[' +
'           this is<br>a test' +
'           ]]>' +          
'       </text>' +
'      </BalloonStyle>' +
'    </Style开发者_如何转开发>' +
'  </Document>' +
'</kml>';

var kmlObject = $wnd.ge.parseKml(kmlString);
$wnd.ge.getFeatures().appendChild(kmlObject);

The code on which this snippet is based came directly from the GE docs. Go figure. Anyone have an idea?


The KML document you're adding later likely can't access the #sitegeom ID you defined at the start in a separate KML document, it's not in-scope.

Try following the Google Earth doc instructions re: this, by placing the style definition in a separate file:

If the Style definition is within the same file, precede the Style ID with a # sign. If the Style definition is in an external file, include the complete URL in the element.

e.g.:

<styleUrl>http://www.example.com/path/to/your/style.kml#sitegeom</styleUrl>


Maybe question not so clear for me, but i think, you need to describe Placemark in your KML and define your style in styleUrl Like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Style id="sitegeom">
      <BalloonStyle>
       <text>
           <![CDATA[
          this is<br>a test
           ]]>          
       </text>
      </BalloonStyle>
    </Style>
    <Placemark>
        <Point>
            <coordinates>104.30000001,52.283333343333</coordinates>
        </Point>
        <styleUrl>#sitegeom</styleUrl>
    </Placemark>
  </Document>
</kml>

Is it right idea?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号