Example #1
0
    public Envelope GetExtent(FeatureType featureType)
    {
        Envelope extent = new Envelope();

        string layerId = featureType == FeatureType.Selection ? _appState.SelectionLayer : _appState.TargetLayer;

        Configuration config = AppContext.GetConfiguration();

        Configuration.LayerRow layerRow = config.Layer.FindByLayerID(layerId);

        CommonDataFrame dataFrame = AppContext.GetDataFrame(_appState.MapTab);
        CommonLayer     layer     = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layerRow.LayerName, true) == 0);

        string query = GetQuery(featureType, layerRow, layer);

        if (query != null)
        {
            extent = layer.GetFeatureExtent(query);
        }

        if (!extent.IsNull && extent.Width == 0 && extent.Height == 0)
        {
            extent = new Envelope(new Coordinate(extent.MinX - 50, extent.MinY - 50), new Coordinate(extent.MaxX + 50, extent.MaxY + 50));
        }

        return(extent);
    }
Example #2
0
    public DataTable GetFeatures(FeatureType featureType, IGeometry spatialConstraint)
    {
        DataTable table = null;

        string layerId = featureType == FeatureType.Selection ? _appState.SelectionLayer : _appState.TargetLayer;

        if (layerId.Length > 0)
        {
            Configuration          config   = AppContext.GetConfiguration();
            Configuration.LayerRow layerRow = config.Layer.FindByLayerID(layerId);

            CommonDataFrame dataFrame = AppContext.GetDataFrame(_appState.MapTab);
            CommonLayer     layer     = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layerRow.LayerName, true) == 0);

            string query = GetQuery(featureType, layerRow, layer);

            if (query != null)
            {
                CommonField keyField = layer.FindField(layerRow.KeyField);

                if (spatialConstraint == null)
                {
                    table = layer.GetFeatureTable(String.Format("{0},{1}", layer.GeometryField.Name, keyField.Name), query);
                }
                else
                {
                    table = layer.GetFeatureTable(String.Format("{0},{1}", layer.GeometryField.Name, keyField.Name), query, spatialConstraint);
                }
            }
        }

        return(table);
    }
Example #3
0
        public Envelope GetZoneExtent(string zone)
        {
            Envelope        extent    = new Envelope();
            CommonDataFrame dataFrame = AppContext.GetDataFrame(this);

            foreach (Configuration.MapTabLayerRow mapTabLayer in GetMapTabLayerRows())
            {
                Configuration.LayerRow layer = mapTabLayer.LayerRow;

                if (!layer.IsZoneFieldNull())
                {
                    CommonLayer commonLayer = dataFrame.Layers.First(o => o.Name == layer.LayerName);
                    CommonField field       = commonLayer.FindField(layer.ZoneField);

                    string zoneValue = field.IsNumeric ? zone : String.Format("'{0}'", zone);
                    extent = commonLayer.GetFeatureExtent(String.Format("{0} = {1}", field.Name, zoneValue));

                    if (!extent.IsNull)
                    {
                        break;
                    }
                }
            }

            return(extent);
        }
Example #4
0
        public override void AddLayer(CommonLayer layer, string definitionQuery)
        {
            ArcImsLayer arcImsLayer = layer as ArcImsLayer;

            if (arcImsLayer == null)
            {
                throw new ArcImsException(String.Format("A {0} cannot be added to an ArcImsMap.", layer.GetType().Name));
            }

            AddLayer(arcImsLayer, definitionQuery);
        }
Example #5
0
        public string GetLevelQuery(CommonLayer layer, string level)
        {
            string query = null;

            if (!IsLevelFieldNull() && !String.IsNullOrEmpty(level))
            {
                CommonField field = layer.FindField(LevelField);
                query = String.Format("{0} = {1}", field.Name, field.IsNumeric ? level : String.Format("'{0}'", level));
            }

            return(query);
        }
Example #6
0
    public string GetLevelQuery(CommonLayer layer, string level)
    {
      string query = null;

      if (!IsLevelFieldNull() && !String.IsNullOrEmpty(level))
      {
        CommonField field = layer.FindField(LevelField);
        query = String.Format("{0} = {1}", field.Name, field.IsNumeric ? level : String.Format("'{0}'", level));
      }

      return query;
    }
