我使用此Show wind direction on Google Maps在Google地图上旋转标记,但是角度设置为220.现在我有一个输入文本框,用户输入角度,当clik on按钮显示旋转标记时谷歌地图。如何编辑此代码以从文本框中获取值?这可能是<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>
答案 0 :(得分:4)
您可以复制他的代码并替换此行:
var angleDegrees = 220;
有类似的东西:
var angleDegrees = document.getElementById('myTextbox').value;
其中'myTextbox'是分配给输入字段的ID。