示例#1
0
    public static void TrackUse(Dictionary <String, String> launchParams, bool isMobile)
    {
        HttpRequest request = HttpContext.Current.Request;

        if (launchParams.Keys.Contains("application"))
        {
            string applicationID = launchParams["application"];
            Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.FindByApplicationID(applicationID);
            applicationID = application.ApplicationID;

            if (!application.IsTrackUseNull() && application.TrackUse == 1)
            {
                string urlQuery = String.Join("&", launchParams.Select(o => o.Key + "=" + o.Value).ToArray());

                using (OleDbConnection connection = AppContext.GetDatabaseConnection())
                {
                    string sql = String.Format("insert into {0}UsageTracking (ApplicationID, UrlQuery, DateStarted, UserAgent, UserHostAddress, UserHostName) values (?, ?, ?, ?, ?, ?)", AppSettings.ConfigurationTablePrefix);

                    using (OleDbCommand command = new OleDbCommand(sql, connection))
                    {
                        command.Parameters.Add("@1", OleDbType.VarWChar).Value = applicationID + (isMobile && applicationID.Length < 46 ? " [m]" : "");
                        command.Parameters.Add("@2", OleDbType.VarWChar).Value = urlQuery.Length < 1000 ? urlQuery : urlQuery.Substring(0, 1000);
                        command.Parameters.Add("@3", OleDbType.Date).Value     = DateTime.Now;
                        command.Parameters.Add("@4", OleDbType.VarWChar).Value = request.UserAgent.Length < 400 ? request.UserAgent : request.UserAgent.Substring(0, 400);
                        command.Parameters.Add("@5", OleDbType.VarWChar).Value = request.UserHostAddress;
                        command.Parameters.Add("@6", OleDbType.VarWChar).Value = request.UserHostName;
                        command.ExecuteNonQuery();
                    }
                }
            }
        }
    }
示例#2
0
    private void LoadMarkupCategories(Configuration.ApplicationRow application, AppState appState, OleDbConnection connection)
    {
        bool selected = false;

        foreach (Configuration.ApplicationMarkupCategoryRow link in application.GetApplicationMarkupCategoryRows())
        {
            string roles = link.MarkupCategoryRow.IsAuthorizedRolesNull() ? "public" : link.MarkupCategoryRow.AuthorizedRoles;

            if (AppUser.RoleIsInList(roles, connection))
            {
                HtmlGenericControl option = new HtmlGenericControl("option");
                option.Attributes["value"] = link.CategoryID;
                option.InnerText           = link.MarkupCategoryRow.DisplayName;

                if (link.CategoryID == appState.MarkupCategory)
                {
                    option.Attributes["selected"] = "selected";
                    selected = true;
                }

                ddlMarkupCategory.Controls.Add(option);
            }
        }

        if (!selected)
        {
            appState.MarkupCategory = "";
            appState.MarkupGroups   = new StringCollection();

            if (ddlMarkupCategory.Controls.Count > 0)
            {
                appState.MarkupCategory = ((HtmlGenericControl)ddlMarkupCategory.Controls[0]).Attributes["value"];
            }
        }
    }
示例#3
0
    private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        AppState appState = new AppState();

        appState.Application = _appState.Application;
        Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application);

        appState.MapTab = application.OverviewMapID;
        appState.Extent = application.GetFullExtentEnvelope();

        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        MapMaker     mapMaker     = new MapMaker(appState, pixelWidth, pixelHeight, 2);
        MapImageData mapImageData = mapMaker.GetImage();

        System.Drawing.Bitmap bitmap      = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image));
        Transformation        trans       = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent);
        MapGraphics           mapGraphics = MapGraphics.FromImage(bitmap, trans);

        double   minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12;
        Envelope extent  = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY));

        if (extent.Width < minSize)
        {
            extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY));
        }

        if (extent.Height < minSize)
        {
            extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5));
        }

        System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red));
        System.Drawing.Pen   pen   = new System.Drawing.Pen(System.Drawing.Color.Red, 4);

        mapGraphics.FillEnvelope(brush, extent);
        mapGraphics.DrawEnvelope(pen, extent);

        MemoryStream stream = new MemoryStream();

        bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] mapImage = stream.ToArray();

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
示例#4
0
 public void Initialize(Configuration config, AppState appState, Configuration.ApplicationRow application)
 {
     foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
     {
         Configuration.MapTabRow mapTabRow = appMapTabRow.MapTabRow;
         AddLayers(mapTabRow, appState);
         AddTiles(mapTabRow, appState);
     }
 }
示例#5
0
    private void CreateMapThemes(Configuration.ApplicationRow application, AppState _appState)
    {
        foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
        {
            HtmlGenericControl li = new HtmlGenericControl("li");
            phlMapTheme.Controls.Add(li);
            li.InnerHtml = appMapTabRow.MapTabRow.DisplayName.Replace(" ", "&nbsp;");
            li.Attributes["data-maptab"] = appMapTabRow.MapTabID;

            if (_appState.MapTab == appMapTabRow.MapTabID)
            {
                selectedTheme.Text = appMapTabRow.MapTabRow.DisplayName;
            }
        }
    }
示例#6
0
    private void MakeOverviewImage()
    {
        AppState appState = new AppState();

        appState.Application = Request.Form["application"];
        Configuration.ApplicationRow application = Configuration.Application.First(o => o.ApplicationID == appState.Application);

        appState.MapTab = application.OverviewMapID;
        appState.Extent = application.GetFullExtentEnvelope();

        int width  = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["width"])));
        int height = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["height"])));

        ReturnJson(GetImageUrl(appState, width, height));
    }
示例#7
0
    public void Initialize(Configuration config, AppState appState, Configuration.ApplicationRow application)
    {
        using (OleDbConnection connection = AppContext.GetDatabaseConnection())
        {
            LoadMarkupCategories(application, appState, connection);

            if (AppAuthentication.Mode != AuthenticationMode.None)
            {
                tboMarkupUser.Attributes["value"]    = AppUser.GetDisplayName(connection);
                tboMarkupUser.Attributes["disabled"] = "disabled";
                chkMarkupLock.Style["visibility"]    = "visible";
                labMarkupLock.Style["visibility"]    = "visible";
                cmdNewMarkup.CssClass = cmdNewMarkup.CssClass.Replace("btnControlLock", "");
            }
        }
    }