Example #7
0
  private string GetQuery(FeatureType featureType, Configuration.LayerRow layerRow, CommonLayer layer, bool inSet)
  {
    StringCollection ids = GetIds(featureType);

    if (ids.Count == 0)
    {
      return null;
    }

    CommonField keyField = layer.FindField(layerRow.KeyField);
    string joinedIds = keyField.IsNumeric ? ids.Join(",") : String.Format("'{0}'", ids.Join("','"));
    return String.Format("{0} {1} ({2})", keyField.Name, inSet ? "in" : "not in", joinedIds);
  }
Example #8
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 #9
0
        public override void AddLayerAndChildren(CommonLayer layer)
        {
            ArcImsLayer arcImsLayer = layer as ArcImsLayer;

            if (arcImsLayer == null)
            {
                throw new ArcImsException(String.Format("A {0} cannot be added to an ArcImsMap.", layer.GetType().Name));
            }

            AddLayer(arcImsLayer);

            if (arcImsLayer.Children != null && arcImsLayer.Children.Count > 0)
            {
                foreach (CommonLayer child in arcImsLayer.Children)
                {
                    AddLayerAndChildren(child);
                }
            }
        }
Example #10
0
    private int GetNumClasses(CommonLayer layer)
    {
        int          numClasses = 0;
        CommonLegend legend     = layer.Legend;

        if (legend != null)
        {
            for (int g = 0; g < legend.Groups.Count; ++g)
            {
                for (int c = 0; c < legend.Groups[g].Classes.Count; ++c)
                {
                    if (!legend.Groups[g].Classes[c].ImageIsTransparent)
                    {
                        ++numClasses;
                    }
                }
            }
        }

        return(numClasses);
    }
Example #11
0
    private void DrawFeatures(Graphics graphics, string layerId, StringCollection ids, Color color, double opacity, string polygonMode, int penWidth, int dotSize)
    {
        if (ids.Count == 0)
        {
            return;
        }

        bool drawPolygonOutlines = polygonMode == "outline";

        // get the layer

        Configuration config = AppContext.GetConfiguration();

        Configuration.LayerRow layerRow = config.Layer.FindByLayerID(layerId);

        CommonDataFrame dataFrame = AppContext.GetDataFrame(_appState.MapTab);
        CommonLayer     layer     = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layerRow.LayerName, true) == 0);

        // build the query string and select the features

        CommonField field     = layer.FindField(layerRow.KeyField);
        string      joinedIds = field.IsNumeric ? ids.Join(",") : String.Format("'{0}'", ids.Join("','"));
        string      query     = String.Format("{0} in ({1})", field.Name, joinedIds);

        string levelQuery = layerRow.GetLevelQuery(layer, _appState.Level);

        if (!String.IsNullOrEmpty(levelQuery))
        {
            query += " and " + levelQuery;
        }

        CommonField keyField = layer.FindField(layerRow.KeyField);
        DataTable   table    = layer.GetFeatureTable(String.Format("{0},{1}", layer.GeometryField.Name, keyField.Name), query);

        if (table == null || table.Rows.Count == 0)
        {
            return;
        }

        OgcGeometryType geometryType = ((IGeometry)table.Rows[0][layer.GeometryField.Name]).OgcGeometryType;

        // prepare the temporary image for drawing transparent highlight graphics

        int width  = Convert.ToInt32(graphics.VisibleClipBounds.Width);
        int height = Convert.ToInt32(graphics.VisibleClipBounds.Height);

        Bitmap   bitMap        = new Bitmap(width, height);
        Graphics imageGraphics = Graphics.FromImage(bitMap);

        imageGraphics.Clear(Color.Transparent);

        // prepare the drawing objects

        Brush brush = new SolidBrush(color);
        Pen   pen   = new Pen(color, Convert.ToSingle(penWidth * _resolution));

        pen.EndCap   = System.Drawing.Drawing2D.LineCap.Square;
        pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
        Pen bufferPen = new Pen(color, Convert.ToSingle(5 * _resolution));

        bufferPen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
        bufferPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;

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

        // draw each shape in the table

        foreach (DataRow row in table.Rows)
        {
            switch (geometryType)
            {
            case OgcGeometryType.Point:
                IPoint point = (IPoint)row[layer.GeometryField.Name];
                DrawPoint(imageGraphics, point, brush, dot);
                break;

            case OgcGeometryType.MultiPoint:
                IMultiPoint multiPoint = (IMultiPoint)row[layer.GeometryField.Name];
                DrawPoint(imageGraphics, (IPoint)multiPoint[0], brush, dot);
                break;

            case OgcGeometryType.MultiLineString:
                DrawMultiLineString(imageGraphics, (IMultiLineString)row[layer.GeometryField.Name], pen);
                break;

            case OgcGeometryType.MultiPolygon:
                if (drawPolygonOutlines)
                {
                    DrawMultiPolygon(imageGraphics, (IMultiPolygon)row[layer.GeometryField.Name], null, null, pen);
                }
                else
                {
                    DrawMultiPolygon(imageGraphics, (IMultiPolygon)row[layer.GeometryField.Name], brush, bufferPen);
                }

                break;
            }
        }

        // draw the temporary image containing the highlight graphics on the output image at
        // the specified opacity

        float[][] matrixItems =
        {
            new float[] { 1, 0, 0,                         0, 0 },
            new float[] { 0, 1, 0,                         0, 0 },
            new float[] { 0, 0, 1,                         0, 0 },
            new float[] { 0, 0, 0, Convert.ToSingle(opacity), 0 },
            new float[] { 0, 0, 0,                         0, 1 }
        };

        ColorMatrix colorMatrix = new ColorMatrix(matrixItems);

        ImageAttributes imageAtts = new ImageAttributes();

        imageAtts.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

        Rectangle drawRect = new Rectangle(0, 0, width, height);

        graphics.DrawImage(bitMap, drawRect, 0, 0, width, height, GraphicsUnit.Pixel, imageAtts);
    }
