GIS工具maptalks开发手册(三)03——官网示例之添加图层和移除图层
效果

代码
index.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>图层 - 添加图层和移除图层</title>
<style type="text/css">
html,
body {
margin: 0px;
height: 100%;
width: 100%;
}
.container {
width: 900px;
height: 500px;
margin: 50px;
position: relative;
}
.pane {
background: #34495e;
line-height: 28px;
color: #fff;
z-index: 10;
position: absolute;
top: 80px;
left: 120px
}
.pane a {
display: block;
color: #fff;
text-align: left;
padding: 0 10px;
min-width: 28px;
min-height: 28px;
float: left
}
</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>
<div class="pane"><a href="javascript:add();">Add layer</a><a href="javascript:remove();">Remove Layer</a></div>
<script>
var map = new maptalks.Map('map', {
center: [-0.113049, 51.498568],
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 marker = new maptalks.Marker(
map.getCenter(),
{
symbol: {
'textName': 'Layer is added.',
'textWeight': 'bold',
'textSize': 50,
'textFill': '#1bbc9b',
'textHaloFill': '#fff',
'textHaloRadius': 5
}
}
);
var layer = new maptalks.VectorLayer('vector', [marker])
.addTo(map);
function add() {
map.addLayer(layer);
}
function remove() {
map.removeLayer(layer);
}
</script>
</body>
</html>






![[附源码]计算机毕业设计招聘系统Springboot程序](https://img-blog.csdnimg.cn/527c110b92624a2daeda7037e7a437c9.png)

![[附源码]Python计算机毕业设计SSM抗新冠肺炎药品进销存管理系统(程序+LW)](https://img-blog.csdnimg.cn/11900315a1194edca5b692c5ef1a5c8e.png)
![[附源码]计算机毕业设计疫情防控管理系统Springboot程序](https://img-blog.csdnimg.cn/7bfc0d1166be449b9cb2a1987a602be4.png)


![[附源码]Python计算机毕业设计Django基于Web的绿色环保网站](https://img-blog.csdnimg.cn/cdb731f6bee344afab0cc51c70981a36.png)





