简体   繁体   中英

rotate marker on google maps

I used this Show wind direction on Google Maps to rotate marker on google map, but there is angle degrees set to 220. Now I have one input text box, where the user enters the angle and when clik on button show rotated marker on google map. How can i edit this code to get values from text box? Is that possible with <canvas> ?

Code is here:

<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>

You can copy his code and replace this line:

var angleDegrees = 220;

With something like:

var angleDegrees = document.getElementById('myTextbox').value;

Where 'myTextbox' is the ID assigned to your input field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM