1

我有这个 kml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Placemark>
      <name>CDATA example</name>
      <description>
        <![CDATA[
          <h1>CDATA Tags are useful!</h1>
          <p><font color="red">Text is <i>more readable</i> and 
          <b>easier to write</b> when you can avoid using entity 
          references.</font></p>
        ]]>
      </description>
      <Point>
        <coordinates>102.595626,14.996729</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

(来自谷歌地图文档的示例)当我将一个类添加到 KML 内的 href 时:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Placemark>
      <name>CDATA example</name>
      <description>
        <![CDATA[
          <h1>CDATA Tags are useful!</h1>
          <p><font color="red">Text is <i>more readable</i> and 
          <b>easier to write</b> when you can avoid using entity 
          references.<a class="read_more" href="http://google.com">Read More</a></font></p>
        ]]>
      </description>
      <Point>
        <coordinates>102.595626,14.996729</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

KMl 只是剥离它我猜这是由于“内容清理” https://developers.google.com/earth/documentation/balloons

这是我当前的 javascript:

jQuery(document).ready(function($) {    
        function initialize() {
        var myLatlng = new google.maps.LatLng(51.201465,-0.30244);
          var mapOptions = {
            zoom: 12,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };

          var map = new google.maps.Map(document.getElementById('map-canvas'),
              mapOptions);

          var kmlLayer = new google.maps.KmlLayer({
            url: 'http://*****.com/new/wp-content/themes/required-starter/KML_Samples.kml?rand='+(new Date()).valueOf(),
            suppressInfoWindows: false,
            map: map
          });

          google.maps.event.addListener(kmlLayer, 'click', function(kmlEvent) {
            var text = kmlEvent.featureData.description;
           alert(text);
          });
        }

        google.maps.event.addDomListener(window, 'load', initialize);
});

我找不到正确的参数来停止数据清理或 kml 文档中的选项以将类添加到描述包装器或气泡中。我想这是由于我的无能,请帮助!克里斯

4

1 回答 1

1

我认为您无法以我所知道的任何方式避免数据清理。但是您可以采取行动并控制数据。例如,首先是一些风格:

<style type="text/css">
.foo .read_more {
    font-family: papyrus, parade;
}
.foo h1,p{
    margin:0;
    padding:0;
}
</style>

然后制作你自己的(好吧,它是谷歌的)信息窗口:

    function initialize() {
    var myLatlng = new google.maps.LatLng(51.201465,-0.30244);
      var mapOptions = {
        zoom: 4,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };

      var map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);

      var kmlLayer = new google.maps.KmlLayer({
        url: 'SomeKmlFile.kml',
        suppressInfoWindows: true,
        map: map
      });
      var infoWindow = new google.maps.InfoWindow({pixelOffset: new google.maps.Size(0, -32)});
      var div = document.createElement('div');

      google.maps.event.addListener(kmlLayer, 'click', function(kmlEvent) {
        var text = kmlEvent.featureData.description;
        div.innerHTML = text;
        div.className = 'foo';
        div.getElementsByTagName('a')[0].className = 'read_more';
        infoWindow.setPosition(kmlEvent.latLng);
        infoWindow.setContent(div);
        infoWindow.open(map);
      });
    }

    google.maps.event.addDomListener(window, 'load', initialize);
于 2013-09-29T01:31:11.543 回答