【发布时间】:2025-12-29 02:15:15
【问题描述】:
我这里有一个笨蛋 - https://plnkr.co/edit/lsx38RaBgv3PlClPimyu?p=preview
这是 Angular 4 中的传单 js 地图
我有按钮可以重新定位地图以打印它并将地图重置到起始位置。
打印按钮重新定位地图,以便我可以打印英国
定位是以地图上的经纬度为中心的center来完成的。
这可行,但如果浏览器窗口大小不同,则会显示地图的不同部分。
如果浏览器窗口较小,它会切断我要打印的英国。
我知道打印插件,但我想从页面打印其他内容
可以将纬度定位在距浏览器窗口左上角一定距离的位置。
import {Component,HostListener, OnInit} from "@angular/core";
declare let L: any;
@Component({
selector: 'map',
templateUrl: './src/map.html'
})
export class MapComponent implements OnInit {
smallScreen: number = 600;
center: any = [54, -5];
zoom: number = 6;
centerSmall: any = [50, 10];
zoomSmall: number = 5;
private atMap: any;
constructor() { }
ngOnInit() {
setTimeout(() => {
this.initialiseMap(this.center, this.zoom);
}, 1000)
}
private initialiseMap(center:any, zoom:number) {
if(this.atMap != undefined || this.atMap != null){
this.atMap.off();
this.atMap.remove();
}
this.atMap = L.map('mapid',{
center: center,
zoomControl: false,
zoom: zoom
});
this.atMap.options.maxZoom = 15;
this.atMap.options.minZoom = 5;
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoidHRtdCIsImEiOiJjajhqeWhjOW8wN2JvMndwbTlqaTV0YjhhIn0.rlysm052tK3vDdZSSg-wQg'
}).addTo(this.atMap);
L.control.zoom({
【问题讨论】: