我正在使用Google Maps API V3来展示Google地图。我创建了一个用于打印地图的自定义控件。但是当我打印它时,标记不在那个打印输出中。谁能告诉我如何打印地图和标记?在此先感谢。
修改
创建地图的代码
function map_start(el,id){
$lat = $("#"+id).attr("lat");
$lang = $("#"+id).attr("long");
var image = "../assets/paleblue_MarkerU.png";
var myOptions = {
center: new google.maps.LatLng($lat,$lang),
zoom: 12,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$map = new google.maps.Map(document.getElementById('inset'),myOptions);
var placeMarker = new google.maps.Marker({
position: new google.maps.LatLng($lat,$lang),
map: $map,
animation: google.maps.Animation.DROP,
icon: image
});
var homeControlDiv = document.createElement('div');
var homeControl = new HomeControl(homeControlDiv, $map);
homeControlDiv.index = 1;
$map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
}
打印地图的自定义控件代码
function HomeControl(controlDiv, map) {
controlDiv.style.padding = '5px';
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = 'white';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '2px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to print the map';
controlDiv.appendChild(controlUI);
var controlText = document.createElement('div');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.fontSize = '12px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.className = "gmnoprint";
controlText.innerHTML = '<b>Print</b>';
controlUI.appendChild(controlText);
google.maps.event.addDomListener(controlUI, 'click', function() {
printDiv('cboxContent')
});
}
打印地图的代码
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
window.location.reload();
}