<!DOCTYPE html> <html> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>空间与UI组件 - 自定义信息框</title> <style type="text/css"> html,body{margin:0px;height:100%;width:100%} .container{width:100%;height:100%} .content{color:#fff;width:190px;height:128px;background-color:#051127;border:1px solid #0c2c45} .pop_title{float:left;padding-left:10px;width:180px;height:36px;line-height:36px;background:url(title.png);font-weight:bold;font-size:16px} .pop_time{float:left;width:183px;height:30px;margin:0 10px;line-height:36px} .pop_dept{float:left;padding:5px;max-width:65px;line-height:15px;text-align:center;border:1px solid #192b41;margin:0 10px} .pop_arrow{float:left;width:15px;height:24px;line-height:24px;background:url(arrow.png) no-repeat center center} .arrow{display:block;width:17px;height:10px;background:url(em.png) no-repeat;position:absolute;left:50%;margin-left:-5px;bottom:-10px} </style> <link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css"> <script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script> <body> <div id="map" class="container"></div> <script> var map = new maptalks.Map('map', { center: [-0.113049,51.49856], zoom: 14, baseLayer: new maptalks.TileLayer('base', { urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', subdomains: ['a','b','c','d'], attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>' }) }); var coordinate = map.getCenter().toFixed(3); var options = { //'autoOpenOn' : 'click', //set to null if not to open window when clicking on map 'single' : false, 'width' : 183, 'height' : 105, 'custom' : true, 'dx' : -3, 'dy' : -12, 'content' : '<div class="content">' + '<div class="pop_title">Custom InfoWindow</div>' + '<div class="pop_time">' + new Date().toLocaleTimeString() + '</div><br>' + '<div class="pop_dept">' + coordinate.x + '</div>' + '<div class="pop_dept">' + coordinate.y + '</div>' + '<div class="arrow"></div>' + '</div>' }; var infoWindow = new maptalks.ui.InfoWindow(options); infoWindow.addTo(map).show(coordinate); </script> </body> </html>