Example #1
0
    public static CommonDataFrame GetDataFrame(string mapTabId)
    {
        Configuration config = GetConfiguration();

        Configuration.MapTabRow mapTab = config.MapTab.FindByMapTabID(mapTabId);
        return(GetDataFrame(mapTab));
    }
Example #2
0
    private List <Bitmap> GetTileImages(bool overlay)
    {
        List <Bitmap> tileImages = new List <Bitmap>();

        StringCollection visibleTiles = _appState.VisibleTiles[_appState.MapTab];
        double           pixelSize    = _appState.Extent.Width / _width;
        int level = Convert.ToInt32(Math.Log(Constants.BasePixelSize / pixelSize, 2));

        if (visibleTiles.Count > 0)
        {
            Configuration.MapTabRow mapTab = AppContext.GetConfiguration().MapTab.FindByMapTabID(_appState.MapTab);

            foreach (Configuration.MapTabTileGroupRow mapTabTileGroup in mapTab.GetMapTabTileGroupRows().Where(o => visibleTiles.Contains(o.TileGroupID)))
            {
                double opacity = mapTabTileGroup.IsOpacityNull() ? 1 : mapTabTileGroup.Opacity;

                foreach (Configuration.TileLayerRow tileLayer in mapTabTileGroup.TileGroupRow.GetTileLayerRows())
                {
                    bool isOverlay = !tileLayer.IsOverlayNull() && tileLayer.Overlay == 1;

                    if (isOverlay == overlay)
                    {
                        Bitmap tileImage = TileAggregator.GetImage(tileLayer.URL, _appState.Extent, level, opacity);
                        tileImages.Add(tileImage);
                    }
                }
            }
        }

        return(tileImages);
    }
Example #3
0
    private void CreatePdfLegend(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        CreatePdfBox(content, row);

        LegendProperties properties = new LegendProperties(row);

        if (properties.NumColumns == 0)
        {
            return;
        }

        List <CommonLayer> layerList = GetLegendLayers();

        if (layerList.Count == 0)
        {
            return;
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);
        List <CommonLayer>      topLayers = dataFrame.TopLevelLayers;

        properties.CurrentX      = 0;
        properties.CurrentY      = properties.Height;
        properties.CurrentColumn = 1;

        bool full = false;

        for (int i = 0; i < topLayers.Count && !full; ++i)
        {
            full = CreateLayerInLegend(content, mapTab, layerList, properties, topLayers[i], 0);
        }
    }
Example #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);
     }
 }
Example #5
0
    public static CommonDataFrame GetDataFrame(Configuration.MapTabRow mapTab)
    {
        Dictionary <String, CommonDataFrame> dataFrames = GetCachedDataFrames();

        string          dataFrameKey = mapTab.GetDataFrameKey();
        CommonDataFrame dataFrame    = null;

        if (dataFrames.ContainsKey(dataFrameKey))
        {
            dataFrame = dataFrames[dataFrameKey];
        }
        else
        {
            Dictionary <String, CommonMapService> services = GetCachedServices();
            CommonMapService service = null;

            string serviceKey = mapTab.GetServiceKey("AGS");

            if (services.ContainsKey(serviceKey))
            {
                service = services[serviceKey];
            }
            else
            {
                serviceKey = mapTab.GetServiceKey("ArcIMS");

                if (services.ContainsKey(serviceKey))
                {
                    service = services[serviceKey];
                }
            }

            if (service == null)
            {
                service = GetService(mapTab, "AGS");

                if (service == null)
                {
                    service = GetService(mapTab, "ArcIMS");
                }
            }

            if (service != null)
            {
                dataFrame = mapTab.IsDataFrameNull() ? service.DefaultDataFrame : service.DataFrames.FirstOrDefault(df => String.Compare(df.Name, mapTab.DataFrame, true) == 0);

                if (dataFrame != null)
                {
                    dataFrames.Add(dataFrameKey, dataFrame);
                }
            }
        }

        return(dataFrame);
    }
