using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.CMSHelper;
using CMS.Controls;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.PortalEngine;
using CMS.SettingsProvider;
public partial class CMSWebParts_Maps_Static_StaticBingMaps : CMSAbstractWebPart
{
#region "Map properties"
///
/// Gets or sets the value that indicates whether the keyboard shortcuts are enabled.
///
public bool EnableKeyboardShortcuts
{
get
{
return ValidationHelper.GetBoolean(GetValue("EnableKeyboardShortcuts"), true);
}
set
{
SetValue("EnableKeyboardShortcuts", value);
}
}
///
/// Gets or sets the value that indicates whether the user can drag the map with the mouse.
///
public bool EnableMapDragging
{
get
{
return ValidationHelper.GetBoolean(GetValue("EnableMapDragging"), true);
}
set
{
SetValue("EnableMapDragging", value);
}
}
///
/// Gets or sets the height of the map.
///
public string Height
{
get
{
return ValidationHelper.GetString(GetValue("Height"), "400");
}
set
{
SetValue("Height", value);
}
}
///
/// Gets or sets the width of the map.
///
public string Width
{
get
{
return ValidationHelper.GetString(GetValue("Width"), "400");
}
set
{
SetValue("Width", value);
}
}
///
/// Gets or sets the initial map type.
/// Road - The road map style.
/// Shaded - The shaded map style, which is a road map with shaded contours.
/// Aerial - The aerial map style.
/// Hybrid - The hybrid map style, which is an aerial map with a label overlay.
/// Birdseye - The bird's eye (oblique-angle) imagery map style.
/// BirdseyeHybrid - The bird's eye hybrid map style, which is a bird's eye map with a label overlay.
///
public string MapType
{
get
{
return ValidationHelper.GetString(GetValue("MapType"), "road");
}
set
{
SetValue("MapType", value);
}
}
///
/// Gets or sets the scale of the map.
///
public int Scale
{
get
{
int value = ValidationHelper.GetInteger(GetValue("Scale"), 3);
if (value < 0)
{
value = 7;
}
return value;
}
set
{
SetValue("Scale", value);
}
}
///
/// Gets or sets the value that indicates whether NavigationControl is displayed.
///
public bool ShowNavigationControl
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowNavigationControl"), true);
}
set
{
SetValue("ShowNavigationControl", value);
}
}
///
/// Gets or sets the value that indicates whether ScaleControl is displayed.
///
public bool ShowScaleControl
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowScaleControl"), true);
}
set
{
SetValue("ShowScaleControl", value);
}
}
///
/// Gets or sets the tool tip text for single marker in detail mode.
///
public string ToolTip
{
get
{
return ValidationHelper.GetString(GetValue("ToolTip"), "");
}
set
{
SetValue("ToolTip", value);
}
}
///
/// Gets or sets the content text for single marker in detail mode.
///
public string Content
{
get
{
return ValidationHelper.GetString(GetValue("Content"), "");
}
set
{
SetValue("Content", value);
}
}
///
/// Gets or sets the scale of the map when zoomed (after marker click event).
///
public int ZoomScale
{
get
{
int value = ValidationHelper.GetInteger(GetValue("ZoomScale"), 10);
if (value < 0)
{
value = 10;
}
return value;
}
set
{
SetValue("ZoomScale", value);
}
}
///
/// Gets or sets the Bing map key.
///
public string MapKey
{
get
{
return ValidationHelper.GetString(GetValue("MapKey"), "");
}
set
{
SetValue("MapKey", value);
}
}
#endregion
#region "Location properties"
///
/// Gets or sets the default location of the center of the map and/or location of single marker in detail mode.
///
public string Location
{
get
{
return ValidationHelper.GetString(GetValue("Location"), "");
}
set
{
SetValue("Location", value);
}
}
///
/// Gets or sets the value that indicates whether server processing is enabled.
///
public bool EnableServerProcessing
{
get
{
return ValidationHelper.GetBoolean(GetValue("EnableServerProcessing"), false);
}
set
{
SetValue("EnableServerProcessing", value);
}
}
///
/// Gets or sets the latitude of the center of the map and/or latitude of single marker in detail mode.
///
public double? Latitude
{
get
{
string lat = DataHelper.GetNotEmpty(GetValue("Latitude"), "");
if (string.IsNullOrEmpty(lat))
{
return null;
}
else
{
return ValidationHelper.GetDoubleSystem(lat, 0);
}
}
set
{
SetValue("Latitude", value);
}
}
///
/// Gets or sets the longitude of the center of the map and/or longitude of single marker in detail mode.
///
public double? Longitude
{
get
{
string lng = DataHelper.GetNotEmpty(GetValue("Longitude"), "");
if (string.IsNullOrEmpty(lng))
{
return null;
}
else
{
return ValidationHelper.GetDoubleSystem(lng, 0);
}
}
set
{
SetValue("Longitude", value);
}
}
///
/// Gets or sets the URL for icon.
///
public string IconURL
{
get
{
return ValidationHelper.GetString(GetValue("IconURL"), "");
}
set
{
SetValue("IconURL", value);
}
}
#endregion
#region "Public properties"
///
/// Cache minutes.
///
public override int CacheMinutes
{
get
{
int result = ValidationHelper.GetInteger(GetValue("CacheMinutes"), -1);
if (result < 0)
{
// If not set, get from the site settings
result = SettingsKeyProvider.GetIntValue(CurrentSiteName + ".CMSCacheMinutes");
}
return result;
}
set
{
SetValue("CacheMinutes", value);
}
}
///
/// Cache item name.
///
public override string CacheItemName
{
get
{
return ValidationHelper.GetString(GetValue("CacheItemName"), "");
}
set
{
SetValue("CacheItemName", value);
}
}
#endregion
#region "Private methods"
///
/// On init event handler.
///
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// Due to new design mode (with preview) we need to move map down for the user to be able to drag and drop the control
if (CMSContext.ViewMode == ViewModeEnum.Design)
{
ltlDesign.Text = "
";
}
}
///
/// OnPreRender override.
///
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (!StopProcessing)
{
// Load map
LoadMap();
// Register Bing javascript files
BasicBingMaps.RegisterMapScripts(Page, ClientID, "~/CMSWebParts/Maps/Static/StaticBingMaps_files/BingMaps.js");
}
}
#endregion
#region "Public methods"
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
}
///
/// Reloads the control data.
///
public override void ReloadData()
{
base.ReloadData();
// Re-load map
LoadMap();
}
///
/// Generates map code and registers Bing javascript files.
///
public void LoadMap()
{
#region "Map properties"
// Set map properties
CMSMapProperties mp = new CMSMapProperties();
mp.EnableMapDragging = EnableMapDragging;
mp.ShowScaleControl = ShowScaleControl;
mp.EnableServerProcessing = EnableServerProcessing;
mp.EnableKeyboardShortcuts = EnableKeyboardShortcuts;
mp.ShowNavigationControl = ShowNavigationControl;
mp.IconURL = IconURL;
mp.MapKey = MapKey;
mp.Latitude = Latitude;
mp.Longitude = Longitude;
mp.ZoomScale = ZoomScale;
mp.Location = Location;
mp.ToolTip = ToolTip;
mp.MapType = MapType;
mp.Content = Content;
mp.Height = Height;
mp.Scale = Scale;
mp.Width = Width;
mp.MapId = ClientID;
mp.Page = Page;
#endregion
// Load map
ltlBingMap.Text = BasicBingMaps.GenerateMap(mp, CacheMinutes, CacheItemName, InstanceGUID);
}
#endregion
}