javascript - 我想通过输入标签为传单标记设置旋转值
问题描述
我有一个范围类型的 HTML 输入标记,我想用它来设置传单标记的 rotationAngle 值。此外,rotationAngle 必须随着用户更改 的值而更新<input>
。
我也在使用https://github.com/bbecquet/Leaflet.RotatedMarker 但无法使用用户输入设置值。
我希望随着输入标签值的变化,rotationAngle 会继续变化。
解决方案
您可以rotationAngle
使用setRotationAngle(newAngle)
方法更新
var map = L.map('map').setView([50.5, 30.5], 18);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var marker = L.marker([50.5, 30.5], {
rotationAngle: 0
}).addTo(map);
function updateAngle(input) {
marker.setRotationAngle(input.value);
}
#map {
position: absolute;
top: 35px;
left: 0;
width: 100%;
height: 80%
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet-rotatedmarker@0.2.0/leaflet.rotatedMarker.min.js"></script>
<input type="number" value="0" min="-360" max="360" onblur="updateAngle(this)">
<div id="map"></div>
推荐阅读
- python - 按特定列排序标题 - 熊猫
- javascript - 401:生成 API 令牌的身份验证失败
- javascript - face-api 出错 - 错误:toNetInput - 预期媒体类型为 HTMLImageElement
- serialization - 串行Arduino中的随机损坏数据
- python - 如何提取 os.stat 中的特定属性?
- json - 使用 Power Query 从 JSON 中的嵌套数组中提取数据
- javascript - 如何使用猫鼬聚合根据字段获取两个匹配文档的总和
- excel - 如何从宏列表中删除无效条目?
- python - 如何匹配两个单独文件中的多个列,并且只输出所有三个列值都匹配的行?
- python - 需要帮助在 python 中正确执行“break”语句