微信小程序开发学习之--地图绘制行政区域图

不知道大家有没有感觉就是在做微信小程序地图功能时刚刚接触时候真的感觉好迷茫呀,文档看不懂,资料找不到,就很难受呀,比如我现在的功能就想想绘制出一个区域的轮廓图,主要是为了显眼,效果图如下:就是绘画出北京的轮廓图,蛋黄酥一样的这块。说清楚了我功能之后就开始说怎么实现了(源码码估计会放在程序的最后一段)。

开发思路

1.首先查看官方文档(点进去看就可以了好多配置,不一一细说)

微信小程序地图开发文档

2.看了官方文档后我还是不知道怎么弄,但是我确定用“polygon”这个东西来绘画出轮廓,这个参数大概的意思就是指定一系列坐标点,根据 points 坐标数据生成闭合多边形,我理解的意思就是你要用很多点,用点成线的形式在地图上描点。出线。

3.知道怎么绘画出轮廓之后,又迷茫了我怎么才能得到点,百度很久后有个大神给出方案

数据可视化平台 点进去看到自己想要的城市,导出点,把点加工下,得到轮廓数据,比如我是用的北京的\后期贴代码上来,直接看就ok。

4.有数据 后就开始写代码,直接上代码 (源码地址就在下一行)微信小程序绘制行政区轮廓图小程序: 用微信小程序内部的map来绘制行政区轮廓范围

(1)html 代码,很简单没啥子东西,就配置配置参数,不懂的话就去看官方文档

<map 
  id="mapId"
  class="map"
  latitude="{{latitude}}"
  longitude="{{longitude}}"
  bindmarkertap="onMarkerTap"
  bindcallouttap="onCalloutTap"
  bindlabeltap="onLabelTap"
  scale='7.5'
  polygons="{{polygon}}"
>

</map>

<view class="btn-area service">
  <button bindtap="removeMarkers">
    移除参与聚合点的marker
  </button>
  <button bindtap="addMarkers">
    添加聚合点marker
  </button>
</view>

(2)css代码

.map {
  width: 100%;
  height: 300px;
}

.btn-area {
  margin: 10px;
  display: flex;
  flex-wrap: wrap;
  border: 1px solid #ccc;
}

button {
  display: inline-block;
  margin: 10px 5px;
}

(3)js代码这块比较重要呀(给自己看,太简单了哈哈哈哈哈哈哈哈哈,不过我就想一个人自娱自乐)

const app = getApp()
const img = '../image/location.png'

