<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google API离线地图</title>
<script type="text/javascript" src="mapapi.js"></script>
<script type="text/javascript" src="configure.js"></script>
<script type="text/javascript" src="maplabel-compiled.js"></script>
<script type="text/javascript">
function BigeMap() { }
BigeMap.prototype.tileSize = new google.maps.Size(256, 256);
BigeMap.prototype.maxZoom = maxZoom;
BigeMap.prototype.minZoom = minZoom;
BigeMap.prototype.name = "本地地图";
BigeMap.prototype.getTile = function (coord, zoom, ownerDocument) {
var img = ownerDocument.createElement("img");
img.style.width = this.tileSize.width + "px";
img.style.height = this.tileSize.height + "px";
var strURL = path;
strURL += zoom + "/" + coord.x + "/" + coord.y + format;
img.src = strURL;
return img;
};
var localMap = new BigeMap();
function initialize() {
var latlng = new google.maps.LatLng(y, x);
var myOptions = {
center: latlng,
zoom: defaultZoom,
mapTypeControl: false,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'localMap']
}
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
map.mapTypes.set('localMap', localMap);
map.setMapTypeId('localMap');
// ===创建用户自定义地标===
var lat = 29.7065;
var lng = 107.1085;
var text = "测试名称"
//标注位置 经纬度
var makerlatlng = new google.maps.LatLng(lat, lng);
// 使用名称标记
var mapLabel = new MapLabel({
text: text,
position: makerlatlng,
map: map,
fontSize: 12,
fontColor: '#ef5a08',
strokeColor: '#f9f9f9',
align: 'bottom'
});
mapLabel.set('position', makerlatlng);
var marker = new google.maps.Marker({
position: makerlatlng, // 标注点的坐标位置
map: map,
draggable: true,
title: text // 标注点的名称
});
marker.bindTo('map', mapLabel);
marker.bindTo('position', mapLabel);
marker.setDraggable(true);
// 使用弹窗显示名称
attachInfowindow(marker, text);
function attachInfowindow(marker, msg) {
var infowindow = new google.maps.InfoWindow(
{
content: msg,
size: new google.maps.Size(50, 50)
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
}
function addMark(lat, lng, text) {
//标注位置 经纬度
var makerlatlng = new google.maps.LatLng(lat, lng);
// 使用名称标记
var mapLabel = new MapLabel({
text: text,
position: makerlatlng,
map: map,
fontSize: 12,
fontColor: '#ef5a08',
strokeColor: '#f9f9f9',
align: 'bottom'
});
mapLabel.set('position', makerlatlng);
var marker = new google.maps.Marker({
position: makerlatlng, // 标注点的坐标位置
map: map,
draggable: true,
title: text // 标注点的名称
});
marker.bindTo('map', mapLabel);
marker.bindTo('position', mapLabel);
marker.setDraggable(true);
// 使用弹窗显示名称
attachInfowindow(marker, text);
function attachInfowindow(marker, msg) {
var infowindow = new google.maps.InfoWindow(
{
content: msg,
size: new google.maps.Size(50, 50)
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
}
// ===========================
</script>
<style>
html { height: 100%; }
body { height: 100%; margin: 0; padding: 0; }
#map_canvas { height: 100%; }
@media print {
html, body, #map_canvas {
height: auto;
}
}
</style>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
- 1
- 2
前往页