Example #6
0
    private List <CommonLayer> GetLegendLayers()
    {
        StringCollection visibleLayers = null;

        if (_pixelSize > 0 && _appState.VisibleLayers.ContainsKey(_appState.MapTab))
        {
            visibleLayers = _appState.VisibleLayers[_appState.MapTab];
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        List <CommonLayer> layerList      = new List <CommonLayer>();
        List <String>      mapTabLayerIds = new List <String>();

        foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
        {
            Configuration.LayerRow layer = mapTabLayer.LayerRow;
            mapTabLayerIds.Add(layer.LayerID);

            CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layer.LayerName, true) == 0);

            if (commonLayer.Type == CommonLayerType.Feature && !layerList.Contains(commonLayer))
            {
                bool hasClasses         = GetNumClasses(commonLayer) > 0;
                bool visibleAtScale     = _pixelSize <= 0 || commonLayer.IsWithinScaleThresholds(_pixelSize);
                bool shownInLegend      = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend    = mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || visibleLayers == null || visibleLayers.Contains(layer.LayerID);
                bool shownInPrintLegend = !(!mapTabLayer.IsShowInPrintLegendNull() && mapTabLayer.ShowInPrintLegend == 0);

                if (hasClasses && visibleAtScale && shownInLegend && checkedInLegend && shownInPrintLegend)
                {
                    layerList.Add(commonLayer);

                    while (commonLayer.Parent != null)
                    {
                        commonLayer = commonLayer.Parent;

                        if (!layerList.Contains(commonLayer))
                        {
                            layerList.Add(commonLayer);
                        }
                    }
                }
            }
        }

        return(layerList);
    }
Example #7
0
    private void GetZoneExtent()
    {
        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab = config.MapTab.First(o => o.MapTabID == Request.Form["maptab"]);
        Envelope extent = mapTab.GetZoneExtent(Request.Form["zone"]);

        if (!extent.IsNull)
        {
            extent.ScaleBy(1.2);
        }

        ReturnJson <double[]>("extent", extent.IsNull ? null : extent.ToArray());
    }
Example #8
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;
        }
    }
Example #9
0
    private void GetMapImage()
    {
        AppState appState = AppState.FromJson(Request.QueryString["state"]);

        // set the default map layers as visible
        Configuration.MapTabRow mapTab = Configuration.MapTab.FindByMapTabID(appState.MapTab);
        appState.VisibleLayers = new System.Collections.Generic.Dictionary <string, StringCollection>()
        {
            { appState.MapTab, new StringCollection(mapTab.GetMapTabLayerRows().Where(e => !e.IsCheckInLegendNull() && e.CheckInLegend == 1).Select(e => e.LayerID)) }
        };

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

        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);
    }
Example #10
0
    private void AddTiles(Configuration.MapTabRow mapTabRow, AppState appState)
    {
        StringCollection visibleTiles = appState.VisibleTiles[mapTabRow.MapTabID];

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

        HtmlGenericControl parentLegend = new HtmlGenericControl("div");

        pnlTileScroll.Controls.Add(parentLegend);
        parentLegend.Attributes["data-maptab"] = mapTabRow.MapTabID;
        parentLegend.Attributes["class"]       = "LegendTop";
        parentLegend.Style["display"]          = mapTabRow.MapTabID == appState.MapTab ? "block" : "none";

        foreach (Configuration.MapTabTileGroupRow mapTabTileGroupRow in mapTabRow.GetMapTabTileGroupRows())
        {
            Configuration.TileGroupRow tileGroupRow = mapTabTileGroupRow.TileGroupRow;

            HtmlGenericControl legendEntry = new HtmlGenericControl("div");
            parentLegend.Controls.Add(legendEntry);
            legendEntry.Attributes["class"] = "LegendEntry";

            HtmlGenericControl legendHeader = new HtmlGenericControl("div");
            legendEntry.Controls.Add(legendHeader);
            legendHeader.Attributes["class"] = "LegendHeader";

            HtmlGenericControl visibility = new HtmlGenericControl("span");
            legendHeader.Controls.Add(visibility);
            visibility.Attributes["class"] = "LegendVisibility";

            HtmlInputCheckBox checkBox = new HtmlInputCheckBox();
            visibility.Controls.Add(checkBox);
            checkBox.Checked                      = visibleTiles.Contains(tileGroupRow.TileGroupID);
            checkBox.Attributes["class"]          = "LegendCheck";
            checkBox.Attributes["data-tilegroup"] = tileGroupRow.TileGroupID;

            HtmlGenericControl name = new HtmlGenericControl("span");
            legendHeader.Controls.Add(name);
            name.Attributes["class"] = "LegendName";
            name.InnerText           = tileGroupRow.DisplayName;
        }
    }
