地图显示西安经济开发区边界线-2023.12

这是2023年12月写的,不知为何没有发出。这里做一个补发

以曲江新区为例

1.目前只有百度地图可以查看经济开发区(但开发文档未提供对应api),其他地图只能查看行政区。

2.使用多边形编辑器吸附功能在地图上描绘出曲江边界线

多边形编辑器吸附功能-矢量覆盖物编辑-示例中心-JS API 2.0 示例 | 高德地图API (amap.com)

3.高德地图显示曲江经济开发区

4.高德地图围墙显示西安六大行政区demo

复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>动态围墙线</title>
</head>

  <script charset="utf-8"
  src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&libraries=visualization,service"></script>

  <!-- <script src="./qujaing.js" ></script> -->
  <script src="./myqujiang.js" ></script>
  
<style type="text/css">
  html,
  body {
    height: 100%;
    margin: 0px;
    padding: 0px;
  }

  #container {
    width: 100%;
    height: 100%;
  }
</style>

<body onload="initMap()">
  <div id="container"></div>
  <script>





 function initMap() {
  //初始化地图
  var map = new TMap.Map("container", {
    zoom: 11, //设置地图缩放级别
    center: new TMap.LatLng(34.214328, 108.944669), //设置地图中心点坐标   雁塔区
    // 以下展示为黑色
    pitch: 40, // 设置地图俯仰角
    mapStyleId: "style4", //个性化样式
    renderOptions: {
      enableBloom: true, // 泛光
    },
    baseMap: {
      type: "vector",
      features: ["base", "building3d"], // 隐藏矢量文字
    },
  });



  var district = new TMap.service.District({
    // 新建一个行政区划类
    polygon: 1, // 返回行政区划边界的类型
  });
  var Wall = new TMap.visualization.Wall({
    styles: {
      style1: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(1,124,247,0.6)",
            1: "rgba(29,250,242,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(29,250,242,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },
      style2: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(255,165,0,0.5)",
            1: "rgba(255,165,0,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(255,165,0,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },
      style3: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(255,0,153,0.5)",
            1: "rgba(255,0,153,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(255,0,153,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },
      style4: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(0,231,255,0.5)",
            1: "rgba(0,231,255,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(0,231,255,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },
      style5: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(0,93,209,0.5)",
            1: "rgba(0,93,209,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(0,93,209,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },
      style6: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(3,89,41,0.5)",
            1: "rgba(3,89,41,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(3,89,41,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },
      style7: {
        color: new TMap.GradientColor({
          stops: {
            0: "rgba(255,111,131,0.5)",
            1: "rgba(255,111,131,1)",
          },
          angle: 90, //渐变色中的断点集合
        }),
        strokeColor: 'rgba(255,111,131,1)', //边线颜色
        strokeWidth: 2, //边线宽度
      },

      
    },
    processAnimation: {
      animationType: "breath", //动画类型名称
      breathAmplitude: 0.5, //呼吸幅度
      yoyo: true, //是否回弹
      duration: 1000, //动画时长
    },

  })
    .addTo(map)

  function convertToPath(array) {
    return array.map((p) => {
      if (p.length == 2) return new TMap.LatLng(p[0], p[1]);
      if (p.length == 3) return new TMap.LatLng(p[0], p[1], p[2]);
    });
  }


// 曲江
  // var  qujiangwallLine = latlngarr
  // var path = convertToPath(qujiangwallLine);
  // var wallData2 = {
  //   path: path, //	经纬度数组
  //   height: 4500, //围墙面高度
  //   styleId: "style1", //围墙面样式配置id
  // };




var wallLineArr = []


function getWall(keyword,index){
  // let newIndex = index+3
  if(!keyword){
    console.log('==============');
    return 
  }
  district
    .search({ keyword })
    .then((result) => {
      console.log('result',result);
      var polygon = result?.result?.[0]?.[0]?.polygon
      var latlngcur = polygon[polygon.length-1]
      var wallLine = latlngcur.map(item => {
        return [item.lat, item.lng]
      })
      var path = convertToPath(wallLine);
      var wallData = {
        path: path, //	经纬度数组
        height: 4500, //围墙面高度
        styleId: "style"+index, //围墙面样式配置id
        keyword: keyword,
      };
      wallLineArr.push(wallData)
  })

}


// // 西安 610100
var keywordArrArr = [['610102','610103','610104','610111','610112',],['610113']] 

  // var keywordArrArr = [['610118','610122','610124'],['610102','610103','610104','610111','610112'],['610113','610114','610115','610116','610117'],]

  // 西安市行政区
  keywordArrArr.map((keywordArr,index)=>{
    
    setTimeout(()=>{
      keywordArr.map((item,index2)=>{
        // let newIndex = index*5+index2+2
        // console.log('newIndex',newIndex);
        // let newIndex = index2+3
        let newIndex = 1
        console.log('newIndex',newIndex);
        getWall(item,newIndex)
      })
      },(index+1)*1000)
  })

  setTimeout(()=>{
    console.log('wallLineArr',wallLineArr);
    Wall.setData(wallLineArr);

  },3500)


}
  </script>
</body>

</html>
相关推荐
寅时码2 小时前
React 之死·终章:一个 useRef,把闭包陷阱、依赖数组、漫天 rerender 全送走
前端·react.js·ai编程
不好听6132 小时前
HTML 事件监听机制:从 DOM Level 0 到 React 合成事件
前端·react.js·html
wordbaby2 小时前
为什么刷新页面就 404?聊聊 SPA 路由与 Nginx 的那点事
前端
daols882 小时前
vxe-table 渲染器教程一:实现金额输入控件
javascript·vue.js·vxe-table
不好听6132 小时前
React 核心概念:JSX、组件与数据驱动
前端·react.js
触底反弹2 小时前
🔥 React 零基础入门(中):500 行屎山代码到组件化的蜕变
前端·javascript·react.js
不好听6132 小时前
React vs Vue:两大前端框架技术选型深度对比
前端·vue.js·react.js
GuWenyue2 小时前
Cursor黑盒拆解!1套LangChain.js手写Mini编程Agent,自动生成React项目,效率提升60%
前端·数据库·人工智能
GuWenyue2 小时前
传统Agent工具两大痛点!300行代码落地MCP跨语言工具,彻底解耦LLM与工具
前端·人工智能·算法
小林ixn3 小时前
从 onclick 到 React 合成事件,再到完整应用逻辑:一次前端架构的深度剖析
前端·react.js·前端框架