2017-08-30 63 views

回答

1

geoXML3 library包含parseKmlString function從字符串解析KML。

function initMap() { 
 
    var map = new google.maps.Map(document.getElementById('map'), { 
 
     zoom: 16, 
 
     center: {lat: 31.40065516914794, lng: -98.30505371484378} 
 
    }); 
 
    
 
    
 
    var parser = new geoXML3.parser({map: map}); 
 
    parser.parseKmlString('<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Placemark><name><![CDATA[]]>Polygon</name><description><![CDATA[]]></description><Polygon><extrude>1</extrude><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><coordinates>-93.46008301171878,31.329035778926478,0 -98.30505371484378,31.40065516914794,0 -97.37121582421878,30.106233605369603,0 -92.65808105859378,30.14749530904506,0</coordinates></LinearRing></outerBoundaryIs> </Polygon></Placemark></Document></kml>'); 
 
    } 
 

 

 
    google.maps.event.addDomListener(window, 'load', initMap);
#map { 
 
     height: 140px; 
 
     }
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<script src="https://rawgit.com/geocodezip/geoxml3/master/polys/geoxml3.js"></script> 
 
<div id="map"></div>

+1

非常感謝你,先生! –

+0

sir @vadim gremyachev,先生我可以問你最後一次關於你的答案在這裏在stackoverflow https://stackoverflow.com/questions/34886358/how-to-render-maps-within-ng-hide-divs-using -ngmap-without-getting-a-gray-rectan ..如果我想使用display:none?可能嗎? –

+0

你好@Paulo,不幸的是隱藏與'display:none'的地圖不能正常工作,而是我會建議使用'visibility:hidden' –

相關問題