Example #11
0
    private static CommonHost GetHost(Configuration.MapTabRow mapTab, string type)
    {
        string userName = mapTab.IsUserNameNull() ? "" : mapTab.UserName;
        string password = mapTab.IsPasswordNull() ? "" : mapTab.Password;

        CommonHost host = null;

        try
        {
            switch (type)
            {
            case "AGS":
                if (String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(password))
                {
                    host = new AgsHost(mapTab.MapHost);
                }
                else
                {
                    try
                    {
                        host = new AgsHost(mapTab.MapHost, userName, password, true);
                    }
                    catch { }

                    if (host == null)
                    {
                        host = new AgsHost(mapTab.MapHost, userName, password, false);
                    }
                }
                break;

            case "ArcIMS":
                host = new ArcImsHost(mapTab.MapHost, userName, password);
                break;
            }
        }
        catch { }

        return(host);
    }
Example #12
0
    private void CreatePdfTiles(PdfContentByte content, Configuration.PrintTemplateContentRow row, bool overlay)
    {
        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        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;

        StringCollection visibleTiles = _appState.VisibleTiles[_appState.MapTab];
        int level = Convert.ToInt32(Math.Log(Constants.BasePixelSize / _pixelSize, 2));

        if (visibleTiles.Count > 0)
        {
            Configuration.MapTabRow mapTab = AppContext.GetConfiguration().MapTab.FindByMapTabID(_appState.MapTab);

            foreach (Configuration.MapTabTileGroupRow mapTabTileGroup in mapTab.GetMapTabTileGroupRows().Where(o => visibleTiles.Contains(o.TileGroupID)))
            {
                double opacity = mapTabTileGroup.IsOpacityNull() ? 1 : mapTabTileGroup.Opacity;

                foreach (Configuration.TileLayerRow tileLayer in mapTabTileGroup.TileGroupRow.GetTileLayerRows())
                {
                    bool isOverlay = !tileLayer.IsOverlayNull() && tileLayer.Overlay == 1;

                    if (isOverlay == overlay)
                    {
                        byte[] tileImage = TileAggregator.GetImageBytes(tileLayer.URL, _appState.Extent, level, opacity);

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

                        content.AddImage(image);
                    }
                }
            }
        }
    }
Example #13
0
    public void AddNoneOption(Configuration.MapTabRow mapTabRow, HtmlGenericControl parentLegend)
    {
        HtmlGenericControl legendEntry = new HtmlGenericControl("div");

        parentLegend.Controls.Add(legendEntry);
        legendEntry.Attributes["class"] = "LegendEntry";

        HtmlGenericControl legendHeader = new HtmlGenericControl("div");

        legendEntry.Controls.Add(legendHeader);
        legendHeader.Attributes["class"] = "LegendHeader";

        HtmlGenericControl visibility = new HtmlGenericControl("span");

        legendHeader.Controls.Add(visibility);
        visibility.Attributes["class"] = "LegendVisibility";

        HtmlInputRadioButton radio = new HtmlInputRadioButton();

        visibility.Controls.Add(radio);
        radio.Attributes["id"]    = "baseTileNone";
        radio.Checked             = false;
        radio.Attributes["class"] = "LegendCheck RadioCheck";
        radio.Attributes["group"] = mapTabRow.MapTabID;
        radio.Attributes["name"]  = mapTabRow.MapTabID;

        HtmlGenericControl label = new HtmlGenericControl("label");

        legendHeader.Controls.Add(label);
        label.Attributes["for"] = radio.Attributes["id"];

        HtmlGenericControl name = new HtmlGenericControl("span");

        label.Controls.Add(name);
        name.Attributes["class"] = "LegendName";
        name.InnerText           = "None";
    }
Example #14
0
    private static CommonMapService GetService(Configuration.MapTabRow mapTab, string type)
    {
        Dictionary <String, CommonMapService> services = GetCachedServices();

        string           serviceKey = mapTab.GetServiceKey(type);
        CommonMapService service    = null;

        if (services.ContainsKey(serviceKey))
        {
            service = services[serviceKey];
        }
        else
        {
            CommonHost host = GetHost(mapTab, type);

            if (host != null)
            {
                try
                {
                    service = host.GetMapService(mapTab.MapService);

                    ArcImsService arcImsService = service as ArcImsService;

                    if (arcImsService != null && !arcImsService.IsArcMap)
                    {
                        arcImsService.LoadToc(true);
                    }

                    services.Add(serviceKey, service);
                }
                catch { }
            }
        }

        return(service);
    }
Example #15
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);
        }
    }
