Leftlet for World Imagery
by LandsD Map API
HTML
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<div id="mapid"></div>
CSS
#mapid {
height:300px;
width:100%;
}
.leaflet-container a {
color: black;
}
.leaflet-container .leaflet-control-attribution {
background: transparent;
font-size: 12px;
font-family: sans-serif;
color: black;
}
.leaflet-control-attribution.leaflet-control>ul>li>a>a:nth-child(1) {
display: none;
}
.landsDLogo {
width: 28px;
height: 28px;
display: inline-flex;
background: url(https://api.hkmapservice.gov.hk/mapapi/landsdlogo.jpg);
background-size: 28px;
position: absolute;
right: 3px;
bottom: 3px;
}
JavaScript
// resize map
const mapdiv = document.getElementById('mapid');
var margin;
if (document.all) {
margin = parseInt(document.body.currentStyle.marginTop, 10) + parseInt(document.body.currentStyle.marginBottom, 10);
} else {
margin = parseInt(document.defaultView.getComputedStyle(document.body, '').getPropertyValue('margin-top')) + parseInt(document.defaultView.getComputedStyle(document.body, '').getPropertyValue('margin-bottom'));
}
mapdiv.style.height = (window.innerHeight - margin) + 'px';
var map = L.map('mapid').setView([22.29227, 114.20847], 8);
var apikey = 'c84e886891014383bcf608423555b0ba';
L.tileLayer('https://api.hkmapservice.gov.hk/osm/xyz/worldimagery/WGS84/tile/{z}/{x}/{y}.png?key=' + apikey, {
attribution: 'Image ©2002 NASA/USGS|Image ©2016 NASA/USGS|Contains modified Copernicus Sentinel data [2022]|<a href="https://api.portal.hkmapservice.gov.hk/disclaimer" target="_blank">© Map information from Lands Department <img src="https://api.hkmapservice.gov.hk/mapapi/landsdlogo.jpg" style="width:25px;height:25px"/></a>' ,
maxZoom: 19,
}).on('load', () => {
if (remove_lf) {
let attr = document.getElementsByClassName("leaflet-control-attribution leaflet-control")[0];
attr.childNodes[1].remove();
remove_lf = false;
}
}).addTo(map);
L.tileLayer('https://api.hkmapservice.gov.hk/osm/xyz/sclabel-en/WGS84/tile/{z}/{x}/{y}.png?key=' + apikey, {
//attribution: "<a href='https://api.portal.hkmapservice.gov.hk/disclaimer' target='_blank'>© Imagery from NASA/Lands Department</a>",
maxZoom: 19,
}).addTo(map);