martes, 27 de enero de 2009

Google Maps WebPart

Directamente desde el sitio de CodeProject, hay un interesante WebPart con comunicacion directa al Google Maps, donde se puede publicar directamente las coordenadas, si bien ya hay bastante material para Virtual Earth, esta es otra alternativa, totalmente free.


Descargarlo directamente desde el Sitio de CodeProject
Introduction
This article presents a Google map WebPart.
Using the code

The rendering on the Google map control is performed in the WebPart Render event. The Google map control is initialized using the ClientScriptManager object.
Collapse
Copy Code
protected override void Render(HtmlTextWriter writer)
{
string rScript = "";
rScript += "\n";
rScript += "\n";
rScript += "
GHeight + "px\">
\n";
writer.Write(rScript);
if (!Page.ClientScript.IsStartupScriptRegistered("MapInit"))
Page.ClientScript.RegisterStartupScript(typeof(string), "MapInit",
"Init()", true);
}
In order to be able to modify the Google map properties, I created an EditorPart class, allowing the user to change the Google API key or the dimensions of the WebPart.
Collapse
Copy Code
public class GoogleMapEditor : System.Web.UI.WebControls.WebParts.EditorPart
{
TextBox googleKey = new TextBox();
TextBox tbWidth = new TextBox();
TextBox tbHeight = new TextBox();
TextBox tbLat = new TextBox();
TextBox tbLong = new TextBox();
TextBox tbZoom = new TextBox();
CheckBox chkDisplayZoom = new CheckBox();
CheckBox chkDragging = new CheckBox();
CheckBox chkIcon = new CheckBox();
Just like a standard WebPart, editor parts must override the CreateChildControls to build a user interface. The user interface is drawn by overriding the RenderContents method.
Collapse
Copy Code
protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write("Google Key
");
googleKey.RenderControl(writer);

writer.Write("
Width
");
tbWidth.RenderControl(writer);

writer.Write("
Height
");
tbHeight.RenderControl(writer);

No hay comentarios: