Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update the Sample image according to the selected element
        /// </summary>
        /// <param name="target">Selected element</param>
        private void UpdateSample(MapObjectHolder target)
        {
            layerObj layer    = null;
            mapObj   map      = null;
            classObj classobj = null;

            if (target.GetType() == typeof(layerObj))
            {
                layer    = target;
                map      = layer.map;
                classobj = layer.getClass(0);
            }
            else if (target.GetType() == typeof(classObj))
            {
                classobj = target;
                if (classobj != null)
                {
                    layer = classobj.layer;
                }
                if (layer != null)
                {
                    map = layer.map;
                }
            }
            if (map == null || layer == null || classobj == null)
            {
                pictureBoxSample.Image = null;
                return;
            }

            styleObj style = classobj.getStyle(0);
            double   size  = style.size;

            // collect all fonts specified in the fontset file
            Hashtable fonts = new Hashtable();
            string    key   = null;

            while ((key = this.map.fontset.fonts.nextKey(key)) != null)
            {
                fonts.Add(key, key);
            }
            textBoxInfo.Text = "";
            if (style.symbol >= 0)
            {
                string font = ((mapObj)StyleLibrary.Styles).symbolset.getSymbol(style.symbol).font;
                if (font != null && !fonts.ContainsKey(font))
                {
                    textBoxInfo.Text = "WARNING: The fontset of the map doesn't contain " + font + " font. This symbol will not be selectable on the map.";
                }
            }

            if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
            {
                // apply magnification for point styles
                style.size = size * trackBarMagnify.Value / 4;
            }

            try
            {
                using (classObj def_class = new classObj(null)) // for drawing legend image
                {
                    using (imageObj image2 = def_class.createLegendIcon(map, layer,
                                                                        pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        classobj.drawLegendIcon(map, layer,
                                                pictureBoxSample.Width, pictureBoxSample.Height, image2, 5, 5);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            finally
            {
                style.size = size;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            listView.Items.Clear();

            if (map != null)
            {
                // setting up the icon background colors createLegendIcon
                // will take over the legend imagecolor setting from the map object
                int red   = map.legend.imagecolor.red;
                int green = map.legend.imagecolor.green;
                int blue  = map.legend.imagecolor.blue;
                map.legend.imagecolor.red   = this.BackColor.R;
                map.legend.imagecolor.green = this.BackColor.G;
                map.legend.imagecolor.blue  = this.BackColor.B;
                listView.BackColor          = this.BackColor;

                using (outputFormatObj format = map.outputformat)
                {
                    string imageType = null;
                    if ((format.renderer != mapscript.MS_RENDER_WITH_GD &&
                         format.renderer != mapscript.MS_RENDER_WITH_AGG) ||
                        string.Compare(format.mimetype.Trim(), "image/vnd.wap.wbmp", true) == 0 ||
                        string.Compare(format.mimetype.Trim(), "image/tiff", true) == 0 ||
                        string.Compare(format.mimetype.Trim(), "image/jpeg", true) == 0)
                    {
                        // falling back to the png type in case of the esoteric or bad looking types
                        imageType = map.imagetype;
                        map.selectOutputFormat("png24");
                    }

                    imageList.Images.Clear();
                    imageList.ImageSize = new Size(30, 20);

                    try
                    {
                        for (int i = 0; i < map.numlayers; i++)
                        {
                            layerObj layer = map.getLayer(i);
                            if (layer.status != mapscript.MS_OFF)
                            {
                                resultObj res;
                                shapeObj  feature;
                                using (resultCacheObj results = layer.getResults())
                                {
                                    if (results != null && results.numresults > 0)
                                    {
                                        // creating the icon for this layer
                                        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
                                                layer.getClass(0).drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                                byte[] img = image.getBytes();
                                                using (MemoryStream ms = new MemoryStream(img))
                                                {
                                                    imageList.Images.Add(Image.FromStream(ms));
                                                }
                                            }
                                        }

                                        // extracting the features found
                                        for (int j = 0; j < results.numresults; j++)
                                        {
                                            res     = results.getResult(j);
                                            feature = layer.getShape(res);
                                            if (feature != null)
                                            {
                                                ListViewItem item = new ListViewItem(layer.name, imageList.Images.Count - 1);
                                                item.SubItems.Add(feature.index.ToString());
                                                item.SubItems.Add(MapUtils.GetShapeTypeName((MS_SHAPE_TYPE)feature.type));
                                                listView.Items.Add(item);

                                                StringBuilder s = new StringBuilder("");
                                                s.AppendLine("Feature Properties:");
                                                for (int k = 0; k < layer.numitems; k++)
                                                {
                                                    s.Append(layer.getItem(k));
                                                    s.Append(" = ");
                                                    s.AppendLine(feature.getValue(k));
                                                }
                                                item.Tag = s.ToString();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        // switch back to the original type
                        if (imageType != null)
                        {
                            map.selectOutputFormat(imageType);
                        }
                        // restoring the original legend backgroundcolor
                        map.legend.imagecolor.red   = red;
                        map.legend.imagecolor.green = green;
                        map.legend.imagecolor.blue  = blue;
                    }

                    listView.SmallImageList = imageList;
                }
                if (listView.Items.Count > 0)
                {
                    listView.Items[0].Selected = true;
                }
                else
                {
                    richTextBox.Text = "";
                }
            }
        }
Ejemplo n.º 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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            listView.Items.Clear();

            if (map != null)
            {
                // setting up the icon background colors createLegendIcon
                // will take over the legend imagecolor setting from the map object
                int red = map.legend.imagecolor.red;
                int green = map.legend.imagecolor.green;
                int blue = map.legend.imagecolor.blue;
                map.legend.imagecolor.red = this.BackColor.R;
                map.legend.imagecolor.green = this.BackColor.G;
                map.legend.imagecolor.blue = this.BackColor.B;
                listView.BackColor = this.BackColor;

                using (outputFormatObj format = map.outputformat)
                {
                    string imageType = null;
                    if ((format.renderer != mapscript.MS_RENDER_WITH_GD &&
                         format.renderer != mapscript.MS_RENDER_WITH_AGG)
                        || string.Compare(format.mimetype.Trim(), "image/vnd.wap.wbmp", true) == 0
                        || string.Compare(format.mimetype.Trim(), "image/tiff", true) == 0
                        || string.Compare(format.mimetype.Trim(), "image/jpeg", true) == 0)
                    {
                        // falling back to the png type in case of the esoteric or bad looking types
                        imageType = map.imagetype;
                        map.selectOutputFormat("png24");
                    }

                    imageList.Images.Clear();
                    imageList.ImageSize = new Size(30, 20);

                    try
                    {
                        for (int i = 0; i < map.numlayers; i++)
                        {
                            layerObj layer = map.getLayer(i);
                            if (layer.status != mapscript.MS_OFF)
                            {
                                resultObj res;
                                shapeObj feature;
                                using (resultCacheObj results = layer.getResults())
                                {
                                    if (results != null && results.numresults > 0)
                                    {
                                        // creating the icon for this layer
                                        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
                                                layer.getClass(0).drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                                byte[] img = image.getBytes();
                                                using (MemoryStream ms = new MemoryStream(img))
                                                {
                                                    imageList.Images.Add(Image.FromStream(ms));
                                                }
                                            }
                                        }

                                        // extracting the features found
                                        for (int j = 0; j < results.numresults; j++)
                                        {
                                            res = results.getResult(j);
                                            feature = layer.getShape(res);
                                            if (feature != null)
                                            {
                                                ListViewItem item = new ListViewItem(layer.name, imageList.Images.Count - 1);
                                                item.SubItems.Add(feature.index.ToString());
                                                item.SubItems.Add(MapUtils.GetShapeTypeName((MS_SHAPE_TYPE)feature.type));
                                                listView.Items.Add(item);

                                                StringBuilder s = new StringBuilder("");
                                                s.AppendLine("Feature Properties:");
                                                for (int k = 0; k < layer.numitems; k++)
                                                {
                                                    s.Append(layer.getItem(k));
                                                    s.Append(" = ");
                                                    s.AppendLine(feature.getValue(k));
                                                }
                                                item.Tag = s.ToString();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        // switch back to the original type
                        if (imageType != null)
                            map.selectOutputFormat(imageType);
                        // restoring the original legend backgroundcolor
                        map.legend.imagecolor.red = red;
                        map.legend.imagecolor.green = green;
                        map.legend.imagecolor.blue = blue;
                    }

                    listView.SmallImageList = imageList;
                }
                if (listView.Items.Count > 0)
                    listView.Items[0].Selected = true;
                else
                    richTextBox.Text = "";
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// get a csharp image from the ms classobj
        /// </summary>
        /// <param name="msClass"></param>
        /// <param name="imageWidth"></param>
        /// <param name="imageHeight"></param>
        /// <returns></returns>
        private Image GetImageFromClass(classObj msClass,int imageWidth,int imageHeight)
        {
            //return GetImageFromClass(m_pDefaultMap, msClass, imageWidth, imageHeight);

            if (msClass == null) return null;

            if (imageWidth < 8)
                imageWidth = 8;
            if (imageHeight < 8)
                imageHeight = 8;

            imageObj pSymbolImage;
            if(msClass.layer == null)
            {
                pSymbolImage = msClass.createLegendIcon(m_pDefaultMap, m_pCurrentLayer,
                    imageWidth, imageHeight);

            }
            else
            {
                pSymbolImage = msClass.createLegendIcon(msClass.layer.map, msClass.layer,
                    imageWidth, imageHeight);
            }

            byte[] buffer = pSymbolImage.getBytes();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            ms.Write(buffer, 0, buffer.Length);
            Image pImage = Image.FromStream(ms);
            ms.Dispose();
            pSymbolImage.Dispose();

            return pImage;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adding a new classObj to the corresponding layerObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="classHolder">Wrapper class containing the classObj and the parent object</param>
        /// /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param>
        private void AddClassNode(TreeNodeCollection nodes, MapObjectHolder classHolder, ImageList imageList)
        {
            layerObj layer = classHolder.GetParent();
            classObj layerclass = classHolder;

            // creating the treeicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image = def_class.createLegendIcon(
                                map, layer, legendIconSize.Width, legendIconSize.Height))
                {
                    // drawing the class icons
                    layerclass.drawLegendIcon(map, layer,
                        legendDrawingSize.Width, legendDrawingSize.Height, image,
                        LegendIconPadding.Left, LegendIconPadding.Top);
                    byte[] img = image.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    if (!showClasses || string.Compare(layer.styleitem, "AUTO", true) == 0)
                        return;

                    TreeNode classNode = null;
                    if (layer.numclasses > 1 ||
                        (layer.numclasses == 1 && target.GetType() == typeof(layerObj) && showRootObject == false)) // classes should always be shown if the layer is not shown (#7118)
                    {
                        classNode = new TreeNode(layerclass.name, imageList.Images.Count - 1,
                                imageList.Images.Count - 1);
                        classNode.Tag = classHolder;
                        classNode.Checked = (layerclass.status != mapscript.MS_OFF);
                        nodes.Add(classNode);
                        nodes = classNode.Nodes;
                    }

                    // drawing the style icons
                    if (showStyles)
                    {
                        for (int k = 0; k < layerclass.numstyles; k++)
                        {
                            styleObj classStyle = layerclass.getStyle(k);

                            if (layerclass.numstyles > 1)
                            {
                                AddStyleNode(nodes, new MapObjectHolder(classStyle, classHolder), imageList);
                            }
                        }
                    }

                    // drawing the labels icons
                    if (showLabels)
                    {
                        for (int l = 0; l < layerclass.numlabels; l++)
                        {
                            labelObj classLabel = layerclass.getLabel(l);

                            if (layerclass.numlabels > 1)
                            {
                                AddLabelNode(nodes, new MapObjectHolder(classLabel, classHolder), imageList, l);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
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);
                }
            }
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
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;
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Update the Sample image according to the selected element
        /// </summary>
        /// <param name="target">Selected element</param>
        private void UpdateSample(MapObjectHolder target)
        {
            layerObj layer = null;
            mapObj map = null;
            classObj classobj = null;
            if (target.GetType() == typeof(layerObj))
            {
                layer = target;
                map = layer.map;
                classobj = layer.getClass(0);
            }
            else if (target.GetType() == typeof(classObj))
            {
                classobj = target;
                if (classobj != null)
                    layer = classobj.layer;
                if (layer != null)
                    map = layer.map;
            }
            if (map == null || layer == null || classobj == null)
            {
                pictureBoxSample.Image = null;
                return;
            }

            styleObj style = classobj.getStyle(0);
            double size = style.size;

            // collect all fonts specified in the fontset file
            Hashtable fonts = new Hashtable();
            string key = null;
            while ((key = this.map.fontset.fonts.nextKey(key)) != null)
                fonts.Add(key, key);
            textBoxInfo.Text = "";
            if (style.symbol >= 0)
            {
                string font = ((mapObj)StyleLibrary.Styles).symbolset.getSymbol(style.symbol).font;
                if (font != null && !fonts.ContainsKey(font))
                {
                    textBoxInfo.Text = "WARNING: The fontset of the map doesn't contain " + font + " font. This symbol will not be selectable on the map.";
                }
            }

            if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
            {
                // apply magnification for point styles
                style.size = size * trackBarMagnify.Value / 4;
            }

            try
            {
                using (classObj def_class = new classObj(null)) // for drawing legend image
                {
                    using (imageObj image2 = def_class.createLegendIcon(map, layer,
                        pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        classobj.drawLegendIcon(map, layer,
                            pictureBoxSample.Width, pictureBoxSample.Height, image2, 5, 5);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            finally
            {
                style.size = size;
            }
        }
Ejemplo n.º 16
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
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());
        }
        /// <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;
        }