Example #12
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 #13
0
    private void AddLayerToLegend(string mapTabId, List <CommonLayer> configuredLayers, List <LayerProperties> layerProperties, HtmlGenericControl container, CommonLayer layer)
    {
        int i = configuredLayers.IndexOf(layer);

        if (i < 0)
        {
            return;
        }

        int  tileWidth  = AppContext.AppSettings.SwatchTileWidth;
        int  tileHeight = AppContext.AppSettings.SwatchTileHeight;
        bool expanded   = AppContext.AppSettings.LegendExpanded;

        HtmlGenericControl legendEntry = new HtmlGenericControl("div");

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

        HtmlGenericControl legendHeader = new HtmlGenericControl("div");

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

        HtmlGenericControl expander = new HtmlGenericControl("span");

        legendHeader.Controls.Add(expander);

        if (layerProperties[i].CheckMode != CheckMode.None)
        {
            HtmlGenericControl visibility = new HtmlGenericControl("span");
            legendHeader.Controls.Add(visibility);
            visibility.Attributes["class"] = "LegendVisibility";

            if (layerProperties[i].CheckMode != CheckMode.Empty)
            {
                HtmlControl check       = null;
                bool        itemChecked = false;

                if (layerProperties[i].IsExclusive)
                {
                    HtmlInputRadioButton radio = new HtmlInputRadioButton();
                    radio.Checked = itemChecked = layerProperties[i].CheckMode == CheckMode.Checked;
                    radio.Name    = String.Format("{0}_{1}", mapTabId, layer.Parent.ID);
                    check         = radio;
                }
                else
                {
                    HtmlInputCheckBox checkBox = new HtmlInputCheckBox();
                    checkBox.Checked = itemChecked = layerProperties[i].CheckMode == CheckMode.Checked;
                    check            = checkBox;
                }

                visibility.Controls.Add(check);
                check.Attributes["class"]      = "LegendCheck";
                check.Attributes["data-layer"] = layerProperties[i].Tag;
                expanded = expanded && itemChecked;
                expander.Attributes["class"] = "LegendExpander " + (expanded ? "Expanded" : "Collapsed");
            }
        }

        HtmlGenericControl name = new HtmlGenericControl("span");

        legendHeader.Controls.Add(name);
        name.Attributes["class"] = "LegendName";

        if (!String.IsNullOrEmpty(layerProperties[i].MetaDataUrl))
        {
            HtmlAnchor a = new HtmlAnchor();
            name.Controls.Add(a);
            a.HRef                = layerProperties[i].MetaDataUrl;
            a.Target              = "metadata";
            a.InnerText           = layerProperties[i].Name;
            a.Attributes["class"] = "LegendMetadata";
        }
        else
        {
            name.InnerText = layerProperties[i].Name;
        }

        HtmlGenericControl content = new HtmlGenericControl("div");

        content.Attributes["class"] = "LegendContent";
        content.Style["display"]    = expanded ? "block" : "none";

        switch (layer.Type)
        {
        case CommonLayerType.Group:
            if (layer.Children != null)
            {
                foreach (CommonLayer childLayer in layer.Children)
                {
                    AddLayerToLegend(mapTabId, configuredLayers, layerProperties, content, childLayer);
                }
            }
            break;

        case CommonLayerType.Feature:
            int layerIndex = layer.DataFrame.Layers.IndexOf(layer);

            if (layer.Legend != null)
            {
                int    n = 0;
                string escapedMapTabId = Server.UrlEncode(mapTabId);

                for (int g = 0; g < layer.Legend.Groups.Count; ++g)
                {
                    int classCount = layer.Legend.Groups[g].Classes.Count;

                    for (int c = 0; c < classCount; ++c)
                    {
                        if (!layer.Legend.Groups[g].Classes[c].ImageIsTransparent)
                        {
                            HtmlGenericControl legendClass = new HtmlGenericControl("div");
                            content.Controls.Add(legendClass);
                            legendClass.Attributes["class"] = "LegendClass";

                            HtmlGenericControl legendSwatch = new HtmlGenericControl("span");
                            legendClass.Controls.Add(legendSwatch);
                            legendSwatch.Attributes["class"] = "LegendSwatch";
                            legendSwatch.Style["background"] = String.Format("transparent url(CompiledSwatch.ashx?maptab={0}&c={1}) no-repeat scroll -{2}px -{3}px",
                                                                             escapedMapTabId, AppContext.ConfigurationKey, tileWidth * layerIndex, tileHeight * n);

                            using (MemoryStream stream = new MemoryStream(layer.Legend.Groups[g].Classes[c].Image))
                            {
                                using (Bitmap swatch = new Bitmap(stream))
                                {
                                    legendClass.Style["height"]  = String.Format("{0}px", swatch.Height);
                                    legendSwatch.Style["width"]  = String.Format("{0}px", swatch.Width);
                                    legendSwatch.Style["height"] = String.Format("{0}px", swatch.Height);
                                }
                            }

                            if (classCount > 1 || layer.Legend.Groups.Count > 1)
                            {
                                HtmlGenericControl className = new HtmlGenericControl("span");
                                legendClass.Controls.Add(className);
                                className.Attributes["class"] = "LegendClassName";
                                className.InnerText           = layer.Legend.Groups[g].Classes[c].Label;
                            }
                        }

                        n += 1;
                    }
                }
            }
            break;

        case CommonLayerType.Annotation:
            if (layer.Children != null)
            {
                foreach (CommonLayer childLayer in layer.Children)
                {
                    AddLayerToLegend(mapTabId, configuredLayers, layerProperties, content, childLayer);
                }
            }
            break;
        }

        if (content.Controls.Count == 0)
        {
            expander.Attributes["class"] = "LegendExpander Empty";
        }
        else
        {
            legendEntry.Controls.Add(content);
        }
    }
