栅格掩膜设置
支持对栅格静态切片服务按照不规则边界进行掩膜处理,只显示指定地理范围内的栅格地图内容。

<!DOCTYPE html>
<html>
<head>
<title>栅格掩膜</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<style>
body {
margin: 0;
padding: 0;
}
html,
body,
#map {
height: 100%;
}
.btn-group {
position: absolute;
top: 20px;
left: 20px;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.9.0-beta/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<div class="btn-group">
<button class="btnItem" onclick="addMask1()">金鸡湖街道</button>
<button class="btnItem" onclick="addMask2()">娄葑街道</button>
<button class="btnItem" onclick="addMask3()">唯亭街道</button>>
</div>
<script>
const map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.70601016502286, 31.32489250629321],
zoom: 13.9,
bearing: 0.20550766176791058,
userId: '***', // 授权码
});
map.on('load', function () {
// 添加数据源
map.addSource('wmts-test-source', {
'type': 'raster',
'tiles': ["<your server url>"],
'tileSize': 256
});
map.addLayer(
{
'id': 'wmts-test-layer',
'type': 'raster',
'source': 'wmts-test-source',
'paint': {
'raster-mask': true, // 开启栅格掩膜
}
}
);
})
function addMask1() {
let geojsonData1 = './金鸡湖街道.geojson'
map.setMaskData(geojsonData1); // 设置栅格掩膜数据
}
function addMask2() {
let geojsonData2 = './娄葑街道.geojson'
map.setMaskData(geojsonData2); // 设置栅格掩膜数据
}
function addMask3() {
let geojsonData3 = './唯亭街道.geojson'
map.setMaskData(geojsonData3); // 设置栅格掩膜数据
}
</script>
</body>
</html>