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

news2024/11/18 16:28:49

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

开发思路

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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

官方Office 技巧免费学习平台-WPS学堂

WPS学堂是WPS官方Office 技巧免费学习平台&#xff0c;目前网站累计上线 3000个免费教学视频图文&#xff0c;包含WPS表格(Excel)、WPS文字&#xff08;Word&#xff09;、WPS演示(PPT)的操作技巧及新手入门系列课视频&#xff0c;而且教学视频都可以直接在线学习&#xff0c;不…

14.2 【Linux】软件磁盘阵列(Software RAID)

14.2.1 什么是 RAID 磁盘阵列全名是“ Redundant Arrays of Inexpensive Disks, RAID ”&#xff0c;英翻中的意思是&#xff1a;容错式廉价磁盘阵列。 RAID 可以通过一个技术&#xff08;软件或硬件&#xff09;&#xff0c;将多个较小的磁盘整合成为一个较大的磁盘设备&…

图数据库Neo4j学习四——Spring Data NEO

1配置 1.1Maven依赖 <!--neo4j --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-neo4j</artifactId> </dependency>1.2yml配置 spring:data:neo4j:uri: bolt://localhost:76…

【机器学习】Cost Function for Logistic Regression

Cost Function for Logistic Regression 1. 平方差能否用于逻辑回归&#xff1f;2. 逻辑损失函数loss3. 损失函数cost附录 导入所需的库 import numpy as np %matplotlib widget import matplotlib.pyplot as plt from plt_logistic_loss import plt_logistic_cost, plt_two_…

利用易查分制作分班查询系统,怎么导入数据?

暑假过半&#xff0c;新学期即将到来&#xff0c;这对学校来说是一个重要的时刻。新学期的开始意味着学校将面临新生入学和老生升入高年级的情况&#xff0c;这就需要进行分班工作的安排。分班工作是一项繁琐而关键的任务&#xff0c;它直接关系到学生们在新学期中的班级和同学…

【Linux进程篇】进程概念(1)

【Linux进程篇】进程概念&#xff08;1&#xff09; 目录 【Linux进程篇】进程概念&#xff08;1&#xff09;进程基本概念描述进程-PCBtask_struct-PCB的一种task_ struct内容分类 组织进程查看进程通过系统调用获取进程标示符通过系统调用创建进程——fork初识 作者&#xff…

SpringMVC源码分析 —— 拦截器是何时调用的

SpringMVC源码分析&#xff0c;拦截器是何时、以什么方式调用的&#xff1f;本文将进行详细说明 环境准备 springboot 2.3.7.RELEASE 笔者创建一个springboot的web项目&#xff0c;使用的springboot的版本是2.3.7.RELEASE 对应的spring-web版本是5.2.12.RELEASE 下面将对上面…

【NLP-新工具】语音转文本与OpenAI的用途

一、说明 OpenAI最近2022发布了一个名为Whisper的新语音识别模型。与DALLE-2和GPT-3不同&#xff0c;Whisper是一个免费的开源模型。它的主要功能就是将语音翻译成文本。本文将介绍如何使用这个重要应用库。 二、 Whisper概念 2.1 Whisper是啥&#xff1f; Whisper 是一种自动…

考完软考,有什么备考心得和学习经验可以分享吗?

恭&#xfffd;&#xfffd;您完成软考考试&#xff01;备考软考确实是一项艰苦的任务&#xff0c;但也是一次很有收获的学习和成长过程。下面分享一些备考心得和学习经验&#xff0c;以及针对系统集成项目管理工程师和信息系统项目管理师考试的备考建议&#xff1a; 备考心得…

PACS系统源码:支持三维重建功能、集成放射科管理RIS系统、图文报告编辑、打印、多级审核机制

PACS系统源码 PACS系统是以最新的IT技术为基础&#xff0c;遵循医疗卫生行业IHE/DICOM3.0和HL7标准&#xff0c;开发的多功能服务器和阅片系统。通过简单高性能的阅片功能&#xff0c;支持繁忙时的影像诊断业务&#xff0c;拥有保存影像的院内Web传输及离线影像等功能&#xf…

【Android】APP网络优化学习笔记

网络优化原因 进行网络优化对于移动应用程序而言非常重要&#xff0c;原因如下&#xff1a; 用户体验&#xff1a; 网络连接是移动应用程序的核心功能之一。通过进行网络优化&#xff0c;可以提高应用的加载速度和响应速度&#xff0c;减少用户等待时间&#xff0c;提供更流…

跨境电商还有人在做吗,这十大选品技巧建议收藏!

随着电商的快速发展&#xff0c;无论国内或者国外电商&#xff0c;竞争都比较激烈&#xff0c;很多人觉得现在入行太晚了&#xff0c;玩不过那些老卖家。 不过我想说的是&#xff1a;做电商很重要的一点就是选品&#xff0c;那些很早一批老卖家可能也是借着红利期走过来的&…

ATFX汇市:美联储加息25基点,虽提振美指,或招致衰退

环球汇市行情摘要—— 上周&#xff0c;美元指数上涨0.6%&#xff0c;收盘在101.7点&#xff0c; 欧元贬值0.96%&#xff0c;收盘价1.1017点&#xff1b; 日元升值0.47%&#xff0c;收盘价141.16点&#xff1b; 英镑贬值0.01%&#xff0c;收盘价1.2852点&#xff1b; 瑞郎…

微信小程序配置上传多个u-upload上传

微信小程序配置上传多个u-upload上传 使用的是uView框架 微信小程序配置上传多个u-upload上传图片 场景需求&#xff1a;根据PC端配置项追加图片配置 小程序根据配置的图片数量&#xff0c;图片名称&#xff0c;进行上传图片 难度在于 我们不知道用户会追加多少个图片配置字段 …

预测性维护和预防性维护的区别

预测性维护和预防性维护是两种不同的设备维护策略&#xff0c;它们在维护时机、方法和效果上存在明显的区别。在工业生产和设备管理中&#xff0c;选择适合的维护方式对于提高设备的可靠性、延长寿命以及降低维护成本至关重要。本文将深入探讨预测性维护和预防性维护的区别及其…

【LeetCode】剑指offer礼物的最大价值

礼物的最大价值 题目描述算法分析编程代码 链接: 礼物的最大价值 题目描述 算法分析 编程代码 class Solution { public:int maxValue(vector<vector<int>>& grid) {int m grid.size();int n grid[0].size();vector<vector<int>> dp(m1,vector…

开利网络受邀参与战略合作伙伴和合控股 聚焦数据价值

近日&#xff0c;开利网络战略合作伙伴和合控股组织的“数据聚焦价值&#xff0c;引导数据化转型”主体研讨会&#xff0c;开利网络作为和合控股的战略合作伙伴和“数利丰”应用技术合作方&#xff0c;受邀进行落地应用分享。 随着“数字中国”战略的提出&#xff0c;数据已然成…

【爬虫逆向案例】某易云音乐(评论)js逆向—— params、encSecKey解密

声明&#xff1a;本文只作学习研究&#xff0c;禁止用于非法用途&#xff0c;否则后果自负&#xff0c;如有侵权&#xff0c;请告知删除&#xff0c;谢谢&#xff01; 【爬虫逆向案例】某易云音乐&#xff08;评论&#xff09;js逆向—— params、encSecKey解密 1、前言2、行动…

day57|● 647. 回文子串 ● 516.最长回文子序列

647. 回文子串 https://leetcode.cn/problems/palindromic-substrings/solution/by-lfool-2mvg/ Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous…

【Spring事务学习】事务分类 隔离级别 事务传播机制

目录 需要知道&#xff1a; &#x1f351;1、什么是事务&#xff1f; &#x1f351;2、事务的主要操作3个 一、Spring中事务的实现方式 &#x1f351;1、编程式事务&#xff08;手动写代码操作事务&#xff09;&#xff08;了解&#xff09; &#x1f351;2、声明式事务&…