@* Generator : WebPagesHelper *@ @using System.Diagnostics @using System.Web.WebPages.Scope @using System.Web.UI.WebControls @using System.Globalization @using Microsoft.Internal.Web.Utils @functions { private const string DefaultWidth = "300px"; private const string DefaultHeight = "300px"; private static readonly object _mapIdKey = new object(); private static readonly object _mapQuestApiKey = new object(); private static readonly object _bingApiKey = new object(); private static readonly object _yahooApiKey = new object(); public static string MapQuestApiKey { get { return (string)ScopeStorage.CurrentScope[_mapQuestApiKey]; } set { ScopeStorage.CurrentScope[_mapQuestApiKey] = value; } } public static string YahooApiKey { get { return (string)ScopeStorage.CurrentScope[_yahooApiKey]; } set { ScopeStorage.CurrentScope[_yahooApiKey] = value; } } public static string BingApiKey { get { return (string)ScopeStorage.CurrentScope[_bingApiKey]; } set { ScopeStorage.CurrentScope[_bingApiKey] = value; } } private static int MapId { get { var value = (int?)HttpContext.Current.Items[_mapIdKey]; return value ?? 0; } set { HttpContext.Current.Items[_mapIdKey] = value; } } private static string GetMapElementId() { return "map_" + MapId; } private static string TryParseUnit(string value, string defaultValue) { if (String.IsNullOrEmpty(value)) { return defaultValue; } try { return Unit.Parse(value, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } catch (ArgumentException) { return defaultValue; } } private static IHtmlString RawJS(string text) { return Raw(HttpUtility.JavaScriptStringEncode(text)); } private static IHtmlString Raw(string text) { return new HtmlString(text); } private static string GetApiKey(string apiKey, object scopeStorageKey) { if (apiKey.IsEmpty()) { return (string)ScopeStorage.CurrentScope[scopeStorageKey]; } return apiKey; } public class MapLocation { private readonly string _latitude; private readonly string _longitude; public MapLocation(string latitude, string longitude) { _latitude = latitude; _longitude = longitude; } public string Latitude { get { return _latitude; } } public string Longitude { get { return _longitude; } } } internal static string GetDirectionsQuery(string location, string latitude, string longitude, Func encoder = null) { encoder = encoder ?? HttpUtility.UrlEncode; Debug.Assert(!(location.IsEmpty() && latitude.IsEmpty() && longitude.IsEmpty())); if (location.IsEmpty()) { return encoder(latitude + "," + longitude); } return encoder(location); } } @** Summary: Generates Html to display a Map Quest map. Parameter: key: Map Quest API key Parameter location: Address of the location to center the map at Parameter latitude: Latitude to center on. If both latitude and longitude are specified, location is ignored. Parameter longitude: Longitude to center on. If both latitude and longitude are specified, location is ignored. Parameter width: Width of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter height: Height of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter zoom: Initial zoom level of the map. Defaults to 7. Parameter type: Map type to display. Valid values are "map", "sat" or "hyb". Parameter showDirectionsLink: Determines if a link to get directions should be displayed when a location is specified. Defaults to true. Parameter directionsLinkText The text for the get directions link. Defaults to "Get Directions". **@ @helper GetMapQuestHtml(string key = null, string location = null, string latitude = null, string longitude = null, string width = "300px", string height = "300px", int zoom = 7, string type = "map", bool showDirectionsLink = true, string directionsLinkText = "Get Directions", bool showZoomControl = true, IEnumerable pushpins = null) { key = GetApiKey(key, _mapQuestApiKey); if (key.IsEmpty()) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "key"); } string mapElement = GetMapElementId(); string loc = "null"; // We want to print the value 'null' in the client if (latitude != null && longitude != null) { loc = String.Format(CultureInfo.InvariantCulture, "{{lat: {0}, lng: {1}}}", HttpUtility.JavaScriptStringEncode(latitude, addDoubleQuotes: false), HttpUtility.JavaScriptStringEncode(longitude, addDoubleQuotes: false)); } // The MapQuest key listed on their website is Url encoded to begin with.
if (showDirectionsLink) { @directionsLinkText } MapId++; } @** Summary: Generates Html to display Bing map. Parameter: key: Bing Maps application key Parameter location: Address of the location to center the map at Parameter latitude: Latitude to center on. If both latitude and longitude are specified, location is ignored. Parameter longitude: Longitude to center on. If both latitude and longitude are specified, location is ignored. Parameter width: Width of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter height: Height of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter zoom: Initial zoom level of the map. Defaults to 14. Parameter type: Map type to display. Valid values are "auto", "aerial", "birdeye", "road" and "mercator". Parameter showDirectionsLink: Determines if a link to get directions should be displayed when a location is specified. Defaults to true. Parameter directionsLinkText The text for the get directions link. Defaults to "Get Directions". **@ @helper GetBingHtml(string key = null, string location = null, string latitude = null, string longitude = null, string width = null, string height = null, int zoom = 14, string type = "auto", bool showDirectionsLink = true, string directionsLinkText = "Get Directions", IEnumerable pushpins = null) { key = GetApiKey(key, _bingApiKey); if (key.IsEmpty()) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "key"); } string mapElement = GetMapElementId(); type = (type ?? "auto").ToLowerInvariant();
if (showDirectionsLink) { // Review: Need to figure out if the link needs to be localized. @directionsLinkText } MapId++; } @** Summary: Generates Html to display a Google map. Parameter location: Address of the location to center the map at Parameter latitude: Latitude to center on. If both latitude and longitude are specified, location is ignored. Parameter longitude: Longitude to center on. If both latitude and longitude are specified, location is ignored. Parameter width: Width of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter height: Height of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter zoom: Initial zoom level of the map. Defaults to 14. Parameter type: Map type to display. Valid values are "ROADMAP", "HYBRID", "SATELLITE" and "TERRAIN". Parameter showDirectionsLink: Determines if a link to get directions should be displayed when a location is specified. Defaults to true. Parameter directionsLinkText The text for the get directions link. Defaults to "Get Directions". **@ @helper GetGoogleHtml(string location = null, string latitude = null, string longitude = null, string width = null, string height = null, int zoom = 14, string type = "ROADMAP", bool showDirectionsLink = true, string directionsLinkText = "Get Directions", IEnumerable pushpins = null) { string mapElement = GetMapElementId(); type = (type ?? "ROADMAP").ToUpperInvariant(); // Map types are in upper case // Google maps does not support null centers. We'll set it to arbitrary values if they are null and only the location is provided. // These locations are somewhere around Microsoft's Redmond Campus. latitude = latitude ?? "47.652437"; longitude = longitude ?? "-122.132424";
if (showDirectionsLink) { @directionsLinkText } MapId++; } @** Summary: Generates Html to display a Yahoo map. Parameter: key: Yahoo application ID Parameter location: Address of the location to center the map at Parameter latitude: Latitude to center on. If both latitude and longitude are specified, location is ignored. Parameter longitude: Longitude to center on. If both latitude and longitude are specified, location is ignored. Parameter width: Width of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter height: Height of the map with units such as 480px, 100% etc. Defaults to 300px. Parameter zoom: Initial zoom level of the map. Defaults to 4. Parameter type: Map type to display. Valid values are "YAHOO_MAP_SAT", "YAHOO_MAP_HYB" and "YAHOO_MAP_REG". Parameter showDirectionsLink: Determines if a link to get directions should be displayed when a location is specified. Defaults to true. Parameter directionsLinkText The text for the get directions link. Defaults to "Get Directions". **@ @helper GetYahooHtml(string key = null, string location = null, string latitude = null, string longitude = null, string width = null, string height = null, int zoom = 4, string type = "YAHOO_MAP_REG", bool showDirectionsLink = true, string directionsLinkText = "Get Directions", IEnumerable pushpins = null) { key = GetApiKey(key, _yahooApiKey); if (key.IsEmpty()) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "key"); } string mapElement = GetMapElementId();
if (showDirectionsLink) { @directionsLinkText } MapId++; }