Page({
  data: {
    //中心经度	
    latitude: 40.2,
    //中心纬度	
    longitude: 116.324520,
    //polygons 多边形
    polygon:[{  
      points: [
          {longitude:116.6212, latitude:41.0283},
          {longitude:116.6157, latitude:41.053},
          {longitude:116.6309, latitude:41.0608},
          {longitude:116.6896, latitude:41.0445},
          {longitude:116.6988, latitude:41.0208},
          {longitude:116.6777, latitude:40.9715},
          {longitude:116.7224, latitude:40.9273},
          {longitude:116.7134, latitude:40.9103},
          {longitude:116.7796, latitude:40.8771},
          {longitude:116.8047, latitude:40.8409},
          {longitude:116.8207, latitude:40.8483},
          {longitude:116.8762, latitude:40.8212},
          {longitude:116.8925, latitude:40.7803},
          {longitude:116.9251, latitude:40.7729},
          {longitude:116.9266, latitude:40.7449},
          {longitude:116.9696, latitude:40.7064},
          {longitude:117.0311, latitude:40.6921},
          {longitude:117.1107, latitude:40.7082},
          {longitude:117.2071, latitude:40.695},
          {longitude:117.3179, latitude:40.6578},
          {longitude:117.4092, latitude:40.6873},
          {longitude:117.5143, latitude:40.6611},
          {longitude:117.5004, latitude:40.6362},
          {longitude:117.462, latitude:40.6531},
          {longitude:117.4489, latitude:40.6515},
          {longitude:117.4482, latitude:40.6278},
          {longitude:117.4212, latitude:40.6354},
          {longitude:117.4218, latitude:40.5694},
          {longitude:117.3877, latitude:40.5608},
          {longitude:117.3502, latitude:40.5822},
          {longitude:117.3118, latitude:40.578},
          {longitude:117.2495, latitude:40.5482},
          {longitude:117.2629, latitude:40.513},
          {longitude:117.2187, latitude:40.5143},
          {longitude:117.2085, latitude:40.5009},
          {longitude:117.2354, latitude:40.4575},
          {longitude:117.2641, latitude:40.4415},
          {longitude:117.2341, latitude:40.4172},
          {longitude:117.2407, latitude:40.3944},
          {longitude:117.2243, latitude:40.3709},
          {longitude:117.2428, latitude:40.3698},
          {longitude:117.2749, latitude:40.3326},
          {longitude:117.2955, latitude:40.2782},
          {longitude:117.3317, latitude:40.2897},
          {longitude:117.3455, latitude:40.2349},
          {longitude:117.39, latitude:40.228},
          {longitude:117.3784, latitude:40.2103},
          {longitude:117.3933, latitude:40.2036},
          {longitude:117.3805, latitude:40.1963},
          {longitude:117.4069, latitude:40.1858},
          {longitude:117.3517, latitude:40.1732},
          {longitude:117.3606, latitude:40.157},
          {longitude:117.3473, latitude:40.1356},
          {longitude:117.3117, latitude:40.1394},
          {longitude:117.2744, latitude:40.1058},
          {longitude:117.2493, latitude:40.1165},
          {longitude:117.2112, latitude:40.0966},
          {longitude:117.1992, latitude:40.0673},
          {longitude:117.1855, latitude:40.085},
          {longitude:117.1803, latitude:40.0695},
          {longitude:117.1564, latitude:40.0787},
          {longitude:117.1392, latitude:40.0641},
          {longitude:117.0856, latitude:40.0751},
          {longitude:117.0218, latitude:40.0296},
          {longitude:116.9304, latitude:40.0553},
          {longitude:116.8707, latitude:40.0411},
          {longitude:116.8502, latitude:40.055},
          {longitude:116.8227, latitude:40.0465},
          {longitude:116.82, latitude:40.0283},
          {longitude:116.7778, latitude:40.0324},
          {longitude:116.7572, latitude:39.9633},
          {longitude:116.7826, latitude:39.9476},
          {longitude:116.7871, latitude:39.8868},
          {longitude:116.8041, latitude:39.8779},
          {longitude:116.8123, latitude:39.8897},
          {longitude:116.9002, latitude:39.8316},
          {longitude:116.9028, latitude:39.8483},
          {longitude:116.9174, latitude:39.8469},
          {longitude:116.9363, latitude:39.7951},
          {longitude:116.9536, latitude:39.7876},
          {longitude:116.8995, latitude:39.7587},
          {longitude:116.9167, latitude:39.7314},
          {longitude:116.8828, latitude:39.7186},
          {longitude:116.9065, latitude:39.6776},
          {longitude:116.8499, latitude:39.6676},
          {longitude:116.8512, latitude:39.6523},
          {longitude:116.8269, latitude:39.6382},
          {longitude:116.8354, latitude:39.617},
          {longitude:116.79, latitude:39.6105},
          {longitude:116.7851, latitude:39.5935},
          {longitude:116.7254, latitude:39.6242},
          {longitude:116.7006, latitude:39.621},
          {longitude:116.7263, latitude:39.5978},
          {longitude:116.7106, latitude:39.588},
          {longitude:116.694, latitude:39.6017},
          {longitude:116.6205, latitude:39.6017},
          {longitude:116.6079, latitude:39.6247},
          {longitude:116.5659, latitude:39.6198},
          {longitude:116.5623, latitude:39.6017},
          {longitude:116.5244, latitude:39.5965},
          {longitude:116.5274, latitude:39.5732},
          {longitude:116.5085, latitude:39.5511},
          {longitude:116.4709, latitude:39.5546},
          {longitude:116.4772, latitude:39.5344},
          {longitude:116.4368, latitude:39.5264},
          {longitude:116.4438, latitude:39.5099},
          {longitude:116.4017, latitude:39.528},
          {longitude:116.4229, latitude:39.4966},
          {longitude:116.4125, latitude:39.4817},
          {longitude:116.4441, latitude:39.4822},
          {longitude:116.4561, latitude:39.4589},
          {longitude:116.4344, latitude:39.4428},
          {longitude:116.3367, latitude:39.4561},
          {longitude:116.3056, latitude:39.4895},
          {longitude:116.2579, latitude:39.5005},
          {longitude:116.2462, latitude:39.5572},
          {longitude:116.204, latitude:39.5888},
          {longitude:116.1541, latitude:39.586},
          {longitude:116.1304, latitude:39.5677},
          {longitude:116.1014, latitude:39.5801},
          {longitude:116.0353, latitude:39.5718},
          {longitude:116.0164, latitude:39.5881},
          {longitude:115.9952, latitude:39.5771},
          {longitude:115.9784, latitude:39.5957},
          {longitude:115.9793, latitude:39.5724},
          {longitude:115.9575, latitude:39.5609},
          {longitude:115.9102, latitude:39.6008},
          {longitude:115.9117, latitude:39.5695},
          {longitude:115.8904, latitude:39.5686},
          {longitude:115.8877, latitude:39.5507},
          {longitude:115.8555, latitude:39.555},
          {longitude:115.8192, latitude:39.5308},
          {longitude:115.8287, latitude:39.507},
          {longitude:115.7521, latitude:39.5117},
          {longitude:115.7385, latitude:39.5463},
          {longitude:115.6921, latitude:39.5658},
          {longitude:115.6893, latitude:39.599},
          {longitude:115.6672, latitude:39.6156},
          {longitude:115.6573, latitude:39.6001},
          {longitude:115.5799, latitude:39.5895},
          {longitude:115.5452, latitude:39.6186},
          {longitude:115.5145, latitude:39.5918},
          {longitude:115.5224, latitude:39.64},
          {longitude:115.4782, latitude:39.6523},
          {longitude:115.5001, latitude:39.6909},
          {longitude:115.4924, latitude:39.7387},
          {longitude:115.4399, latitude:39.7521},
          {longitude:115.4249, latitude:39.7745},
          {longitude:115.4832, latitude:39.7987},
          {longitude:115.5071, latitude:39.7837},
          {longitude:115.5522, latitude:39.7947},
          {longitude:115.5693, latitude:39.8138},
          {longitude:115.5143, latitude:39.8377},
          {longitude:115.5292, latitude:39.8755},
          {longitude:115.509, latitude:39.8842},
          {longitude:115.5205, latitude:39.9022},
          {longitude:115.4807, latitude:39.9358},
          {longitude:115.4262, latitude:39.9504},
          {longitude:115.4545, latitude:40.0297},
          {longitude:115.5522, latitude:40.0792},
          {longitude:115.5576, latitude:40.0951},
          {longitude:115.5907, latitude:40.0964},
          {longitude:115.5991, latitude:40.12},
          {longitude:115.7411, latitude:40.1322},
          {longitude:115.777, latitude:40.1776},
          {longitude:115.8066, latitude:40.1533},
          {longitude:115.8519, latitude:40.148},
          {longitude:115.8481, latitude:40.184},
          {longitude:115.8721, latitude:40.1872},
          {longitude:115.8981, latitude:40.2364},
          {longitude:115.9689, latitude:40.2639},
          {longitude:115.9228, latitude:40.3247},
          {longitude:115.9183, latitude:40.3539},
          {longitude:115.8593, latitude:40.3624},
          {longitude:115.8604, latitude:40.3757},
          {longitude:115.7708, latitude:40.4426},
          {longitude:115.7822, latitude:40.4921},
          {longitude:115.736, latitude:40.5038},
          {longitude:115.7532, latitude:40.5388},
          {longitude:115.7906, latitude:40.5609},
          {longitude:115.8198, latitude:40.5593},
          {longitude:115.8277, latitude:40.5873},
          {longitude:115.8854, latitude:40.5952},
          {longitude:115.9078, latitude:40.6173},
          {longitude:115.9668, latitude:40.6063},
          {longitude:115.9834, latitude:40.5788},
          {longitude:116.0256, latitude:40.6067},
          {longitude:116.03, latitude:40.5974},
          {longitude:116.1217, latitude:40.6292},
          {longitude:116.1106, latitude:40.6469},
          {longitude:116.1349, latitude:40.6671},
          {longitude:116.1646, latitude:40.6634},
          {longitude:116.1779, latitude:40.7079},
          {longitude:116.2338, latitude:40.7591},
          {longitude:116.2476, latitude:40.7918},
          {longitude:116.2734, latitude:40.7629},
          {longitude:116.3089, latitude:40.7519},
          {longitude:116.3295, latitude:40.7738},
          {longitude:116.4617, latitude:40.7698},
          {longitude:116.4572, latitude:40.7983},
          {longitude:116.3344, latitude:40.9046},
          {longitude:116.3342, latitude:40.9213},
          {longitude:116.3703, latitude:40.9437},
          {longitude:116.3985, latitude:40.906},
          {longitude:116.4742, latitude:40.8961},
          {longitude:116.4475, latitude:40.9538},
          {longitude:116.4562, latitude:40.9813},
          {longitude:116.5163, latitude:40.9752},
          {longitude:116.5633, latitude:40.9936},
          {longitude:116.5988, latitude:40.9747},
          {longitude:116.6145, latitude:40.9833},
          {longitude:116.6212, latitude:41.0283}
      ],
       fillColor: "#4F94CD33",
        fillColor: "#ffff0033",
        strokeColor: "#FFF",
        strokeWidth: 2,
        zIndex: 5,
  }]	

  },
  onLoad: function () {
    this.mapCtx = wx.createMapContext('mapId')
    this.setData({
      polygon: this.data.polygon,
    });
  },
})

