一.需要文件
- gapi3文件夹:存放接口等
- tilemap文件夹:存放图片
- gapi.js文件
- maptool.js文件
二.html配置
<script type="text/javascript" src="gapi.js"></script>
<script type="text/javascript" src="maptool.js"></script>
三.使用
html中使用div 展示地图
<div id="map_canvas" style="width=100%; height: 900px;"></div>
text/javascript中创建离线对象
////////////////////////////////CoordMapType对象定义:显示目标位置div/////////////////////////////////////////////////////////////////
function CoordMapType(tileSize) {//创建对象方法(构造函数)this.tileSize = tileSize;
}CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {var div = ownerDocument.createElement('DIV');var ymax = 1 << zoom;var y = ymax - coord.y - 1;
// div.innerHTML = coord.x + "," + y + "," + zoom;div.style.width = this.tileSize.width + 'px';div.style.height = this.tileSize.height + 'px';div.style.fontSize = '10';div.style.borderStyle = 'solid';div.style.borderWidth = '0px';div.style.borderColor = '#AAAAAA';return div;
};////////////////////////////////LocalMapType对象定义:使用本地地图实体类型/////////////////////////////////////////////////////////////////
function LocalMapType() {}LocalMapType.prototype.tileSize = new google.maps.Size(256, 256);
LocalMapType.prototype.maxZoom = 18;
LocalMapType.prototype.minZoom = 1;
LocalMapType.prototype.name = "本地";
LocalMapType.prototype.alt = "显示本地地图";
LocalMapType.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 ymax = 1 << zoom;var y = ymax - coord.y - 1;var strURL = "tilemap\\sjztms\\" + zoom + "\\" + coord.x + "\\" + y + ".png";img.src = strURL; return img;
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
载入地图(除了需要使用离线地图对象外,API使用方法和在线地图一样)
var localMapType = new LocalMapType();
var myLatlng = new google.maps.LatLng(30.732137,103.968976);
var myOptions = {center: myLatlng,zoom: 13 ,zoomControl :false,streetViewControl: false,disableDoubleClickZoom: true,mapTypeControl: false,mapTypeControlOptions: {mapTypeIds: ["local", google.maps.MapTypeId.ROADMAP]}
}
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);map.mapTypes.set('local', localMapType);map.setMapTypeId('local');map.overlayMapTypes.insertAt(0, new CoordMapType(new google.maps.Size(256, 256)));
allmap=map;