javascript - 如何使用传单和 Javascript 在 map 上添加图像

标签 javascript leaflet leaflet.draw

我正在寻找一种使用 Javascript 将图像添加到“传单 map ”的方法。

我想做的是加载图像,调整其大小和位置,并将其附加到传单 map 。

最佳答案

这是一个基本演示,展示了如何使用 imageOverlay 添加图像.

您可以通过提供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>

关于javascript - 如何使用传单和 Javascript 在 map 上添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41502713/

相关文章:

javascript - 传单 map 无法识别图层

javascript - 识别何时单击 Leaflet Draw 取消按钮

javascript - 是否可以在 Leaflet.Draw 中设置大小和数量限制?

javascript - jQuery Selectbox append 选项 OnChange

javascript - 来自 vuex 的 @click 在 vue 组件上不起作用

javascript - 未捕获的类型错误 : Cannot read property 'removeLayer' of undefined Vue and Leaflet

leaflet - 如何使用传单的 map.eachLayer 查找标记?

javascript - 将鼠标悬停在剑道网格上添加新按钮/链接

javascript - 面板内的 Sencha touch 2 列表

r - 如何从github使用R脚本?