OpenLayers加载高德地图(谷歌暂时访问不了,那就访问国内地图吧,速度更快)

<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0″>
<meta name=”apple-mobile-web-app-capable” content=”yes”>
<title>OpenLayers加载高德地图</title>
<link rel=”stylesheet” href=”theme/default/style.css” type=”text/css”>
<script src=”lib/OpenLayers.js”></script>
<script type=”text/javascript”>
var map, layer,marker;
var layerOptions=null;

function init(){
//map = new OpenLayers.Map(‘map’);
map = new OpenLayers.Map({
 div: “map”,
 projection: “EPSG:900913”,  //指定投影很关键
 displayProjection: new OpenLayers.Projection(“EPSG:4326”)});

var gdLayer = new OpenLayers.Layer.XYZ(“高德地图”, [ 
                      “http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}”, 

                       “http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}”, 

                        “http://webrd03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}”, 

                        “http://webrd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}” 

        ], { 
            isBaseLayer: true, 
            visibility: true, 
            displayInLayerSwitcher: true 
        }); 
map.addLayer(gdLayer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
var lonlat=new OpenLayers.LonLat(102.70734, 25.04505);
  alert( map.getProjectionObject()); //当前是EPSG:900913投影
var lonlat2 = lonlat.clone().transform( new OpenLayers.Projection(“EPSG:4326”), map.getProjectionObject() );//转换投影
map.setCenter(lonlat2, 8);//指定地图中心与初始缩放级别
map.addControl(new OpenLayers.Control.MousePosition());
}
</script>
<body onload=”init()”>
<div id=”map” style=”position:relative;width: 80%;height: 80%;border: 1px solid #ccc;”>
</div>
</body>
</html>
/*致谢
*To修哥的博客http://blog.csdn.net/devcopper
*/

转载自:https://blog.csdn.net/u011135103/article/details/37728055

You may also like...