当前位置:网站首页>天地图给多边形加标注
天地图给多边形加标注
2022-08-02 08:30:00 【Z_Xshan】
先看效果图

该开始开发的时候用的是高德高德用起来还是比较简单的 但是后来公司要换成天地图 然后就去学习了天地图 来记录下以免朋友们踩坑
这里用vue3举例 看代码
创建初始化地图
//地图初始化
const init = () => {
//添加图层
const imageURL =
"http://t0.tianditu.gov.cn/vec_w/wmts?" +
"SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&FORMAT=tiles" +
"&TILEMATRIXSET=w&STYLE=default&LAYER=vec&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=您的key";
const imageURLT =
"http://t0.tianditu.gov.cn/cva_w/wmts?" +
"SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&FORMAT=tiles" +
"&TILEMATRIXSET=w&STYLE=default&LAYER=cva&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=您的key";
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] };
data.map = new T.Map("map", config); //创建地图对象
data.map.centerAndZoom(
new T.LngLat(116.63072 ,40.054952),
// new T.LngLat(118.63372,37.24352),
14
); //初始化地图
addPolygon(); //添加多边形
};添加多边形覆盖物
//多边形
const addPolygon = () => {
data.area.forEach((item) => {
let list = getList(item);//多边形的坐标 详细看文档
let polygon = new T.Polygon(list, {
color: "#06d7f9",
weight: 3,
opacity: 1,
fillColor: "#06d7f9",
fillOpacity: 0.3,
});
data.map.addOverLay(polygon);
data.polygons.push(polygon);
//这里是给都多边形加的标注
polygon.addEventListener("click", function(e){overlay_style(e,item,polygon)});
});
};标注的方法
//获取marker的属性
function overlay_style(e,i,polygon) {
var p = e.target;
if (p instanceof T.Polygon) {
var infoWin1 = new T.InfoWindow();
var sContent =
"<div style='margin:0px;'>" +
"<div style='margin:10px 10px; '>" +
"<img style='float:left;margin:0px 10px' src='http://lbs.tianditu.gov.cn/images/logo.png' width='101' height='49' title='天安门'/>" +
"<div style='margin:10px 0px 10px 120px;'>电话 : (010)88187700 <br>地址:北京市顺义区机场东路国门商务区地理信息产业园2号楼天地图大厦" +
"</div>" +
"<input id='keyWord' value='机场' type='text' style='border: 1px solid #cccccc;width: 180px;height: 20px;line-height: 20px;padding-left: 10px;display: block;float: left;'>" +
"<input style='margin-left:195px; width: 80px;height: 24px; text-align: center; background: #5596de;color: #FFF;border: none;display: block;cursor: pointer;' type='button' value='周边搜索' onClick=\"localsearch.searchNearby(document.getElementById('keyWord').value,center,radius)\">" +
"</div>" +
"</div>";
infoWin1.setContent(sContent);
polygon.openInfoWindow(infoWin1);
}
else {
alert("无法获知该覆盖物类型");
}
}边栏推荐
猜你喜欢

【电子电路】长按键拉低电平,适用在有休眠机制的MCU但是没有看门狗,一个按键多个功能场景下使用

Business Intelligence Platform BI Business Intelligence Analysis Platform How to Choose the Right Business Intelligence Platform BI

MySQL 中 count() 和 count(1) 有什么区别?哪个性能最好?

OneNote 教程,如何在 OneNote 中创建更多空间?

Redisson实现分布式锁

Jenkins--基础--6.1--Pipeline--介绍

Button to control the running water light (timer)

Jenkins--基础--5.4--系统配置--全局工具配置

Write a small game in C (three chess)

小康股份更名赛力斯,如何走出一条高端产品的“丝绸之路”?
随机推荐
在 QT Creator 上配置 opencv 环境的一些认识和注意点
postman下载安装汉化及使用
C语言_条件编译
Scala类型转换
Redisson报异常attempt to unlock lock, not locked by current thread by node id解决方案
Button to control the running water light (timer)
USACO美国信息学奥赛竞赛12月份开赛,中国学生备赛指南
普林斯顿微积分读本03第二章--编程实现函数图像绘制、三角学回顾
【C】关于柔性数组.简要的谈谈柔性数组
R语言plotly可视化:使用plotly可视化模型预测真阳性率(True positive)TPR和假阳性率(False positive)FPR在不同阈值(threshold)下的曲线
What is the function of the import command of the page directive in JSP?
unity pdg 设置隐藏不需要的节点以及实现自动勾选自动加载项
A young man with strong blood and energy actually became a housekeeper. How did he successfully turn around and change careers?
pnpm的安装与使用
自定义卡包效果实现
[OC学习笔记]Block三种类型
RestTemlate源码分析及工具类设计
小康股份更名赛力斯,如何走出一条高端产品的“丝绸之路”?
QT web development - Notes - 3
Analysis of software testing technology How far is Turing test from us