我使用这个在谷歌地图上显示风向来旋转谷歌地图上的标记,但是角度设置为 220。现在我有一个输入文本框,用户在其中输入角度,当点击按钮时在谷歌地图上显示旋转标记. 如何编辑此代码以从文本框中获取值?这可能<canvas>
吗?
代码在这里:
<body onload="xz()" onunload="GUnload()">
<div id="map" style="width: 400px; height: 300px"></div>
<script type="text/javascript">
function xz()
{
if (GBrowserIsCompatible()) {
var angleDegrees = document.getElementById('angle').value;
var map = new GMap2(document.getElementById("map"));
var arrowIcon = new Image();
var marker = new ELabel( new GLatLng(55.50, 2.50), '<canvas id="arrowcanvas" width="32" height="32"><\/canvas>', null, new GSize(-16, 16));
arrowIcon.src = "http://i49.tinypic.com/mafqee.png";
map.addOverlay(marker);
map.setCenter(new GLatLng(53.85, -1.80), 3);
var canvas = document.getElementById("arrowcanvas").getContext('2d');
var angleRadians = (angleDegrees / 180) * Math.PI;
var cosa = Math.cos(angleRadians);
var sina = Math.sin(angleRadians);
canvas.clearRect(0, 0, 32, 32);
canvas.save();
canvas.rotate(angleRadians);
canvas.translate(16 * sina + 16 * cosa, 16 * cosa - 16 * sina);
canvas.drawImage(arrowIcon, -16, -16);
canvas.restore();
}
}
</script>
<form>
<input type="text" size="13" id="angle" name="angle" value=""> </input>
<input type="submit" id="button2" value="Prika?i" class="btnsearch" onsubmit="xz(); return false;">
</form>
</body>