Пример #1
0
        /// <summary>
        /// Update the list item according to a modified style
        /// </summary>
        /// <param name="index">the index of the lit item</param>
        /// <param name="style">the style object</param>
        private void UpdateStyleInList(int index)
        {
            layerObj layer;

            if (target.GetParent().GetType() == typeof(scalebarObj))
            {
                layer = new layerObj(null);
            }
            else
            {
                layer = target.GetParent().GetParent();
            }

            ListViewItem item  = listViewStyles.Items[index];
            styleObj     style = (styleObj)item.Tag;

            classObj styleclass = new classObj(null);

            styleclass.insertStyle(style, -1);
            // creating the list icon
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(map, layer, 30, 20))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        // modify the layer type in certain cases for drawing correct images
                        string geomtransform = style.getGeomTransform().ToLower();
                        if (geomtransform != null)
                        {
                            if (geomtransform.Contains("labelpoly"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            }
                            else if (geomtransform.Contains("labelpnt"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            }
                        }
                        styleclass.drawLegendIcon(map, layer, 20, 10, image2, 5, 5);
                    }
                    finally
                    {
                        layer.type = type;
                    }

                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images[item.ImageIndex] = Image.FromStream(ms);
                    }


                    item.SubItems[1].Text = style.size.ToString();
                    item.SubItems[2].Text = style.width.ToString();
                    item.SubItems[3].Text = style.symbolname;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Update the preview according to the changes
        /// </summary>
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                               map, layer, pictureBoxPreview.Width, pictureBoxPreview.Height))
                    {
                        styleclass.drawLegendIcon(map, layer,
                                                  pictureBoxPreview.Width - 10, pictureBoxPreview.Height - 10, image2, 4, 4);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxPreview.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            else
            {
                pictureBoxPreview.Image = null;
            }
        }
Пример #3
0
        private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name)
        {
            ListViewItem item       = null;
            classObj     styleclass = new classObj(null);

            styleclass.insertStyle(classStyle, -1);
            mapObj map2 = map;

            if (layer.map != null)
            {
                map2 = layer.map;
            }
            // creating the listicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                           map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview
                        //// modify the layer type in certain cases for drawing correct images
                        //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                        //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                        //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt"))
                        //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                        styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2);
                    }
                    finally
                    {
                        layer.type = type;
                    }
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    // add new item
                    item             = new ListViewItem(name, imageList.Images.Count - 1);
                    item.ToolTipText = name;
                    item.Tag         = classStyle;
                    listView.Items.Add(item);
                }
            }
            return(item);
        }
