using System; using System.Data; using System.Web; using System.Web.UI.WebControls; using System.Web.UI; using CMS.CMSHelper; using CMS.Controls; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; using CMS.SettingsProvider; public partial class CMSWebParts_Maps_Documents_GoogleMaps : CMSAbstractWebPart { #region "Variables" private bool reloadData = false; #endregion #region "Location properties" /// /// Gets or sets the address field. /// public string LocationField { get { return ValidationHelper.GetString(GetValue("LocationField"), string.Empty); } set { SetValue("LocationField", value); } } /// /// Gets or sets the default location of the center of the map. /// public string DefaultLocation { get { return ValidationHelper.GetString(GetValue("DefaultLocation"), string.Empty); } set { SetValue("DefaultLocation", 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 of the center of the map. /// 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 of the center of the map. /// 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 source latitude field. /// public string LatitudeField { get { return ValidationHelper.GetString(GetValue("LatitudeField"), ""); } set { SetValue("LatitudeField", value); } } /// /// Gets or sets the source longitude field. /// public string LongitudeField { get { return ValidationHelper.GetString(GetValue("LongitudeField"), ""); } set { SetValue("LongitudeField", value); } } #endregion #region "Map properties" /// /// 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 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 tool tip text field (fieled for markers tool tip text). /// public string ToolTipField { get { return ValidationHelper.GetString(GetValue("ToolTipField"), ""); } set { SetValue("ToolTipField", value); } } /// /// Gets or sets the icon field (fieled for icon URL). /// public string IconField { get { return ValidationHelper.GetString(GetValue("IconField"), ""); } set { SetValue("IconField", 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 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 MapTypeControl is displayed. /// public bool ShowMapTypeControl { get { return ValidationHelper.GetBoolean(GetValue("ShowMapTypeControl"), true); } set { SetValue("ShowMapTypeControl", 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 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 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 initial map type. /// ROADMAP - This map type displays a normal street map. /// SATELLITE - This map type displays a transparent layer of major streets on satellite images. /// HYBRID - This map type displays a transparent layer of major streets on satellite images. /// TERRAIN - This map type displays maps with physical features such as terrain and vegetation. /// public string MapType { get { return ValidationHelper.GetString(GetValue("MapType"), "ROADMAP"); } set { SetValue("MapType", value); } } /// /// The Navigation control may appear in one of the following style options: /// Default picks an appropriate navigation control based on the map's size and the device on which the map is running. /// Small displays a mini-zoom control, consisting of only + and - buttons. This style is appropriate for mobile devices. /// Zoom & Pan displays the standard zoom slider control with a panning control, as on Google Maps. /// Android displays the small zoom control as used on the native Maps application on Android devices. /// public int NavigationControlType { get { return ValidationHelper.GetInteger(GetValue("NavigationControlType"), 0); } set { SetValue("NavigationControlType", value); } } #endregion #region "Document properties" /// /// Cache item name. /// public override string CacheItemName { get { return base.CacheItemName; } set { base.CacheItemName = value; ucDocumentSource.CacheItemName = value; } } /// /// Cache dependencies, each cache dependency on a new line. /// public override string CacheDependencies { get { return ValidationHelper.GetString(base.CacheDependencies, ucDocumentSource.CacheDependencies); } set { base.CacheDependencies = value; ucDocumentSource.CacheDependencies = value; } } /// /// Cache minutes. /// public override int CacheMinutes { get { return base.CacheMinutes; } set { base.CacheMinutes = value; ucDocumentSource.CacheMinutes = value; } } /// /// Check permissions. /// public bool CheckPermissions { get { return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), false); } set { SetValue("CheckPermissions", value); ucDocumentSource.CheckPermissions = value; } } /// /// Class names. /// public string ClassNames { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Classnames"), ucDocumentSource.ClassNames), ucDocumentSource.ClassNames); } set { SetValue("ClassNames", value); ucDocumentSource.ClassNames = value; } } /// /// Combine with default culture. /// public bool CombineWithDefaultCulture { get { return ValidationHelper.GetBoolean(GetValue("CombineWithDefaultCulture"), false); } set { SetValue("CombineWithDefaultCulture", value); ucDocumentSource.CombineWithDefaultCulture = value; } } /// /// Filter out duplicate documents. /// public bool FilterOutDuplicates { get { return ValidationHelper.GetBoolean(GetValue("FilterOutDuplicates"), ucDocumentSource.FilterOutDuplicates); } set { SetValue("FilterOutDuplicates", value); ucDocumentSource.FilterOutDuplicates = value; } } /// /// Culture code. /// public string CultureCode { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("CultureCode"), ucDocumentSource.CultureCode), ucDocumentSource.CultureCode); } set { SetValue("CultureCode", value); ucDocumentSource.CultureCode = value; } } /// /// Maximal relative level. /// public int MaxRelativeLevel { get { return ValidationHelper.GetInteger(GetValue("MaxRelativeLevel"), -1); } set { SetValue("MaxRelativeLevel", value); ucDocumentSource.MaxRelativeLevel = value; } } /// /// Order by clause. /// public string OrderBy { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("OrderBy"), ucDocumentSource.OrderBy), ucDocumentSource.OrderBy); } set { SetValue("OrderBy", value); ucDocumentSource.OrderBy = value; } } /// /// Nodes path. /// public string Path { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Path"), null), null); } set { SetValue("Path", value); ucDocumentSource.Path = value; } } /// /// Gets or sets the name of the transforamtion which is used for displaying the results. /// public string TransformationName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("TransformationName"), ""), ""); } set { SetValue("TransformationName", value); } } /// /// Select only published nodes. /// public bool SelectOnlyPublished { get { return ValidationHelper.GetBoolean(GetValue("SelectOnlyPublished"), true); } set { SetValue("SelectOnlyPublished", value); ucDocumentSource.SelectOnlyPublished = value; } } /// /// Site name. /// public string SiteName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("SiteName"), ""), CMSContext.CurrentSiteName); } set { SetValue("SiteName", value); ucDocumentSource.SiteName = value; } } /// /// Where condition. /// public string WhereCondition { get { return DataHelper.GetNotEmpty(GetValue("WhereCondition"), ucDocumentSource.WhereCondition); } set { SetValue("WhereCondition", value); ucDocumentSource.WhereCondition = value; } } /// /// Select top N items. /// public int SelectTopN { get { return ValidationHelper.GetInteger(GetValue("SelectTopN"), ucDocumentSource.SelectTopN); } set { SetValue("SelectTopN", value); ucDocumentSource.SelectTopN = value; } } #endregion #region "Relationships properties" /// /// Related node is on the left side. /// public bool RelatedNodeIsOnTheLeftSide { get { return ValidationHelper.GetBoolean(GetValue("RelatedNodeIsOnTheLeftSide"), false); } set { SetValue("RelatedNodeIsOnTheLeftSide", value); ucDocumentSource.RelatedNodeIsOnTheLeftSide = value; } } /// /// Relationship name. /// public string RelationshipName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("RelationshipName"), ucDocumentSource.RelationshipName), ucDocumentSource.RelationshipName); } set { SetValue("RelationshipName", value); ucDocumentSource.RelationshipName = value; } } /// /// Relationship with node GUID. /// public Guid RelationshipWithNodeGUID { get { return ValidationHelper.GetGuid(GetValue("RelationshipWithNodeGuid"), Guid.Empty); } set { SetValue("RelationshipWithNodeGuid", value); ucDocumentSource.RelationshipWithNodeGuid = value; } } #endregion #region "Public properties" /// /// Hide control for zero rows. /// public bool HideControlForZeroRows { get { return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), ucGoogleMap.HideControlForZeroRows); } set { SetValue("HideControlForZeroRows", value); ucGoogleMap.HideControlForZeroRows = value; } } /// /// Zero rows text. /// public string ZeroRowsText { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("ZeroRowsText"), ucGoogleMap.ZeroRowsText), ucGoogleMap.ZeroRowsText); } set { SetValue("ZeroRowsText", value); ucGoogleMap.ZeroRowsText = value; } } /// /// Gets whethter datasource is empty or not. /// public bool HasData { get { return !StopProcessing && !DataHelper.DataSourceIsEmpty(ucDocumentSource.DataSource); } } /// /// Gets or sets name of source. /// public string DataSourceName { get { return ValidationHelper.GetString(GetValue("DataSourceName"), ""); } set { SetValue("DataSourceName", 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 = "
"; } } /// /// On load event handler. /// protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!StopProcessing) { // Special case for inline widget ucGoogleMap.MapProperties.MapId = ClientID; } } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do nothing ucGoogleMap.Visible = false; } else { #region "Data source properties" // Set Documents data source control ucDocumentSource.Path = Path; ucDocumentSource.ClassNames = ClassNames; ucDocumentSource.CombineWithDefaultCulture = CombineWithDefaultCulture; ucDocumentSource.CultureCode = CultureCode; ucDocumentSource.MaxRelativeLevel = MaxRelativeLevel; ucDocumentSource.OrderBy = OrderBy; ucDocumentSource.SelectOnlyPublished = SelectOnlyPublished; ucDocumentSource.SelectTopN = SelectTopN; ucDocumentSource.SiteName = SiteName; ucDocumentSource.WhereCondition = WhereCondition; ucDocumentSource.FilterOutDuplicates = FilterOutDuplicates; ucDocumentSource.CheckPermissions = CheckPermissions; ucDocumentSource.RelationshipName = RelationshipName; ucDocumentSource.RelationshipWithNodeGuid = RelationshipWithNodeGUID; ucDocumentSource.RelatedNodeIsOnTheLeftSide = RelatedNodeIsOnTheLeftSide; ucDocumentSource.CacheDependencies = CacheDependencies; ucDocumentSource.CacheMinutes = CacheMinutes; ucDocumentSource.CacheItemName = CacheItemName; #endregion #region "Google map caching options" // Set caching options if server processing is enabled if (ucDocumentSource != null && EnableServerProcessing) { ucGoogleMap.CacheItemName = ucDocumentSource.CacheItemName; if (ucDocumentSource.CacheMinutes <= 0) { // If zero or less, get from the site settings ucGoogleMap.CacheMinutes = SettingsKeyProvider.GetIntValue(CurrentSiteName + ".CMSCacheMinutes"); } else { ucGoogleMap.CacheMinutes = ucDocumentSource.CacheMinutes; } // Cache depends on data source and properties of web part ucGoogleMap.CacheDependencies = CacheHelper.GetCacheDependencies(CacheDependencies, ucDocumentSource.GetDefaultCacheDependencies()); } #endregion #region "Map properties" // Set BasicGoogleMaps control CMSMapProperties mp = new CMSMapProperties(); mp.EnableKeyboardShortcuts = EnableKeyboardShortcuts; mp.EnableMapDragging = EnableMapDragging; mp.EnableServerProcessing = EnableServerProcessing; mp.Height = Height; mp.Latitude = Latitude; mp.LatitudeField = LatitudeField; mp.Location = DefaultLocation; mp.LocationField = LocationField; mp.Longitude = Longitude; mp.LongitudeField = LongitudeField; mp.IconField = IconField; mp.MapId = ClientID; mp.MapType = MapType; mp.NavigationControlType = NavigationControlType; mp.Scale = Scale; mp.ShowNavigationControl = ShowNavigationControl; mp.ShowScaleControl = ShowScaleControl; mp.ShowMapTypeControl = ShowMapTypeControl; mp.ToolTipField = ToolTipField; mp.Width = Width; mp.ZoomScale = ZoomScale; ucGoogleMap.DataBindByDefault = false; ucGoogleMap.MapProperties = mp; ucGoogleMap.ItemTemplate = CMSDataProperties.LoadTransformation(this, TransformationName, false); ucGoogleMap.MainScriptPath = "~/CMSWebParts/Maps/Documents/GoogleMaps_files/GoogleMaps.js"; ucGoogleMap.HideControlForZeroRows = HideControlForZeroRows; if (!String.IsNullOrEmpty(ZeroRowsText)) { ucGoogleMap.ZeroRowsText = ZeroRowsText; } #endregion if (reloadData) { ucDocumentSource.DataSource = null; } // Connects Google map with data source ucGoogleMap.DataSource = ucDocumentSource.DataSource; ucGoogleMap.RelatedData = ucDocumentSource.RelatedData; } } /// /// OnPrerender override (Set visibility). /// protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (HasData) { ucGoogleMap.DataBind(); } Visible = ucGoogleMap.Visible; if (!HasData && HideControlForZeroRows) { Visible = false; } } #endregion #region "Public methods" /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Reloads the data. /// public override void ReloadData() { ReloadData(false); } /// /// Reloads the data. /// /// Indicates if the reload should be forced public void ReloadData(bool forceReload) { reloadData = forceReload; SetupControl(); } /// s /// Clears cache /// public override void ClearCache() { ucDocumentSource.ClearCache(); } #endregion }