Example #16
0
    private bool CreateLayerInLegend(PdfContentByte content, Configuration.MapTabRow mapTab, List <CommonLayer> layerList, LegendProperties properties, CommonLayer layer, float indent)
    {
        if (!layerList.Contains(layer))
        {
            return(false);
        }

        float layerHeight = GetLayerHeightInLegend(layerList, properties, layer);

        if (properties.CurrentY < properties.Height && properties.CurrentY - layerHeight < 0)
        {
            if (properties.CurrentColumn == properties.NumColumns)
            {
                return(true);
            }

            properties.CurrentX      += properties.ColumnWidth + properties.ColumnSpacing;
            properties.CurrentY       = properties.Height;
            properties.CurrentColumn += 1;
        }

        int numClasses = GetNumClasses(layer);

        Configuration.LayerRow configLayer = mapTab.GetMapTabLayerRows().Where(o => String.Compare(o.LayerRow.LayerName, layer.Name, true) == 0).Select(o => o.LayerRow).FirstOrDefault();
        string layerName = configLayer != null && !configLayer.IsDisplayNameNull() ? configLayer.DisplayName : layer.Name;

        // write the layer name

        if (layer.Type == CommonLayerType.Group || numClasses > 1)
        {
            properties.CurrentY -= properties.FontSize;
            string name = layerName;

            try
            {
                while (content.GetEffectiveStringWidth(name, false) > properties.ColumnWidth - indent)
                {
                    name = name.Substring(0, name.Length - 1);
                }
            }
            catch { }

            content.BeginText();
            content.SetFontAndSize(properties.BaseFont, properties.FontSize);
            content.SetRGBColorFill(0, 0, 0);
            content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, name, properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
            content.EndText();
        }

        if (layer.Type == CommonLayerType.Group)
        {
            properties.CurrentY -= properties.LayerSpacing;

            foreach (CommonLayer childLayer in layer.Children)
            {
                CreateLayerInLegend(content, mapTab, layerList, properties, childLayer, indent + 1.5f * properties.FontSize);
            }
        }
        else
        {
            properties.CurrentY -= properties.ClassSpacing;

            foreach (CommonLegendGroup legendGroup in layer.Legend.Groups)
            {
                foreach (CommonLegendClass legendClass in legendGroup.Classes)
                {
                    if (!legendClass.ImageIsTransparent)
                    {
                        properties.CurrentY -= properties.SwatchHeight;

                        MemoryStream          stream = new MemoryStream(legendClass.Image);
                        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
                        float w = properties.SwatchHeight * bitmap.Width / bitmap.Height;

                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(legendClass.Image);
                        image.SetAbsolutePosition(properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY - properties.SwatchHeight * 0.1f);
                        image.ScaleAbsolute(w, properties.SwatchHeight);
                        content.AddImage(image);

                        string label = numClasses > 1 ? legendClass.Label : layerName;

                        try
                        {
                            while (content.GetEffectiveStringWidth(label, false) > properties.ColumnWidth - properties.SwatchWidth - properties.ClassSpacing)
                            {
                                label = label.Substring(0, label.Length - 1);
                            }
                        }
                        catch { }

                        content.BeginText();
                        content.SetFontAndSize(properties.BaseFont, properties.FontSize);
                        content.SetRGBColorFill(0, 0, 0);
                        content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, label, properties.OriginX + properties.CurrentX + indent + properties.SwatchWidth + properties.ClassSpacing, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
                        content.EndText();

                        properties.CurrentY -= properties.ClassSpacing;
                    }
                }
            }

            properties.CurrentY -= properties.LayerSpacing - properties.ClassSpacing;
        }

        return(false);
    }