Пример #4
0
        /// <summary>
        /// Export a legend image with specific requirements (bug 1015)
        /// </summary>
        /// <param name="map">The map object</param>
        /// <param name="width">The desired legend width</param>
        /// <param name="height">The desired legend height</param>
        /// <returns></returns>
        public static byte[] ExportLegend(mapObj map)
        {
            int      width  = 10;
            int      height = 10;
            Bitmap   bmp    = null;
            Graphics g      = null;

            for (int phase = 0; phase < 2; phase++)
            {
                if (phase == 0)
                {
                    bmp = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                }
                else
                {
                    bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                }

                g = Graphics.FromImage(bmp);

                Stack groupPositions = new Stack();              // for storing the group text positions

                Font legendFont = new Font("MS Sans Sherif", 8); // set default font

                g.Clear(Color.White);                            // clear the background

                int xPos    = 5;                                 // padding
                int yPos    = 5;
                int xOffset = 24;                                // legend indent in pixels
                int yOffset = 18;                                // item height in pixels

                // force the recalculation of the current scale
                map.setExtent(map.extent.minx, map.extent.miny, map.extent.maxx, map.extent.maxy);

                // start drawing the legend in reverse layer order
                using (intarray ar = map.getLayersDrawingOrder())
                {
                    for (int i = map.numlayers - 1; i >= 0; i--)
                    {
                        layerObj layer = map.getLayer(ar.getitem(i));

                        if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend" ||
                            layer.status == mapscript.MS_OFF || layer.name.StartsWith("~"))
                        {
                            continue;
                        }


                        if (map.scaledenom > 0)
                        {
                            if (layer.maxscaledenom > 0 && map.scaledenom > layer.maxscaledenom)
                            {
                                continue;
                            }
                            if (layer.minscaledenom > 0 && map.scaledenom <= layer.minscaledenom)
                            {
                                continue;
                            }
                        }

                        if (layer.maxscaledenom <= 0 && layer.minscaledenom <= 0)
                        {
                            if (layer.maxgeowidth > 0 && ((map.extent.maxx - map.extent.minx) > layer.maxgeowidth))
                            {
                                continue;
                            }
                            if (layer.mingeowidth > 0 && ((map.extent.maxx - map.extent.minx) < layer.mingeowidth))
                            {
                                continue;
                            }
                        }

                        // draw raster or WMS layers
                        if (layer.type == MS_LAYER_TYPE.MS_LAYER_RASTER)
                        {
                            if (phase == 1)
                            {
                                g.DrawIcon(global::MapLibrary.Properties.Resources.raster, xPos, yPos);
                                g.DrawString(layer.name, legendFont, Brushes.Black, xPos + 30, yPos + 2);
                            }

                            SizeF size = g.MeasureString(layer.name, legendFont);
                            if (xPos + 30 + size.Width + 5 > width)
                            {
                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                            }

                            yPos += yOffset;
                            continue;
                        }

                        int    numClasses  = 0;
                        Image  legendImage = null;
                        string legendText  = null;

                        for (int j = 0; j < layer.numclasses; j++)
                        {
                            classObj layerclass = layer.getClass(j);

                            if (layerclass.name == "EntireSelection" || layerclass.name == "CurrentSelection")
                            {
                                continue;
                            }

                            if (layerclass.status == mapscript.MS_OFF)
                            {
                                continue;
                            }

                            if (map.scaledenom > 0)
                            {  /* verify class scale here */
                                if (layerclass.maxscaledenom > 0 && (map.scaledenom > layerclass.maxscaledenom))
                                {
                                    continue;
                                }
                                if (layerclass.minscaledenom > 0 && (map.scaledenom <= layerclass.minscaledenom))
                                {
                                    continue;
                                }
                            }

                            if (numClasses == 1)
                            {
                                // draw subclasses
                                xPos += xOffset;

                                if (phase == 1)
                                {
                                    // drawing the first class item (same as the layer)
                                    g.DrawImage(legendImage, xPos, yPos);
                                    g.DrawString(legendText, legendFont,
                                                 Brushes.Black, xPos + 30, yPos + 2);
                                }

                                SizeF size = g.MeasureString(legendText, legendFont);
                                if (xPos + 30 + size.Width + 5 > width)
                                {
                                    width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                }

                                yPos += yOffset;
                            }

                            ++numClasses; // number of visible classes

                            // creating the treeicons
                            using (classObj def_class = new classObj(null)) // for drawing legend images
                            {
                                using (imageObj image = def_class.createLegendIcon(map, layer, 30, 20))
                                {
                                    // drawing the class icons
                                    layerclass.drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                    byte[] img = image.getBytes();
                                    using (MemoryStream ms = new MemoryStream(img))
                                    {
                                        legendImage = Image.FromStream(ms);
                                        legendText  = layerclass.name;

                                        if (phase == 1)
                                        {
                                            g.DrawImage(legendImage, xPos, yPos);
                                        }
                                        if (numClasses > 1)
                                        {
                                            // draw the class item
                                            if (phase == 1)
                                            {
                                                g.DrawString(layerclass.name, legendFont,
                                                             Brushes.Black, xPos + 30, yPos + 3);
                                            }

                                            SizeF size = g.MeasureString(layerclass.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                            {
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                            }
                                        }
                                        else
                                        {
                                            // draw the layer item
                                            if (phase == 1)
                                            {
                                                g.DrawString(layer.name, legendFont,
                                                             Brushes.Black, xPos + 30, yPos + 3);
                                            }

                                            SizeF size = g.MeasureString(layer.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                            {
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                            }

                                            if (string.Compare(layer.styleitem, "AUTO", true) == 0)
                                            {
                                                yPos += yOffset;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            yPos += yOffset;
                        }

                        if (numClasses > 1)
                        {
                            xPos -= xOffset;
                        }
                    }
                }
                height = yPos + 5;
            }

            g.Flush();
            MemoryStream ms2 = new MemoryStream();

            bmp.Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
            return(ms2.ToArray());
        }
Пример #5
0
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                // apply current settings (opacity) to colors
                colorPickerColor.SetColor(pstyle.color);
                colorPickerBackColor.SetColor(pstyle.backgroundcolor);
                colorPickerOutlineColor.SetColor(pstyle.outlinecolor);

                // select the proper map containing symbols
                mapObj stylemap = map;
                if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default")
                {
                    if (comboBoxCategory.Text != "Inline Symbols")
                        stylemap = StyleLibrary.Styles;
                    styleObj classStyle = (styleObj)listView.SelectedItems[0].Tag;
                    pstyle.setSymbolByName(stylemap, classStyle.symbolname);
                }
                else
                {
                    pstyle.symbol = 0;
                    pstyle.symbolname = null;
                }

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                                     stylemap, layer, pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        MS_LAYER_TYPE type = layer.type;
                        try
                        {
                            // modify the layer type in certain cases for drawing correct images
                            if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt") || comboBoxGeomTransform.Text.ToLower().Contains("centroid"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                            styleclass.drawLegendIcon(stylemap, layer,
                            pictureBoxSample.Width - 10, pictureBoxSample.Height - 10, image2, 4, 4);
                        }
                        finally
                        {
                            layer.type = type;
                        }

                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
        }
Пример #6
0
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                // apply current settings (opacity) to colors
                colorPickerColor.SetColor(pstyle.color);
                colorPickerBackColor.SetColor(pstyle.backgroundcolor);
                colorPickerOutlineColor.SetColor(pstyle.outlinecolor);

                // select the proper map containing symbols
                mapObj stylemap = map;
                if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default")
                {
                    if (comboBoxCategory.Text != "Inline Symbols")
                    {
                        stylemap = StyleLibrary.Styles;
                    }
                    styleObj classStyle = (styleObj)listView.SelectedItems[0].Tag;
                    pstyle.setSymbolByName(stylemap, classStyle.symbolname);
                }
                else
                {
                    pstyle.symbol     = 0;
                    pstyle.symbolname = null;
                }

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                               stylemap, layer, pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        MS_LAYER_TYPE type = layer.type;
                        try
                        {
                            // modify the layer type in certain cases for drawing correct images
                            if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            }
                            else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt") || comboBoxGeomTransform.Text.ToLower().Contains("centroid"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            }

                            styleclass.drawLegendIcon(stylemap, layer,
                                                      pictureBoxSample.Width - 10, pictureBoxSample.Height - 10, image2, 4, 4);
                        }
                        finally
                        {
                            layer.type = type;
                        }

                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
        }
Пример #7
0
        private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name)
        {
            ListViewItem item = null;
            classObj styleclass = new classObj(null);
            styleclass.insertStyle(classStyle, -1);
            mapObj map2 = map;
            if (layer.map != null)
                map2 = layer.map;
            // creating the listicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                 map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview
                        //// modify the layer type in certain cases for drawing correct images
                        //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                            //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                        //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt"))
                            //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                        styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2);
                    }
                    finally
                    {
                        layer.type = type;
                    }
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    // add new item
                    item = new ListViewItem(name, imageList.Images.Count - 1);
                    item.ToolTipText = name;
                    item.Tag = classStyle;
                    listView.Items.Add(item);
                }
            }
            return item;
        }