Example #14
0
  private void AddLayerToLegend(string mapTabId, List<CommonLayer> configuredLayers, List<LayerProperties> layerProperties, HtmlGenericControl container, CommonLayer layer)
  {
    int i = configuredLayers.IndexOf(layer);

    if (i < 0)
    {
      return;
    }

    int tileWidth = AppSettings.SwatchTileWidth;
    int tileHeight = AppSettings.SwatchTileHeight;
    bool expanded = AppSettings.LegendExpanded;

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

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

    HtmlGenericControl expander = new HtmlGenericControl("span");
    legendHeader.Controls.Add(expander);
    expander.Attributes["class"] = "LegendExpander " + (expanded ? "Expanded" : "Collapsed");

    if (layerProperties[i].CheckMode != CheckMode.None)
    {
      HtmlGenericControl visibility = new HtmlGenericControl("span");
      legendHeader.Controls.Add(visibility);
      visibility.Attributes["class"] = "LegendVisibility";

      if (layerProperties[i].CheckMode != CheckMode.Empty)
      {
        HtmlControl check = null;

        if (layerProperties[i].IsExclusive)
        {
          HtmlInputRadioButton radio = new HtmlInputRadioButton();
          radio.Checked = layerProperties[i].CheckMode == CheckMode.Checked;
          radio.Name = String.Format("{0}_{1}", mapTabId, layer.Parent.ID);
          check = radio;
        }
        else
        {
          HtmlInputCheckBox checkBox = new HtmlInputCheckBox();
          checkBox.Checked = layerProperties[i].CheckMode == CheckMode.Checked;
          check = checkBox;
        }

        visibility.Controls.Add(check);
        check.Attributes["class"] = "LegendCheck";
        check.Attributes["data-layer"] = layerProperties[i].Tag;
      }
    }

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

    if (!String.IsNullOrEmpty(layerProperties[i].MetaDataUrl))
    {
      HtmlAnchor a = new HtmlAnchor();
      name.Controls.Add(a);
      a.HRef = layerProperties[i].MetaDataUrl;
      a.Target = "metadata";
      a.InnerText = layerProperties[i].Name;
      a.Attributes["class"] = "LegendMetadata";
    }
    else
    {
      name.InnerText = layerProperties[i].Name;
    }

    HtmlGenericControl content = new HtmlGenericControl("div");
    content.Attributes["class"] = "LegendContent";
    content.Style["display"] = expanded ? "block" : "none";

    switch (layer.Type)
    {
      case CommonLayerType.Group:
        if (layer.Children != null)
        {
          foreach (CommonLayer childLayer in layer.Children)
          {
            AddLayerToLegend(mapTabId, configuredLayers, layerProperties, content, childLayer);
          }
        }
        break;

      case CommonLayerType.Feature:
        int layerIndex = layer.DataFrame.Layers.IndexOf(layer);

        if (layer.Legend != null)
        {
          int n = 0;
          string escapedMapTabId = Server.UrlEncode(mapTabId);

          for (int g = 0; g < layer.Legend.Groups.Count; ++g)
          {
            int classCount = layer.Legend.Groups[g].Classes.Count;

            for (int c = 0; c < classCount; ++c)
            {
              if (!layer.Legend.Groups[g].Classes[c].ImageIsTransparent)
              {
                HtmlGenericControl legendClass = new HtmlGenericControl("div");
                content.Controls.Add(legendClass);
                legendClass.Attributes["class"] = "LegendClass";

                HtmlGenericControl legendSwatch = new HtmlGenericControl("span");
                legendClass.Controls.Add(legendSwatch);
                legendSwatch.Attributes["class"] = "LegendSwatch";
                legendSwatch.Style["background"] = String.Format("transparent url(CompiledSwatch.ashx?maptab={0}&c={1}) no-repeat scroll -{2}px -{3}px",
                  escapedMapTabId, AppContext.ConfigurationKey, tileWidth * layerIndex, tileHeight * n);

                using (MemoryStream stream = new MemoryStream(layer.Legend.Groups[g].Classes[c].Image))
                {
                  using (Bitmap swatch = new Bitmap(stream))
                  {
                    legendClass.Style["height"] = String.Format("{0}px", swatch.Height);
                    legendSwatch.Style["width"] = String.Format("{0}px", swatch.Width);
                    legendSwatch.Style["height"] = String.Format("{0}px", swatch.Height);
                  }
                }

                if (classCount > 1 || layer.Legend.Groups.Count > 1)
                {
                  HtmlGenericControl className = new HtmlGenericControl("span");
                  legendClass.Controls.Add(className);
                  className.Attributes["class"] = "LegendClassName";
                  className.InnerText = layer.Legend.Groups[g].Classes[c].Label;
                }
              }

              n += 1;
            }
          }
        }
        break;

      case CommonLayerType.Annotation:
        if (layer.Children != null)
        {
          foreach (CommonLayer childLayer in layer.Children)
          {
            AddLayerToLegend(mapTabId, configuredLayers, layerProperties, content, childLayer);
          }
        }
        break;
    }

    if (content.Controls.Count == 0)
    {
      expander.Attributes["class"] = "LegendExpander Empty";
    }
    else
    {
      legendEntry.Controls.Add(content);
    }
  }
