Ejemplo n.º 1
0
        /// <summary>

        /// </summary>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="mapInfo"></param>
        /// <returns></returns>
        public bool saveUpdatedGoogleMap(CmsPage page, int identifier, GoogleMapInfo mapInfo)
        {
            string sql = "update googlemap set ";

            sql += " APIKey = '" + dbEncode(mapInfo.APIKey) + "', ";
            sql += " KMLOverlayUrl = '" + dbEncode(mapInfo.KMLOverlayUrl) + "', ";
            sql += " PopupHtml = '" + dbEncode(mapInfo.PopupHtml) + "', ";
            sql += " Latitude = " + mapInfo.Latitude + ", ";
            sql += " Longitude = " + mapInfo.Longitude + ", ";
            sql += " MapType = '" + dbEncode(Enum.GetName(typeof(GoogleMapInfo.MapDisplay), mapInfo.displayType)) + "' ";
            sql += " where pageid= " + page.ID.ToString();
            sql += " AND identifier = " + identifier.ToString() + "; ";
            //sql = sql + " SELECT LAST_INSERT_ID() as newId;";

            int numAffected = this.RunUpdateQuery(sql);

            if (numAffected > 0)
            {
                return(page.setLastUpdatedDateTimeToNow());
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        } // RenderEdit

        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            string width  = "400px";
            string height = "200px";

            if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2)
            {
                width  = PlaceholderUtils.getParameterValue("width", width, paramList);
                height = PlaceholderUtils.getParameterValue("height", height, paramList);
            }
            else
            {
                throw new ArgumentException("Invalid CmsTemplateEngineVersion");
            }

            GoogleMapInfo mapInfo = (new GoogleMapDb()).getGoogleMap(page, identifier, true);

            StringBuilder html = new StringBuilder();

            html.Append(getMapHtml(mapInfo, page, identifier, width, height));

            writer.Write(html.ToString());
        } // RenderView
Ejemplo n.º 3
0
        } // getHtmlContent

        public GoogleMapInfo createNewGoogleMap(CmsPage page, int identifier)
        {
            GoogleMapInfo info = new GoogleMapInfo();

            string sql = "insert into googlemap (pageid, identifier, APIKey, PopupHtml, KMLOverlayUrl, Latitude, Longitude, MapType) values (";

            sql  = sql + page.ID.ToString() + "," + identifier.ToString() + ",";
            sql += "'" + dbEncode(info.APIKey) + "', '" + dbEncode(info.PopupHtml) + "', '" + dbEncode(info.KMLOverlayUrl) + "', " + info.Latitude + ", " + info.Longitude + ",  ";
            sql += "'" + dbEncode(Enum.GetName(typeof(GoogleMapInfo.MapDisplay), info.displayType)) + "' ";
            sql += "); ";

            int newId = this.RunInsertQuery(sql);

            if (newId > -1)
            {
                page.setLastUpdatedDateTimeToNow();
                return(info);
            }
            else
            {
                return(new GoogleMapInfo());
            }
        }
