hclzb.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8" />
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0" />
  6. <title>荟萃楼珠宝黑龙江省</title>
  7. <script>
  8. window._AMapSecurityConfig = {
  9. securityJsCode: '3526b49c1c46354a5f0676002636f360',
  10. };
  11. </script>
  12. <script src="https://webapi.amap.com/loader.js"></script>
  13. <script type="text/javascript">
  14. var _this = this;
  15. let center = [126.661998, 48.742253];
  16. let zoom = 6.5;
  17. // 引入,实例化
  18. AMapLoader.load({
  19. key: '94943af79a8a349d045c2b8645cc9db4', // 申请好的Web端开发者Key,首次调用 load 时必填
  20. version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  21. plugins: ['AMap.PlaceSearch'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  22. })
  23. .then((AMap) => {
  24. var map = new AMap.Map('container', {
  25. center,
  26. zoom,
  27. mapStyle: 'amap://styles/88ab842bd66e2dcb61aff7f507779c45',
  28. });
  29. // 隐藏黑龙江以外的地方
  30. AMap.plugin('AMap.DistrictSearch', function () {
  31. new AMap.DistrictSearch({
  32. extensions: 'all',
  33. subdistrict: 1, // 这个是获取下面一层级的数据,获取城市
  34. }).search('黑龙江', function (status, result) {
  35. // 外多边形坐标数组和内多边形坐标数组
  36. // 获取城市列表
  37. let cityList = result.districtList[0].districtList;
  38. let outer = [new AMap.LngLat(-360, 90, true), new AMap.LngLat(-360, -90, true), new AMap.LngLat(360, -90, true), new AMap.LngLat(360, 90, true)];
  39. let holes = result.districtList[0].boundaries;
  40. let pathArray = [outer];
  41. pathArray.push.apply(pathArray, holes);
  42. let polygon = new AMap.Polygon({
  43. pathL: pathArray,
  44. strokeColor: 'red', //城市边界颜色
  45. strokeWeight: 3,
  46. fillColor: '#112473', // 遮罩背景色黑色
  47. fillOpacity: 1,
  48. });
  49. polygon.setPath(pathArray);
  50. map.add(polygon);
  51. for (let i = 0; i < cityList.length; i++) {
  52. const { name } = cityList[i];
  53. _this.setBorder(map, name, i);
  54. }
  55. });
  56. });
  57. // 查找荟萃楼的点
  58. _this.findPoint(map);
  59. })
  60. .catch((e) => {
  61. console.error(e); //加载错误提示
  62. });
  63. // 色谱
  64. let colors = [
  65. '#70F2FF',
  66. '#7F1CAD',
  67. '#F1D4E8',
  68. '#9D2932',
  69. '#54004E',
  70. '#00FF00',
  71. '#177CB0',
  72. '#1E90FF',
  73. '#000080',
  74. '#00FFFF',
  75. '#3CB371',
  76. '#CC99FF',
  77. '#FF6600',
  78. '#ED5736',
  79. '#494166',
  80. '#D9B612',
  81. '#A98175',
  82. '#EFDEB0',
  83. ];
  84. // 设置边界及区域多边形
  85. function setBorder(map, cityName, i) {
  86. let color = colors[i];
  87. AMap.plugin('AMap.DistrictSearch', function async() {
  88. new AMap.DistrictSearch({
  89. // level: 'city',
  90. extensions: 'all',
  91. subdistrict: 0,
  92. }).search(cityName, function (status, result) {
  93. // 用城市代码确定黑龙江城市
  94. let holes = result.districtList.map((i) => i.boundaries);
  95. holes = holes[0];
  96. // 会返回好几个数组,这些数组的点不知道是什么,但边界线一定是点最多的
  97. let lengthArr = holes.map((i) => i.length);
  98. let num = lengthArr.reduce((n1, n2) => (n1 > n2 ? n1 : n2));
  99. let index = lengthArr.findIndex((i) => i === num);
  100. let pathArray = holes[index];
  101. //生成行政区划的多边形
  102. new AMap.Polygon({
  103. map: map,
  104. path: pathArray,
  105. strokeWeight: 1, //轮廓线宽度
  106. strokeColor: 'red', //轮廓线颜色
  107. fillOpacity: 0.3, // 多边形透明度
  108. fillColor: color, // 多边形颜色
  109. });
  110. });
  111. });
  112. }
  113. // 添加点
  114. function addMarkers(map) {
  115. if (!map) return;
  116. }
  117. let marks = [];
  118. // 查询点
  119. function findPoint(map, pageIndex = 1) {
  120. // 查询 荟萃楼珠宝
  121. var placeSearch = new AMap.PlaceSearch({
  122. // city 指定搜索所在城市,支持传入格式有:城市名、citycode和adcode
  123. city: '黑龙江',
  124. pageSize: 100,
  125. pageIndex,
  126. map,
  127. autoFitView: false,
  128. });
  129. placeSearch.search('荟萃楼珠宝', function (status, result) {
  130. // 查询成功时,result即对应匹配的POI信息
  131. let poiList = result.poiList;
  132. let pois = poiList.pois;
  133. marks.push(...pois);
  134. // 计算是否需要再查询
  135. let total = poiList.count;
  136. if (total > marks.length) _this.findPoint(map, pageIndex + 1);
  137. });
  138. }
  139. </script>
  140. <style>
  141. body {
  142. height: 100%;
  143. width: 100%;
  144. color: #333;
  145. background: #e8e8e8;
  146. font: 14px 'Microsoft YaHei', arial, helvetica, clean, sans-serif;
  147. overflow: hidden !important;
  148. -webkit-text-size-adjust: none;
  149. margin: 0 auto;
  150. }
  151. #container {
  152. height: 100vh;
  153. width: 100wh;
  154. }
  155. </style>
  156. <body>
  157. <div id="container"></div>
  158. </body>
  159. </html>