示例#8
0
    public void ProcessRequest(HttpContext context)
    {
        HttpResponse response = context.Response;

        response.Clear();

        AppState appState      = AppState.FromJson(context.Request.Form["state"]);
        string   templateID    = context.Request.Form["template"];
        string   scaleMode     = context.Request.Form["scalemode"];
        double   originalWidth = Convert.ToDouble(context.Request.Form["width"]);

        // if the user entered a feet-per-inch scale, compute the pixel width of the map
        // for the scale given the extent width

        if (scaleMode == "input")
        {
            double extentWidth = appState.Extent.Width * (AppContext.AppSettings.MapUnits == "feet" ? 1 : Constants.FeetPerMeter);
            double scale       = Convert.ToDouble(context.Request.Form["scale"]);

            originalWidth = extentWidth * 96 / scale;
            scaleMode     = "scale";
        }

        PreserveMode preserveMode = (PreserveMode)Enum.Parse(typeof(PreserveMode), scaleMode, true);

        // read in the user inputs

        List <String> input = new List <String>();

        Configuration.ApplicationRow   application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application);
        Configuration.PrintTemplateRow template    = application.GetPrintTemplates().First(o => o.TemplateID == templateID);

        foreach (Configuration.PrintTemplateContentRow element in template.GetPrintTemplateContentRows().Where(o => o.ContentType == "input"))
        {
            string fieldName = String.Format("input_{0}_{1}", template.TemplateID, element.SequenceNo);
            input.Add(context.Request.Form[fieldName]);
        }

        // produce the PDF output

        PdfMap pdfMap = new PdfMap(appState, templateID, input, preserveMode, originalWidth);

        pdfMap.Write(response);
        response.End();
    }
示例#9
0
文件: AppConfig.cs 项目: jsmeyers/GPV
        public ApplicationData(Configuration config, Configuration.ApplicationRow app)
        {
            ApplicationID = app.ApplicationID;
            DisplayName   = app.DisplayName;

            DefaultMapTab = (!app.IsDefaultMapTabNull() ? app.DefaultMapTab : "");
            FullExtent    = app.GetFullExtentEnvelope().ToArray();

            MapTabs = new List <MapTabData>(config.ApplicationMapTab.Count);
            foreach (Configuration.ApplicationMapTabRow mapTab in config.ApplicationMapTab.Where(e => e.ApplicationID == ApplicationID))
            {
                var configMapTab = config.MapTab.FirstOrDefault(t => t.MapTabID == mapTab.MapTabID);
                if (configMapTab != null)
                {
                    MapTabs.Add(new MapTabData(configMapTab));
                }
            }
        }
示例#10
0
    public void Initialize(Configuration config, AppState appState, Configuration.ApplicationRow application)
    {
        int m = 0;

        foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
        {
            Configuration.MapTabRow mapTabRow = appMapTabRow.MapTabRow;
            AddTileGroupsForMapTab(mapTabRow, appState, m, true);
            m += 1;
        }

        foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
        {
            Configuration.MapTabRow mapTabRow = appMapTabRow.MapTabRow;
            AddTileGroupsForMapTab(mapTabRow, appState, m, false);
            m += 1;
        }
    }
示例#11
0
    private void DrawCoordinates(Graphics graphics)
    {
        if (_appState.Coordinates.Count == 0)
        {
            return;
        }

        Pen pen = new Pen(Color.Black, Convert.ToSingle(_resolution * 2));

        pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat;

        System.Drawing.Font font = AppSettings.CoordinatesFont;
        font = new System.Drawing.Font(font.FontFamily, Convert.ToSingle(font.Size * _resolution), font.Style, font.Unit);
        SolidBrush textBrush   = new SolidBrush(Color.Black);
        SolidBrush shadowBrush = new SolidBrush(Color.White);

        Configuration config = AppContext.GetConfiguration();

        Configuration.ApplicationRow application = config.Application.FindByApplicationID(_appState.Application);

        StringFormat format = new StringFormat();

        format.LineAlignment = StringAlignment.Far;

        string[] modes = application.IsCoordinateModesNull() ? new string[] { "ne" } : application.CoordinateModes.ToLower().Split(',');

        for (int i = 0; i < _appState.Coordinates.Count; ++i)
        {
            IPoint p = new NetTopologySuite.Geometries.Point(_appState.Coordinates[i]);

            if (_appState.CoordinateLabels[i] != "1")
            {
                DrawCross(graphics, p, pen, 10);
                DrawText(graphics, p, _appState.CoordinateLabels[i], font, textBrush, shadowBrush, 2, -3, format);
            }
            else
            {
                DrawCoordinate(graphics, p, modes, pen, font, textBrush, shadowBrush, format);
            }
        }
    }
示例#12
0
    public void Initialize(Configuration config, Configuration.ApplicationRow application)
    {
        foreach (Configuration.PrintTemplateRow template in application.GetPrintTemplates())
        {
            HtmlGenericControl option = new HtmlGenericControl("option");
            option.InnerText           = template.TemplateTitle;
            option.Attributes["value"] = template.TemplateID;
            ddlPrintTemplate.Controls.Add(option);

            foreach (Configuration.PrintTemplateContentRow element in template.GetPrintTemplateContentRows().Where(o => o.ContentType == "input"))
            {
                HtmlGenericControl div = new HtmlGenericControl("div");
                div.Attributes["data-templateID"] = template.TemplateID;
                div.Attributes["class"]           = "printInput";
                div.Style["width"]   = "100%";
                div.Style["display"] = "none";

                HtmlGenericControl label = new HtmlGenericControl("label");
                div.Controls.Add(label);
                label.InnerText = element.DisplayName;

                HtmlGenericControl tbo = new HtmlGenericControl("input");
                div.Controls.Add(tbo);
                tbo.Attributes["type"]  = "text";
                tbo.Attributes["name"]  = String.Format("input_{0}_{1}", template.TemplateID, element.SequenceNo);
                tbo.Attributes["class"] = "Input Text";

                pnlPrintInputs.Controls.Add(div);
            }
        }

        foreach (Configuration.ExternalMapRow externalMap in config.ExternalMap)
        {
            HtmlGenericControl opt = new HtmlGenericControl("option");
            ddlExternalMap.Controls.Add(opt);
            opt.Attributes["value"] = externalMap.DisplayName;
            opt.InnerText           = externalMap.DisplayName;
        }
    }