Example #17
0
    public static DataListBuilder SearchMapTab(string mapTabID, string[] visibleLayers, string levelID, double x, double y,
                                               double distance, double scale, bool addSpace)
    {
        DataListBuilder dataListBuilder = new DataListBuilder();

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.First(o => o.MapTabID == mapTabID);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        Dictionary <String, Configuration.LayerRow>         layers         = new Dictionary <String, Configuration.LayerRow>();
        Dictionary <String, Configuration.LayerFunctionRow> layerFunctions = new Dictionary <String, Configuration.LayerFunctionRow>();

        bool useDefaultVisible = visibleLayers.Length == 1 && visibleLayers[0] == "*";

        foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
        {
            bool isCandidateLayer = mapTab.IsInteractiveLegendNull() || mapTab.InteractiveLegend == 0;

            if (!isCandidateLayer)
            {
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || visibleLayers.Any(o => o == mapTabLayer.LayerID);
                bool defaultVisible  = useDefaultVisible && !mapTabLayer.IsCheckInLegendNull() && mapTabLayer.CheckInLegend == 1;
                isCandidateLayer = !shownInLegend || checkedInLegend || defaultVisible;
            }

            if (isCandidateLayer)
            {
                Configuration.LayerRow         layer         = mapTabLayer.LayerRow;
                Configuration.LayerFunctionRow layerFunction = layer.GetLayerFunctionRows().FirstOrDefault(o => o.FunctionName.ToLower() == "identify");

                if (layerFunction != null)
                {
                    layers.Add(layer.LayerName, layer);
                    layerFunctions.Add(layer.LayerName, layerFunction);
                }
            }
        }

        foreach (CommonLayer commonLayer in dataFrame.Layers)
        {
            DataTable table = null;

            if (layers.ContainsKey(commonLayer.Name) && commonLayer.IsWithinScaleThresholds(scale))
            {
                Configuration.LayerRow layer = layers[commonLayer.Name];

                if (commonLayer.Type == CommonLayerType.Feature)
                {
                    CommonField keyField   = commonLayer.FindField(layer.KeyField);
                    string      levelQuery = layer.GetLevelQuery(commonLayer, levelID);
                    table = commonLayer.GetFeatureTable(keyField.Name, levelQuery, x, y, commonLayer.FeatureType == OgcGeometryType.MultiPolygon ? 0 : distance * scale);
                }

                if (commonLayer.Type == CommonLayerType.Image && commonLayer is AgsLayer)
                {
                    string id = ((AgsLayer)commonLayer).GetRasterValue(x, y);
                    table = new DataTable();
                    table.Columns.Add("ID");
                    table.Rows.Add(id);
                }
            }

            if (table != null && table.Rows.Count > 0)
            {
                Configuration.LayerFunctionRow layerFunction = layerFunctions[commonLayer.Name];

                foreach (DataRow row in table.Rows)
                {
                    string id = row[0].ToString();

                    using (OleDbCommand command = layerFunction.GetDatabaseCommand())
                    {
                        command.Parameters[0].Value = id;

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

                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            dataListBuilder.AddFromReader(reader, addSpace);
                        }

                        command.Connection.Dispose();
                    }
                }
            }
        }

        return(dataListBuilder);
    }
