This project is read-only.

Drawing circle function

Feb 29, 2008 at 3:50 AM
Hi Velio

I am trying out ur code for drawing the circle as like below.

Actually, am clicking on the position of Lat and Long on Google map, getting two values in two html textboxes, then passing tht values in ur drawcircle function as first two parameters.

But, i cant able to figure out whts my prbm may be? Its not coming up with circle. Please have a look and point my mistake.

This is my code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Circle.aspx.cs" Inherits="Circle" %>

<%@ Register Assembly="Artem.GoogleMap" Namespace="Artem.Web.UI.Controls" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxSPW5CJgpdgOs4yyMovOaVhKvvhSfpvagV18eOyDWu7VytS6Bi1CWxw"
type="text/javascript"></script>

<script type="text/javascript">
function showTest(overlay,position) {
if(position) {
var el = document.getElementById('txtlat');
el.value = position.lat();
el = document.getElementById('txtlng');
el.value = position.lng();
}
}
</script>

<SCRIPT LANGUAGE="JavaScript">
function testResults (form) {
var TestLat = txtlat.value;
alert ("You typed: " + TestLat);
}
</script>

<script type="text/javascript">
//<![CDATA[
var map;

// Taken from Kip
function drawCircle(lat, lng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity) {
var d2r = Math.PI/180;
var r2d = 180/Math.PI;
var Clat = (radius/3963)*r2d;
var Clng = Clat/Math.cos(lat*d2r);
var Cpoints = [];
for (var i=0; i < 33; i++) {
var theta = Math.PI * (i/16);
Cy = lat + (Clat * Math.sin(theta));
Cx = lng + (Clng * Math.cos(theta));
var P = new GPoint(Cx,Cy);
Cpoints.push(P);
}

var polygon = new GPolygon(Cpoints, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity);
map.addOverlay(polygon);
}

function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(42.351505, -71.094455), 9);

//drawCircle(42.351505, -71.094455, 10.0, "#000080", 1, 0.75, "#0000FF",.5);
drawCircle(txtlat.value, txtlng.value, 10.0, "#000080", 1, 0.75, "#0000FF",.5);
}
}

function Button1_onclick() {

if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(42.351505, -71.094455), 9);

drawCircle(txtlat.value, txtlng.value, 10.0, "#000080", 1, 0.75, "#0000FF",.5);
}
}

//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">


<input id="txtlat" runat="server" type="text" value="42.30575300304638" />
<input id="txtlng" runat="server" type="text" value="-71.45782470703125" />

<br />
<br />
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)">
<input id="Button1" type="button" value="Show" language="javascript" onclick="Button1_onclick()" /><br />
<form runat="server">
<br />
<cc1:GoogleMap ID="GoogleMap1" runat="server" Zoom="9" Latitude="42.351505" Longitude="-71.094455" ShowClientClickPosition="true" View="Normal" OnClientClick="showTest" >
</cc1:GoogleMap>
</form>

<br />
<br />
<br />
<div id="map" style="width: 650px; height: 500px">
<br />
</div>

</body>
</html>

Rdgs,
PriyaRajan.D.
Feb 29, 2008 at 7:07 AM
I'll see what I can do.
Regards
Mar 5, 2008 at 3:41 AM
Hi Velio,

Let me wait for the ans from u for some more time.

Rdgs,
PriyaRajan.D.
Mar 5, 2008 at 7:41 AM
Hi,
Sorry, working on next release and have to implement a lot of changes and features.
I will do it as soon as I can, but probably won't be this week.
However, you have the formula here above you should just code it in C# in the code behind.

Regards
Mar 18, 2008 at 6:38 PM
Hi,
This was implemented.
Now you can add GoogleCirclePolygon to Polygons collection of GoogleMap control.
Check out the online sample here

Regards