示例#13
0
    private void GetOverviewImage()
    {
        Configuration.ApplicationRow application = Configuration.Application.First(o => o.ApplicationID == Request.Params["application"]);

        int width  = Convert.ToInt32(Request.Params["width"]);
        int height = Convert.ToInt32(Request.Params["height"]);

        string[] bbox = Request.Params["bbox[]"].Split(',');

        AppState appState = new AppState()
        {
            Application = application.ApplicationID,
            MapTab      = application.OverviewMapID,
            Extent      = new Envelope(new Coordinate(Convert.ToDouble(bbox[0]), Convert.ToDouble(bbox[1])), new Coordinate(Convert.ToDouble(bbox[2]), Convert.ToDouble(bbox[3])))
        };

        MapMaker     mapMaker     = new MapMaker(appState, width, height);
        MapImageData mapImageData = mapMaker.GetImage();

        Response.ContentType = mapImageData.Type == CommonImageType.Png ? "image/png" : "image/jpeg";
        Response.BinaryWrite(mapImageData.Image);
    }
示例#14
0
文件: AppConfig.cs 项目: jsmeyers/GPV
    private bool IsUserAuthorized(Configuration.ApplicationRow application)
    {
        string roles = application.IsAuthorizedRolesNull() ? "public" : application.AuthorizedRoles;

        return(AppUser.RoleIsInList(roles));
    }
示例#15
0
    public void Initialize(Configuration config, AppState appState, Configuration.ApplicationRow application)
    {
        foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
        {
            Configuration.MapTabRow mapTabRow = appMapTabRow.MapTabRow;
            CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTabRow);

            bool      isInteractive = !mapTabRow.IsInteractiveLegendNull() && mapTabRow.InteractiveLegend == 1;
            CheckMode checkMode     = CheckMode.None;

            List <CommonLayer>     configuredLayers = new List <CommonLayer>();
            List <LayerProperties> layerProperties  = new List <LayerProperties>();
            List <String>          mapTabLayerIds   = new List <String>();

            string name        = null;
            string metaDataUrl = null;

            StringCollection visibleLayers = isInteractive ? appState.VisibleLayers[mapTabRow.MapTabID] : null;

            // find layers attached via MapTabLayer

            foreach (Configuration.MapTabLayerRow mapTabLayerRow in mapTabRow.GetMapTabLayerRows())
            {
                if (!mapTabLayerRow.IsShowInLegendNull() && mapTabLayerRow.ShowInLegend == 1)
                {
                    CommonLayer layer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, mapTabLayerRow.LayerRow.LayerName, true) == 0);

                    name        = mapTabLayerRow.LayerRow.IsDisplayNameNull() ? mapTabLayerRow.LayerRow.LayerName : mapTabLayerRow.LayerRow.DisplayName;
                    metaDataUrl = mapTabLayerRow.LayerRow.IsMetaDataURLNull() ? null : mapTabLayerRow.LayerRow.MetaDataURL;
                    bool isExclusive = mapTabLayerRow.IsIsExclusiveNull() ? false : mapTabLayerRow.IsExclusive == 1;

                    string tag = mapTabLayerRow.LayerID;
                    mapTabLayerIds.Add(tag);

                    if (isInteractive)
                    {
                        bool layerVisible = visibleLayers != null && visibleLayers.Contains(mapTabLayerRow.LayerID);
                        checkMode = mapTabLayerRow.IsCheckInLegendNull() || mapTabLayerRow.CheckInLegend < 0 ? CheckMode.Empty :
                                    layerVisible ? CheckMode.Checked : CheckMode.Unchecked;
                    }

                    configuredLayers.Add(layer);
                    layerProperties.Add(new LayerProperties(name, tag, checkMode, isExclusive, metaDataUrl));
                }
            }

            // find layers attached via BaseMapID

            if (!mapTabRow.IsBaseMapIDNull() && !mapTabRow.IsShowBaseMapInLegendNull() && mapTabRow.ShowBaseMapInLegend == 1)
            {
                if (checkMode != CheckMode.None)
                {
                    checkMode = CheckMode.Empty;
                }

                foreach (DataRow row in config.Layer.Select("BaseMapID = '" + mapTabRow.BaseMapID + "'"))
                {
                    Configuration.LayerRow layerRow = (Configuration.LayerRow)row;

                    if (!mapTabLayerIds.Contains(layerRow.LayerID))
                    {
                        CommonLayer layer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layerRow.LayerName, true) == 0);
                        metaDataUrl = layerRow.IsMetaDataURLNull() ? null : layerRow.MetaDataURL;

                        configuredLayers.Add(layer);
                        layerProperties.Add(new LayerProperties(layerRow.Name, null, checkMode, false, metaDataUrl));
                    }
                }
            }

            // add group layers as necessary

            for (int i = 0; i < configuredLayers.Count; ++i)
            {
                checkMode = !isInteractive ? CheckMode.None : layerProperties[i].CheckMode == CheckMode.Checked ? CheckMode.Checked : CheckMode.Unchecked;
                CommonLayer parent = configuredLayers[i].Parent;

                while (parent != null)
                {
                    int index = configuredLayers.IndexOf(parent);

                    if (index < 0)
                    {
                        configuredLayers.Add(parent);
                        layerProperties.Add(new LayerProperties(parent.Name, null, checkMode, false, null));
                    }
                    else
                    {
                        if (checkMode == CheckMode.Checked && layerProperties[index].CheckMode == CheckMode.Unchecked)
                        {
                            layerProperties[index].CheckMode = CheckMode.Checked;
                        }
                    }

                    parent = parent.Parent;
                }
            }

            // create the top level legend control for this map tab

            HtmlGenericControl parentLegend = new HtmlGenericControl("div");
            pnlLegendScroll.Controls.Add(parentLegend);
            parentLegend.Attributes["data-maptab"] = appMapTabRow.MapTabID;
            parentLegend.Attributes["class"]       = "LegendTop";
            parentLegend.Style["display"]          = appMapTabRow.MapTabID == appState.MapTab ? "block" : "none";

            // add the Legend controls for the configured layers

            foreach (CommonLayer layer in dataFrame.TopLevelLayers)
            {
                AddLayerToLegend(mapTabRow.MapTabID, configuredLayers, layerProperties, parentLegend, layer);
            }
        }
    }
示例#16
0
    public void Initialize(Configuration config, AppState appState, Configuration.ApplicationRow application)
    {
        Configuration.ZoneLevelRow zoneLevel = application.ZoneLevelRow;

        if (zoneLevel != null)
        {
            string zoneName  = !zoneLevel.IsZoneTypeDisplayNameNull() ? zoneLevel.ZoneTypeDisplayName : "Zone";
            string levelName = !zoneLevel.IsLevelTypeDisplayNameNull() ? zoneLevel.LevelTypeDisplayName : "Level";

            Configuration.ZoneRow[]  zones  = zoneLevel.GetZoneRows();
            Configuration.LevelRow[] levels = zoneLevel.GetLevelRows();
            bool hasCombos = false;

            HtmlGenericControl zoneBody        = new HtmlGenericControl("tbody");
            HtmlGenericControl levelByZoneBody = new HtmlGenericControl("tbody");
            HtmlGenericControl levelBody       = new HtmlGenericControl("tbody");

            if (zones.Length > 0 || levels.Length > 0)
            {
                pnlZoneLevelControl.Style["display"] = "block";

                if (zones.Length > 0)
                {
                    optTabZone.Text             = zoneName;
                    optTabZone.Style["display"] = "block";
                    optTabZone.CssClass         = "Tab Selected";
                    tblZone.Controls.Add(zoneBody);
                    tblZone.Style["display"] = "block";

                    hasCombos = zones.Any(o => o.GetZoneLevelComboRows().Length > 0);

                    if (hasCombos)
                    {
                        optTabLevelByZone.Text             = String.Format("{0} by {1}", levelName, zoneName);
                        optTabLevelByZone.Style["display"] = "block";
                        tblLevelByZone.Controls.Add(levelByZoneBody);
                    }
                }

                if (levels.Length > 0)
                {
                    optTabLevel.Text             = levelName;
                    optTabLevel.Style["display"] = "block";
                    tblLevel.Controls.Add(levelBody);

                    if (zones.Length == 0)
                    {
                        optTabLevel.CssClass      = "Tab Selected";
                        tblLevel.Style["display"] = "block";
                    }
                }
            }

            foreach (Configuration.ZoneRow zone in zones)
            {
                AddZoneRow(zoneBody, zone);
            }

            foreach (Configuration.LevelRow level in levels)
            {
                AddLevelRow(levelBody, level, null);
            }

            if (hasCombos)
            {
                foreach (Configuration.ZoneRow zone in zones)
                {
                    AddZoneRow(levelByZoneBody, zone);

                    Configuration.ZoneLevelComboRow[] zoneLevelCombos = zone.GetZoneLevelComboRows().OrderBy(o => o.LevelRowParent.SequenceNo).ToArray();

                    foreach (Configuration.ZoneLevelComboRow zoneLevelCombo in zoneLevelCombos)
                    {
                        AddLevelRow(levelByZoneBody, zoneLevelCombo.LevelRowParent, zoneLevelCombo.ZoneRowParent);
                    }
                }
            }
        }
    }
示例#17
0
    private void DrawMarkup(Graphics graphics)
    {
        if (_appState.Markup.Count == 0 && _appState.MarkupGroups.Count == 0)
        {
            return;
        }

        List <Markup> markupList = new List <Markup>();

        if (_appState.MarkupGroups.Count > 0)
        {
            using (OleDbConnection connection = AppContext.GetDatabaseConnection())
            {
                foreach (string groupId in _appState.MarkupGroups)
                {
                    string sql = String.Format("update {0}MarkupGroup set DateLastAccessed = ? where GroupID = {1}",
                                               AppSettings.ConfigurationTablePrefix, groupId);

                    using (OleDbCommand command = new OleDbCommand(sql, connection))
                    {
                        command.Parameters.Add("@1", OleDbType.Date).Value = DateTime.Now;
                        command.ExecuteNonQuery();
                    }

                    sql = String.Format("select Shape, Color, Glow, Text, Measured from {0}Markup where GroupID = {1} and Deleted = 0",
                                        AppSettings.ConfigurationTablePrefix, groupId);

                    using (OleDbCommand command = new OleDbCommand(sql, connection))
                    {
                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Markup markup = new Markup();

                                markup.Shape    = reader.GetString(0);
                                markup.Color    = reader.GetString(1);
                                markup.Glow     = !reader.IsDBNull(2) ? reader.GetString(2) : null;
                                markup.Text     = !reader.IsDBNull(3) ? reader.GetString(3) : null;
                                markup.Measured = !reader.IsDBNull(4) ? (int?)reader.GetInt32(4) : null;

                                markupList.Add(markup);
                            }
                        }
                    }
                }
            }
        }

        if (_appState.Markup.Count > 0)
        {
            markupList.AddRange(_appState.Markup);
        }

        SolidBrush pointBrush   = new SolidBrush(Color.Red);
        SolidBrush polygonBrush = new SolidBrush(Color.FromArgb(128, 255, 192, 192));
        Pen        pen          = new Pen(Color.Red, Convert.ToSingle(2 * _resolution));

        pen.EndCap   = System.Drawing.Drawing2D.LineCap.Square;
        pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;

        float dotSize = Convert.ToSingle(10 * _resolution);

        System.Drawing.Font font = AppSettings.MarkupFont;
        font = new System.Drawing.Font(font.FontFamily, Convert.ToSingle(font.Size * _resolution), font.Style, font.Unit);
        System.Drawing.Font coordinatesFont = AppSettings.CoordinatesFont;
        coordinatesFont = new System.Drawing.Font(coordinatesFont.FontFamily, Convert.ToSingle(coordinatesFont.Size * _resolution), coordinatesFont.Style, coordinatesFont.Unit);
        SolidBrush textBrush = new SolidBrush(Color.FromArgb(192, 0, 0));
        SolidBrush glowBrush = new SolidBrush(Color.Black);

        StringFormat format = new StringFormat();

        format.LineAlignment = StringAlignment.Far;

        Configuration config = AppContext.GetConfiguration();

        Configuration.ApplicationRow application = config.Application.FindByApplicationID(_appState.Application);
        string[] modes = application.IsCoordinateModesNull() ? new string[] { "ne" } : application.CoordinateModes.ToLower().Split(',');

        WKTReader wktReader = new WKTReader();

        foreach (Markup markup in markupList)
        {
            IGeometry geometry   = wktReader.Read(markup.Shape);
            Color     color      = ColorTranslator.FromHtml(markup.Color);
            bool      isMeasured = markup.Measured.HasValue && markup.Measured == 1;
            bool      isGlow     = !String.IsNullOrEmpty(markup.Glow);

            if (isGlow)
            {
                glowBrush.Color = ColorTranslator.FromHtml(markup.Glow);
            }

            switch (geometry.OgcGeometryType)
            {
            case OgcGeometryType.Point:
                bool isText = !String.IsNullOrEmpty(markup.Text);

                if (isText)
                {
                    textBrush.Color = color;
                    DrawText(graphics, (IPoint)geometry, markup.Text, font, textBrush, isGlow ? glowBrush : null, 0, 0, format);

                    if (isMeasured)
                    {
                        pen.Color  = color;
                        pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat;
                        DrawCross(graphics, (IPoint)geometry, pen, 10);
                    }
                }
                else
                {
                    if (isMeasured)
                    {
                        pen.Color       = color;
                        pen.EndCap      = System.Drawing.Drawing2D.LineCap.Flat;
                        textBrush.Color = color;
                        DrawCoordinate(graphics, (IPoint)geometry, modes, pen, coordinatesFont, textBrush, isGlow ? glowBrush : null, format);
                    }
                    else
                    {
                        pointBrush.Color = color;
                        DrawPoint(graphics, (IPoint)geometry, pointBrush, dotSize);
                    }
                }
                break;

            case OgcGeometryType.LineString:
                pen.Color  = color;
                pen.EndCap = System.Drawing.Drawing2D.LineCap.Square;
                DrawLineString(graphics, (ILineString)geometry, pen);
                break;

            case OgcGeometryType.Polygon:
                pen.Color          = color;
                pen.EndCap         = System.Drawing.Drawing2D.LineCap.Square;
                polygonBrush.Color = Color.FromArgb(128, color);
                DrawPolygon(graphics, (IPolygon)geometry, polygonBrush, null, pen);
                break;
            }

            if (isMeasured && geometry.OgcGeometryType != OgcGeometryType.Point)
            {
                DrawMeasure(graphics, geometry);
            }
        }
    }