Example #18
0
    public MapImageData GetImage()
    {
        StringCollection visibleLayers = null;

        if (_appState.VisibleLayers.ContainsKey(_appState.MapTab))
        {
            visibleLayers = _appState.VisibleLayers[_appState.MapTab];
        }

        string keyExtent = _appState.Extent.ToDelimitedString();
        string keySize   = _width.ToString() + "," + _height.ToString();
        string keyLayers = visibleLayers != null?visibleLayers.ToString('|') : "";

        string key = String.Format("{0}|{1}|{2}|{3}|{4}|{5}", _appState.MapTab, _appState.Level, keyExtent, keySize, _resolution, keyLayers);

        CommonImageType imageType = CommonImageType.Png;

        byte[] image = null;

        MapImageData mapImageData = AppContext.ServerImageCache.Retrieve(key);

        if (mapImageData != null)
        {
            imageType = mapImageData.Type;
            image     = mapImageData.Image;
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        bool isInteractive = !mapTab.IsInteractiveLegendNull() && mapTab.InteractiveLegend == 1;

        // create the base image if not found in the cache

        if (image == null)
        {
            CommonMap map = dataFrame.GetMap(_width, _height, _extent);

            map.Resolution = _resolution;
            map.ImageType  = CommonImageType.Png;

            double pixelSize = map.Extent.Width / _width;

            Dictionary <int, CommonLayer> layerList      = new Dictionary <int, CommonLayer>();
            Dictionary <int, String>      definitionList = new Dictionary <int, String>();
            List <String> mapTabLayerIds = new List <String>();

            foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
            {
                Configuration.LayerRow layer = mapTabLayer.LayerRow;
                mapTabLayerIds.Add(layer.LayerID);

                CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layer.LayerName, true) == 0);
                int         index       = dataFrame.Layers.IndexOf(commonLayer);

                bool visibleAtScale  = commonLayer.IsWithinScaleThresholds(pixelSize);
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = !isInteractive || mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || (visibleLayers != null && visibleLayers.Contains(layer.LayerID));

                bool validLevel = layer.IsLevelFieldNull() || !String.IsNullOrEmpty(_appState.Level);

                if (!layerList.ContainsKey(index) && visibleAtScale && (!shownInLegend || checkedInLegend) && validLevel)
                {
                    if (commonLayer.Type == CommonLayerType.Image)
                    {
                        map.ImageType = CommonImageType.Jpg;
                    }

                    layerList.Add(index, commonLayer);
                    definitionList.Add(index, layer.GetLevelQuery(commonLayer, _appState.Level));
                }
            }

            if (!mapTab.IsBaseMapIDNull())
            {
                foreach (Configuration.LayerRow layer in config.Layer.Where(o => !o.IsBaseMapIDNull() && o.BaseMapID == mapTab.BaseMapID))
                {
                    if (!mapTabLayerIds.Contains(layer.LayerID))
                    {
                        CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(o => String.Compare(o.Name, layer.LayerName, true) == 0);
                        int         index       = dataFrame.Layers.IndexOf(commonLayer);

                        bool visibleAtScale = commonLayer.IsWithinScaleThresholds(pixelSize);

                        if (!layerList.ContainsKey(index) && visibleAtScale)
                        {
                            if (commonLayer.Type == CommonLayerType.Image)
                            {
                                map.ImageType = CommonImageType.Jpg;
                            }

                            layerList.Add(index, commonLayer);
                            definitionList.Add(index, layer.GetLevelQuery(commonLayer, _appState.Level));
                        }
                    }
                }
            }

            int[] indexes = new int[layerList.Keys.Count];
            layerList.Keys.CopyTo(indexes, 0);
            List <int> indexList = new List <int>(indexes);
            indexList.Sort();

            for (int i = 0; i < indexList.Count; ++i)
            {
                map.AddLayer(layerList[indexList[i]], definitionList[indexList[i]]);
            }

            imageType = map.ImageType;
            image     = map.GetImageBytes();

            AppContext.ServerImageCache.Store(key, new MapImageData(imageType, image));
        }


        // draw the selected feature graphics and markup

        if (_appState.TargetIds.Count > 0 || _appState.SelectionIds.Count > 0 || _appState.MarkupGroups.Count > 0 || _appState.Markup.Count > 0)
        {
            Bitmap bitmap = new Bitmap(new MemoryStream(image));
            bitmap.SetResolution(dataFrame.Dpi, dataFrame.Dpi);
            Graphics graphics = Graphics.FromImage(bitmap);

            if (_appState.TargetIds.Count > 0 || _appState.SelectionIds.Count > 0)
            {
                StringCollection targetIds;
                StringCollection filteredIds;
                StringCollection selectionIds;

                PrepareIds(out targetIds, out filteredIds, out selectionIds);

                DrawFeatures(graphics, _appState.TargetLayer, filteredIds, AppSettings.FilteredColor, AppSettings.FilteredOpacity, AppSettings.FilteredPolygonMode, AppSettings.FilteredPenWidth, AppSettings.FilteredDotSize);
                DrawFeatures(graphics, _appState.SelectionLayer, selectionIds, AppSettings.SelectionColor, AppSettings.SelectionOpacity, AppSettings.SelectionPolygonMode, AppSettings.SelectionPenWidth, AppSettings.SelectionDotSize);
                DrawFeatures(graphics, _appState.TargetLayer, targetIds, AppSettings.TargetColor, AppSettings.TargetOpacity, AppSettings.TargetPolygonMode, AppSettings.TargetPenWidth, AppSettings.TargetDotSize);
                DrawFeatures(graphics, _appState.TargetLayer, _appState.ActiveMapId, AppSettings.ActiveColor, AppSettings.ActiveOpacity, AppSettings.ActivePolygonMode, AppSettings.ActivePenWidth, AppSettings.ActiveDotSize);

                IGeometry selectionBuffer = _appState.SelectionManager.GetSelectionBuffer();

                if (selectionBuffer != null)
                {
                    Brush bufferBrush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * AppSettings.BufferOpacity), AppSettings.BufferColor));
                    Pen   bufferPen   = AppSettings.BufferOutlineOpacity > 0 ? new Pen(new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * AppSettings.BufferOutlineOpacity), AppSettings.BufferOutlineColor)), AppSettings.BufferOutlinePenWidth) : null;

                    switch (selectionBuffer.OgcGeometryType)
                    {
                    case OgcGeometryType.Polygon:
                        DrawPolygon(graphics, (IPolygon)selectionBuffer, bufferBrush, null, bufferPen);
                        break;

                    case OgcGeometryType.MultiPolygon:
                        DrawMultiPolygon(graphics, (IMultiPolygon)selectionBuffer, bufferBrush, null, bufferPen);
                        break;
                    }
                }
            }

            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            DrawMarkup(graphics);

            MemoryStream memoryStream = new MemoryStream();

            if (imageType == CommonImageType.Jpg)
            {
                ImageCodecInfo    imageCodecInfo    = GetEncoderInfo("image/jpeg");
                EncoderParameters encoderParameters = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L);
                bitmap.Save(memoryStream, imageCodecInfo, encoderParameters);
            }
            else
            {
                bitmap.Save(memoryStream, bitmap.RawFormat);
            }

            image = memoryStream.ToArray();
        }

        return(new MapImageData(imageType, image));
    }