Ejemplo n.º 4
0
        public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            string width  = "400px";
            string height = "200px";

            if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2)
            {
                width  = PlaceholderUtils.getParameterValue("width", width, paramList);
                height = PlaceholderUtils.getParameterValue("height", height, paramList);
            }
            else
            {
                throw new ArgumentException("Invalid CmsTemplateEngineVersion");
            }

            GoogleMapInfo mapInfo = (new GoogleMapDb()).getGoogleMap(page, identifier, true);
            string        mapId   = "GoogleMap_" + page.ID.ToString() + "_" + identifier.ToString();

            string action = PageUtils.getFromForm(mapId + "Action", "");

            if (action.Trim().ToLower() == "update")
            {
                mapInfo.APIKey = PageUtils.getFromForm(mapId + "API", mapInfo.APIKey);
                string PopupHtml = PageUtils.getFromForm(mapId + "PopupHtml", mapInfo.PopupHtml);
                PopupHtml                 = PopupHtml.Replace(Environment.NewLine, " ");
                PopupHtml                 = PopupHtml.Replace("\r", " ");
                PopupHtml                 = PopupHtml.Replace("\n", " ");
                mapInfo.PopupHtml         = PopupHtml;
                mapInfo.Latitude          = PageUtils.getFromForm(mapId + "Latitude", mapInfo.Latitude);
                mapInfo.Longitude         = PageUtils.getFromForm(mapId + "Longitude", mapInfo.Longitude);
                mapInfo.intitialZoomLevel = PageUtils.getFromForm(mapId + "intitialZoomLevel", mapInfo.intitialZoomLevel);
                mapInfo.displayType       = (GoogleMapInfo.MapDisplay)PageUtils.getFromForm(mapId + "type", typeof(GoogleMapInfo.MapDisplay), GoogleMapInfo.MapDisplay.G_NORMAL_MAP);
                mapInfo.KMLOverlayUrl     = PageUtils.getFromForm(mapId + "KMLOverlayUrl", mapInfo.KMLOverlayUrl);

                (new GoogleMapDb()).saveUpdatedGoogleMap(page, identifier, mapInfo);
            }

            StringBuilder html = new StringBuilder();

            html.Append("Google Maps API Key: ");
            html.Append(PageUtils.getInputTextHtml(mapId + "API", mapInfo + "API", mapInfo.APIKey, 30, 255));
            html.Append("<br>");
            html.Append("KML Overlay Url (specifying a KML will override Popup information below): ");
            html.Append(PageUtils.getInputTextHtml(mapId + "KMLOverlayUrl", mapInfo + "KMLOverlayUrl", mapInfo.KMLOverlayUrl.ToString(), 50, 255));
            html.Append("<br>");
            html.Append("Popup Html (max 255 chars):");
            html.Append(PageUtils.getTextAreaHtml(mapId + "PopupHtml", mapInfo + "PopupHtml", mapInfo.PopupHtml, 50, 2));
            html.Append("<br>");
            html.Append("Popup Latitude (decimal degrees): ");
            html.Append(PageUtils.getInputTextHtml(mapId + "Latitude", mapInfo + "Latitude", mapInfo.Latitude.ToString(), 5, 255));
            html.Append("<br>");
            html.Append("Popup Longitude (decimal degrees): ");
            html.Append(PageUtils.getInputTextHtml(mapId + "Longitude", mapInfo + "Longitude", mapInfo.Longitude.ToString(), 5, 255));
            html.Append("<br>");
            html.Append("Display Type: " + PageUtils.getDropDownHtml(mapId + "type", mapInfo + "type", Enum.GetNames(typeof(GoogleMapInfo.MapDisplay)), Enum.GetName(typeof(GoogleMapInfo.MapDisplay), mapInfo.displayType)));
            html.Append("<br>");
            string[] zoomLevels = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
            html.Append("Initial Zoom Level: " + PageUtils.getDropDownHtml(mapId + "intitialZoomLevel", mapInfo + "intitialZoomLevel", zoomLevels, mapInfo.intitialZoomLevel.ToString()));
            html.Append("<br>");
            html.Append(PageUtils.getHiddenInputHtml(mapId + "Action", "update"));

            // -- Render the map
            html.Append(getMapHtml(mapInfo, page, identifier, width, height));

            writer.Write(html.ToString());
        } // RenderEdit
