Javascript 包含google maps中geojson属性的弹出窗口
我希望有一个弹出窗口,其中包含存储在geojson中的每个点的属性。我可以获得要渲染的贴图和标记,但单击该点时没有包含属性的弹出框 我相信这是件简单的事情,但我已经尝试过了,但仍然无法让它工作 这是我的密码:Javascript 包含google maps中geojson属性的弹出窗口,javascript,google-maps-api-3,geojson,Javascript,Google Maps Api 3,Geojson,我希望有一个弹出窗口,其中包含存储在geojson中的每个点的属性。我可以获得要渲染的贴图和标记,但单击该点时没有包含属性的弹出框 我相信这是件简单的事情,但我已经尝试过了,但仍然无法让它工作 这是我的密码: <!DOCTYPE html> <html> <head> <style> #map { width: 100%; height
<!DOCTYPE html>
<html>
<head>
<style>
#map {
width: 100%;
height: 600px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="POINTS.js"></script>
<script>
function initialize() {
features = []
var mapDiv = document.getElementById('map');
map = new google.maps.Map(mapDiv, {
center: {lat: 44.540, lng: -78.546},
zoom: 2
});
// When the user clicks, open an infowindow
var infowindow = new google.maps.InfoWindow();
map.data.addListener('click', function(event) {
var myHTML = event.feature.getProperty("id");
infowindow.setContent("<div style='width:150px;'>"+myHTML+"</div>");
// position the infowindow on the marker
var anchor = new google.maps.MVCObject();
anchor.set("position", event.latLng);
infoWindow.open(map, anchor);
});
// load data
map.data.addGeoJson(data);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=MY_KEY&libraries=visualization&callback=initialize">
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
var data = {
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 1, "X": 144.961836, "Y": -36.749381 }, "geometry": { "type": "Point", "coordinates": [ 144.961836873913285, -36.749381167692619 ] } }
]
}