Example #19
0
    private void AddTileGroupsForMapTab(Configuration.MapTabRow mapTabRow, AppState appState, int m, bool asBaseMap)
    {
        StringCollection visibleTiles = appState.VisibleTiles[mapTabRow.MapTabID];

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

        HtmlGenericControl parentLegend = new HtmlGenericControl("div");

        pnlBaseMapScroll.Controls.Add(parentLegend);
        parentLegend.Attributes["data-maptab"] = mapTabRow.MapTabID;
        parentLegend.Attributes["class"]       = "LegendTop";
        parentLegend.Style["display"]          = mapTabRow.MapTabID == appState.MapTab ? "block" : "none";

        HtmlGenericControl typeEntry = new HtmlGenericControl("div");

        parentLegend.Controls.Add(typeEntry);
        typeEntry.Attributes["class"] = "LegendEntry";

        HtmlGenericControl typeHeader = new HtmlGenericControl("div");

        typeEntry.Controls.Add(typeHeader);
        typeHeader.Attributes["class"] = "LegendHeader";

        HtmlGenericControl typeName = new HtmlGenericControl("span");

        typeHeader.Controls.Add(typeName);
        typeName.Attributes["class"] = "LegendName";
        typeName.InnerText           = asBaseMap ? "BaseMaps" : "Overlays";

        int g = 0;

        foreach (Configuration.MapTabTileGroupRow mapTabTileGroupRow in mapTabRow.GetMapTabTileGroupRows())
        {
            Configuration.TileGroupRow tileGroupRow = mapTabTileGroupRow.TileGroupRow;
            bool isBaseMap = tileGroupRow.GetTileLayerRows().Any(t => t.IsOverlayNull() || t.Overlay == 0);

            if (isBaseMap == asBaseMap)
            {
                HtmlGenericControl legendEntry = new HtmlGenericControl("div");
                parentLegend.Controls.Add(legendEntry);
                legendEntry.Attributes["class"] = "LegendEntry";

                HtmlGenericControl legendHeader = new HtmlGenericControl("div");
                legendEntry.Controls.Add(legendHeader);
                legendHeader.Attributes["class"] = "LegendHeader";

                HtmlGenericControl visibility = new HtmlGenericControl("span");
                legendHeader.Controls.Add(visibility);
                visibility.Attributes["class"] = "LegendVisibility";

                HtmlControl onOffControl;

                if (isBaseMap)
                {
                    HtmlInputRadioButton radio = new HtmlInputRadioButton();
                    radio.Attributes["id"]    = string.Format("baseTile{0}-{1}", m, g);
                    radio.Checked             = visibleTiles.Contains(tileGroupRow.TileGroupID);
                    radio.Attributes["class"] = "LegendCheck RadioCheck";
                    onOffControl = radio;
                }
                else
                {
                    HtmlInputCheckBox checkBox = new HtmlInputCheckBox();
                    checkBox.Attributes["id"]    = string.Format("overlayTile{0}-{1}", m, g);
                    checkBox.Checked             = visibleTiles.Contains(tileGroupRow.TileGroupID);
                    checkBox.Attributes["class"] = "LegendCheck OverlaysCheck";
                    onOffControl = checkBox;
                }

                visibility.Controls.Add(onOffControl);
                onOffControl.Attributes["group"]          = mapTabRow.MapTabID;
                onOffControl.Attributes["name"]           = mapTabRow.MapTabID;
                onOffControl.Attributes["data-tilegroup"] = tileGroupRow.TileGroupID;

                HtmlGenericControl label = new HtmlGenericControl("label");
                legendHeader.Controls.Add(label);
                label.Attributes["for"] = onOffControl.Attributes["id"];

                HtmlGenericControl name = new HtmlGenericControl("span");
                label.Controls.Add(name);
                name.Attributes["class"] = "LegendName";
                name.InnerText           = tileGroupRow.DisplayName;

                g += 1;
            }
        }

        if (g == 0)
        {
            parentLegend.Controls.Remove(typeEntry);
        }
        else if (asBaseMap)
        {
            AddNoneOption(mapTabRow, parentLegend);
        }
    }