Example #15
0
 private string GetQuery(FeatureType featureType, Configuration.LayerRow layerRow, CommonLayer layer)
 {
     return(GetQuery(featureType, layerRow, layer, true));
 }
Example #16
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 #17
0
        private Map GenerateVillages(int amount, CommonLayer.Map map, int width, int height)
        {
            Random r = new Random();

            int _nameCounter = 65;

            for (int i = 0; i < amount; i++)
            {
                //Temp Values
                int _CurX = r.Next(width);
                int _CurY = r.Next(height);
                string name = "" + Convert.ToChar(_nameCounter);

                //Create new Village
                Village v = new Village();
                v.ID = Guid.NewGuid();
                v.Name = name;
                v.XCoor = _CurX;
                v.YCoor = _CurY;

                v.MapID = map.ID;

                //Add new Village to Map
                map.Village.Add(v);

                //Add plus one to the counter
                _nameCounter++;
            }

            return map;
        }
Example #18
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 #19
0
 public static CommonField FindField(this CommonLayer layer, string name)
 {
     return(layer.Fields.FirstOrDefault(f => String.Compare(f.Name, name, true) == 0 ||
                                        String.Compare(f.Alias, name, true) == 0 ||
                                        f.Name.EndsWith("." + name, StringComparison.CurrentCultureIgnoreCase)));
 }
