3

我在我的应用程序中使用 WebView 来显示 Leaflet 地图。

在 HTML 文件中,我有以下学分和链接:

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=xxxxx', {
  maxZoom: 18,
  attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
  '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
  'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
  id: 'mapbox.streets'
}).addTo(mymap);

这看起来像这样:

在此处输入图像描述

有没有办法将归因控件放在左上角而不是右下角?

4

2 回答 2

5

当然你可以控制地图上的一切;)

let map = L.map('map', {
  attributionControl: false
}).setView([51.505, -0.09], 13);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);


L.control.attribution({
  position: 'topright'
}).addTo(map);
body {
  height: 100%;
  margin: 0;
}

#map {
  width: 100%;
  height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.css">

<div id="map"></div>

于 2019-10-18T22:38:36.880 回答
0

我改变了使用位置

// HTML

<div #map></div>

// 在打字稿中声明

@ViewChild('map', { static: false }) mapElement: ElementRef;

// 调用方法

 loadMyMap() {
    this.map = L.map(this.mapElement.nativeElement,{
      
    }).setView([0, 0], 10);
    L.tileLayer('link for tiles', {
      attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(this.map);
 
    this.map.attributionControl.setPosition('topright');
  }

这也避免了文本“供电者”

于 2021-01-05T13:29:45.517 回答