天地图api总结

天地图案例

<template><div id="map" class="tdmap"><div class="button_click"><el-button @click="mark" type="primary" size="mini">添加点位</el-button><el-button @click="polyg" type="primary" size="mini">绘制区域</el-button><el-button @click="polyl" type="primary" size="mini">绘制路线</el-button><el-button @click="rect" type="primary" size="mini">绘制矩形</el-button><el-button @click="circ" type="primary" size="mini">绘制圆</el-button><el-button @click="clear" type="primary" size="mini">清除默认添加的覆盖物</el-button><el-button @click="clearClick" type="primary" size="mini">清除手工添加的覆盖物</el-button><el-inputv-model="input"placeholder="请输入内容"style="margin-left: 20px"></el-input><el-button @click="search" type="primary" size="mini">搜索</el-button></div></div>
</template><script>
const T = window.T;
export default {data() {return {map: "",mockList: ["118.6114,37.24864","118.61775,37.24885","118.63286,37.2496","118.64865,37.25144",],area: [["118.56359,37.26715", "118.55836,37.26012", "118.56892,37.26005"],["118.55793,37.25704","118.5569,37.24816","118.56806,37.24816","118.56823,37.2567",],["118.56214,37.24543","118.56085,37.24147","118.5563,37.24119","118.56068,37.24017","118.55759,37.23764","118.56179,37.23955","118.56368,37.23757","118.56317,37.2401","118.56711,37.23969","118.56325,37.24126",],],line: [["118.56668,37.26729","118.58059,37.26722","118.569,37.24113","118.58557,37.24277","118.58411,37.22992","118.58059,37.22131",],["118.58497,37.25745","118.58522,37.25042","118.5884,37.25049","118.59303,37.25076","118.59364,37.24618",],["118.59767,37.2444","118.58737,37.22923","118.59904,37.22575","118.59982,37.22787",],],recta: [["118.63767,37.23265", "118.62308,37.22288"],["118.67955,37.23942", "118.66101,37.2278"],],circleList: [["118.69123", "37.26271", "1117.0034000701808"],["118.55905", "37.2183", "600.6030888877458"],["118.69629", "37.2265", "1053.7729265767698"],],icon: "",markerInfoWin: "",submarker: "",// marker:'',markers: [],// polygon:'',polygondraw: "",polygons: [],markspot: "",labels: [],marks: [],input: "",geocoder: "",pdefinedOverlays: [],polygs: [],polylinedraw: "",polyls: [],div: "",// polyline:'',polylines: [],// rectangle:'',rectang: "",rectangles: [],rectangs: [],// cricle:'',cirel: "",cricles: [],cirels: [],};},mounted() {this.$nextTick(() => {this.init();});},methods: {//地图初始化init() {//添加图层const imageURL ="http://t0.tianditu.gov.cn/img_w/wmts?" +"SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +"&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" +"&tk=f6a256d612b541a0520a1cd3bbbec82f"; //卫星图影像const imageURLT ="http://t0.tianditu.gov.cn/cia_w/wmts?" +"SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +"&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" +"&tk=f6a256d612b541a0520a1cd3bbbec82f"; //卫星图标记const lay = new T.TileLayer(imageURL, { minZoom: 6, maxZoom: 18 }); //创建图层对象const lay2 = new T.TileLayer(imageURLT, { minZoom: 6, maxZoom: 18 }); //创建图层对象var config = { layers: [lay, lay2] };this.map = new T.Map("map"); //创建地图对象this.map.centerAndZoom(new T.LngLat(118.63372, 37.24352), 14); //初始化地图this.addCovering();this.addToolCovering();},//初始化在地图上添加覆盖物addCovering() {//创建marker图标样式this.icon = new T.Icon({iconUrl: "images/position_icon.png",iconSize: new T.Point(36, 36),iconAnchor: new T.Point(15, 30),});// 创建信息窗口对象this.markerInfoWin = new T.InfoWindow("", {offset: new T.Point(2, -30),});// this.addMarker(); //添加marker标注this.addPolygon(); //添加多边形// this.addPolyline(); //添加线条// this.addRectangle(); //添加矩形// this.addCircle(); //添加圆形},//创建工具类对象addToolCovering() {//标注点对象this.markspot = new T.MarkTool(this.map, {follow: true,icon: this.icon,});this.markspot.addEventListener("mouseup", this.onMorkPolygon);//多边形对象this.polygondraw = new T.PolygonTool(this.map, {color: "#F59200",width: 10,opacity: 1,fillColor: "#F59200",fillOpacity: 0.3,showLabel: false,});this.polygondraw.addEventListener("draw", this.onDrawPolygon);//线对象this.polylinedraw = new T.PolylineTool(this.map, {color: "red",width: 10,opacity: 1,showLabel: false,});this.polylinedraw.addEventListener("draw", this.onDrawPolyline);//矩形对象this.rectang = new T.RectangleTool(this.map, {color: "#01A1ED",width: 10,opacity: 1,fillColor: "#01A1ED",fillOpacity: 0.3,});this.rectang.addEventListener("draw", this.onDrawRectangle);//圆形对象this.cirel = new T.CircleTool(this.map, {color: "#b800ff",width: 10,opacity: 1,fillColor: "#b800ff",fillOpacity: 0.3,});this.cirel.addEventListener("drawend", this.onDrawCirele);},//marker标注的位置addMarker() {//添加多个marker标注this.mockList.forEach((item, index) => {let point = item.split(",");//创建label对象,morker的文字标注let latlng = new T.LngLat(point[0], point[1]);let label = new T.Label({text: `天地图marker${index + 1}的文字标注`,position: latlng,offset: new T.Point(0, -10),});//设置label对象的css样式label.setFontColor("#fff");label.setBackgroundColor("transparent");label.setBorderColor("transparent");this.map.addOverLay(label); //向地图对象添加marker文字标注this.labels.push(label); //变量用于清除覆盖对象let html = "<div>天地图信息窗</div>"; //marker信息窗显示的内容//创建marker对象let marker = new T.Marker(new T.LngLat(point[0], point[1]), {icon: this.icon,});marker.content = html;this.map.addOverLay(marker); //向地图对象添加markermarker.addEventListener("click", this.infoClick); //向marker对象添加事件监听,鼠标点击this.markers.push(marker); //变量用于清除覆盖对象//自定义覆盖物,对某一位置特殊处理,例如marker标注位置需要特殊css动画let definedOverlay = T.Overlay.extend({initialize: function (lnglat, options) {this.lnglat = lnglat;this.setOptions(options);},onAdd: function (map) {this.map = map;var div = (this.div = document.createElement("div"));div.className = "div_class";div.style.position = "absolute";div.style.MozUserSelect = "none";div.onmouseover = function () {this.style.backgroundColor = "#6BADCA";this.style.borderColor = "#0000ff";};div.onmouseout = function () {this.style.backgroundColor = "#EE5D5B";this.style.borderColor = "#BC3B3A";};map.getPanes().overlayPane.appendChild(this.div);this.update(this.lnglat);},onRemove: function () {var parent = this.div.parentNode;if (parent) {parent.removeChild(this.div);this.map = null;this.div = null;}},setLnglat: function (lnglat) {this.lnglat = lnglat;this.update();},getLnglat: function () {return this.lnglat;},setPos: function (pos) {this.lnglat = this.map.layerPointToLngLat(pos);this.update();},update: function () {var pos = this.map.lngLatToLayerPoint(this.lnglat);this.div.style.top = pos.y - 54 + "px";this.div.style.left = pos.x - 35 + "px";},});let p = new T.LngLat(point[0], point[1]);var pdefinedOverlay = new definedOverlay(p, {});this.map.addOverLay(pdefinedOverlay);this.pdefinedOverlays.push(pdefinedOverlay); //变量用于清除覆盖对象});},//点击marker标注infoClick(e) {let point = e.lnglat;this.markerInfoWin.setContent(e.target.content);this.map.openInfoWindow(this.markerInfoWin, point); //开启信息窗口},//多边形addPolygon() {this.area.forEach((item) => {let list = this.getList(item);console.log(list);let polygon = new T.Polygon(list, {color: "#06d7f9",weight: 3,opacity: 1,fillColor: "#06d7f9",fillOpacity: 0.3,});this.map.addOverLay(polygon);this.polygons.push(polygon);});},//线条addPolyline() {this.line.forEach((item) => {let list = this.getList(item);let polyline = new T.Polyline(list, {color: "#CBDE02",weight: 3,opacity: 1,});this.map.addOverLay(polyline);this.polylines.push(polyline);});},//矩形addRectangle() {this.recta.forEach((item) => {let list = this.getList(item);let bounds = new T.LngLatBounds(list[0], list[1]);let rectangle = new T.Rectangle(bounds, {color: "#1ded26",width: 10,opacity: 1,fillColor: "#1ded26",fillOpacity: 0.3,});this.map.addOverLay(rectangle);this.rectangles.push(rectangle);});},//圆形addCircle() {this.circleList.forEach((item) => {let cricle = new T.Circle(new T.LngLat(item[0], item[1]),parseFloat(item[2]),{color: "#ff007e",weight: 3,opacity: 1,fillColor: "#ff007e",fillOpacity: 0.3,});this.map.addOverLay(cricle);this.cricles.push(cricle);});},getList(obj) {let item = obj;let list = [];item.forEach((i) => {let arr = i.split(",");list.push(new T.LngLat(arr[0], arr[1]));});return list;},//添加marker标注mark() {this.markspot.open();},//获取marker标注的位置onMorkPolygon(e) {let monkerStr = `${e.currentLnglat.lng},${e.currentLnglat.lat}`;this.marks.push(e.currentMarker);console.log(monkerStr);},//绘制多边形polyg() {this.polygondraw.open();},//获取绘制的多边形路径onDrawPolygon(e) {let position = [];e.currentLnglats.forEach((item) => {let str = `${item.lng},${item.lat}`;position.push(str);});this.polygs.push(e.currentPolygon);console.log(position);},//绘制路线(线工具)polyl() {this.polylinedraw.open();},//获取绘制的线条的路径onDrawPolyline(e) {let position = [];e.currentLnglats.forEach((item) => {let str = `${item.lng},${item.lat}`;position.push(str);});this.polyls.push(e.currentPolyline);console.log(position);},//绘制矩形rect() {this.rectang.open();},//获取绘制的矩形坐标onDrawRectangle(e) {let obj = e.currentBounds;let position = [`${obj.Lq.lng},${obj.Lq.lat}`,`${obj.kq.lng},${obj.kq.lat}`,];this.rectangs.push(e.currentRectangle);console.log(position);},//绘制圆形circ() {this.cirel.open();},//获取绘制的圆坐标onDrawCirele(e) {let obj = e.currentCenter;let position = [obj.lng, obj.lat, e.currentRadius];this.cirels.push(e.currentCircle);console.log(position);},//根据需求清除地图的覆盖物clear() {this.polygons.forEach((item) => {this.map.removeOverLay(item);});this.labels.forEach((item) => {this.map.removeOverLay(item);});this.markers.forEach((item) => {this.map.removeOverLay(item);});this.pdefinedOverlays.forEach((item) => {this.map.removeOverLay(item);});this.polylines.forEach((item) => {this.map.removeOverLay(item);});this.rectangles.forEach((item) => {this.map.removeOverLay(item);});this.cricles.forEach((item) => {this.map.removeOverLay(item);});},clearClick() {this.marks.forEach((item) => {this.map.removeOverLay(item);});this.polygs.forEach((item) => {this.map.removeOverLay(item);});this.polyls.forEach((item) => {this.map.removeOverLay(item);});this.rectangs.forEach((item) => {this.map.removeOverLay(item);});this.cirels.forEach((item) => {this.map.removeOverLay(item);});},//根据名字查询位置search() {this.map.removeOverLay(this.submarker);this.geocoder = new T.Geocoder();this.geocoder.getPoint(this.input, this.searchResult);},//查询位置的结果searchResult(result) {if (result.getStatus() == 0) {this.map.panTo(result.getLocationPoint(), 12);//创建标注对象this.submarker = new T.Marker(result.getLocationPoint());//向地图上添加标注this.map.addOverLay(this.submarker);} else {alert(result.getMsg());}},},
};
</script>
<style lang="less">
.div_class {outline: none;transform-origin: 0 0;display: block;opacity: 0.7;
}.div_class::after {content: "";-webkit-border-radius: 100%;border-radius: 100%;height: 80px;width: 80px;position: absolute;box-shadow: 0 0 6px 2px #dd524d;animation: pulsate 1s ease-out;animation-iteration-count: infinite; /*无穷反复*/animation-delay: 1.1s;
}
@keyframes pulsate {0% {transform: scale(0.1, 0.1);opacity: 0;filter: alpha(opacity=0);}50% {opacity: 1;filter: none;}100% {transform: scale(1.2, 1.2);opacity: 0;filter: alpha(opacity=0);}
}.tdmap {width: 100%;height: 800px;z-index: 0;
}
.button_click {position: absolute;display: flex;z-index: 401;
}
</style>

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

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

相关文章

module ‘plotting‘ has no attribute ‘EpisodeStats‘

plotting.py 的版本不同&#xff0c;可以使用下列版本 reinforcement-learning/lib/plotting.py at master dennybritz/reinforcement-learning GitHubImplementation of Reinforcement Learning Algorithms. Python, OpenAI Gym, Tensorflow. Exercises and Solutions to a…

C++之左值、右值、完美转发

1、左值、右值概念 左值&#xff1a; 是指在内存中有明确的地址&#xff0c;可以进行取地址操作。 // 以下的a、p、*p、b都是左值 int a 3; int* p &a; *p; const int b 2; 右值&#xff1a; 只提供数据&#xff0c;无法进行取地址操作。 double x …

如何将云服务器上操作系统由centos切换为ubuntu

本文将介绍如何将我们购买的云服务器上之前装的centos切换为ubuntu&#xff0c;云服务器以华为云为例&#xff0c;要切换的ubuntu版本为ubuntu20.04。 参考官方文档&#xff1a;切换操作系统_弹性云服务器 ECS (huaweicloud.com) 首先打开华为云官网&#xff0c;登录后点击右…

frm一级4个1大神复习经验分享系列(二)

先说一下自己的情况&#xff0c;8月份中旬开始备考&#xff0c;中间一直是跟着网课走&#xff0c;notes和官方书都没看&#xff0c;然后10月份下旬开始刷题一直到考试。下面分享一些自己备考的经验和走过的弯路。 一级 一级整体学习下来的感受是偏重于基础的理论知识。FRM一级侧…

MongoDB分片集群容灾方案

MongoDB分片集群容灾方案 1. 集群同步工具介绍1.1 第三方数据同步工具mongoshake1.2 官方同步工具mongosync 2. 工具对比2.1 数据一致性2.2 稳定性和可靠性2.3 维护成本 3. 总结 1. 集群同步工具介绍 最近客户咨询MongoDB分片集群市面上主流的容灾方案&#xff0c;所以抽空整理…

Java | String类型使用注意事项

String不支持下标访问&#xff01; String s1"wgh";中&#xff0c;创建了一个String对象&#xff08;此语句等效为String s1new String("wgh")&#xff09;。直接用字符串字面量构造的字符串在常量池里&#xff1b;用new String方法构造的字符串在堆里。 …

安卓六种页面加载优化方案对比总结

根据工作经验&#xff0c;笔者提炼了六种页面加载优化方式&#xff0c;按照业务与非业务&#xff0c;将六种加载方式分为两类&#xff1a; 业务类 控制业务与UI的执行顺序、控制多业务之间的执行顺序 ①预加载&#xff1a;是指在进入页面之前&#xff0c;提前获得页面所需得数据…

Conda入门教程

Conda是一个强大的开源包和环境管理系统&#xff0c;专为Python设计&#xff0c;但也可以用于其他语言。以下是Conda的入门教程&#xff0c;帮助你开始使用Conda进行Python环境和包的管理。 一、安装Conda 访问Conda的官网&#xff08;https://conda.io/projects/conda/en/la…

操作系统 - 计算机系统概述

事前提一嘴 室友考完研了&#xff0c;下一年就是我了&#xff0c;真不想和他们一起考&#xff0c;压力太大了&#xff0c;这里分享一点笔记吧 采用王道考研的书以及视频&#xff0c;去掉了一些书上的废话&#xff0c;加上了视频中的重点&#xff0c;最后总结出来的 如有侵权&a…

直播预告|中服云第5代`工业物联产品线上发布会

我国作为全球制造业的领军者&#xff0c;拥有世界上最完整且健全的制造业产业链。但随着各企业规模的扩大和设备的增加&#xff0c;企业设备管理面临的难点和挑战也越来越多。 为了满足企业不断提高的设备管理需求&#xff0c;中服云即将推出全新的“设备全生命周期管理系统5.…

SOA 与“微服务”的区别

SOA&#xff08;面向服务的架构&#xff09;与微服务之间的区别可以从多个维度进行分析。以下是一些主要的区别点&#xff1a; 服务粒度&#xff1a; SOA&#xff1a;服务粒度相对较粗。在SOA中&#xff0c;服务可能涵盖多个功能或业务领域&#xff0c;例如&#xff0c;在一个大…

机器学习之聚类学习

聚类算法 概念 根据样本之间相似性&#xff0c;将样本划分到不同类别种&#xff0c;不同相似度计算方法&#xff0c;会得到不同聚类结果&#xff0c;常用相似度计算方法为&#xff1a;欧氏距离 目的是在没有先验知识情况下&#xff0c;自动发现数据集种内在结构和模式 无监督…

告别裸奔,聊聊主流消息队列的认证和鉴权!

大家好&#xff0c;我是君哥。 我们在使用消息队列时&#xff0c;经常关注的是消息队列收发消息的功能。但好多时候需要对客户端有一定的限制&#xff0c;比如只有持有令牌的客户端才能访问集权&#xff0c;不允许 Producer 发送消息到某一个 Topic&#xff0c;或者某一个 Top…

朗之万动力学(Langevin dynamics)

朗之万动力学&#xff08;Langevin dynamics&#xff09; 是一种模拟经典粒子运动的方法&#xff0c;常用于物理、化学和材料科学等领域。它是由法国物理学家保罗朗之万&#xff08;Paul Langevin&#xff09;于1908年提出的&#xff0c;用于描述布朗运动&#xff0c;即微小粒…

四、通信和网络安全—局域网|广域网|远程连接和攻击技术(CISSP)

目录 1.局域网和广域网 1.1 WAN技术总结 2.远程连接—无线技术 2.1 VPN 2.2 隧道协议总结

人脸识别——Webface-OCC遮挡人脸识别算法解析

1. 概述 自2019年被誉为人脸识别技术的元年&#xff0c;各地纷纷引入这项技术。然而&#xff0c;自2020年起&#xff0c;为了抵御冠状病毒&#xff08;COVID-19&#xff09;的全球传播&#xff0c;人们普遍开始佩戴口罩。众所周知&#xff0c;现有人脸识别模型在面对遮挡物&am…

Dalle2学习

Dalle2 mini有GitHub库并且有网页可以直接测试

网络之再谈体系结构

大家都知道的是网络的体系结构&#xff0c;现代软件常用的体系结构无非是TCP/IP协议栈&#xff0c;OSI因为实现复杂并且效率没有TCP/IP协议栈好&#xff0c;所以不用OSI&#xff0c;但是&#xff0c;最近在复习网络知识的时候&#xff0c;发现了一些奇怪的地方&#xff0c;那就…

C/C++连接MySQL

本章Gitee仓库地址&#xff1a;mysql连接基本操作 文章目录 1. mysql connect库2. mysql相关接口2.1 mysql_init()2.2 mysql_real_connect()2.3 mysql_query()2.4 mysql_store_result()2.41 mysql_num_rows2.42 mysql_num_fields2.43 mysql_fetch_row2.44 mysql_fetch_fields 2…

中国上市企业行业异质性数据分析

数据简介&#xff1a;企业行业异质性数据是指不同行业的企业在运营、管理、财务等方面的差异性数据。这些数据可以反映不同行业企业的特点、优势和劣势&#xff0c;以及行业间的异质性对企业经营和投资的影响。通过对企业行业异质性数据的分析&#xff0c;投资者可以更好地了解…