[英]How to add images on map using leaflet and Javascript
I am looking for a way to add images to a 'leaflet map' using Javascript. 我正在寻找一种使用Javascript将图像添加到“传单地图”的方法。
What I want to do is to load image, adjust its size and position, and attach it to a leaflet map. 我要做的是加载图像,调整其大小和位置,并将其附加到传单地图上。
Here's a basic demo showing how to add an image using imageOverlay
. 这是一个基本演示,展示了如何使用imageOverlay
添加图像。
You adjust the position and size of the image by providing imageBounds
您可以通过提供imageBounds
调整图像的位置和大小
// center of the map var center = [-33.8650, 151.2094]; // Create the map var map = L.map('map').setView(center, 5); // Set up the OSM layer L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>', maxZoom: 18 }).addTo(map); // add a marker in the given location L.marker(center).addTo(map); L.marker([-35.8650, 154.2094]).addTo(map); var imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Sydney_Opera_House_-_Dec_2008.jpg/1024px-Sydney_Opera_House_-_Dec_2008.jpg', imageBounds = [center, [-35.8650, 154.2094]]; L.imageOverlay(imageUrl, imageBounds).addTo(map);
html, body { height: 100%; } #map { height: 100%; }
<script src="https://unpkg.com/leaflet@1.0.2/dist/leaflet.js"></script> <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.0.2/dist/leaflet.css"> <div id="map"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.