Пример #8
0
        /// <summary>
        /// Adding a new labelObj to the corresponding classObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="labelHolder">Wrapper class containing the labelObj and the parent object</param>
        /// <param name="imageList">The image list where the label image should be stored.</param>
        /// <param name="index">The current index of the label object.</param>
        private void AddLabelNode(TreeNodeCollection nodes, MapObjectHolder labelHolder, ImageList imageList, int index)
        {
            layerObj layer = labelHolder.GetParent().GetParent();
            classObj layerclass = labelHolder.GetParent();
            labelObj classLabel = labelHolder;

            classObj labelclass = new classObj(null);
            labelclass.name = MapUtils.GetClassName(layer);
            labelclass.addLabel(classLabel);
            // creating the treeicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                map, layer, legendIconSize.Width, legendIconSize.Height))
                {
                    MS_LAYER_TYPE layertype = layer.type;
                    layer.type = MS_LAYER_TYPE.MS_LAYER_ANNOTATION;
                    labelclass.drawLegendIcon(map, layer,
                        legendDrawingSize.Width, legendDrawingSize.Height, image2,
                        LegendIconPadding.Left, LegendIconPadding.Top);
                    layer.type = layertype;
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    TreeNode labelNode = new TreeNode("Label (" + index + ")",
                        imageList.Images.Count - 1, imageList.Images.Count - 1);
                    labelNode.Tag = labelHolder;
                    labelNode.Checked = true;
                    nodes.Add(labelNode);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Adding a new styleObj to the corresponding classObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="styleHolder">Wrapper class containing the styleObj and the parent object</param>
        /// /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param>
        private void AddStyleNode(TreeNodeCollection nodes, MapObjectHolder styleHolder, ImageList imageList)
        {
            layerObj layer = styleHolder.GetParent().GetParent();
            classObj layerclass = styleHolder.GetParent();
            styleObj classStyle = styleHolder;

            classObj styleclass = new classObj(null);
            styleclass.name = MapUtils.GetClassName(layer);
            styleclass.insertStyle(classStyle, -1);
            // creating the treeicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                 map, layer, legendIconSize.Width, legendIconSize.Height))
                {
                    styleclass.drawLegendIcon(map, layer,
                        legendDrawingSize.Width, legendDrawingSize.Height, image2,
                        LegendIconPadding.Left, LegendIconPadding.Top);
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    TreeNode styleNode = new TreeNode("Style (" + nodes.Count + ")",
                        imageList.Images.Count - 1, imageList.Images.Count - 1);
                    styleNode.Tag = styleHolder;
                    styleNode.Checked = true;
                    nodes.Add(styleNode);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Update the list item according to a modified style
        /// </summary>
        /// <param name="index">the index of the lit item</param>
        /// <param name="style">the style object</param>
        private void UpdateStyleInList(int index)
        {
            layerObj layer;
            if (target.GetParent().GetType() == typeof(scalebarObj))
                layer = new layerObj(null);
            else
                layer = target.GetParent().GetParent();

            ListViewItem item = listViewStyles.Items[index];
            styleObj style = (styleObj)item.Tag;

            classObj styleclass = new classObj(null);
            styleclass.insertStyle(style, -1);
            // creating the list icon
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(map, layer, 30, 20))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        // modify the layer type in certain cases for drawing correct images
                        string geomtransform = style.getGeomTransform().ToLower();
                        if (geomtransform != null)
                        {
                            if (geomtransform.Contains("labelpoly"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            else if (geomtransform.Contains("labelpnt"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                        }
                        styleclass.drawLegendIcon(map, layer, 20, 10, image2, 5, 5);
                    }
                    finally
                    {
                        layer.type = type;
                    }

                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images[item.ImageIndex] = Image.FromStream(ms);
                    }

                    item.SubItems[1].Text = style.size.ToString();
                    item.SubItems[2].Text = style.width.ToString();
                    item.SubItems[3].Text = style.symbolname;
                }
            }
        }
        /// <summary>
        /// Update the preview according to the changes
        /// </summary>
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                                     map, layer, pictureBoxPreview.Width, pictureBoxPreview.Height))
                    {
                        styleclass.drawLegendIcon(map, layer,
                            pictureBoxPreview.Width - 10, pictureBoxPreview.Height - 10, image2, 4, 4);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxPreview.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            else
                pictureBoxPreview.Image = null;
        }