Skip to content

Commit

Permalink
RealtimeMap.vue: add satelite image layer (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkcyf committed Dec 3, 2023
1 parent f1ec633 commit 8395862
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion docs/.vuepress/components/RealtimeMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,40 @@ export default {
const mapLockControl = new MapLockControl();
this.map.addControl(mapLockControl, 'top-left');
class RasterToggleControl {
onAdd(map) {
this.map = map;
this.container = document.createElement('div');
this.container.className = 'maplibregl-ctrl maplibregl-ctrl-group'; // 使用默认控件样式
this.container.style.marginLeft = '10px'; // 与左边框的距离
this.container.style.marginBottom = '10px'; // 与底边框的距离
const button = document.createElement('button');
button.className = 'maplibregl-ctrl-icon'; // 使用默认控件图标样式
button.innerHTML = '🌍'; // 自定义图标内容
button.onclick = () => {
const visibility = this.map.getLayoutProperty('raster-layer', 'visibility');
if (visibility === 'visible') {
this.map.setLayoutProperty('raster-layer', 'visibility', 'none');
} else {
this.map.setLayoutProperty('raster-layer', 'visibility', 'visible');
}
};
this.container.appendChild(button);
return this.container;
}
onRemove() {
this.container.parentNode.removeChild(this.container);
this.map = undefined;
}
}
const rasterToggleControl = new RasterToggleControl();
// Add geolocate control to the map.
this.map.addControl(
new maplibre.GeolocateControl({
Expand All @@ -400,11 +434,32 @@ export default {
trackUserLocation: true,
// Draw an arrow next to the location dot to indicate which direction the device is heading.
showUserHeading: true
})
}), 'top-right'
);
this.map.addControl(rasterToggleControl, 'top-right');
this.map.on('load', () => {
this.map.addSource('raster-tiles', {
type: 'raster',
tiles: ['https://gac-geo.googlecnapps.cn/maps/vt?lyrs=s&x={x}&y={y}&z={z}'],
tileSize: 256
});
this.map.addLayer({
id: 'raster-layer',
type: 'raster',
source: 'raster-tiles',
layout: {
'visibility': 'none' // 初始设置为不可见
},
minzoom: 0,
maxzoom: 22
});
this.map.addSource('line1', {
'type': 'geojson',
'data': {
Expand Down

0 comments on commit 8395862

Please sign in to comment.