gpt4 book ai didi

javascript - 用传单旋转标记

转载 作者:技术小花猫 更新时间:2023-10-29 11:38:47 25 4
gpt4 key购买 nike

我有带坐标查找器的传单 map ,坐标推荐包含航向点。我正在尝试将我的图标标记旋转到航向点。代码:(直播地址:http://84.95.7.35/~hzcoil/index2.html)

<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js" type="text/javascript"></script>
<script src="http://84.95.7.35/~hzcoil/js/jquery-1.11.0.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />

<script>
function init() {

var latScaleVal = 8300;
var longScaleVal = 8300;
var latScale = latScaleVal / 256;
var longScale = longScaleVal / 256;
var fixLat = function(e) {
if (e > 0) {
e = -e
} else {
e = Math.abs(e)
}
return e
};

var coords = function(e, t) {
e = fixLat(e);
var n = e / latScale + latScaleVal / 2 / latScale;
var r = t / longScale + longScaleVal / 2 / longScale;
return [-n, r]
};


var mapMinZoom = 0;
var mapMaxZoom = 6;
var map = L.map('map', {
maxZoom: mapMaxZoom,
minZoom: mapMinZoom,
crs: L.CRS.Simple
}).setView([0, 0], mapMaxZoom);

var mapBounds = new L.LatLngBounds(
map.unproject([0, 8192], mapMaxZoom),
map.unproject([8192, 0], mapMaxZoom));

map.fitBounds(mapBounds);
L.tileLayer('http://www.h1z1maps.com/images/newmap/{z}/{x}/{y}.jpg', {
minZoom: mapMinZoom, maxZoom: mapMaxZoom,
bounds: mapBounds,
noWrap: true
}).addTo(map);


var roticon = L.icon({
iconUrl: "https://www.mapbox.com/maki/renders/airport-24@2x.png",
className: 'RotatedMarker',
iconSize: [50, 50],
iconAnchor: [10, 21],
popupAnchor: [5, -35]
});


$("#findmyloc").on("submit", function() {
try {
var e = $("#locbox").val().match(/-?[0-9.0-9]+/g);
$("#locbox").val("");
var goto = L.marker(coords(e[0], e[2], e[3]), {icon:roticon}).addTo(map);
} catch (t) {
console.log(t)
}
return false
});

}
</script>

<style>
html, body, #map { width:700px; height:500px; margin:0; padding:0; }
</style>


</head>
<body onload="init()">
<div id="map"></div>

<form id="findmyloc">
<input id="locbox" type="text" value="x=2196.170 y=39.880 z=1895.350, Heading: 0.624" />
<input type="submit" class="search" value="submit" />
</form>
</body>

我发现了这个: https://github.com/bbecquet/Leaflet.PolylineDecorator/blob/master/src/L.RotatedMarker.js

我花了大约 5 个小时来处理它,但我无法将它与我的代码相匹配。这是它的坐标推荐:x=2196.170 y=39.880 z=1895.350, Heading: 0.624“标题”应该是旋转。

如何将它与我的代码相匹配?

最佳答案

您的示例页面不包含 RotatedMarker 扩展。

一旦包含它,您就可以通过使用 rotatedMarker 方法调用它来创建标记并在选项对象中传递 Angular (它必须以度为单位,而不是弧度)

var goto = L.rotatedMarker( coords(e[0], e[2]), {
icon:roticon,
angle:+e[3]*180/Math.PI // convert to degrees
}).addTo(map);

演示在 http://plnkr.co/edit/QioXRLA8PYnrlb2ZH7kr?p=preview

关于javascript - 用传单旋转标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28153532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com