我希望谷歌地图(geoxml3)专家可以提供帮助。我想要做的事情非常简单,但我还不够精通编码来完成它。
我有一个简单的地图使用谷歌地图api v3和geoxml3加载一些KML数据。
然后我有一个自定义生成的侧边栏,对应于每个地标。
我只想添加放大和缩小按钮到infowindow,如下例所示。
http://www.geocodezip.com/v3_MW_example_map3_zoom.html
我知道我必须创建一个自定义标记并添加html内容,但是我在使用kml点击时遇到了很多麻烦。
我没有尝试使用自定义标记btw ...
此处示例:
http://webstgcc.onthenet.com.au/map/map.html
到目前为止我的代码:
var geoXml = null;
var map = null;
var myLatLng = null;
var infowindow = null;
var filename = "KML_Samples.kml";
var image = "";
function initialize() {
myLatLng = new google.maps.LatLng(-28.014408,153.463898);
var myOptions = {
zoom: 11,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googlemap"),myOptions);
infowindow = new google.maps.InfoWindow({maxWidth:300});
geoXml = new geoXML3.parser({
map: map,
infowindow: infowindow,
singleInfoWindow: true,
markerOptions: {icon: image},
afterParse: useTheData
});
geoXml.parse(filename);
};
function kmlClick(marker) {
google.maps.event.trigger(geoXml.docs[0].markers[marker],"click");
}
function useTheData(doc){
// Geodata handling goes here, using JSON properties of the doc object
for (var i = 0; i < doc[0].markers.length; i++){}
};
google.maps.event.addDomListener(window, 'load', initialize);
我花了很长时间才开始工作,所以如果这真的很简单,请原谅我。
非常感谢任何帮助。
答案 0 :(得分:2)
向geoXML3.parser()
一种简单的方法,它使用内置函数创建的标记,只修改infoWindow的内容:
infowindow = new google.maps.InfoWindow({minWidth:250, maxWidth:300});
geoXml = new geoXML3.parser({
map: map,
infowindow: infowindow,
singleInfoWindow: 1,
afterParse: useTheData,
createMarker: function (placemark, doc) {
//get the marker from the built-in createMarker-function
var marker=geoXML3.instances[0].createMarker(placemark, doc);
//modify the content
if(marker.infoWindow){
marker.infoWindowOptions.content=
'<div class="geoxml3_infowindow"><h3>' + placemark.name +
'</h3><div>' + placemark.description + '</div>'+
'<code onclick="map.setCenter(new google.maps.LatLng'+
marker.getPosition().toString()+
');map.setZoom(map.getZoom()+1);">zoom in</code><br/>'+
'<code onclick="map.setCenter(new google.maps.LatLng'+
marker.getPosition().toString()+
');map.setZoom(map.getZoom()-1);">zoom out</code>'+
'</div>';
}
return marker;
}
});