示例#18
0
    private void GetQueryGridData()
    {
        AppState appState = AppState.FromJson(Request.Form["state"]);

        Configuration.ApplicationRow application = Configuration.Application.First(o => o.ApplicationID == appState.Application);
        Configuration.QueryRow       query       = Configuration.Query.First(o => o.QueryID == appState.Query);

        List <String> zones  = new List <String>();
        List <String> levels = new List <String>();

        if (!application.IsZoneLevelIDNull())
        {
            zones  = application.ZoneLevelRow.GetZoneRows().Select(o => o.ZoneID).ToList();
            levels = application.ZoneLevelRow.GetLevelRows().Select(o => o.LevelID).ToList();
        }

        Dictionary <String, Object> result = new Dictionary <String, Object>();

        using (OleDbCommand command = query.GetDatabaseCommand())
        {
            command.Parameters[0].Value = appState.TargetIds.Join(",");

            if (command.Parameters.Count > 1)
            {
                command.Parameters[1].Value = AppUser.GetRole();
            }

            using (OleDbDataReader reader = command.ExecuteReader())
            {
                // get the indexes of the ID columns

                int mapIdColumn   = reader.GetColumnIndex("MapID");
                int dataIdColumn  = reader.GetColumnIndex("DataID");
                int zoneIdColumn  = zones.Count > 0 ? reader.GetColumnIndex("ZoneID") : -1;
                int levelIdColumn = levels.Count > 0 ? reader.GetColumnIndex("LevelID") : -1;

                // write the column headers

                List <String> headers = new List <String>();

                for (int i = 0; i < reader.FieldCount; ++i)
                {
                    if (i != mapIdColumn && i != dataIdColumn && i != zoneIdColumn && i != levelIdColumn)
                    {
                        headers.Add(reader.GetName(i));
                    }
                }

                result.Add("headers", headers);

                // write the data

                List <Dictionary <String, Object> > rows = new List <Dictionary <String, Object> >();

                while (reader.Read())
                {
                    if (!reader.IsDBNull(mapIdColumn) && !reader.IsDBNull(dataIdColumn))
                    {
                        Dictionary <String, String> id = new Dictionary <String, String>();

                        id.Add("m", reader.GetValue(mapIdColumn).ToString());

                        if (dataIdColumn > -1 && !reader.IsDBNull(dataIdColumn))
                        {
                            id.Add("d", reader.GetValue(dataIdColumn).ToString());
                        }

                        if (zoneIdColumn > -1 && !reader.IsDBNull(zoneIdColumn))
                        {
                            string zoneId = reader.GetValue(zoneIdColumn).ToString();

                            if (zones.Contains(zoneId))
                            {
                                id.Add("z", zoneId);
                            }
                        }

                        if (levelIdColumn > -1 && !reader.IsDBNull(levelIdColumn))
                        {
                            string levelId = reader.GetValue(levelIdColumn).ToString();

                            if (levels.Contains(levelId))
                            {
                                id.Add("l", levelId);
                            }
                        }

                        List <Object> values = new List <Object>();

                        for (int i = 0; i < reader.FieldCount; ++i)
                        {
                            if (i != mapIdColumn && i != dataIdColumn && i != zoneIdColumn && i != levelIdColumn)
                            {
                                values.Add(reader.IsDBNull(i) ? null : reader.GetValue(i));
                            }
                        }

                        Dictionary <String, Object> row = new Dictionary <String, Object>();
                        row.Add("id", id);
                        row.Add("v", values);

                        rows.Add(row);
                    }
                }

                result.Add("rows", rows);
            }

            command.Connection.Dispose();
        }

        ReturnJson(result);
    }
