Introduction
Placing objects over a Microsoft Bing™ Map adds functionality and enhances user experience. The following example demonstrates how to place a command button over a Bing™ Map, which will open another NASCAR Race Tracks Map in a full-screen mode.
Background
Microsoft Bing™ Map, a rather popular interactive mapping technology, could be enhanced by adding objects (web controls, images, scripts, etc.) placed over the map (a working demo is available at: www.webinfocentral.com/RESOURCES/NascarMap.aspx).
Using the code
In order to put the ASP.NET server Button control over a Bing™ Map, it is placed within an HTML "<div>" element with its z-index property set to 100. Please note, that in this particular case setting, z-index:1 will do the job, but in real-life development, you have to make sure that the object of interest has its z-index property properly set in order to appear atop the corresponding objects stack, including the Map.
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="Default_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MICROSOFT BING MAP | DEMO</title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2">
</script>
<script type="text/javascript">
function DrawMap() {(new VEMap('Map')).LoadMap(); }
</script>
</head>
<body onload="DrawMap();">
<form id="form1" runat="server">
-->
<div id='Map' style="position:absolute; width:800px; height:600px;"></div>
-->
<div style="position:absolute; z-index:100; top: 10px; left:620px">
<asp:Button ID="Button1" runat="server" Text="SHOW NASCAR MAP" />
</div>
</form>
</body>
</html>
The code-behind:
using System;
public partial class Default_aspx : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string _URL = "http://www.webinfocentral.com/_RESOURCES/NascarMap.aspx";
string _scriptJS =GetScript
(_URL, "NascarMap", true, false, false, false, false, false, false, false);
Button1.Attributes.Add("onclick", _scriptJS);
}
#region Open Full Screen Window using JavaScript
private string GetScript
(string URL,
string Name,
bool FullScreen,
bool MenuBar,
bool Resizable,
bool Toolbar,
bool Location,
bool StatusBar,
bool Copyhistory,
bool ScrollBar)
{
string ret = "javascript:void window.open ('";
ret = ret + URL + "', '" + Name + "', '";
ret = ret + "fullScreen=" + ((FullScreen) ? "1" : "0") + ",";
ret = ret + "resizable=" + ((Resizable) ? "1" : "0") + ",";
ret = ret + "menuBar=" + ((MenuBar) ? "1" : "0") + ",";
ret = ret + "toolbar=" + ((Toolbar) ? "1" : "0") + ",";
ret = ret + "location=" + ((Location) ? "1" : "0") + ",";
ret = ret + "statusBar=" + ((StatusBar) ? "1" : "0") + ",";
ret = ret + "copyhistory=" + ((Copyhistory) ? "1" : "0") + ",";
ret = ret + "scrollBar=" + ((ScrollBar) ? "1" : "0") + ",";
ret = ret + "')";
return ret;
}
#endregion
}
Points of interest
- Browser compatibility
- IE 6.0/7.0/8.0
- Firefox 2.0/3.0
- Safari/Chrome