get

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/55171.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

xinput1_4.dll丢失的解决方法,三种解决方法分享

xinput1_4.dll是一个动态链接库文件&#xff08;DLL&#xff09;&#xff0c;它是Microsoft DirectX的一部分&#xff0c;用于处理游戏控制器输入。当你的电脑提示xinput1_4.dll文件丢失时&#xff0c;意味着与这个文件相关的游戏或应用程序无法正常运行。 当你的电脑提示xinp…

<C++> 引用

1.引用的概念 引用&#xff08;Reference&#xff09;是一种别名&#xff0c;用于给变量或对象起另一个名称。引用可以理解为已经存在的变量或对象的别名&#xff0c;通过引用可以访问到原始变量或对象的内容。引用在声明时使用 & 符号来定义。 示例&#xff1a; #inclu…

ad+硬件每日学习十个知识点(16)23.7.27 (总线保持、lin报文、逻辑器件手册解读)

文章目录 1.总线保持是怎么实现的&#xff1f;有什么需要注意的&#xff08;驱动电流和电阻&#xff09;&#xff1f;2.LIN报文3.芯片datasheet的features、applications、description看完&#xff0c;应该能大致判断逻辑器件能否满足我们的要求。4.什么是逻辑器件的传输延时&a…

InnoDB存储引擎——事务原理

