情不知从何起,一往而情深
排名
6
文章
199
粉丝
4
评论
3
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

高德地图web自定义样式信息窗体

6234人阅读 2022/3/28 16:02 总访问:1110470 评论:0 收藏:0 手机
分类: 前端

代码如下:

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  7. <title>默认样式信息窗体</title>
  8. <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
  9. <style>
  10. html, body, #container {
  11. height: 100%;
  12. width: 100%;
  13. }
  14. .content-window-card {
  15. position: relative;
  16. box-shadow: none;
  17. bottom: 0;
  18. left: 0;
  19. width: auto;
  20. padding: 0;
  21. }
  22. .content-window-card p {
  23. height: 2rem;
  24. }
  25. .custom-info {
  26. border: solid 1px silver;
  27. }
  28. div.info-top {
  29. position: relative;
  30. background: none repeat scroll 0 0 #F9F9F9;
  31. border-bottom: 1px solid #CCC;
  32. border-radius: 5px 5px 0 0;
  33. }
  34. div.info-top div {
  35. display: inline-block;
  36. color: #333333;
  37. font-size: 14px;
  38. font-weight: bold;
  39. line-height: 31px;
  40. padding: 0 10px;
  41. }
  42. div.info-top img {
  43. position: absolute;
  44. top: 10px;
  45. right: 10px;
  46. transition-duration: 0.25s;
  47. }
  48. div.info-top img:hover {
  49. box-shadow: 0px 0px 5px #000;
  50. }
  51. div.info-middle {
  52. font-size: 12px;
  53. padding: 10px 6px;
  54. line-height: 20px;
  55. }
  56. div.info-bottom {
  57. height: 0px;
  58. width: 100%;
  59. clear: both;
  60. text-align: center;
  61. }
  62. div.info-bottom img {
  63. position: relative;
  64. z-index: 104;
  65. }
  66. span {
  67. margin-left: 5px;
  68. font-size: 11px;
  69. }
  70. .info-middle img {
  71. float: left;
  72. margin-right: 6px;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <div id="container"></div>
  78. <div class="info">
  79. 点击地图上的点标记,打开所添加的自定义信息窗体
  80. </div>
  81. <script type="text/javascript"
  82. src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
  83. <script type="text/javascript"> //地图初始化时,在地图上添加一个marker标记,鼠标点击marker可弹出自定义的信息窗体
  84. var map = new AMap.Map("container", {
  85. resizeEnable: true,
  86. center: [116.481181, 39.989792],
  87. zoom: 16
  88. });
  89. addMarker();
  90. //添加marker标记
  91. function addMarker() {
  92. map.clearMap();
  93. var marker = new AMap.Marker({
  94. map: map,
  95. position: [116.481181, 39.989792]
  96. });
  97. //鼠标点击marker弹出自定义的信息窗体
  98. AMap.event.addListener(marker, 'click', function () {
  99. infoWindow.open(map, marker.getPosition());
  100. });
  101. }
  102. //实例化信息窗体
  103. var title = 'TNBLOG<span style="font-size:11px;color:#F00;">技术分享</span>',
  104. content = [];
  105. content.push("<img src='http://tpc.googlesyndication.com/simgad/5843493769827749134'>地址:重庆蔚羽科技XX3号楼东北8.3公里");
  106. content.push("电话:010-xxxxxx");
  107. content.push("<a href='https://www.tnblog.net/'>详细信息</a>");
  108. var infoWindow = new AMap.InfoWindow({
  109. isCustom: true, //使用自定义窗体
  110. content: createInfoWindow(title, content.join("<br/>")),
  111. offset: new AMap.Pixel(16, -45)
  112. });
  113. //构建自定义信息窗体
  114. function createInfoWindow(title, content) {
  115. var info = document.createElement("div");
  116. info.className = "custom-info input-card content-window-card";
  117. //可以通过下面的方式修改自定义窗体的宽高
  118. //info.style.width = "400px";
  119. // 定义顶部标题
  120. var top = document.createElement("div");
  121. var titleD = document.createElement("div");
  122. var closeX = document.createElement("img");
  123. top.className = "info-top";
  124. titleD.innerHTML = title;
  125. closeX.src = "https://webapi.amap.com/images/close2.gif";
  126. closeX.onclick = closeInfoWindow;
  127. top.appendChild(titleD);
  128. top.appendChild(closeX);
  129. info.appendChild(top);
  130. // 定义中部内容
  131. var middle = document.createElement("div");
  132. middle.className = "info-middle";
  133. middle.style.backgroundColor = 'white';
  134. middle.innerHTML = content;
  135. info.appendChild(middle);
  136. // 定义底部内容
  137. var bottom = document.createElement("div");
  138. bottom.className = "info-bottom";
  139. bottom.style.position = 'relative';
  140. bottom.style.top = '0px';
  141. bottom.style.margin = '0 auto';
  142. var sharp = document.createElement("img");
  143. sharp.src = "https://webapi.amap.com/images/sharp.png";
  144. bottom.appendChild(sharp);
  145. info.appendChild(bottom);
  146. return info;
  147. }
  148. //关闭信息窗体
  149. function closeInfoWindow() {
  150. map.clearInfoWindow();
  151. }
  152. </script>
  153. </body>
  154. </html>

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

vue-cli加入高德地图最简单的方式

vue-cli加入高德地图最简单的方式在这里就不多说怎么搭建vue-cli项目如果不会自行百度即可很多1、打开高德地图开放平台首先...

高德地图注册自定义窗体和移除点击事件

//注册自定义窗体varinfoWindow=newAMap.InfoWindow({isCustom:true,//使用自定义窗体 content:createInfoWindow(content),...

高德地图js api出现INVALID_USER_SCODE

自2021年12月02日升级,升级之后所申请的 key 必须配备安全密钥 jscode 一起使用。 是因为没有设置安全密钥才会有这个错。...

高德地图获取鼠标点击的经纬度

官网demo: &lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;m...

高德地图实现一定范围内的关键字搜索

可能你的js后面还需要加载的插件:https://webapi.amap.com/maps?v=1.4.15&amp;key=2xx&amp;plugin=AMap.DistrictSearch,A...

高德地图实现搜索

可能你的js后面还需要加载的插件:https://webapi.amap.com/maps?v=1.4.15&amp;key=2xx&amp;plugin=AMap.DistrictSearch,A...

ABP 里高德地图的用法、Get请求

依赖包usingAbp.Authorization; usingAbp.UI; usingNewtonsoft.Json; usingNewtonsoft.Json.Linq; usingSystem.IO; us...

高德地图卫星图和路网图

代码如下: &lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;...

uniapp 离线打包配置高德地图

没有申请key的去高德开放平台申请的Android平台Keyhttps://console.amap.com/dev/key/app SHA1 在前面申请云端证书里面找 ...

webstorm破解激活方法

破解webstorm试了很多方法:License server填入网址;搭建本地服务器;其他版本破解补丁都没用最后用3.1版本的jar包才破解...

C腾讯地图web端定位地址搜索及手机导航

前段时间项目涉及到腾讯地图的业务,这里马克一下。一开始做腾讯地图功能完全是懵逼的,一搜网上做百度地图居多,问为什么...

让IIS支持webp格式图片让IIS支持vtt格式,iis设置mime类型,iis配置支持的类型

webp格式图片可以让图片体积变小。也让下载图片变得更加困难一点 在线制作webp工具 https://www.upyun.com/webp?utm_mediu...

Java web学习路线

第二阶段:JavaWeb第一部分:HTML51. html概述2. html基本标签3. 图片标签4. 超链接标签5. 表格标签6. 无序列表标签7. 有序...

c webservice一:基本使用

什么是webserviceWebservie是一种网络服务是一种与语言无关的服务webserver主要作用:1:可以跨平台跨语言访问2:可以做SOA...

c webservice二:基本分布式访问

使用webservice接口有个好处就是可以分布式访问。例如我们在玩游戏的时候先要选择一个区,然后在进入游戏。这样是因为如果...