示例#19
0
    private void DefaultMethod()
    {
        Configuration config = AppContext.GetConfiguration();

        Configuration.ApplicationRow applicationRow = config.Application.First(o => o.ApplicationID == Request.Form["app"]);
        Configuration.SearchRow      searchRow      = config.Search.First(o => o.SearchID == Request.Form["search"]);

        JavaScriptSerializer        serializer = new JavaScriptSerializer();
        Dictionary <String, Object> criteria   = serializer.Deserialize <Dictionary <String, Object> >(Request.Form["criteria"]);

        List <String> levels = new List <String>();

        if (!applicationRow.IsZoneLevelIDNull())
        {
            levels = applicationRow.ZoneLevelRow.GetLevelRows().Select(o => o.LevelID).ToList();
        }

        List <String> where = new List <String>();
        List <Object> parameters = new List <Object>();

        foreach (string criteriaID in criteria.Keys)
        {
            Configuration.SearchInputFieldRow searchInputFieldRow = config.SearchInputField.First(o => o.FieldID == criteriaID);

            switch (searchInputFieldRow.FieldType)
            {
            case "autocomplete":
            case "date":
            case "list":
            case "number":
            case "text":
                where.Add(searchInputFieldRow.ColumnName + " = ?");
                parameters.Add(criteria[criteriaID]);
                break;

            case "daterange":
            case "numberrange":
                ArrayList values = (ArrayList)criteria[criteriaID];

                if (values[0] != null)
                {
                    where.Add(searchInputFieldRow.ColumnName + " >= ?");
                    parameters.Add(values[0]);
                }

                if (values[1] != null)
                {
                    where.Add(searchInputFieldRow.ColumnName + " <= ?");
                    parameters.Add(values[1]);
                }
                break;
            }
        }

        Dictionary <String, Object> result = new Dictionary <String, Object>();

        using (OleDbCommand command = searchRow.GetSelectCommand())
        {
            command.CommandText = String.Format(command.CommandText, String.Join(" and ", where.ToArray()));

            for (int i = 0; i < parameters.Count; ++i)
            {
                command.Parameters.AddWithValue(i.ToString(), parameters[i]);
            }

            using (OleDbDataReader reader = command.ExecuteReader())
            {
                // get the indexes of the ID columns

                int mapIdColumn   = reader.GetColumnIndex("MapID");
                int dataIdColumn  = reader.GetColumnIndex("DataID");
                int levelIdColumn = levels.Count > 0 ? reader.GetColumnIndex("LevelID") : -1;

                // write the column headers

                List <String> headers = new List <String>();

                for (int i = 0; i < reader.FieldCount; ++i)
                {
                    if (i != mapIdColumn && i != dataIdColumn && i != levelIdColumn)
                    {
                        headers.Add(reader.GetName(i));
                    }
                }

                result.Add("headers", headers);

                // write the data

                List <Dictionary <String, Object> > rows = new List <Dictionary <String, Object> >();

                while (reader.Read())
                {
                    if (!reader.IsDBNull(mapIdColumn) && !reader.IsDBNull(dataIdColumn))
                    {
                        Dictionary <String, String> id = new Dictionary <String, String>();

                        id.Add("m", reader.GetValue(mapIdColumn).ToString());

                        if (dataIdColumn > -1 && !reader.IsDBNull(dataIdColumn))
                        {
                            id.Add("d", reader.GetValue(dataIdColumn).ToString());
                        }

                        if (levelIdColumn > -1 && !reader.IsDBNull(levelIdColumn))
                        {
                            string levelId = reader.GetValue(levelIdColumn).ToString();

                            if (levels.Contains(levelId))
                            {
                                id.Add("l", levelId);
                            }
                        }

                        List <Object> values = new List <Object>();

                        for (int i = 0; i < reader.FieldCount; ++i)
                        {
                            if (i != mapIdColumn && i != dataIdColumn && i != levelIdColumn)
                            {
                                values.Add(reader.IsDBNull(i) ? null : reader.GetValue(i));
                            }
                        }

                        Dictionary <String, Object> row = new Dictionary <String, Object>();
                        row.Add("id", id);
                        row.Add("v", values);

                        rows.Add(row);
                    }
                }

                result.Add("rows", rows);
            }
        }

        ReturnJson(result);
    }
示例#20
0
    public void ProcessRequest(HttpContext context)
    {
        Response = context.Response;

        string appId = context.Request.QueryString["app"];
        int    groupId;

        if (!String.IsNullOrEmpty(appId) && Int32.TryParse(context.Request.QueryString["group"], out groupId))
        {
            Response.Clear();

            List <String> placemarks           = new List <String>();
            Dictionary <String, String> styles = new Dictionary <String, String>();
            string appName   = null;
            string groupName = null;

            using (OleDbConnection connection = AppContext.GetDatabaseConnection())
            {
                string sql = String.Format("update {0}MarkupGroup set DateLastAccessed = ? where GroupID = ?", WebConfigSettings.ConfigurationTablePrefix);

                using (OleDbCommand command = new OleDbCommand(sql, connection))
                {
                    command.Parameters.Add("@1", OleDbType.Date).Value    = DateTime.Now;
                    command.Parameters.Add("@2", OleDbType.Integer).Value = groupId;
                    command.ExecuteNonQuery();

                    command.CommandText = String.Format("select Shape, Color, Text from {0}Markup where GroupID = ? and Deleted = 0", WebConfigSettings.ConfigurationTablePrefix);
                    command.Parameters.Clear();
                    command.Parameters.Add("@1", OleDbType.Integer).Value = groupId;

                    WKTReader wktReader = new WKTReader();

                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            IGeometry geometry    = wktReader.Read(reader.GetString(0));
                            string    coordinates = GetCoordinates(geometry);
                            string    color       = reader.GetString(1);
                            bool      isText      = !reader.IsDBNull(2);

                            string styleId = GetStyle(geometry.OgcGeometryType, color, isText, styles);

                            switch (geometry.OgcGeometryType)
                            {
                            case OgcGeometryType.Point:
                                string name = isText ? String.Format("<name>{0}</name>", reader.GetString(2)) : "";
                                placemarks.Add(String.Format("<Placemark>{0}<styleUrl>#{1}</styleUrl><Point>{2}</Point></Placemark>", name, styleId, coordinates));
                                break;

                            case OgcGeometryType.LineString:
                                placemarks.Add(String.Format("<Placemark><styleUrl>#{0}</styleUrl><LineString>{1}</LineString></Placemark>", styleId, coordinates));
                                break;

                            case OgcGeometryType.Polygon:
                                placemarks.Add(String.Format("<Placemark><styleUrl>#{0}</styleUrl><Polygon><outerBoundaryIs><LinearRing>{1}</LinearRing></outerBoundaryIs></Polygon></Placemark>", styleId, coordinates));
                                break;
                            }
                        }
                    }

                    Configuration config = AppContext.GetConfiguration();
                    Configuration.ApplicationRow application = config.Application.Select(String.Format("ApplicationID = '{0}'", appId))[0] as Configuration.ApplicationRow;
                    appName = application.DisplayName;

                    command.CommandText = String.Format("select DisplayName from {0}MarkupGroup where GroupID = ?", WebConfigSettings.ConfigurationTablePrefix);
                    groupName           = command.ExecuteScalar() as string;
                }
            }

            string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmssff");
            string kmzName   = String.Format("Markup_{0}.kmz", timeStamp);
            string kmlName   = String.Format("Markup_{0}.kml", timeStamp);

            string kml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
          <kml xmlns=""http://earth.google.com/kml/2.2"">
            <Folder>
              <name>{0}</name>
              <Document>
                <name>Markup: {1}</name>
                {2}
                {3}
              </Document>
            </Folder>
          </kml>";

            string[] styleArray = new string[styles.Values.Count];
            styles.Values.CopyTo(styleArray, 0);

            kml = String.Format(kml, appName, groupName, String.Join("", styleArray), String.Join("", placemarks.ToArray()));

            Response.ContentType = "application/vnd.google-earth.kmz";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + kmzName);

            ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream);

            MemoryStream memoryStream = new MemoryStream();
            byte[]       buffer       = (new UTF8Encoding()).GetBytes(kml);

            ZipEntry entry = new ZipEntry(kmlName);
            entry.Size = buffer.Length;
            zipStream.PutNextEntry(entry);
            zipStream.Write(buffer, 0, buffer.Length);

            zipStream.Finish();
            Response.End();
        }
    }