1.什么是事务 2.redo log 脏页是指缓冲区的数据与磁盘中的数据不一致时的状态。脏页的数据并不是实时刷新的&#xff0c;而是一段时间之后通过后台线程把脏页的数据刷线到磁盘&#xff0c;假如说脏页的数据在往磁盘中刷新的时候出错了&#xff0c;内存中的数据没有刷新到磁盘当…

软件测试技能大赛任务二单元测试试题

任务二 单元测试 执行代码测试 本部分按照要求&#xff0c;执行单元测试&#xff0c;编写java应用程序&#xff0c;按照要求的覆盖方法设计测试数据&#xff0c;使用JUnit框架编写测试类对程序代码进行测试&#xff0c;对测试执行结果进行截图&#xff0c;将相关代码和相关截…

如何运行疑难解答程序来查找和修复Windows 10中的常见问题

如果Windows 10中出现问题&#xff0c;运行疑难解答可能会有所帮助。疑难解答人员可以为你找到并解决许多常见问题。 一、在控制面板中运行疑难解答 1、打开控制面板&#xff08;图标视图&#xff09;&#xff0c;然后单击“疑难解答”图标。 2、单击“疑难解答”中左上角的…

RocketMQ 在业务消息场景的优势详解

作者&#xff1a;隆基 01 消息场景 RocketMQ 5.0 是消息事件流一体的实时数据处理平台&#xff0c;是业务消息领域的事实标准&#xff0c;很多互联网公司在业务消息场景会使用 RocketMQ。 我们反复提到的“消息、业务消息”&#xff0c;指的是分布式应用解耦&#xff0c;是 R…

nmake编译Qt第三方库出现无法打开包含文件type_traits

最近需要为个人项目ShaderLab添加内嵌的代码编辑窗口功能&#xff0c;支持语法高亮和Intellisense&#xff0c;最初使用了QCodeEditor,发现这个第三方的库对词法分析的实现效果不太行. 代码换行后直接缩进到首行&#xff0c;无法定位到前一句的首行 考虑换QScintilla&#xff…

Java 基础进阶总结(一)反射机制学习总结

文章目录 一、初识反射机制1.1 反射机制概述1.2 反射机制概念1.3 Java反射机制提供的功能1.4 反射机制的优点和缺点 二、反射机制相关的 API2.1 一、初识反射机制 1.1 反射机制概述 JAVA 语言是一门静态语言&#xff0c;对象的各种信息在程序运行时便已经确认下来了&#xff0…

