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:100%;height:100%}
</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 c = new maptalks.Coordinate(-0.113049,51.49856);
var map = new maptalks.Map('map', {
center: c.sub(0.006, 0.002),
zoom: 14,
baseLayer: new maptalks.TileLayer('base', {
'urlTemplate' : 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
'subdomains' : ['a','b','c','d']
})
});
var layer = new maptalks.VectorLayer('vector').addTo(map);
var rect1 = new maptalks.Rectangle(
c.sub(0.03, 0), 600, 600,
{
symbol:{
'polygonFill' : {
'type' : 'linear',
'colorStops' : [
[0.00, '#fff'],
[0.50, '#fff27e'],
[1, '#f87e4b']
]
},
'polygonOpacity' : 1,
'lineColor' : '#fff'
}
}
).addTo(layer);
var rect2 = new maptalks.Rectangle(
c.sub(0.02, 0), 600, 600,
{
symbol:{
'polygonFill' : {
'type' : 'linear',
'places' : [0, 0, 1, 1],
'colorStops' : [
[0.00, '#fff'],
[0.50, '#fff27e'],
[1, '#f87e4b']
]
},
'polygonOpacity' : 1,
'lineColor' : '#fff'
}
}
).addTo(layer);
var rect3 = new maptalks.Rectangle(
c, 600, 600,
{
symbol:{
'polygonFill' : {
'type' : 'radial',
'colorStops' : [
[0.00, 'rgba(216,115,149,0)'],
[0.50, 'rgba(216,115,149,1)'],
[1.00, 'rgba(216,115,149,1)']
]
},
'polygonOpacity' : 1,
'lineWidth' : 0
}
}
).addTo(layer);
var rect4 = new maptalks.Rectangle(
c.add(0.01, 0), 600, 600,
{
symbol:{
'polygonFill' : {
'type' : 'radial',
'places' : [0.5, 0.5, 1, 1, 1, 0.1],
'colorStops' : [
[0.00, '#1bbc9b'],
[0.55, 'rgb(135,196,240)'],
[1.00, '#34495e']
]
},
'polygonOpacity' : 1,
'lineColor' : '#fff'
}
}).addTo(layer);
</script>
</body>
</html>