示例#21
0
    public void Initialize(Configuration.ApplicationRow application)
    {
        // find all searches for this application

        List <Configuration.SearchRow> searches = new List <Configuration.SearchRow>();

        foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
        {
            Configuration.MapTabRow mapTabRow = appMapTabRow.MapTabRow;

            foreach (Configuration.MapTabLayerRow mapTabLayerRow in mapTabRow.GetMapTabLayerRows().Where(o => !o.IsAllowTargetNull() && o.AllowTarget > 0))
            {
                Configuration.LayerRow layerRow = mapTabLayerRow.LayerRow;

                foreach (Configuration.SearchRow searchRow in layerRow.GetSearchRows())
                {
                    if (!searches.Any(o => o.SearchID == searchRow.SearchID))
                    {
                        searches.Add(searchRow);
                    }
                }
            }
        }

        // generate the search interfaces

        foreach (Configuration.SearchRow searchRow in searches)
        {
            // create the panel for this search

            HtmlGenericControl search = new HtmlGenericControl("div");
            search.Attributes["data-search"] = searchRow.SearchID;
            search.Attributes["class"]       = "Search";
            search.Style["display"]          = "none";

            foreach (Configuration.SearchInputFieldRow searchInputFieldRow in searchRow.GetSearchInputFieldRows().OrderBy(o => o.SequenceNo))
            {
                // add UI elements for this criterion
                HtmlGenericControl searchInputField = new HtmlGenericControl("div");
                search.Controls.Add(searchInputField);
                searchInputField.Attributes["data-criteria"] = searchInputFieldRow.FieldID;
                searchInputField.Attributes["class"]         = "SearchInputField";

                HtmlGenericControl searchLabel = new HtmlGenericControl("span");
                searchInputField.Controls.Add(searchLabel);
                searchLabel.InnerText           = searchInputFieldRow.DisplayName;
                searchLabel.Attributes["class"] = "Label";

                HtmlGenericControl betweenText;

                switch (searchInputFieldRow.FieldType)
                {
                case "autocomplete":
                    AddInputFieldValue(searchInputField, new HtmlInputText("text"), searchInputFieldRow, "Autocomplete");
                    break;

                case "date":
                    AddInputFieldValue(searchInputField, new HtmlInputText("text"), searchInputFieldRow, "Date");
                    break;

                case "daterange":
                    AddInputFieldValue(searchInputField, new HtmlInputText("text"), searchInputFieldRow, "DateRange 1");

                    betweenText = new HtmlGenericControl("span");
                    searchInputField.Controls.Add(betweenText);
                    betweenText.InnerText = " - ";

                    AddInputFieldValue(searchInputField, new HtmlInputText("text"), searchInputFieldRow, "DateRange 2");
                    break;

                case "list":
                    HtmlSelect select = CreateSelect(searchInputFieldRow);
                    AddInputFieldValue(searchInputField, select, searchInputFieldRow, "List");
                    break;

                case "number":
                    AddInputFieldValue(searchInputField, AddNumericTip(new HtmlInputText("text")), searchInputFieldRow, "Number");
                    break;

                case "numberrange":
                    AddInputFieldValue(searchInputField, AddNumericTip(new HtmlInputText("text")), searchInputFieldRow, "NumberRange 1");

                    betweenText = new HtmlGenericControl("span");
                    searchInputField.Controls.Add(betweenText);
                    betweenText.InnerText = " - ";

                    AddInputFieldValue(searchInputField, AddNumericTip(new HtmlInputText("text")), searchInputFieldRow, "NumberRange 2");
                    break;

                case "text":
                    AddInputFieldValue(searchInputField, new HtmlInputText("text"), searchInputFieldRow, "Text");
                    break;
                }

                search.Controls.Add(new HtmlGenericControl("br"));
            }

            pnlSearchScroll.Controls.Add(search);
        }
    }
示例#22
0
    private void Page_PreRender(object sender, EventArgs e)
    {
        ddlTarget.Style["background-color"]    = ColorTranslator.ToHtml(AppSettings.TargetColorUI);
        ddlSelection.Style["background-color"] = ColorTranslator.ToHtml(AppSettings.SelectionColorUI);

        lnkAdminEmail.HRef  = "mailto:" + AppSettings.AdminEmail;
        lnkAdminEmail2.HRef = lnkAdminEmail.HRef;
        pVersion.InnerText  = "GPV version " + Version.ToString();

        string applicationID = Request.QueryString["application"];

        if (applicationID == null)
        {
            return;
        }

        Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.FirstOrDefault(o => o.ApplicationID == applicationID);

        if (application == null)
        {
            return;
        }

        pnlAbout.Visible   = true;
        labAboutTitle.Text = "About " + application.DisplayName;

        if (!application.IsAboutNull())
        {
            labAboutText.InnerHtml = application.About + "<p/>";
        }

        string tabNames = Request.QueryString["functiontabs"];

        string[] functionTabs = tabNames == null ? new string[] { } : tabNames.Split(',');

        bool hasSelection = functionTabs.Any(o => o.ToLower() == "selection");
        bool hasLegend    = functionTabs.Any(o => o.ToLower() == "legend");
        bool hasLocation  = functionTabs.Any(o => o.ToLower() == "location");
        bool hasMarkup    = functionTabs.Any(o => o.ToLower() == "markup");

        if (hasSelection)
        {
            spnNoSelection.Visible  = false;
            spnHasSelection.Visible = true;
            pnlSelection.Visible    = true;
        }

        if (hasLegend)
        {
            spnNoLegend.Visible  = false;
            spnHasLegend.Visible = true;
        }

        if (hasLocation)
        {
            spnNoLocation.Visible  = false;
            spnHasLocation.Visible = true;
        }

        if (hasMarkup)
        {
            spnNoMarkup.Visible  = false;
            spnHasMarkup.Visible = true;
            pnlMarkup.Visible    = true;

            if (AppAuthentication.Mode != AuthenticationMode.None)
            {
                spnMarkupOpen.Visible       = false;
                spnMarkupSecure.Visible     = true;
                spnMarkupNameOpen.Visible   = false;
                spnMarkupNameSecure.Visible = true;
                liLock.Visible = true;
                spnMarkupSelectOpen.Visible   = false;
                spnMarkupSelectSecure.Visible = true;
            }
        }

        bool hasZones  = !application.IsZoneLevelIDNull() && application.ZoneLevelRow.GetZoneRows().Length > 0;
        bool hasLevels = !application.IsZoneLevelIDNull() && application.ZoneLevelRow.GetLevelRows().Length > 0;
        bool hasCombos = hasZones && application.ZoneLevelRow.GetZoneRows().Any(o => o.GetZoneLevelComboRows().Length > 0);

        pnlZoneLevel.Visible = hasZones || hasLevels;

        if (hasZones)
        {
            string zoneName      = application.ZoneLevelRow.ZoneTypeDisplayName;
            string zoneNameLower = zoneName.ToLower();

            if (String.Compare(zoneName, "Building", true) == 0)
            {
                spnZoneName.InnerText = " (Building in this example and in the current application)";
            }
            else
            {
                spnZoneName.InnerText = String.Format(" (Building in this example, {0} in the current application)", zoneName);
            }

            pZoneTab.Visible         = true;
            spnZoneTabName.InnerText = zoneName;
            litZoneName1.Text        = zoneNameLower;
            litZoneName2.Text        = zoneNameLower;
            litZoneName3.Text        = zoneNameLower;
            litZoneLevel.Text        = zoneNameLower;
        }

        if (hasLevels)
        {
            string levelName      = application.ZoneLevelRow.LevelTypeDisplayName;
            string levelNameLower = levelName.ToLower();

            pMapLevel.Visible     = true;
            spnMapLevel.InnerText = levelName;

            if (String.Compare(levelName, "Floor", true) == 0)
            {
                spnLevelName.InnerText = " (Floor in this example and in the current application)";
            }
            else
            {
                spnLevelName.InnerText = String.Format(" (Floor in this example, {0} in the current application)", levelName);
            }

            pnlLevel.Visible    = true;
            spnLevel1.InnerText = levelName;
            spnLevel2.InnerText = levelNameLower;
            labLevel.Text       = levelName;

            string lev = !application.IsDefaultLevelNull() ? application.DefaultLevel : application.ZoneLevelRow.GetLevelRows()[0].DisplayName;
            ddlLevel.Items.Add(lev);

            pLevelTab.Visible         = true;
            spnLevelTabName.InnerText = levelName;

            litLevelName1.Text = levelNameLower;
            litLevelName2.Text = levelNameLower;
            litLevelName3.Text = levelNameLower;
            litZoneLevel.Text  = hasZones ? litZoneLevel.Text + " and " + levelNameLower : levelNameLower;
        }

        if (hasCombos)
        {
            pComboTab.Visible         = true;
            spnComboTabName.InnerText = application.ZoneLevelRow.LevelTypeDisplayName + " by " + application.ZoneLevelRow.ZoneTypeDisplayName;
        }
    }
