设置渐变色面图层
支持自定义色带的渐变色,以及属性驱动的渐变角度。

<!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;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</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>
<script>
let map = new mapmost.Map({
container: 'map',
zoom: 12.544032465932002,
center: [120.7298482755258, 31.337044616618797],
style: ‘<your style url>',
userId: '***', // 授权码
});
map.on('load', () => {
map.addSource('poly', {
type: 'geojson',
fillMetrics: true, // 开启面范围度量。这个属性对定义了`fill-gradient`值的面图层是必须的。
data: './polygon.geojson',
});
map.addLayer({
id: 'poly',
source: 'poly',
type: 'fill',
paint: {
'fill-opacity': 1.0,
'fill-gradient': [ // 设置渐变色带
'interpolate',
['linear'],
['fill-gradient-progress'],
0, [204, 255, 40],
1, [0, 15, 255]
],
'fill-gradient-angle': 45, // 设置渐变角度
}
});
});
</script>
</body>
</html>