I just checked in an initial prototype of a reusable Virtual Earth component for ASP.NET MVC. The “VEToolkit.Web.MVC.Map” component is written as an Extension to the ASP.NET MVC AjaxHelper class, and allows for a simpler experience when implementing Virtual Earth mapping within ASP.NET MVC applications. This is an early prototype of what the component will be; it’s not a final release; but you are free to use it.
Download the latest Change Set of VEToolkit
The code is subject to change at any time, since this is currently in a prototype stage, but below is a basic overview of what’s there so far. <h3>Include a Basic Map on the Page</h3>
Include the “VEToolkit.Web.MVC” namespace within the page by adding the following Include directive to the top of the Page: <pre class="csharpcode"><%@ Import Namespace="VEToolkit.Web.MVC" %></pre>
Add the following to the Page to add a basic Virtual Earth map:
And that’s it; you’ll have “default” sized Virtual Earth map on the page.
Specify you own name for the global VEMap Variable that’s used
Here’s an example of how to specify your own ID (or variable name) to be used for the global VEMap object that’s created:
Now to get a hold of the global reference to the VEMap object, you can just access it by name, like so:
<input type="button" value="Zoom In" onclick="myMap.ZoomIn();" /> <input type="button" value="Zoom Out" onclick="myMap.ZoomOut();" />
Set a couple Map Properties
Here’s a modified example of the above that sets the Center Location, Zoom Level and Map Style:
<%=Ajax.Map("myMap") .SetCenter(new Location(44, -78)) .SetZoom(6) .SetMapStyle(MapStyle.Road)%>
Here’s an example:
As stated above, this is just a basic overview of what’s been implemented so far in the VEToolkit ASP.NET MVC Prototype. There are a couple more things in there than I mentioned above, but I thought I’d keep the intro very basic until development moved further along.
This blog post is licensed under the Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the blog post content. All other content on this website is not licensed under Creative Commons licensing.