zhaoxing
2023-10-30 ed34f974d31fb84204fb595ef406d9cf46d610c6
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"use script"; //开发环境建议开启严格模式
 
//对应widget.js中MyWidget实例化后的对象
var thisWidget;
 
//当前页面业务
function initWidgetView(_thisWidget) {
  thisWidget = _thisWidget;
 
  $("#xzqh-select").citypicker({
    simple: true,
    //province: '安徽省',
    //city: '合肥市',
    //district: '蜀山区'
  });
 
  var $xzqhselect = $("#xzqh-select");
  $xzqhselect.hide(); //隐藏
  $xzqhselect.citypicker("open");
 
  var timetemp = -1;
  $(".city-picker-dropdown").on("click", ".city-select a", function () {
    var dmnm = String($xzqhselect.data("citypicker").getCode());
    var dmmc = $xzqhselect.data("citypicker").getVal();
 
    $("#cityname").html("地区:" + dmmc);
 
    //调用地图定位
    if (timetemp != -1) {
      clearTimeout(timetemp);
      timetemp = -1;
    }
    timetemp = setTimeout(function () {
      centerAtRegion(dmnm, dmmc);
    }, 200);
    //调用地图定位
  });
}
 
//定位至指定区域
function centerAtRegion(dmnm, dmmc) {
  var jsonurl;
  var dmxh;
  if (dmnm.substring(2) == "0000") {
    //省
    jsonurl = "/sheng/china.json";
    dmxh = dmnm.substring(0, 2);
  } else if (dmnm.substring(4) == "00") {
    //市
    jsonurl = "/shi/" + dmnm.substring(0, 2) + ".json";
    dmxh = dmnm.substring(0, 4);
  } else {
    //县区
    jsonurl = "/xian/" + dmnm.substring(0, 4) + "00.json";
    dmxh = dmnm;
    $("#con_wdx_1").hide();
  }
 
  $.getJSON("//data.mars3d.cn/file/geojson/xzqh" + jsonurl, function (geojson) {
    if (!thisWidget.isActivate) {
      return;
    }
 
    var length = geojson.features.length;
    for (var index = 0; index < length; index++) {
      if (geojson.features[index].properties.id == dmxh) {
        thisWidget.showRegionExtent(geojson.features[index]);
        break;
      }
    }
  });
 
  //显示名称
  var temp = dmmc.lastIndexOf("/");
  if (temp != -1) {
    dmmc = dmmc.substring(temp + 1);
  }
  if (dmmc.length <= 2) {
    dmmc = dmmc + "&nbsp;";
  } else if (dmmc.length > 3) {
    dmmc = dmmc.substring(0, 2) + "..";
  }
 
  $("#xzqh_sel").html(dmmc);
}
 
function goHome() {
  $("#cityname").html("");
  $("#xzqh-select").citypicker("reset");
 
  thisWidget.goHome();
}