2013-09-27 36 views
1

我有此KML文件: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> 

(來自谷歌地圖文檔拍攝的實施例) 當我一類添加到A HREF的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.<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文檔中的選項將類添加到描述包裝器或氣泡。 我想這是由於我的勉強,請幫助! Chris

回答

1

我不認爲你可以避免我知道的任何方式的數據清理。但是您可以採取行動並控制數據。比如,第一部分風格:

​​

然後使自己的(嗯,好吧這是谷歌)信息窗口:

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);