Example #20
0
    private void SelectFeatures()
    {
        AppState appState  = AppState.FromJson(Request.Form["state"]);
        bool     updated   = false;
        bool     truncated = false;

        if (Request.Form["geo"] == null)
        {
            appState.SelectionManager.SelectTargets();
            updated = true;
        }
        else
        {
            double[] geo = Request.Form["geo"].Split(',').Select(o => Convert.ToDouble(o)).ToArray();

            CommonDataFrame        dataFrame   = AppContext.GetDataFrame(appState.MapTab);
            Configuration.LayerRow layer       = Configuration.Layer.First(o => o.LayerID == (appState.Action == Action.Select ? appState.TargetLayer : appState.SelectionLayer));
            CommonLayer            commonLayer = dataFrame.Layers.FirstOrDefault(o => String.Compare(o.Name, layer.LayerName, true) == 0);
            CommonField            keyField    = commonLayer.FindField(layer.KeyField);

            string levelQuery = layer.GetLevelQuery(commonLayer, appState.Level);

            DataTable table = null;

            if (geo.Length == 4)
            {
                Envelope box = EnvelopeExtensions.FromArray(geo);

                if (!layer.IsMaxSelectionAreaNull() && layer.MaxSelectionArea > 0 && box.Width * box.Height > layer.MaxSelectionArea)
                {
                    throw new AppException("The selection shape was too large; try again with a smaller shape");
                }

                table = commonLayer.GetFeatureTable(keyField.Name, levelQuery, box.ToPolygon());
            }
            else
            {
                table = commonLayer.GetFeatureTable(keyField.Name, levelQuery, geo[0], geo[1], geo[2]);
            }

            UpdateMode mode = (UpdateMode)Enum.Parse(typeof(UpdateMode), Request.Form["mode"], true);

            if (table != null && table.Rows.Count > 0)
            {
                if (appState.Action == Action.Select)
                {
                    updated = UpdateIds(appState.TargetIds, table, mode);

                    if (!layer.IsMaxNumberSelectedNull())
                    {
                        truncated = appState.TargetIds.Truncate(layer.MaxNumberSelected);
                    }

                    if (mode != UpdateMode.Remove && table.Rows.Count == 1)
                    {
                        updated = UpdateActive(appState, table.Rows[0][0].ToString()) || updated;
                    }
                }
                else
                {
                    updated = UpdateIds(appState.SelectionIds, table, mode);

                    if (!layer.IsMaxNumberSelectedNull())
                    {
                        appState.SelectionIds.Truncate(layer.MaxNumberSelected);
                    }

                    if (updated)
                    {
                        truncated = appState.SelectionManager.SelectTargets();
                    }
                }
            }
            else if (mode == UpdateMode.New)
            {
                updated = appState.Action == Action.Select ? appState.TargetIds.Count > 0 : appState.SelectionIds.Count > 0;
                appState.TargetIds.Clear();
                appState.SelectionIds.Clear();
                appState.ActiveMapId  = "";
                appState.ActiveDataId = "";
            }
        }

        if (!updated)
        {
            ReturnJson(null);
        }

        if (!appState.TargetIds.Contains(appState.ActiveMapId))
        {
            appState.ActiveMapId  = "";
            appState.ActiveDataId = "";
        }

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

        state.Add("ActiveMapId", appState.ActiveMapId);
        state.Add("ActiveDataId", appState.ActiveDataId);
        state.Add("TargetIds", appState.TargetIds);
        state.Add("SelectionIds", appState.SelectionIds);

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

        result.Add("state", state);
        result.Add("truncated", truncated);
        ReturnJson(result);
    }
