示例描述

该示例展示通过map.setValueField()接口选择同一数据中的不同指标制作专题地图。

效果演示

示例代码

<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 type="text/javascript" >
    var map = null;
    function init(){
     map = new Dituhui.Map("myMap", "http://dev.dituhui.com/sdk/1.0.0/swfs/", "100000", Dituhui.MapType.RANGE, "setData", "onError");
    }  
    var dataP = [{"name":"安徽","2011GDP(亿元)":15110.31,"2012GDP(亿元)":"15308"},
                {"name":"北京","2011GDP(亿元)":14246.11,"2012GDP(亿元)":"16382.424"},
                {"name":"福建","2011GDP(亿元)":19195.69,"2012GDP(亿元)":"25273.923"},
                {"name":"甘肃","2011GDP(亿元)":5000.47,"2012GDP(亿元)":"5090.82"},
                {"name":"广东","2011GDP(亿元)":52673.59,"2012GDP(亿元)":"53477.408"},
                {"name":"广西","2011GDP(亿元)":12503.83,"2012GDP(亿元)":"11284.6"},
                {"name":"贵州","2011GDP(亿元)":5701.84,"2012GDP(亿元)":"5644.14"},
                {"name":"海南","2011GDP(亿元)":2515.29,"2012GDP(亿元)":"2526.17"},
                {"name":"河北","2011GDP(亿元)":24228.18,"2012GDP(亿元)":"24674.262"},
                {"name":"河南","2011GDP(亿元)":27232.04,"2012GDP(亿元)":"27598.975"},
                {"name":"黑龙江","2011GDP(亿元)":16000.43,"2012GDP(亿元)":"14318.736"},
                {"name":"湖北","2011GDP(亿元)":19635.19,"2012GDP(亿元)":"19650.752"},
                {"name":"湖南","2011GDP(亿元)":17410.21,"2012GDP(亿元)":"19520.402"},
                {"name":"吉林","2011GDP(亿元)":11583.8,"2012GDP(亿元)":"10475.2"},
                {"name":"江苏","2011GDP(亿元)":48604.26,"2012GDP(亿元)":"48604.152"},
                {"name":"江西","2011GDP(亿元)":12391.3,"2012GDP(亿元)":"11153.432"},
                {"name":"辽宁","2011GDP(亿元)":22025.92,"2012GDP(亿元)":"22530"},
                {"name":"内蒙古","2011GDP(亿元)":8750.95,"2012GDP(亿元)":"11517.81"},
                {"name":"宁夏","2011GDP(亿元)":2060.79,"2012GDP(亿元)":"2085.4"},
                {"name":"青海","2011GDP(亿元)":1634.72,"2012GDP(亿元)":"1636.59"},
                {"name":"山东","2011GDP(亿元)":45429.21,"2012GDP(亿元)":"45429.985"},
                {"name":"山西","2011GDP(亿元)":11100.18,"2012GDP(亿元)":"11235.1"},
                {"name":"陕西","2011GDP(亿元)":11190.99,"2012GDP(亿元)":"12266.756"},
                {"name":"上海","2011GDP(亿元)":21026.68,"2012GDP(亿元)":"19731.64"},
                {"name":"四川","2011GDP(亿元)":19594.19,"2012GDP(亿元)":"21139.267"},
                {"name":"天津","2011GDP(亿元)":10530.71,"2012GDP(亿元)":"11180.875"},
                {"name":"西藏","2011GDP(亿元)":605.83,"2012GDP(亿元)":"605"},
                {"name":"新疆","2011GDP(亿元)":6474.54,"2012GDP(亿元)":"6519.068"},
                {"name":"云南","2011GDP(亿元)":11714.35,"2012GDP(亿元)":"8756.244"},
                {"name":"浙江","2011GDP(亿元)":32000.1,"2012GDP(亿元)":"32000.445"},
                {"name":"重庆","2011GDP(亿元)":10011.13,"2012GDP(亿元)":"10018.07"}];
    var mapStyles = [
      {min:0,max:8756},
      {min:8756,max:11517},
      {min:11517,max:19731},
      {min:19731,max:58604}];
    function setData()
    {
     var option = 
     {
      data: dataP, 
      styles:mapStyles, 
      valueField:'2011GDP(亿元)',
      backgroundColor:"#F5F5F5",
      legendTitle:"2011GDP(亿元)",
      isRLabelVisible:true
     };
     map.setMapOptions(option);
    }
    function onError(errorcode)
    {
     alert(errorcode);          
    }
    window.onload = init;
    function changeFeild(){
      var d=document.getElementById("field").value;
      /*切换制图指标*/
      map.setValueField(d);
    }
  </script>
  </head>
  <body>
    <label>选择制图指标: <select id="field" onchange="changeFeild()"> 
      <option value="2011GDP(亿元)">2011GDP(亿元)</option>
      <option value="2012GDP(亿元)">2012GDP(亿元)</option>
    </select></label>
    <div id='myMap' style='width:660px;height:600px'>
    </div>
  </body>
</html>