遇到问题及现象
使用openlayer实现地图掩模效果 类似高德上的区域掩模效果
我的效果
目标效果--高德上的区域掩模效果
相关代码
//海宁区域
_that.areaLayer = new VectorLayer({
name: '海宁区域',
source: new VectorSource({
url: '/data/HainingArea.geojson',
format: new GeoJSON()
}),
style: new Style({
stroke: new Stroke({
color: 'rgba(16, 66, 118, 0.6)', //'#1E71B8',
width: 6
}),
fill: new Fill({
color: 'rgba(50, 103, 174, 0.1)' // 'rgba(50, 103, 174, 0.1)' //'rgba(15, 62, 115, 0.1)'
})
})
})
// 创建卫星图图层
_that.satelliteLayer = new TileLayer({
name: '海宁卫星区域',
source: new XYZSource({
url: 'https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
maxZoom: 19
})
})
// 创建地图视图
const view = new View({
center: fromLonLat(_that.Coordinates, 'EPSG:3857'),
zoom: 11.4,
zIndex: 8,
maxZoom: 18,
minZoom: 6,
projection: 'EPSG:3857'
})
window.map = new Map({
target: 'map',
layers: [
_that.satelliteLayer,
_that.areaLayer,
_that.waterLayer,
_that.riverLayer,
_that.riverBoundaryLayer
],
view: view,
extent: [120.30239196, 30.24771399, 120.87324612, 30.59070399], // 设置地图限制范围
controls: defaultControls({
//加载控件到地图容器中
zoom: false,
rotate: false,
attribution: false
})
})