示例描述

该示例展示通过 map.centerAndZoom 接口将地图初始范围控制在以北京为中心的显示范围内。centerAndZoom详细描述请参见地图显示范围

效果演示

示例代码

<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script src='http://dev.dituhui.com/sdk/1.0.0/js/dituhui-flash.js'></script>
  <script src='http://dev.dituhui.com/sdk/1.0.0/js/sample-data.js'></script>
  <script type="text/javascript" >
    var map = null;
    /*初始化地图,设置地图模板为分段设色:
   Dituhui.MapType.RANGE*/
    function init(){
     map = new Dituhui.Map("myMap", "http://dev.dituhui.com/sdk/1.0.0/swfs/", "100000", Dituhui.MapType.RANGE, "setData", "onError");
    }  
    function setData()
    {
      var mapStyles = [
      {min:1,max:4},
      {min:4,max:8},
      {min:8,max:12},
      {min:12,max:16}];
     var option = 
     {
      data: data, 
      styles:mapStyles, 
      valueField:'gdprate',
      backgroundColor:"#F5F5F5",
      legendTitle:"GDP增速%"
     };
     map.setMapOptions(option);
     /*(116.4, 39.9)为北京经纬度坐标
     */
     map.centerAndZoom(5,new Dituhui.Point(116.4, 39.9));
    }
    function onError(errorcode)
    {
     /*errorcode:错误编码,有关错误编码的详细描述可参考:
     "开发指南"-->"API参考"-->"错误编码"*/
     alert(errorcode);          
    }
    window.onload = init;
  </script>
  </head>
  <body>
   <div id='myMap' style='width:660px;height:600px'>
  </div>
  </body>
</html>