|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article presents a Google map WebPart. Using the codeThe rendering on the Google map control is performed in the WebPart protected override void Render(HtmlTextWriter writer)
{
string rScript = "";
rScript += "<script src=\"http://maps.google.com/maps?file=api&v=2&key=" +
m_rGoogleKey + "\"\n type=\"text/javascript\"></script>\n";
rScript += "<script type=\"text/javascript\">\n";
rScript += "//<![CDATA[\n";
rScript += "function Init()\n";
rScript += "{\n";
rScript += "var map = new GMap2(document.getElementById(\"map\"));\n";
if (DisableDragging)
rScript += "map.disableDragging();\n";
rScript += "var latlng = new GLatLng(" + m_dLatitude + ", " + m_dLongitude + ");\n";
rScript += "map.setCenter(latlng, " + m_nZoomLevel + ");\n";
if (DisplayZoomControl)
rScript += "map.addControl(new GLargeMapControl());\n";
rScript += "map.addControl(new GMapTypeControl());\n";
rScript += "var mkr = new GMarker(latlng);\n";
if (DisplayIcon)
rScript += "map.addOverlay(mkr);\n";
rScript += "}\n";
rScript += "//]]>\n";
rScript += "</script>\n";
rScript += " <div id=\"map\" style=\"width: " + GWidth + "px; height: " +
GHeight + "px\"></div>\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 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 protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write("Google Key <br/>");
googleKey.RenderControl(writer);
writer.Write("<br/>Width<br/>");
tbWidth.RenderControl(writer);
writer.Write("<br/>Height<br/>");
tbHeight.RenderControl(writer);
Figure 1. Custom Editor
Result
Figure 2. Google Map WebPart
|
||||||||||||||||||||||||||||||||