我在Google地图上有一个KML图层,其中包含许多多边形。单击每个多边形时,将使用默认的Google Maps信息窗口显示属性表中的数据。这是代码:
google.maps.event.addListener(kmlLayer, 'click', function(event) {
var content = event.featureData.infoWindowHtml;
var testimonial = document.getElementById('capture');
testimonial.innerHTML = content;
是否可以仅显示某些属性数据,而不能显示信息窗口中的每一列?当前正在显示多边形后面的所有数据。这也是信息窗口的图像,因此,例如,我只想在信息窗口中显示“名称”,“自治区”和“ KM2”数据:
One option would be to use the suppressInfoWindows:true
kmlOption, then create your own infowindow with whatever content you want in it.
The KmlLayer click event contains the KmlFeatureData from the KML, which you can parse to customize the information displayed.
KmlFeatureData object specification
Data for a single KML feature in JSON format, returned when a KML feature is clicked. The data contained in this object mirrors that associated with the feature in the KML or GeoRSS markup in which it is declared.
Properties
- author Type: KmlAuthor
The feature's
<atom:author>
, extracted from the layer markup (if specified).
- description Type: string
The feature's
<description>
, extracted from the layer markup.
- id Type: string
该功能是
<id>
从图层标记中提取的。如果未指定,则将为此功能生成一个唯一的ID。
- infoWindowHtml类型:字符串
要素的气球样式文本(如果已设置)。
- 名称类型:字符串
该功能是
<name>
从图层标记中提取的。
- 片段类型:字符串
该功能是
<Snippet>
从图层标记中提取的。
代码段:
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var kmllayer = new google.maps.KmlLayer({
map: map,
url: "http://www.geocodezip.com/geoxml3_test/us_states.xml",
suppressInfoWindows: true
});
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(kmllayer, 'click', function(evt) {
infowindow.setContent(evt.featureData.name);
infowindow.setPosition(evt.latLng);
infowindow.open(map);
})
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas"></div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句