微信小程序防盗链referer问题处理

公司使用百度云存储一些资源&#xff0c;然后现在要做防盗链&#xff0c;在CDN加入Referer白名单后发现PC是正常的&#xff0c;微信小程序无法正常访问资源了。然后是各种查啊&#xff0c;然后发现是微信小程序不支持Referer的修改&#xff0c;且在小程序开发工具是Referer是固…

优先级队列 (堆)

目录 一&#xff0c;堆的概念 二&#xff0c; 堆的存储结构 三&#xff0c; 堆的实现 3.1 shiftDown() 3.2 shiftUp() 3.3 shiftDown 与 shiftUp 的时间复杂度 四&#xff0c;堆排序 一&#xff0c;堆的概念 堆常用于实现优先队列&#xff08;Priority Queue&#xff0…

偶数科技与白鲸开源完成兼容性认证

近日&#xff0c;偶数科技自主研发的云原生分布式数据库 OushuDB v5.0 完成了与白鲸开源集成调度工具 WhaleStudio v2.0 的兼容性相互认证测试。 测试结果显示&#xff0c;双方产品相互良好兼容&#xff0c;稳定运行、安全&#xff0c;同时可以满足性能需求&#xff0c;为企业级…

git从主仓库同步到fork仓库

git从主仓库同步到fork仓库 1. fork远程仓库到本地仓库2. 将远程仓库添加到本地3. 更新本地项目主库地址4. 将远程仓库更新到本地仓库5. 将本地仓库合到远程分支 1. fork远程仓库到本地仓库 方式一&#xff1a;通过git命令 git clone fork库地址方式二&#xff1a;通过git页面…

【100天精通python】Day22:字符串常用操作大全

目录 专栏导读 一、 字符串常用操作 1 拼接字符串 2 计算字符串长度 3 截取字符串 4 分割合并字符串 5 检索字符串 6 字母的大小写转换 7 去除字符串的空格和特殊字符 8 格式化字符串 二 、字符串编码转换 2.1 使用encode()方法编码 2.2 使用decoder()方法编码 专栏…

mysql的json处理

写在前面 需要注意&#xff0c;5.7以上版本才支持&#xff0c;但如果是生产环境需要使用的话&#xff0c;尽量使用8.0版本&#xff0c;因为8.0版本对json处理做了比较大的性能优化。你你可以使用select version();来查看版本信息。 本文看下MySQL的json处理。在正式开始让我们先…

HarmonyOS 开发基础(四) 子父组件双向绑定

一、知识点在代码注释里 index.ets // 导出方式直接从文件夹 import MyInput from "../common/commons/myInput" Entry Component /* 组件可以基于struct实现&#xff0c;组件不能有继承关系&#xff0c;struct可以比class更加快速的创建和销毁。*/ struct Index {…

【hive】Install hive using mysql as hive metadata service

文章目录 一. Requirements二. Installing Hive from a Stable Release三. Running Hive四. Running Hive CLI五.Running HiveServer2 and Beeline1. 下载安装mysql2. 下载mysql驱动3. 配置hive-site.xml4. 初始化元数据库5. 通过beeline进行连接 一. Requirements Users are s…

BES 平台 SDK之LED的配置

本文章是基于BES2700 芯片&#xff0c;其他BESxxx 芯片可做参考&#xff0c;如有不当之处&#xff0c;欢迎评论区留言指出。仅供参考学习用&#xff01; BES 平台 SDK之代码架构讲解二_谢文浩的博客-CSDN博客 关于SDK 系统框架简介可参考上一篇文章。链接如上所示&#xff01…

防火墙监控工具

防火墙监控是跟踪在高效防火墙性能中起着关键作用的重要防火墙指标&#xff0c;防火墙监控通常应包括&#xff1a; 防火墙日志监控防火墙规则监控防火墙配置监控防火墙警报监控 防火墙监控服务的一个重要方面是它应该是主动的。主动识别内部和外部安全威胁有助于在早期阶段识…

Devops系统中jira平台迁移

需求:把aws中的devops系统迁移到华为云中,其中主要是jira系统中的数据迁移,主要方法为在华为云中建立一套 与aws相同的devops平台,再把数据库和文件系统中的数据迁移,最后进行测试。 主要涉及到的服务集群CCE、数据库mysql、弹性文件服务SFS、数据复制DRS、弹性负载均衡ELB。 迁…