Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Leaflet attribution control position

Tags:

leaflet

I am using in my app a WebView to display a Leaflet map.

Inside the HTML file I have the following credits and links:

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);

This looks like this:

enter image description here

Is there a way to place the attribution control at the top left corner for example instead of the bottom right corner?

like image 670
Ben Avatar asked Sep 06 '25 03:09

Ben


1 Answers

Of course you can control everything on the map;)

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>
like image 128
Grzegorz T. Avatar answered Sep 07 '25 22:09

Grzegorz T.