Example #21
0
 public override void AddLayer(CommonLayer layer)
 {
     AddLayer(layer, "");
 }
Example #22
0
 private string GetQuery(FeatureType featureType, Configuration.LayerRow layerRow, CommonLayer layer)
 {
   return GetQuery(featureType, layerRow, layer, true);
 }
Example #23
0
  private int GetNumClasses(CommonLayer layer)
  {
    int numClasses = 0;
    CommonLegend legend = layer.Legend;

    if (legend != null)
    {
      for (int g = 0; g < legend.Groups.Count; ++g)
      {
        for (int c = 0; c < legend.Groups[g].Classes.Count; ++c)
        {
          if (!legend.Groups[g].Classes[c].ImageIsTransparent)
          {
            ++numClasses;
          }
        }
      }
    }

    return numClasses;
  }
Example #24
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 #25
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 #26
0
    private float GetLayerHeightInLegend(List <CommonLayer> layerList, LegendProperties properties, CommonLayer layer)
    {
        float height = 0;

        if (layer.Type == CommonLayerType.Group)
        {
            height = properties.FontSize + properties.LayerSpacing;

            foreach (CommonLayer childLayer in layer.Children)
            {
                if (layerList.Contains(childLayer))
                {
                    height += GetLayerHeightInLegend(layerList, properties, childLayer);
                    break;
                }
            }
        }
        else
        {
            int numClasses = GetNumClasses(layer);

            if (numClasses > 1)
            {
                height = properties.FontSize + properties.ClassSpacing;
            }

            height += numClasses * (properties.SwatchHeight + properties.ClassSpacing) - properties.ClassSpacing;
        }

        return(height);
    }
Example #27
0
  private float GetLayerHeightInLegend(List<CommonLayer> layerList, LegendProperties properties, CommonLayer layer)
  {
    float height = 0;

    if (layer.Type == CommonLayerType.Group)
    {
      height = properties.FontSize + properties.LayerSpacing;

      foreach (CommonLayer childLayer in layer.Children)
      {
        if (layerList.Contains(childLayer))
        {
          height += GetLayerHeightInLegend(layerList, properties, childLayer);
          break;
        }
      }
    }
    else
    {
      int numClasses = GetNumClasses(layer);

      if (numClasses > 1)
      {
        height = properties.FontSize + properties.ClassSpacing;
      }

      height += numClasses * (properties.SwatchHeight + properties.ClassSpacing) - properties.ClassSpacing;
    }

    return height;
  }
Example #28
0
  private string GetQuery(FeatureType featureType, Configuration.LayerRow layerRow, CommonLayer layer, bool inSet)
  {
    StringCollection ids = GetIds(featureType);

    if (ids.Count == 0)
    {
      return null;
    }

    CommonField keyField = layer.FindField(layerRow.KeyField);
    string joinedIds = keyField.IsNumeric ? ids.Join(",") : String.Format("'{0}'", ids.Join("','"));
    return String.Format("{0} {1} ({2})", keyField.Name, inSet ? "in" : "not in", joinedIds);
  }
