设置漫游方向箭头中间的还原按钮点击后的地图状态

此示例展示的是如何设置地图还原状态

关键代码

var myOptions = {
  zoom: 12,
  center: new sogou.maps.Point(12956000,4824875),
  mapControl: true,
  mapControlType: 1,
  //设置还原地图状态
  panControlOptions: {center:new sogou.maps.Point(12956000,4824875),level:15},
  scaleControl: true,
  mapTypeId: sogou.maps.MapTypeId.ROADMAP
}
var map = new sogou.maps.Map(document.getElementById("map_canvas"),myOptions);
			

代码解析

在创建地图时,设置参数时设置还原地图状态。

var myOptions = {
  zoom: 12,
  center: new sogou.maps.Point(12956000,4824875),
  mapControl: true,
  mapControlType: 1,
  //设置还原地图状态
  panControlOptions: {center:new sogou.maps.Point(12956000,4824875),level:15},
  scaleControl: true,
  mapTypeId: sogou.maps.MapTypeId.ROADMAP
}
			

完整代码

<!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>搜狗地图 JavaScript API 示例: 设置漫游方向箭头中间的还原按钮点击后的地图状态 示例</title>
<style type="text/css">
html {height: auto;}
body {height: auto;margin: 0;padding: 0;}
#map_canvas {width:1000px;height: 500px;position: absolute;}
@media print {#map_canvas {height: 950px;}}
</style>
<script type="text/javascript" src="//api.go2map.com/maps/js/api_v2.5.1.js"></script>
<script type="text/javascript">
 /**
  * 设置漫游方向箭头中间的还原按钮点击后的地图状态
  */
  function initialize() {
    var myOptions = {
      zoom: 12,
      center: new sogou.maps.Point(12956000,4824875),
      mapControl: true,
	  mapControlType: 1,
	  //设置还原地图状态
	  panControlOptions: {center:new sogou.maps.Point(12956000,4824875),level:15},
      scaleControl: true,
      mapTypeId: sogou.maps.MapTypeId.ROADMAP
    }
    var map = new sogou.maps.Map(document.getElementById("map_canvas"),
                                  myOptions);
  }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>
</html>
			

运行代码