Example #20
0
    private void DefaultMethod()
    {
        string v = Request.Form["visiblelayers"];

        string[] visibleLayers = v == null ? new string[0] : v.Split('\u0001');

        string level    = Request.Form["level"];
        double x        = Convert.ToDouble(Request.Form["x"]);
        double y        = Convert.ToDouble(Request.Form["y"]);
        double distance = Convert.ToDouble(Request.Form["distance"]);
        double scale    = Convert.ToDouble(Request.Form["scale"]);

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.First(o => o.MapTabID == Request.Form["maptab"]);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        Dictionary <String, Configuration.LayerRow>         layers         = new Dictionary <String, Configuration.LayerRow>();
        Dictionary <String, Configuration.LayerFunctionRow> layerFunctions = new Dictionary <String, Configuration.LayerFunctionRow>();

        foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
        {
            bool isCandidateLayer = mapTab.IsInteractiveLegendNull() || mapTab.InteractiveLegend == 0;

            if (!isCandidateLayer)
            {
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || visibleLayers.Any(o => o == mapTabLayer.LayerID);
                isCandidateLayer = !shownInLegend || checkedInLegend;
            }

            if (isCandidateLayer)
            {
                Configuration.LayerRow         layer         = mapTabLayer.LayerRow;
                Configuration.LayerFunctionRow layerFunction = layer.GetLayerFunctionRows().FirstOrDefault(o => o.FunctionName.ToLower() == "maptip");

                if (layerFunction != null)
                {
                    layers.Add(layer.LayerName, layer);
                    layerFunctions.Add(layer.LayerName, layerFunction);
                }
            }
        }

        string tipText = null;

        for (int i = 0; i < dataFrame.Layers.Count - 1 && tipText == null; ++i)
        {
            CommonLayer commonLayer = dataFrame.Layers[i];
            string      id          = null;

            if (layers.ContainsKey(commonLayer.Name) && commonLayer.IsWithinScaleThresholds(scale))
            {
                if (commonLayer.Type == CommonLayerType.Feature)
                {
                    Configuration.LayerRow layer = layers[commonLayer.Name];
                    string levelQuery            = layer.GetLevelQuery(commonLayer, level);

                    CommonField keyField = commonLayer.FindField(layer.KeyField);
                    DataTable   table    = commonLayer.GetFeatureTable(keyField.Name, levelQuery, x, y, commonLayer.FeatureType == OgcGeometryType.MultiPolygon ? 0 : distance * scale);

                    if (table != null && table.Rows.Count > 0)
                    {
                        id = table.Rows[table.Rows.Count - 1][0].ToString();
                    }
                }

                if (commonLayer.Type == CommonLayerType.Image)
                {
                    id = ((AgsLayer)commonLayer).GetRasterValue(x, y);
                }
            }

            if (!String.IsNullOrEmpty(id))
            {
                Configuration.LayerFunctionRow layerFunction = layerFunctions[commonLayer.Name];

                using (OleDbCommand command = layerFunction.GetDatabaseCommand())
                {
                    command.Parameters[0].Value = id;

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

                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            StringCollection text = new StringCollection();

                            for (int j = 0; j < reader.FieldCount; ++j)
                            {
                                if (!reader.IsDBNull(j))
                                {
                                    text.Add(reader.GetValue(j).ToString());
                                }
                            }

                            if (text.Count > 0)
                            {
                                tipText = text.Join("\n");
                            }
                        }
                    }

                    command.Connection.Close();
                }
            }
        }

        if (tipText == null)
        {
            ReturnJson(null);
        }
        else
        {
            Dictionary <String, Object> result = new Dictionary <String, Object>();
            result.Add("tipText", tipText);
            ReturnJson(result);
        }
    }
Example #21
0
    private void AddLayers(Configuration.MapTabRow mapTabRow, AppState appState)
    {
        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));
            }
        }

        // 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");

        pnlLayerScroll.Controls.Add(parentLegend);
        parentLegend.Attributes["data-maptab"] = mapTabRow.MapTabID;
        parentLegend.Attributes["class"]       = "LegendTop";
        parentLegend.Style["display"]          = mapTabRow.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);
        }
    }
Example #22
0
 public MapTabData(Configuration.MapTabRow mapTab)
 {
     MapTabID    = mapTab.MapTabID;
     DisplayName = mapTab.DisplayName;
 }