我有一个 kml 点加载到融合表层中。我想使用geoxml3将数据解析为图层范围上的une map.fitBounds,但这不起作用。下面的确切代码适用于 KML 多边形,但不适用于 KML 点图层。
代码:
var queryText = encodeURIComponent("SELECT * FROM 1CNJWjLDYgBkJGZVslJ67Fak4DyqadEFuIabzQ60 ");
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
query.send(zoomTo);
}
function zoomTo(response) {
if (!response) {
alert('no response');
return;
}
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
FTresponse = response;
//for more information on the response object, see the documentation
//http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse
numRows = response.getDataTable().getNumberOfRows();
numCols = response.getDataTable().getNumberOfColumns();
var geoXml = new geoXML3.parser();
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < numCols; i++){
if (FTresponse.getDataTable().getColumnLabel(i) == 'geometry') {
var ColIndex = i;
}
}
if (!ColIndex){
alert('Geometry column "geometry" not found.')
}
for (var i = 0; i < numRows; i++){
var kml = FTresponse.getDataTable().getValue(i,ColIndex);
geoXml.parseKmlString("<Placemark>"+kml+"</Placemark>");
bounds.union(geoXml.docs[i].bounds);
}
map.fitBounds(bounds);
}