Ejemplo n.º 5
0
        } // RenderView

        private string getMapHtml(GoogleMapInfo info, CmsPage page, int identifier, string width, string height)
        {
            StringBuilder html = new StringBuilder();

            // -- only render map if all values have been entered in
            bool renderMap = false;

            if (info.APIKey != "" && info.Latitude != Double.MinValue && info.Longitude != Double.MinValue)
            {
                renderMap = true;
            }
            if (info.KMLOverlayUrl != "")
            {
                renderMap = true;
            }

            if (renderMap)
            {
                page.HeadSection.AddJavascriptFile(JavascriptGroup.Library, "http://maps.google.com/maps?file=api&amp;v=2&amp;key=" + info.APIKey);

                string mapId            = "GoogleMap_" + page.ID.ToString() + "_" + identifier.ToString();
                string loadFunctionName = "LoadMap" + mapId;
                // string onLoadJS = CmsPage.getOnloadJavascript(loadFunctionName);

                string        newLine = Environment.NewLine;
                StringBuilder js      = new StringBuilder();

                js.Append("function " + loadFunctionName + " () {" + newLine);
                js.Append("   if (GBrowserIsCompatible()) {" + newLine);
                js.Append("       var map = new GMap2(document.getElementById(\"" + mapId + "\"));" + newLine);
                js.Append("       map.addControl(new GSmallMapControl());" + newLine);
                js.Append("       map.addControl(new GMapTypeControl());" + newLine);
                string mapType = Enum.GetName(typeof(GoogleMapInfo.MapDisplay), info.displayType);
                js.Append("       map.setMapType(" + mapType + ");" + newLine);


                bool usePopup = (String.Compare(info.KMLOverlayUrl.Trim(), "") == 0);
                if (usePopup)
                {
                    js.Append("   var OfficeLatLng = new GLatLng(" + info.Latitude.ToString() + ", " + info.Longitude + ");" + newLine);

                    js.Append("   map.setCenter(OfficeLatLng, " + info.intitialZoomLevel.ToString() + ");" + newLine);

                    js.Append("   // Creates a marker at the given point" + newLine);
                    js.Append("   function createMarker(point, address) {" + newLine);
                    js.Append("       var marker = new GMarker(point);" + newLine);

                    js.Append("       map.openInfoWindowHtml(point, address);" + newLine);

                    js.Append("       GEvent.addListener(marker, \"click\", function() {" + newLine);
                    js.Append("           marker.openInfoWindowHtml(address);" + newLine);
                    js.Append("           });" + newLine);
                    js.Append("       return marker;" + newLine);
                    js.Append("   } // createMarker " + newLine);

                    js.Append("   map.addOverlay(createMarker(OfficeLatLng, \"" + info.PopupHtml + "\"));" + newLine);
                }
                else
                {
                    // KML overlay
                    // html.Append("var gx = new GGeoXml(\"http://kml.lover.googlepages.com/my-vacation-photos.kml\");" + newLine);
                    js.Append("   var gx = new GGeoXml(\"" + info.KMLOverlayUrl + "\");" + newLine);

                    js.Append("   map.addOverlay(gx);" + newLine);
                }
                js.Append("   } // if combatible" + newLine);
                js.Append("} // " + loadFunctionName + newLine);

                page.HeadSection.AddJSStatements(js.ToString());
                page.HeadSection.AddJSOnReady(loadFunctionName + "();");



                html.Append("<div id=\"" + mapId + "\" style=\"width: " + width + "; height: " + height + "; clear: both;\"></div>");
            }
            return(html.ToString());
        } // getMapHtml
Ejemplo n.º 6
0
        // ALTER TABLE googlemap ADD COLUMN `KMLOverlayUrl` TEXT NOT NULL AFTER `MapType`;
        public GoogleMapInfo getGoogleMap(CmsPage page, int identifier, bool createNewIfDoesNotExist)
        {
            if (page.ID < 0 || identifier < 0)
            {
                return(new GoogleMapInfo());
            }

            string  sql = "select APIKey, PopupHtml, KMLOverlayUrl, Latitude, Longitude,intitialZoomLevel, MapType from googlemap c where c.pageid = " + page.ID.ToString() + " and c.identifier = " + identifier.ToString() + " and deleted is null;";
            DataSet ds  = this.RunSelectQuery(sql);

            if (this.hasSingleRow(ds))
            {
                DataRow       dr   = ds.Tables[0].Rows[0];
                GoogleMapInfo info = new GoogleMapInfo();
                info.APIKey    = dr["APIKey"].ToString();
                info.PopupHtml = dr["PopupHtml"].ToString();
                info.Latitude  = Convert.ToDouble(dr["Latitude"]);
                info.Longitude = Convert.ToDouble(dr["Longitude"]);
                try
                {
                    info.intitialZoomLevel = Convert.ToInt32(dr["intitialZoomLevel"]);
                }
                catch
                {
                    throw new Exception("you need to add a intitialZoomLevel column to the database!!");
                    // ALTER TABLE `googlemap` ADD COLUMN `intitialZoomLevel` int(10) unsigned NOT NULL default 13 AFTER `Longitude`;
                }

                try
                {
                    info.displayType = (GoogleMapInfo.MapDisplay)Enum.Parse(typeof(GoogleMapInfo.MapDisplay), dr["MapType"].ToString());
                }
                catch
                {
                    throw new Exception("you need to add a MapType column to the database!!");
                    // ALTER TABLE `googlemap` ADD COLUMN `MapType` VARCHAR(60) NOT NULL AFTER `Longitude`;
                }

                try
                {
                    info.KMLOverlayUrl = dr["KMLOverlayUrl"].ToString();
                }
                catch
                {
                    throw new Exception("you need to add a KMLOverlayUrl column to the database!!");
                    // ALTER TABLE `googlemap` ADD COLUMN `KMLOverlayUrl` VARCHAR(255) NOT NULL default '' AFTER `PopupHtml`;
                }
                return(info);
            }
            else
            {
                if (createNewIfDoesNotExist)
                {
                    return(createNewGoogleMap(page, identifier));
                }
                else
                {
                    throw new Exception("getGoogleMap database error: placeholder does not exist");
                }
            }
            return(new GoogleMapInfo());
        } // getHtmlContent