1
2
3
4
5
6
获取地区轮廓线
7
8
9
10 body {
11 font-size: 13px;
12 margin: 10px
13 }
14 #container {
15 width: 800px;
16 height: 500px;
17 border: 1px solid gray
18 }
19
20
21
22
23
24
25
输入省、直辖市或县名称:
26
27
28
29 var fso = new ActiveXObject("Scripting.FileSystemObject");
30
31 var folderName = "C:\\china\\";
32 if (!fso.FolderExists(folderName)) fso.CreateFolder(folderName);
33
34 var map = new BMap.Map("container");
35 map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
36 map.addControl(new BMap.NavigationControl({
37 type: BMAP_NAVIGATION_CONTROL_SMALL
38 }));
39 map.enableScrollWheelZoom();
40 //直辖市
41 if (cityData.municipalities && cityData.municipalities.length > 0) {
42 for (var i = 0, n = cityData.municipalities.length; i < n; i++) {
43 var mu = cityData.municipalities[i];
44 getBoundary(mu.n, "");
45 }
46 }
47 // 普通省
48 for (var i = 0, n = cityData.provinces.length; i < n; i++) {
49 var pv = cityData.provinces[i];
50 var newFolderName = folderName + pv.n
51 if (!fso.FolderExists(newFolderName)) newFolderName = fso.CreateFolder(folderName + pv.n);
52 getBoundary(pv.n, "");
53 for (var j = 0, m = pv.cities.length; j < m; j++) {
54 getBoundary(pv.cities[j].n, pv.n);
55 }
56
57 }
58
59 // 其他地区
60 if (cityData.other && cityData.other.length > 0) {
61 for (var i = 0, n = cityData.other.length; i < n; i++) {
62 var oth = cityData.other[i];
63 getBoundary(oth.n, "");
64 }
65
66 }
67
68 function getBoundary(name, pvName) {
69 var bdary = new BMap.Boundary();
70
71 bdary.get(name, function(rs) { //获取行政区域
72 // map.clearOverlays(); //清除地图覆盖物
73 // var count = rs.boundaries.length; //行政区域的点有多少个
74 // for (var i = 0; i < count; i++) {
75 // var ply = new BMap.Polygon(rs.boundaries[i], {
76 // strokeWeight: 2,
77 // strokeColor: "#ff0000"
78 // }); //建立多边形覆盖物
79 // map.addOverlay(ply); //添加覆盖物
80 // map.setViewport(ply.getPath()); //调整视野
81
82 // }
83 var fileName = "";
84 var newFileObject = null;
85 if (pvName == "") newFileObject = fso.CreateTextFile(folderName + name + ".txt", true)
86 else newFileObject = fso.CreateTextFile(folderName + pvName + "\\" + name + ".txt", true);
87
88 newFileObject.write(rs.boundaries[0]);
89 newFileObject.Close();
90 // eventsTable.innerHTML = rs.boundaries[0].length +':'+ rs.boundaries[0];
91 });
92 }
93
94
95
96