fix: 修复 setZoomAndCenter/setZoom 缩放层级不同的问题

This commit is contained in:
2912401452 2022-04-08 14:18:56 +08:00
parent 3d71d65fa1
commit e296c52587
3 changed files with 10 additions and 30 deletions

View File

@ -250,7 +250,7 @@ export default class AMapService
} }
public setZoomAndCenter(zoom: number, center: [number, number]): void { public setZoomAndCenter(zoom: number, center: [number, number]): void {
this.map.setZoomAndCenter(zoom, center); this.map.setZoomAndCenter(zoom + 1, center);
} }
public setMapStyle(style: string): void { public setMapStyle(style: string): void {

View File

@ -328,7 +328,7 @@ export default class AMapService
); );
} }
public setZoomAndCenter(zoom: number, center: [number, number]): void { public setZoomAndCenter(zoom: number, center: [number, number]): void {
this.map.setZoomAndCenter(zoom, center); this.map.setZoomAndCenter(zoom + 1, center);
} }
public setMapStyle(style: string): void { public setMapStyle(style: string): void {
this.map.setMapStyle(this.getMapStyle(style)); this.map.setMapStyle(this.getMapStyle(style));

View File

@ -19,32 +19,6 @@ export default class Amap2demo extends React.Component {
} }
public async componentDidMount() { public async componentDidMount() {
function initScene() {
return new Promise((resolve, reject) => {
const scene = new Scene({
id: 'map',
map: new GaodeMapV2({
// center: [121.434765, 31.256735],
// zoom: 14.83,
pitch: 0,
style: 'light',
center: [120, 30],
zoom: 4,
}),
});
scene.on('loaded', () => {
setTimeout(() => {
resolve(scene);
}, 200);
});
});
}
// for (let i = 0; i < 20; i++) {
// console.log('init ' + (i + 1));
// let scene = await initScene();
// scene.destroy();
// }
const scene = new Scene({ const scene = new Scene({
id: 'map', id: 'map',
@ -63,7 +37,7 @@ export default class Amap2demo extends React.Component {
); );
scene.on('loaded', () => { scene.on('loaded', () => {
for (let i = 0; i < 20; i++) {
// const layer = new PointLayer().source([ // const layer = new PointLayer().source([
// { lng: 120, lat: 30, name: '00' } // { lng: 120, lat: 30, name: '00' }
// ], { // ], {
@ -78,6 +52,12 @@ export default class Amap2demo extends React.Component {
// scene.addLayer(layer); // scene.addLayer(layer);
setTimeout(() => {
scene.setZoom(4)
// scene.setZoomAndCenter(4, [120, 30])
console.log('rezoom')
}, 2000)
const lineLayer = new LineLayer() const lineLayer = new LineLayer()
.source( .source(
[ [
@ -103,7 +83,7 @@ export default class Amap2demo extends React.Component {
.color('#f00'); .color('#f00');
scene.addLayer(lineLayer); scene.addLayer(lineLayer);
}
}); });
} }