示例#23
0
    private void SaveMapKml()
    {
        AppState appState = AppState.FromJson(Request.Form["state"]);
        int      width    = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["width"])));
        int      height   = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["height"])));

        MapMaker     mapMaker     = new MapMaker(appState, width, height);
        MapImageData mapImageData = mapMaker.GetImage();

        Configuration.ApplicationRow application = Configuration.Application.Select(String.Format("ApplicationID = '{0}'", appState.Application))[0] as Configuration.ApplicationRow;
        string appName = application.DisplayName;

        DateTime now       = DateTime.Now;
        string   timeStamp = now.ToString("yyyyMMddHHmmssff");
        string   dateNow   = now.ToString("MM/dd/yyyy hh:mm tt");

        string kmzName   = String.Format("Map_{0}.kmz", timeStamp);
        string kmlName   = String.Format("Map_{0}.kml", timeStamp);
        string imageName = String.Format("Map_{0}.", timeStamp) + (mapImageData.Type == CommonImageType.Png ? "png" : "jpg");

        double f = AppSettings.MapUnits == "feet" ? Constants.MetersPerFoot : 1;

        CoordinateSystem coordSys = AppSettings.CoordinateSystem;

        double lat;
        double lon;

        coordSys.ToGeodetic(appState.Extent.MinX * f, appState.Extent.MinY * f, out lon, out lat);
        double minLat = lat;
        double maxLat = lat;
        double minLon = lon;
        double maxLon = lon;

        coordSys.ToGeodetic(appState.Extent.MinX * f, appState.Extent.MaxY * f, out lon, out lat);
        minLat = Math.Min(minLat, lat);
        maxLat = Math.Max(maxLat, lat);
        minLon = Math.Min(minLon, lon);
        maxLon = Math.Max(maxLon, lon);

        coordSys.ToGeodetic(appState.Extent.MaxX * f, appState.Extent.MaxY * f, out lon, out lat);
        minLat = Math.Min(minLat, lat);
        maxLat = Math.Max(maxLat, lat);
        minLon = Math.Min(minLon, lon);
        maxLon = Math.Max(maxLon, lon);

        coordSys.ToGeodetic(appState.Extent.MaxX * f, appState.Extent.MinY * f, out lon, out lat);
        minLat = Math.Min(minLat, lat);
        maxLat = Math.Max(maxLat, lat);
        minLon = Math.Min(minLon, lon);
        maxLon = Math.Max(maxLon, lon);

        Coordinate p = appState.Extent.Centre;
        double     cLat;
        double     cLon;

        coordSys.ToGeodetic(p.X * f, p.Y * f, out cLon, out cLat);

        p.X = appState.Extent.MaxX;
        double eLat;
        double eLon;

        coordSys.ToGeodetic(p.X * f, p.Y * f, out eLon, out eLat);

        double rotation = Math.Atan2(eLat - cLat, eLon - cLon) * 180 / Math.PI;

        string kml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
        <kml xmlns=""http://earth.google.com/kml/2.2"">
          <Folder>
            <name>{0}</name>
            <GroundOverlay>
              <name>Map: created {1}</name>
              <Icon>
                <href>{2}</href>
              </Icon>
              <LatLonBox>
                <north>{3}</north>
                <south>{4}</south>
                <east>{5}</east>
                <west>{6}</west>
                <rotation>{7}</rotation>
              </LatLonBox>
            </GroundOverlay>
          </Folder>
        </kml>";

        kml = String.Format(kml, appName, dateNow, imageName, maxLat, minLat, maxLon, minLon, rotation);

        Response.ContentType = "application/vnd.google-earth.kmz";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + kmzName);

        ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream);

        MemoryStream memoryStream = new MemoryStream();

        byte[] buffer = (new UTF8Encoding()).GetBytes(kml);

        ZipEntry entry = new ZipEntry(kmlName);

        entry.Size = buffer.Length;
        zipStream.PutNextEntry(entry);
        zipStream.Write(buffer, 0, buffer.Length);

        entry      = new ZipEntry(imageName);
        entry.Size = mapImageData.Image.Length;
        zipStream.PutNextEntry(entry);
        zipStream.Write(mapImageData.Image, 0, mapImageData.Image.Length);

        zipStream.Finish();
    }