Example #29
0
    public bool SelectTargets()
    {
        if (String.IsNullOrEmpty(_appState.TargetLayer) || String.IsNullOrEmpty(_appState.SelectionLayer))
        {
            return(false);
        }

        _appState.TargetIds.Clear();

        if (_appState.SelectionIds.Count == 0)
        {
            return(false);
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.LayerRow targetLayerRow = config.Layer.FindByLayerID(_appState.TargetLayer);

        CommonDataFrame dataFrame   = AppContext.GetDataFrame(_appState.MapTab);
        CommonLayer     targetLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, targetLayerRow.LayerName, true) == 0);
        CommonField     keyField    = targetLayer.FindField(targetLayerRow.KeyField);

        DataTable targetTable = null;
        string    filter      = "";
        string    sort        = "";
        bool      truncated   = false;

        IGeometry selectionShape;

        switch (_appState.Action)
        {
        case Action.FindAllWithin:
            Configuration.ProximityRow proximity = config.Proximity.FindByProximityID(_appState.Proximity);

            targetTable = GetFeatures(FeatureType.Selection);

            if (targetTable.Rows.Count > 0)
            {
                selectionShape = MergeShapes(targetTable);

                if (proximity.Distance > 0)
                {
                    selectionShape = selectionShape.Buffer(proximity.Distance);
                }

                targetTable = targetLayer.GetFeatureTable(String.Format("{0},{1}", targetLayer.GeometryField.Name, keyField.Name), selectionShape);
            }
            break;

        case Action.FindNearest1:
        case Action.FindNearest2:
        case Action.FindNearest3:
        case Action.FindNearest4:
        case Action.FindNearest5:
            Envelope extent = config.Application.FindByApplicationID(_appState.Application).GetFullExtentEnvelope();

            double minDist = targetLayerRow.IsMinNearestDistanceNull() ? 100 : targetLayerRow.MinNearestDistance;
            double maxDist = targetLayerRow.IsMaxNearestDistanceNull() ? Math.Max(extent.Width, extent.Height) : targetLayerRow.MaxNearestDistance;
            int    count   = Convert.ToInt32(Enum.GetName(typeof(Action), _appState.Action).Substring(11));

            targetTable = GetFeatures(FeatureType.Selection);

            if (targetTable.Rows.Count > 0)
            {
                selectionShape = MergeShapes(targetTable);

                double distance = minDist;

                do
                {
                    targetTable = targetLayer.GetFeatureTable(String.Format("{0},{1}", targetLayer.GeometryField.Name, keyField.Name), selectionShape.Buffer(distance));
                    distance   *= 1.414213562;
                }while ((targetTable == null || targetTable.Rows.Count < count) && distance < maxDist);

                if (targetTable != null)
                {
                    targetTable.Columns.Add("Distance", typeof(double));
                    targetTable.Columns.Add("Index", typeof(int));
                    filter = "Index <= " + count.ToString();
                    sort   = "Index";

                    DataColumn targetShapeColumn    = targetTable.Columns.Cast <DataColumn>().First(c => c.DataType.IsSubclassOf(typeof(Geometry)));
                    int        targetDistanceColumn = targetTable.Columns.IndexOf("Distance");

                    DataTable  selectionTable       = GetFeatures(FeatureType.Selection);
                    DataColumn selectionShapeColumn = selectionTable.Columns.Cast <DataColumn>().First(c => c.DataType.IsSubclassOf(typeof(Geometry)));

                    foreach (DataRow selectionRow in selectionTable.Rows)
                    {
                        selectionShape = (Geometry)selectionRow[selectionShapeColumn];

                        foreach (DataRow targetRow in targetTable.Rows)
                        {
                            double d = selectionShape.Distance((Geometry)targetRow[targetShapeColumn]);

                            if (targetRow.IsNull(targetDistanceColumn))
                            {
                                targetRow[targetDistanceColumn] = d;
                            }
                            else
                            {
                                targetRow[targetDistanceColumn] = Math.Min((double)targetRow[targetDistanceColumn], d);
                            }
                        }
                    }

                    DataRow[] targetRows = targetTable.Select("", "Distance");

                    for (int i = 0; i < targetRows.Length; ++i)
                    {
                        targetRows[i]["Index"] = i + 1;
                    }
                }
            }
            break;
        }

        if (targetTable != null)
        {
            int maxTargets = targetLayerRow.IsMaxNumberSelectedNull() ? Int32.MaxValue : targetLayerRow.MaxNumberSelected;
            int c          = targetTable.Columns.IndexOf(keyField.Name);

            foreach (DataRow row in targetTable.Select(filter, sort))
            {
                if (!row.IsNull(c))
                {
                    if (_appState.TargetIds.Count == maxTargets)
                    {
                        truncated = true;
                        break;
                    }

                    _appState.TargetIds.Add(row[c].ToString());
                }
            }
        }

        return(truncated);
    }