Example #1
0
        /// <summary>
        /// Let the editor to update the modified values to the underlying object.
        /// </summary>
        public void UpdateValues()
        {
            if (map == null)
            {
                return;
            }

            if (listView.SelectedItems.Count > 0)
            {
                styleObj style = target;
                mapObj   map2;
                if (target.GetParent().GetType() == typeof(labelObj))
                {
                    map2 = target.GetParent().GetParent().GetParent().GetParent();
                }
                else
                {
                    map2 = target.GetParent().GetParent().GetParent();
                }
                string symbolName = (string)listView.SelectedItems[0].Tag;
                if (symbolName == "(default)")
                {
                    style.symbol     = 0;
                    style.symbolname = null;
                }
                else
                {
                    style.setSymbolByName(map2, symbolName);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Update the style object according to the current Editor state.
        /// </summary>
        /// <param name="style">The object to be updated.</param>
        private void Update(styleObj style)
        {
            // general tab
            style.size = double.Parse(textBoxSize.Text);
            style.width = double.Parse(textBoxWidth.Text);
            style.angle = double.Parse(textBoxAngle.Text);
            // display tab
            this.colorPickerColor.ApplyTo(style.color);
            this.colorPickerBackColor.ApplyTo(style.backgroundcolor);
            this.colorPickerOutlineColor.ApplyTo(style.outlinecolor);
            
            style.gap = double.Parse(textBoxGap.Text);

            string[] values = textBoxPattern.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length > 0)
            {
                double[] result = new double[values.Length];
                for (int i = 0; i < values.Length; i++)
                    result[i] = double.Parse(values[i], ni);
                style.pattern = result;
            }
            else
                style.patternlength = 0;

            if (comboBoxSymbol.SelectedIndex > 0)
                style.setSymbolByName(map, comboBoxSymbol.SelectedItem.ToString());
            else
            {
                // no symbol selected
                style.symbol = 0;
                style.symbolname = null;
            }
        }
Example #3
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;
            }
        }
Example #4
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;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Click event handler of the buttonEditStyle control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonEditStyle_Click(object sender, EventArgs e)
        {
            if (listViewStyles.SelectedItems.Count == 0)
            {
                return;
            }

            try
            {
                styleObj style = (styleObj)listViewStyles.SelectedItems[0].Tag;

                MapObjectHolder styletarget = new MapObjectHolder(style, target);
                styletarget.PropertyChanged += new EventHandler(styletarget_PropertyChanged);

                //MapPropertyEditorForm stylePropertyEditor = new MapPropertyEditorForm(styletarget);
                //stylePropertyEditor.ShowDialog(this);
                if (this.EditProperties != null)
                {
                    this.EditProperties(this, styletarget);
                }

                isStyleChanged = true;
                UpdatePreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #6
0
 public static void RemoveAllBindings(styleObj style)
 {
     for (int i = 0; i < mapscript.MS_STYLE_BINDING_LENGTH; i++)
     {
         style.removeBinding(i);
     }
 }
Example #7
0
        /// <summary>
        /// SelectedIndexChanged event handler of the listView control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView.SelectedItems.Count > 0)
            {
                //STEPH: only applied the property of the selected style when user click on a style, not when dialog first load to display
                if (!firstLoad)
                {
                    styleObj style = (styleObj)listView.SelectedItems[0].Tag;
                    textBoxPattern.Text = GetPattenString(style.pattern);
                    textBoxGap.Text     = style.gap.ToString();
                    if (style.size < 0) // set default
                    {
                        textBoxSize.Text = "8";
                    }
                    else
                    {
                        textBoxSize.Text = style.size.ToString();
                    }

                    textBoxWidth.Text = style.width.ToString();
                    textBoxAngle.Text = style.angle.ToString();
                }
                //STEPH: reset flag
                firstLoad = false;
            }
            UpdatePreview();
            UpdateEnabledState();
            SetDirty(true);
        }
 internal static HandleRef getCPtrAndSetReference(styleObj obj, object parent) {
   if (obj != null)
   {
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
Example #9
0
 /// <summary>
 /// Create a new classObj with random color setting added to the parent layer.
 /// </summary>
 /// <param name="layer">The parent layer object.</param>
 public static void CreateRandomClass(layerObj layer)
 {
     using (classObj newclass = new classObj(layer))
     {
         newclass.name     = GetClassName(layer);
         newclass.template = "query.html";
         styleObj style = new styleObj(newclass);
         style.size = 8; // set default size (#4339)
         SetDefaultColor(layer.type, style);
     }
 }
Example #10
0
    public void testGetStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj style    = classobj.getStyle(0);

        map = null; layer = null; classobj = null;
        gc();
        assert(style.refcount == 2, "testGetStyleObj");
    }
Example #11
0
        /// <summary>
        /// Click event handler of the buttonAddStyle control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonAddStyle_Click(object sender, EventArgs e)
        {
            styleObj style = new styleObj(null);

            style.setGeomTransform("labelpnt");
            style.color = new colorObj(0, 0, 0, 255);
            style.size  = 8;
            AddStyleToList(style);
            isStyleChanged = true;
            UpdatePreview();
        }
 internal static HandleRef getCPtrAndDisown(styleObj obj, object parent) {
   if (obj != null)
   {
     obj.swigCMemOwn = false;
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
Example #13
0
    public void testGetStyleObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj classobj  = layer.getClass(0);
        styleObj style     = classobj.getStyle(0);
        styleObj reference = classobj.getStyle(0);

        assert(style.refcount == 3, "testGetStyleObjDestroy precondition");
        map = null; layer = null; classobj = null; style = null;
        gc();
        assert(reference.refcount == 2, "testGetStyleObjDestroy");
    }
Example #14
0
    public void testInsertStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, -1);

        assert(newStyle.refcount == 2, "testInsertStyleObj precondition");
        map = null; layer = null; classobj = null;
        gc();
        assert(newStyle.refcount == 2, "testInsertStyleObj");
    }
Example #15
0
    public void testRemoveStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, 0);
        classobj.removeStyle(0);

        map = null; layer = null; classobj = null;
        gc();
        assert(newStyle.refcount == 1, "testRemoveStyleObj");
    }
Example #16
0
    public void testStyleObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj classobj  = layer.getClass(0);
        styleObj newStyle  = new styleObj(classobj);
        styleObj reference = classobj.getStyle(classobj.numstyles - 1);

        assert(newStyle.refcount == 3, "testStyleObjDestroy");
        newStyle.Dispose();         // force the destruction for Mono on Windows because of the constructor overload
        map = null; layer = null; classobj = null; newStyle = null;
        gc();
        assert(reference.refcount == 2, "testStyleObjDestroy");
    }
Example #17
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);
        }
Example #18
0
 /// <summary>
 /// Get default color color.
 /// </summary>
 /// <returns>The default color</returns>
 public static void SetDefaultColor(MS_LAYER_TYPE type, styleObj style)
 {
     // set default color (#4337) to black for line color and white for brush color
     if (type == MS_LAYER_TYPE.MS_LAYER_POLYGON)
     {
         style.color        = new colorObj(255, 255, 255, 255);
         style.outlinecolor = new colorObj(0, 0, 0, 255);
         style.symbol       = 0;
         style.symbolname   = null;
     }
     else
     {
         style.color = new colorObj(0, 0, 0, 255);
     }
 }
Example #19
0
        /// <summary>
        /// Refresh the style list of this label object.
        /// </summary>
        private void RefreshStyles()
        {
            listViewStyles.Items.Clear();
            imageList.ImageSize = new Size(30, 20);

            // populate list in reverse order
            for (int i = label.numstyles - 1; i >= 0; --i)
            {
                styleObj style = label.getStyle(i).clone();
                AddStyleToList(style);
            }

            listViewStyles.SmallImageList = imageList;

            UpdateControlState();
        }
Example #20
0
        /// <summary>
        /// EditProperties Event handler for the layerControlStyles object.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">Event parameters.</param>
        private void layerControlStyles_EditProperties(object sender, MapObjectHolder target)
        {
            try
            {
                MapPropertyEditorForm mapPropertyEditor;
                if (target.GetType() == typeof(classObj))
                {
                    classObj classobj = target;

                    if (classobj.numstyles <= 0)
                    {
                        // adding an empty style to this class
                        styleObj style = new styleObj(classobj);
                    }

                    mapPropertyEditor = new MapPropertyEditorForm(
                        new MapObjectHolder(classobj.getStyle(0), target), new StyleLibraryPropertyEditor());
                }
                else if (target.GetType() == typeof(styleObj))
                {
                    mapPropertyEditor = new MapPropertyEditorForm(target, new StyleLibraryPropertyEditor());
                }
                else
                {
                    return;
                }
                propertyChanged         = false;
                target.PropertyChanged += new EventHandler(target_PropertyChanged);
                mapPropertyEditor.ShowDialog(this);
                if (propertyChanged)
                {
                    layerControlStyles.RefreshView();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #21
0
        public override void ApplyBinding()
        {
            if (target == null)
            {
                return;
            }

            if (target.GetParent().GetParent().GetType() != typeof(layerObj))
            {
                return;
            }

            styleObj style = target;

            if (BindingState)
            {
                style.setBinding((int)styleBinding, itemList.SelectedItem.ToString());
            }
            else
            {
                style.removeBinding((int)styleBinding);
            }
        }
Example #22
0
        public style mapStyle(styleObj styleFromXML)
        {
            style recipeStyle = new style();

            recipeStyle.category    = styleFromXML.CATEGORY_NUMBER.ToString();
            recipeStyle.description = styleFromXML.STYLE_GUIDE;
            recipeStyle.maxABV      = styleFromXML.ABV_MAX.Value;
            recipeStyle.minABV      = styleFromXML.ABV_MIN.Value;
            recipeStyle.maxColor    = styleFromXML.COLOR_MAX == null ? 0 : styleFromXML.COLOR_MAX.Value;
            recipeStyle.minColor    = styleFromXML.COLOR_MIN == null ? 0 : styleFromXML.COLOR_MIN.Value;
            recipeStyle.maxFG       = styleFromXML.FG_MAX == null ? 0 : styleFromXML.FG_MAX.Value;
            recipeStyle.minFG       = styleFromXML.FG_MIN == null ? 0 : styleFromXML.FG_MIN.Value;
            recipeStyle.maxIBU      = styleFromXML.IBU_MAX == null ? 0 : styleFromXML.IBU_MAX.Value;
            recipeStyle.minIBU      = styleFromXML.IBU_MIN == null ? 0 : styleFromXML.IBU_MIN.Value;
            recipeStyle.name        = styleFromXML.NAME;
            recipeStyle.maxOG       = styleFromXML.OG_MAX == null ? 0 : styleFromXML.OG_MAX.Value;
            recipeStyle.minOG       = styleFromXML.OG_MIN == null ? 0 : styleFromXML.OG_MIN.Value;

            //styleFromXML.STYLE_LETTER;
            //styleFromXML.TYPE;
            //styleFromXML.VERSION;
            return(recipeStyle);
        }
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
                return null;

            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);
            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;
            while ((key = map.fontset.fonts.nextKey(key)) != null)
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));

            newLayer = new layerObj(newMap);
            newLayer.type = layer.type;
            newLayer.status = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;
            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // bindings are not supported with sample maps
                for (int s = 0; s < classobj.numstyles; s++)
                    StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                for (int l = 0; l < classobj.numlabels; l++)
                    LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            SortedDictionary<string,string> items = new SortedDictionary<string,string>();
            int i = 0;

            shapeObj shape;

            layer.open();

            layer.whichShapes(layer.getExtent());

            while ((shape = layer.nextShape()) != null)
            {
                string value = shape.getValue(comboBoxColumns.SelectedIndex);
                if (checkBoxZero.Checked && (value == "" || value == ""))
                    continue;

                if (!items.ContainsValue(value))
                {
                    if (i == 100)
                    {
                        if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?","MapManager",
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
                        {
                            break;
                        }
                    }

                    items.Add(value, value);

                    ++i;
                }
            }

            if (layer.getResults() == null)
                layer.close(); // close only is no query results

            i = 0;
            foreach (string value in items.Keys)
            {
                double percent = ((double)(i + 1)) / items.Count * 100;

                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.clone();
                    // bindings are not supported with sample maps
                    for (int s = 0; s < classobj.numstyles; s++)
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                    for (int l = 0; l < classobj.numlabels; l++)
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = value;
                classobj.setExpression("('[" + comboBoxColumns.SelectedItem + "]' = '" + value + "')");
                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                        break;
                }
                ++i;
            }

            return new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null));
        }
        /// <summary>
        /// Update the style object according to the current Editor state.
        /// </summary>
        /// <param name="style">The object to be updated.</param>
        private void Update(styleObj style)
        {
            // general tab
            style.size = double.Parse(textBoxSize.Text);
            styleBindingControllerSize.ApplyBinding();
            style.minsize = double.Parse(textBoxMinSize.Text);
            style.maxsize = double.Parse(textBoxMaxSize.Text);
            style.width = double.Parse(textBoxWidth.Text);
            styleBindingControllerWidth.ApplyBinding();
            style.angle = double.Parse(textBoxAngle.Text);
            styleBindingControllerAngle.ApplyBinding();
            style.minwidth = double.Parse(textBoxMinWidth.Text);
            style.maxwidth = double.Parse(textBoxMaxWidth.Text);
            // display tab
            this.colorPickerColor.ApplyTo(style.color);
            styleBindingControllerColor.ApplyBinding();
            this.colorPickerBackColor.ApplyTo(style.backgroundcolor);
            this.colorPickerOutlineColor.ApplyTo(style.outlinecolor);
            styleBindingControllerOutlineColor.ApplyBinding();
            style.offsetx = int.Parse(textBoxOffsetX.Text);
            style.offsety = int.Parse(textBoxOffsetY.Text);
            style.opacity = trackBarOpacity.Value;
            // set up alpha values according to opacity
            int alpha = Convert.ToInt32(style.opacity * 2.55);
            style.color.alpha = alpha;
            style.outlinecolor.alpha = alpha;
            style.backgroundcolor.alpha = alpha;
            style.mincolor.alpha = alpha;
            style.maxcolor.alpha = alpha;

            if (checkBoxAntialias.Checked)
                style.antialias = mapscript.MS_TRUE;
            else
                style.antialias = mapscript.MS_FALSE;

            if (checkBoxAutoAngle.Checked)
                style.autoangle = mapscript.MS_TRUE;
            else
                style.autoangle = mapscript.MS_FALSE;

            if (comboBoxGeomTransform.Text != "")
                style.setGeomTransform(comboBoxGeomTransform.Text);
            else
                style.setGeomTransform(null);

            style.gap = double.Parse(textBoxGap.Text);

            string[] values = textBoxPattern.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length > 0)
            {
                double[] result = new double[values.Length];
                for (int i = 0; i < values.Length; i++)
                    result[i] = double.Parse(values[i], ni);
                style.pattern = result;
            }
            else
                style.patternlength = 0;

            if (textBoxMaxZoom.Text == "")
                style.maxscaledenom = -1;
            else
                style.maxscaledenom = double.Parse(textBoxMaxZoom.Text);

            if (textBoxMinZoom.Text == "")
                style.minscaledenom = -1;
            else
                style.minscaledenom = double.Parse(textBoxMinZoom.Text);
        }
 public int insertStyle(styleObj style, int index) {
   int ret = mapscriptPINVOKE.classObj_insertStyle(swigCPtr, styleObj.getCPtrAndSetReference(style, ThisOwn_false()), index);
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Example #26
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;
            }
        }
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
            {
                return(null);
            }

            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);

            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;

            while ((key = map.fontset.fonts.nextKey(key)) != null)
            {
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));
            }

            newLayer                = new layerObj(newMap);
            newLayer.type           = layer.type;
            newLayer.status         = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;

            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // bindings are not supported with sample maps
                for (int s = 0; s < classobj.numstyles; s++)
                {
                    StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                }
                for (int l = 0; l < classobj.numlabels; l++)
                {
                    LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                }
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj      = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol     = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            SortedDictionary <string, string> items = new SortedDictionary <string, string>();
            int i = 0;

            shapeObj shape;

            layer.open();

            layer.whichShapes(layer.getExtent());

            if (checkBoxClassItem.Checked)
            {
                layer.classitem = comboBoxColumns.SelectedItem.ToString();
            }

            while ((shape = layer.nextShape()) != null)
            {
                string value = shape.getValue(comboBoxColumns.SelectedIndex);
                if (checkBoxZero.Checked && (value == "" || value == ""))
                {
                    continue;
                }

                if (!items.ContainsValue(value))
                {
                    if (i == 100)
                    {
                        if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?", "MapManager",
                                            MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
                        {
                            break;
                        }
                    }

                    items.Add(value, value);

                    ++i;
                }
            }

            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
            i = 0;
            foreach (string value in items.Keys)
            {
                double percent = ((double)(i + 1)) / items.Count * 100;

                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.clone();
                    // bindings are not supported with sample maps
                    for (int s = 0; s < classobj.numstyles; s++)
                    {
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                    }
                    for (int l = 0; l < classobj.numlabels; l++)
                    {
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                    }
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = value;
                if (checkBoxClassItem.Checked)
                {
                    classobj.setExpression(value);
                }
                else
                {
                    classobj.setExpression("('[" + comboBoxColumns.SelectedItem + "]' = '" + value + "')");
                }

                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color           = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor    = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                    {
                        break;
                    }
                }
                ++i;
            }

            return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)));
        }
Example #28
0
    public static void Main(string[] args)
    {
        if (args.Length < 2) usage();

          // creating a new map from scratch
          mapObj map = new mapObj(null);
          // adding a layer
          layerObj layer = new layerObj(map);
          layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
          layer.status = mapscript.MS_ON;
          layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
          // define the attribute names from the inline layer
          layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
          // define the class
          classObj classobj = new classObj(layer);
          classobj.template = "query";   // making the layer queryable
          // setting up the text based on multiple attributes
          classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
          // define the label
          classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
          classobj.label.force = mapscript.MS_TRUE;
          classobj.label.size = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
          classobj.label.position = (int)MS_POSITIONS_ENUM.MS_LC;
          classobj.label.wrap = ' ';
          // set up attribute binding
          classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
          // define the style
          styleObj style = new styleObj(classobj);
          style.color = new colorObj(0, 255, 255, 0);
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

          Random rand = new Random((int)DateTime.Now.ToFileTime()); ;

          // creating the shapes
          for (int i = 0; i < 10; i++)
          {
          shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

          // setting the shape attributes
          shape.initValues(4);
          shape.setValue(0, Convert.ToString(i));
          shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
          shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

          lineObj line = new lineObj();
          line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
          shape.add(line);
          layer.addFeature(shape);
          }

          map.width = 500;
          map.height = 500;
          map.setExtent(0,0,450,450);
          map.selectOutputFormat(args[0]);
          imageObj image = map.draw();
          image.save(args[1], map);

          //perform a query
          layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

          resultObj res;
          shapeObj feature;
          using (resultCacheObj results = layer.getResults())
          {
          if (results != null && results.numresults > 0)
          {
              // extracting the features found
              layer.open();
              for (int j = 0; j < results.numresults; j++)
              {
                  res = results.getResult(j);
                  feature = layer.getShape(res);
                  if (feature != null)
                  {
                      Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                      for (int k = 0; k < layer.numitems; k++)
                      {
                          Console.Write("     " + layer.getItem(k));
                          Console.Write(" = ");
                          Console.Write(feature.getValue(k));
                          Console.WriteLine();
                      }
                  }
              }
              layer.close();
          }
          }
    }
Example #29
0
 /// <summary>
 /// Create a new classObj with random color setting added to the parent layer.
 /// </summary>
 /// <param name="layer">The parent layer object.</param>
 public static void CreateRandomClass(layerObj layer)
 {
     using (classObj newclass = new classObj(layer))
     {
         newclass.name = GetClassName(layer);
         newclass.template = "query.html";
         styleObj style = new styleObj(newclass);
         style.size = 8; // set default size (#4339)
         SetDefaultColor(layer.type, style);
     }
 }
Example #30
0
        private void listViewSymbol_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (m_pDefaultMap == null) return;
            if (listViewSymbol.SelectedIndices.Count == 0) return;

            //make sure there is only one style in class
            while (m_pEditingClass.numstyles > 1)
                m_pEditingClass.removeStyle(0);

            //index 0 is the orienge symbol
            if(listViewSymbol.SelectedIndices[0] == 0)
            {
                pictureBoxPreview.Image =
                    GetImageFromClass(m_pCurrentLayer.getClass(m_iClassIndex)
                    , pictureBoxPreview.Width, pictureBoxPreview.Height);
            }
            else
            {
                if (m_pEditingClass != null)
                    m_pEditingClass.Dispose();

                m_pEditingClass = new classObj(null);
                styleObj pStyle = new styleObj(m_pEditingClass);
                pStyle.setSymbolByName(m_pDefaultMap, listViewSymbol.SelectedItems[0].Text);
                pStyle.color = new colorObj(0, 0, 0, 0);

                if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    pStyle.size = 10;
                    pStyle.angle = 0;
                }
                else if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_LINE)
                {
                    pStyle.size = 8;
                    pStyle.width = 1;
                }
                else if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_POLYGON)
                {
                    pStyle.size = 8;
                    pStyle.outlinewidth = 1;
                    pStyle.outlinecolor = new colorObj(0, 0, 0, 0);
                }

                if (m_pSymbolOptions != null)
                    m_pSymbolOptions.Symbol = pStyle;

                DrawSymbol2Preview();

            }
        }
Example #31
0
        /// <summary>
        /// Click event handler of the addLayerToolStripMenuItem control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void addLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (target == null)
                return;
            if (target.GetType() != typeof(mapObj))
                return;

            TreeNode source = CurrentTree.SelectedNode;
            if (source != null && source.Tag != null)
                RaiseItemSelect((MapObjectHolder)source.Tag);

            layerObj layer;
            classObj classobj;
            styleObj style;
            if (IsStyleLibraryControl)
            {
                AddStyleCategoryForm form = new AddStyleCategoryForm(MapUtils.GetUniqueLayerName(map, "New Category", 0));
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    if (form.CategoryType != "(Empty Category)")
                    {
                        layer = CreateNewLayer();
                        layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
                        layer.template = "query.html";
                        layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                        layer.name = MapUtils.GetUniqueLayerName(map, form.CategoryName, 0);

                        classobj = new classObj(layer);
                        classobj.name = form.CategoryName;
                        style = new styleObj(classobj);
                        layer.setMetaData("character-count", form.CharCount.ToString());

                        MapUtils.SetDefaultColor(layer.type, style);
                        style.width = 1;
                        style.size = 24;

                        // create all symbols
                        StyleLibrary.ExpandFontStyles();

                        this.selected = new MapObjectHolder(layer, target);

                        RefreshView();

                        if (target != null)
                            target.RaisePropertyChanged(this);

                        return;
                    }
                }
                else
                    return;
            }

            layer = CreateNewLayer();
            layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            layer.template = "query.html";
            layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
            if (!IsStyleLibraryControl)
                layer.name = MapUtils.GetUniqueLayerName(map, "New Layer", 0);

            classobj = new classObj(layer);
            classobj.name = MapUtils.GetClassName(layer);
            style = new styleObj(classobj);

            // initialize with the default marker if specified in the symbol file for point symbols
            symbolObj symbol;
            for (int i = 0; i < map.symbolset.numsymbols; i++)
            {
                symbol = map.symbolset.getSymbol(i);

                if (symbol.name == "default-marker")
                {
                    layer.getClass(0).getStyle(0).symbol = i;
                    layer.getClass(0).getStyle(0).symbolname = "default-marker";
                    break;
                }
            }

            MapUtils.SetDefaultColor(layer.type, style);
            style.width = 1;
            style.size = 8; // set default size (#4339)

            this.selected = new MapObjectHolder(layer, target);

            RefreshView();

            if (target != null)
                target.RaisePropertyChanged(this);
        }
Example #32
0
	public void testRemoveStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,0);
		classobj.removeStyle(0);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 1, "testRemoveStyleObj");
	}
Example #33
0
        private const double KGtoOZ = KGtoLB * 16;//35.71428571428571;

        public recipe ParseBeerXML(string xml)
        {
            //All the converted items
            RECIPE recipeFromXML = new RECIPE();
            List <fermentableObj> Fermentables = new List <fermentableObj>();
            List <hopObj>         Hops         = new List <hopObj>();
            List <yeastObj>       Yeasts       = new List <yeastObj>();
            List <miscObj>        Miscs        = new List <miscObj>();
            styleObj Style = new styleObj();

            //Load the string into an xml object
            XmlDocument   xdoc       = new XmlDocument();
            XmlSerializer serializer = new XmlSerializer((typeof(RECIPE)));

            xdoc.LoadXml(xml);

            //convert the xml object to json
            string  json = JsonConvert.SerializeXmlNode(xdoc);
            JObject recipeInfoFromXML = JObject.Parse(json);

            // get the recipe info
            JToken results = recipeInfoFromXML["RECIPES"]["RECIPE"];

            recipeFromXML = results.ToObject <RECIPE>();

            //same with style
            results = recipeInfoFromXML["RECIPES"]["RECIPE"]["STYLE"];
            Style   = results.ToObject <styleObj>();

            /*
             * When it converts xml to json, due to the way that Json uses list objects and XML does not
             * the parser can't tell the difference between a list and not a list...
             *
             * So we come to this...
             *
             * The try catches handle list vs not list.
             *
             * For example
             * recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children().Children()
             *
             * retrieves items if they are encapsulated in a json list.
             *
             * recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children()
             *
             * retrieves items if they are not encapsulated in a list.
             *
             * So this should handle both instances because if you parse too deep it can't figure out what object you're
             * trying to map into and it throws an exception.
             *
             * */
            try
            {
                IList <JToken> fermentablesList = recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children().Children().ToList();
                foreach (JToken result in fermentablesList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    fermentableObj searchResult = result.ToObject <fermentableObj>();
                    Fermentables.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> fermentablesList = recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children().ToList();
                foreach (JToken result in fermentablesList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    fermentableObj searchResult = result.ToObject <fermentableObj>();
                    Fermentables.Add(searchResult);
                }
            }

            try
            {
                IList <JToken> hopsList = recipeInfoFromXML["RECIPES"]["RECIPE"]["HOPS"].Children().Children().Children().ToList();
                foreach (JToken result in hopsList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    hopObj searchResult = result.ToObject <hopObj>();
                    Hops.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> hopsList = recipeInfoFromXML["RECIPES"]["RECIPE"]["HOPS"].Children().Children().ToList();
                foreach (JToken result in hopsList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    hopObj searchResult = result.ToObject <hopObj>();
                    Hops.Add(searchResult);
                }
            }


            try
            {
                IList <JToken> yeastList = recipeInfoFromXML["RECIPES"]["RECIPE"]["YEASTS"].Children().Children().Children().ToList();
                foreach (JToken result in yeastList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    yeastObj searchResult = result.ToObject <yeastObj>();
                    Yeasts.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> yeastList = recipeInfoFromXML["RECIPES"]["RECIPE"]["YEASTS"].Children().Children().ToList();
                foreach (JToken result in yeastList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    yeastObj searchResult = result.ToObject <yeastObj>();
                    Yeasts.Add(searchResult);
                }
            }

            try
            {
                IList <JToken> miscList = recipeInfoFromXML["RECIPES"]["RECIPE"]["MISCS"].Children().Children().Children().ToList();
                foreach (JToken result in miscList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    miscObj searchResult = result.ToObject <miscObj>();
                    Miscs.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> miscList = recipeInfoFromXML["RECIPES"]["RECIPE"]["MISCS"].Children().Children().ToList();
                foreach (JToken result in miscList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    miscObj searchResult = result.ToObject <miscObj>();
                    Miscs.Add(searchResult);
                }
            }

            recipe final = MapRecipeInfo(recipeFromXML, Fermentables, Hops, Yeasts, Miscs, Style);

            final.equipmentProfile = getDefaultEquipmentProfile();
            final.recipeStats      = makeEmptyRecipeStats();
            final.recipeStats      = MathFunctions.GlobalFunctions.updateStats(final);
            DataAccess accessor = new DataAccess();

            accessor.PostRecipe(final);

            return(final);
        }
Example #34
0
        public recipe MapRecipeInfo(RECIPE XMLRecipe, List <fermentableObj> Fermentables, List <hopObj> Hops, List <yeastObj> Yeasts, List <miscObj> Miscs, styleObj Style)
        {
            recipe beerNetRecipe = new recipe();

            beerNetRecipe.isPublic         = true;
            beerNetRecipe.recipeParameters = new RecipeParameters();
            beerNetRecipe.fermentables     = new List <fermentableAddition>();
            beerNetRecipe.hops             = new List <hopAddition>();
            beerNetRecipe.adjuncts         = new List <adjunctAddition>();
            beerNetRecipe.yeasts           = new List <yeastAddition>();

            beerNetRecipe.name        = XMLRecipe.NAME;
            beerNetRecipe.description = "Converted from Beer XML.";

            beerNetRecipe.recipeParameters.ibuCalcType         = "basic";
            beerNetRecipe.recipeParameters.fermentableCalcType = "basic";
            beerNetRecipe.recipeParameters.ibuBoilTimeCurveFit = -0.04;

            beerNetRecipe.hops         = mapHopAdditions(Hops);
            beerNetRecipe.fermentables = mapFermentableAdditions(Fermentables);
            beerNetRecipe.yeasts       = mapYeastAdditions(Yeasts);
            beerNetRecipe.adjuncts     = mapAdjuntAdditions(Miscs);
            beerNetRecipe.style        = mapStyle(Style);
            //  beerNetRecipe.style = FUUUUUCKCKKK;  NEEED TO ADD STYLE
            // beerNetRecipe.recipeParameters.intoFermenterVolume = 5; NEED EQUIPMENT PROFILE

            return(beerNetRecipe);
        }
        private void UpdateStyleList()
        {
            string selectedName = style.symbolname;
            if (listView.SelectedItems.Count > 0)
                selectedName = listView.SelectedItems[0].Text;

            // populate the style listview
            listView.Items.Clear();
            imageList.Images.Clear();

            ListViewItem selected = null;

            if (comboBoxCategory.Text != "")
            {
                // Create "no symbol" entry
                styleObj nosymbolstyle = new styleObj(null);
                MapUtils.SetDefaultColor(layer.type, nosymbolstyle);
                ListViewItem nosymbolitem = AddListItem(nosymbolstyle, layer, "Default");
                if (selectedName == null)
                    selected = nosymbolitem;

                if (comboBoxCategory.Text == "Inline Symbols")
                {
                    for (int i = 0; i < map.symbolset.numsymbols; i++)
                    {
                        symbolObj symbol = map.symbolset.getSymbol(i);
                        if (symbol.inmapfile == mapscript.MS_TRUE &&
                            !StyleLibrary.HasSymbol(symbol.name))
                        {
                            styleObj libstyle = new styleObj(null);
                            //if (symbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_PATTERNMAP)
                            //    MapUtils.SetDefaultColor(MS_LAYER_TYPE.MS_LAYER_LINE, libstyle);
                            //else
                                MapUtils.SetDefaultColor(layer.type, libstyle);
                            libstyle.setSymbolByName(map, symbol.name);
                            libstyle.size = 8;
                            MS_LAYER_TYPE type = layer.type;
                            try
                            {
                                //STEPH: change layer passed to the list view to be consistent with the other symbol categories
                                //so that it uses a point layer to display the style in the list
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                                ListViewItem item = AddListItem(libstyle, layer, symbol.name);
                                if (selectedName == item.Text)
                                    selected = item;
                            }
                            finally
                            {
                                layer.type = type;
                            }
                        }
                    }
                }
                else
                {
                    // collect all fonts specified in the fontset file
                    Hashtable fonts = new Hashtable();
                    string key = null;
                    while ((key = map.fontset.fonts.nextKey(key)) != null)
                        fonts.Add(key, key);

                    mapObj styles = StyleLibrary.Styles;
                    layerObj stylelayer = styles.getLayerByName(comboBoxCategory.Text);
                    for (int i = 0; i < stylelayer.numclasses; i++)
                    {
                        classObj classobj = stylelayer.getClass(i);
                        int symbolIndex = classobj.getStyle(0).symbol;
                        if (symbolIndex >= 0)
                        {
                            string font = styles.symbolset.getSymbol(symbolIndex).font;
                            if (font != null && !fonts.ContainsKey(font))
                                continue; // this font cannot be found in fontset
                        }

                        ListViewItem item = AddListItem(classobj.getStyle(0), stylelayer, classobj.name);
                        if (selectedName == item.Text)
                            selected = item;
                    }
                }
            }

            if (selected != null)
            {
                selected.Selected = true;
                selected.EnsureVisible();
            }
        }
Example #36
0
 public static void RemoveAllBindings(styleObj style)
 {
     for (int i = 0; i < mapscript.MS_STYLE_BINDING_LENGTH; i++)
     {
         style.removeBinding(i);
     }
 }
Example #37
0
        /// <summary>
        /// show all the predefined symbols
        /// </summary>
        private void LoadSymbolFromLib()
        {
            classObj pClass = new classObj(null);
            styleObj pStyle = new styleObj(pClass);

            colorObj pColor = new colorObj(0,0,0,0);

            int iSymbolCount = m_pDefaultMap.getNumSymbols();

            symbolSetObj pSymSet = m_pDefaultMap.symbolset;

            for(int i=1;i < iSymbolCount;i++)
            {
                pStyle.symbol = i;
                pStyle.color = pColor;

                symbolObj pSymbol = pSymSet.getSymbol(i);

                if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    //type cartoline if only for line type
                    if (pSymbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_CARTOLINE)
                        continue;

                    pStyle.size = 10;
                    pStyle.angle = 0;
                }
                else if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_LINE)
                {
                    pStyle.size = 6;
                    pStyle.width = 1;
                }
                else if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_POLYGON)
                {
                    //type cartoline if only for line type
                    if (pSymbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_CARTOLINE)
                        continue;

                    pStyle.size = 8;
                    pStyle.outlinewidth = 1;
                    pStyle.outlinecolor = pColor;
                }

                imageListPreview.Images.Add(GetImageFromClass(pClass, 48, 48));

                listViewSymbol.Items.Add(pSymbol.name, imageListPreview.Images.Count - 1);
            }

            pStyle.Dispose();
            pClass.Dispose();
            pColor.Dispose();
        }
Example #38
0
 /// <summary>
 /// Get default color color.
 /// </summary>
 /// <returns>The default color</returns>
 public static void SetDefaultColor(MS_LAYER_TYPE type,  styleObj style)
 {
     // set default color (#4337) to black for line color and white for brush color
     if (type == MS_LAYER_TYPE.MS_LAYER_POLYGON)
     {
         style.color = new colorObj(255, 255, 255, 0);
         style.outlinecolor = new colorObj(0, 0, 0, 0);
         style.symbol = 0;
         style.symbolname = null;
     }
     else
     {
         style.color = new colorObj(0, 0, 0, 0);
     }
 }
Example #39
0
	public void testStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle=new styleObj(classobj);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 2, "testStyleObj");
	}
 /// <summary>
 /// Click event handler of the buttonAddStyle control
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="e">The event parameters.</param>
 private void buttonAddStyle_Click(object sender, EventArgs e)
 {
     styleObj style = new styleObj(null);
     style.setGeomTransform("labelpnt");
     style.color = new colorObj(0, 0, 0, 0);
     style.size = 8;
     AddStyleToList(style);
     isStyleChanged = true;
     UpdatePreview();
 }
        /// <summary>
        /// Adding a new style to the list
        /// </summary>
        /// <param name="style">the style to add</param>
        private void AddStyleToList(styleObj style)
        {
            layerObj layer;
            if (target.GetParent().GetType() == typeof(scalebarObj))
                layer = new layerObj(null);
            else
                layer = target.GetParent().GetParent();

            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.Add(Image.FromStream(ms));
                    }

                    ListViewItem item = new ListViewItem(
                        new string[] { "", style.size.ToString(), style.width.ToString(), style.symbolname });

                    item.ImageIndex = imageList.Images.Count - 1;
                    item.Tag = style;

                    listViewStyles.Items.Add(item);
                }
            }
        }
 internal static HandleRef getCPtr(styleObj obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Example #43
0
        /// <summary>
        /// Update the label object according to the current Editor state.
        /// </summary>
        /// <param name="label">The object to be updated.</param>
        private void Update(labelObj label)
        {
            label.anglemode          = (MS_POSITIONS_ENUM)comboBoxAngleMode.SelectedItem;
            label.autominfeaturesize = checkBoxAutoMinFeatureSize.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;
            label.partials           = checkBoxPartials.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;
            label.force = checkBoxForce.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;

            label.setExpression(this.textBoxExpression.Text);
            label.setText(this.textBoxText.Text);

            colorPickerColor.ApplyTo(label.color);
            colorPickerOutlineColor.ApplyTo(label.outlinecolor);
            colorPickerShadowColor.ApplyTo(label.shadowcolor);

            label.size        = int.Parse(textBoxSize.Text);
            label.minsize     = int.Parse(textBoxMinSize.Text);
            label.maxsize     = int.Parse(textBoxMaxSize.Text);
            label.mindistance = int.Parse(textBoxMinDistance.Text);
            label.offsetx     = int.Parse(textBoxOffsetX.Text);
            label.offsety     = int.Parse(textBoxOffsetY.Text);
            if (textBoxWrap.Text == "")
            {
                label.wrap = '\0';
            }
            else
            {
                label.wrap = Convert.ToChar(textBoxWrap.Text);
            }

            label.shadowsizex = int.Parse(textBoxShadowSizeX.Text);
            label.shadowsizey = int.Parse(textBoxShadowSizeY.Text);

            if (textBoxEncoding.Text == "")
            {
                label.encoding = null;
            }
            else
            {
                label.encoding = textBoxEncoding.Text;
            }
            label.angle = double.Parse(textBoxAngle.Text);

            label.position = (int)comboBoxPosition.SelectedItem;

            label.align = (int)comboBoxAlign.SelectedItem;

            if ((string)(comboBoxFont.SelectedItem) == "(none)")
            {
                label.font = null;
            }
            else
            {
                label.font = (string)(comboBoxFont.SelectedItem);
            }

            label.priority = int.Parse(textBoxPriority.Text);
            if (textBoxMaxScale.Text == "")
            {
                label.maxscaledenom = -1;
            }
            else
            {
                label.maxscaledenom = double.Parse(textBoxMaxScale.Text);
            }

            if (textBoxMinScale.Text == "")
            {
                label.minscaledenom = -1;
            }
            else
            {
                label.minscaledenom = double.Parse(textBoxMinScale.Text);
            }
            label.maxlength      = int.Parse(textBoxMaxLength.Text);
            label.minfeaturesize = int.Parse(textBoxMinFeatureSize.Text);
            label.buffer         = int.Parse(textBoxBuffer.Text);
            label.repeatdistance = int.Parse(textBoxRepeatDistance.Text);

            if (isStyleChanged)
            {
                // reconstruct styles
                while (label.numstyles > 0)
                {
                    label.removeStyle(0);
                }
                // insert styles in reverse order
                for (int i = listViewStyles.Items.Count - 1; i >= 0; --i)
                {
                    ListViewItem item  = listViewStyles.Items[i];
                    styleObj     style = (styleObj)item.Tag;
                    label.insertStyle(style.clone(), -1);
                }
            }
        }
Example #44
0
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
                return null;

            int index;

            for (index = 0; index < fieldName.Length; index++)
            {
                if (fieldName[index] == comboBoxColumns.Text)
                    break;
            }
            if (index == fieldName.Length)
                return null;

            NumberFormatInfo ni = new NumberFormatInfo();
            ni.NumberDecimalSeparator = ".";
            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);
            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;
            while ((key = map.fontset.fonts.nextKey(key)) != null)
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));

            newLayer = new layerObj(newMap);
            newLayer.type = layer.type;
            newLayer.status = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;
            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // bindings are not supported with sample maps
                for (int s = 0; s < classobj.numstyles; s++)
                    StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                for (int l = 0; l < classobj.numlabels; l++)
                    LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            // calculate breaks
            int classes = (int)numericUpDownClasses.Value;
            double[] breaks = null;
            if (comboBoxMode.SelectedIndex == 0)
                breaks = CalculateEqualInterval(classes, index);

            if (breaks == null)
                return null;

            for (int i = 0; i < classes; i++)
            {
                double percent = ((double)(i + 1)) / classes * 100;
                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.clone();
                    // bindings are not supported with sample maps
                    for (int s = 0; s < classobj.numstyles; s++)
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                    for (int l = 0; l < classobj.numlabels; l++)
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = breaks[i].ToString(ni) + " - " + breaks[i + 1].ToString(ni);
                classobj.setExpression("(([" + comboBoxColumns.SelectedItem + "] >= "
                    + breaks[i].ToString(ni) + ") && ([" + comboBoxColumns.SelectedItem + "] <= "
                    + breaks[i+1].ToString(ni) + "))");
                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                        break;
                }
            }

            return new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null));
        }
Example #45
0
        /// <summary>
        /// Click event handler of the addStyleToolStripMenuItem control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void addStyleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MapObjectHolder selected = (MapObjectHolder)CurrentTree.SelectedNode.Tag;
            RaiseItemSelect(selected);
            classObj classobj;
            if (selected.GetType() == typeof(layerObj))
            {
                layerObj layer = selected;
                classobj = layer.getClass(0);
                MapObjectHolder classHolder = new MapObjectHolder(classobj, selected);
                styleObj style = new styleObj(classobj);
                MapUtils.SetDefaultColor(layer.type, style);
                style.width = 1;

                this.selected = new MapObjectHolder(style, classHolder);

                RefreshView();
                //if (EditProperties != null)
                //    EditProperties(this, new MapObjectHolder(style, classHolder));
                if (target != null)
                    target.RaisePropertyChanged(this);
            }
            else if (selected.GetType() == typeof(classObj))
            {
                layerObj layer = selected.GetParent();
                classobj = selected;
                styleObj style = new styleObj(classobj);
                MapUtils.SetDefaultColor(layer.type, style);
                style.width = 1;

                this.selected = new MapObjectHolder(style, selected);

                RefreshView();
                //if (EditProperties != null)
                //    EditProperties(this, new MapObjectHolder(style, selected));
                if (target != null)
                    target.RaisePropertyChanged(this);
            }
            else
                return;
        }
Example #46
0
        /// <summary>
        /// Click event handler of the addClassToolStripMenuItem control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void addClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MapObjectHolder selected = (MapObjectHolder)CurrentTree.SelectedNode.Tag;
            RaiseItemSelect(selected);
            layerObj layer = selected;
            classObj classobj = new classObj(layer);
            classobj.name = MapUtils.GetClassName(layer);
            styleObj style = new styleObj(classobj);
            //STEPH: set default colour to be consistent with adding new style
            MapUtils.SetDefaultColor(layer.type, style);
            if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
            {
                style.symbolname = "default-marker";
                style.size = 8;
            }

            this.selected = new MapObjectHolder(classobj, selected);

            RefreshView();

            if (target != null)
                target.RaisePropertyChanged(this);
        }
        /// <summary>
        /// Let the editor to update the modified values to the underlying object.
        /// </summary>
        public void UpdateValues()
        {
            if (layer == null)
                return;
            if (dirtyFlag)
            {
                MS_CONNECTION_TYPE connectiontype = layer.connectiontype;
                if (layer.connectiontype != (MS_CONNECTION_TYPE)comboBoxConnectionType.SelectedItem)
                {
                    // try to change the connection type
                    try
                    {
                        if ((MS_CONNECTION_TYPE)comboBoxConnectionType.SelectedItem == MS_CONNECTION_TYPE.MS_PLUGIN
                            && comboBoxPlugin.SelectedIndex >= 0)
                            layer.setConnectionType((int)comboBoxConnectionType.SelectedItem, comboBoxPlugin.Text);
                        else
                            layer.setConnectionType((int)comboBoxConnectionType.SelectedItem, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error setting the connection type, " + ex.Message,
                                "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        // reverting to the old values
                        layer.connectiontype = connectiontype;
                        return;
                    }
                }

                if ((MS_LAYER_TYPE)comboBoxType.SelectedItem == MS_LAYER_TYPE.MS_LAYER_ANNOTATION &&
                        layer.type != MS_LAYER_TYPE.MS_LAYER_ANNOTATION)
                {
                    // remove the styles to prevent from drawing the shapes under the text
                    for (int i = 0; i < layer.numclasses; i++)
                    {
                        classObj c = layer.getClass(i);
                        while (c.numstyles > 0)
                            c.removeStyle(0);
                        // add a new empty style (#6616)
                        styleObj style = new styleObj(c);
                    }
                }

                MS_LAYER_TYPE type = layer.type;
                layer.type = (MS_LAYER_TYPE)comboBoxType.SelectedItem;

                string connection = layer.connection;
                if (textBoxConnection.Text == ""
                    || layer.connectiontype == MS_CONNECTION_TYPE.MS_INLINE)
                    layer.connection = null;
                else
                    layer.connection = textBoxConnection.Text;

                string data = layer.data;
                if (textBoxData.Text == ""
                    || layer.connectiontype == MS_CONNECTION_TYPE.MS_INLINE)
                    layer.data = null;
                else
                    layer.data = textBoxData.Text;

                // inline layers must have at least one shape
                if (layer.connectiontype == MS_CONNECTION_TYPE.MS_INLINE)
                    layer.addFeature(new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_NULL));

                string filter = layer.getFilterString();
                if (textBoxFilter.Text == "")
                    layer.setFilter(null);
                else
                    layer.setFilter(textBoxFilter.Text);

                // at this point we try to open the layer
                try
                {
                    layer.open();
                    if (layer.getResults() == null)
                        layer.close(); // close only is no query results
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error opening layer, " + ex.Message,
                            "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // reverting to the old values
                    layer.connection = connection;
                    layer.data = data;
                    layer.type = type;
                    layer.setFilter(filter);
                    layer.connectiontype = connectiontype;
                    return;
                }

                // setting up the projection if it have been changed
                //steph - it wasn't updating the coordsys-name if changing projection with same proj4 text but different display name
                string key = layer.getFirstMetaDataKey();
                string coordsys = "";
                while (key != null)
                {
                    if (key == "coordsys_name")
                    {
                        coordsys = layer.getMetaData("coordsys_name");
                        break;
                    }
                    key = layer.getNextMetaDataKey(key);
                }
                if (layer.getProjection() != this.textBoxProjection.Tag.ToString() || this.textBoxProjection.Text != coordsys)
                {
                    if (this.textBoxProjection.Tag.ToString().Trim().StartsWith("+"))
                    {
                        layer.setProjection(this.textBoxProjection.Tag.ToString());
                        layer.setMetaData("coordsys_name", this.textBoxProjection.Text);
                    }
                    else
                        layer.setProjection("+AUTO");
                }

                if (checkBoxVisible.CheckState == CheckState.Checked)
                    layer.status = mapscript.MS_ON;
                else
                    layer.status = mapscript.MS_OFF;

                if (checkBoxQueryable.CheckState == CheckState.Checked)
                    layer.template = "query";
                else
                {
                    layer.template = null;
                    for (int c = 0; c < layer.numclasses; c++)
                        layer.getClass(c).template = null;
                }

                layer.maxscaledenom = -1;
                layer.minscaledenom = -1;
                layer.maxgeowidth = -1;
                layer.mingeowidth = -1;
                if (checkBoxDisplayRange.Checked)
                {
                    if (comboBoxDisplayRange.SelectedIndex == 0)
                    {
                        if (textBoxMaxScale.Text == "")
                            layer.maxscaledenom = -1;
                        else
                            layer.maxscaledenom = double.Parse(textBoxMaxScale.Text);

                        if (textBoxMinScale.Text == "")
                            layer.minscaledenom = -1;
                        else
                            layer.minscaledenom = double.Parse(textBoxMinScale.Text);
                    }
                    else
                    {
                        if (layer.map != null)
                        {
                            MS_UNITS mapunits = layer.map.units;

                            if (textBoxMaxZoom.Text == "")
                                layer.maxgeowidth = -1;
                            else
                                layer.maxgeowidth = double.Parse(textBoxMaxZoom.Text);
                            if (textBoxMinZoom.Text == "")
                                layer.mingeowidth = -1;
                            else
                                layer.mingeowidth = double.Parse(textBoxMinZoom.Text);
                        }
                        else
                        {
                            if (textBoxMaxZoom.Text == "")
                                layer.maxgeowidth = -1;
                            else
                                layer.maxgeowidth = double.Parse(textBoxMaxZoom.Text);
                            if (textBoxMinZoom.Text == "")
                                layer.mingeowidth = -1;
                            else
                                layer.mingeowidth = double.Parse(textBoxMinZoom.Text);
                        }
                    }
                }

                if (layer.opacity != mapscript.MS_GD_ALPHA)
                    layer.opacity = trackBarOpacity.Value;

                // labelling  & style tab
                if (comboBoxLabelItem.SelectedItem.ToString() == "(no label)")
                    layer.labelitem = null;
                else
                {
                    layer.labelitem = comboBoxLabelItem.SelectedItem.ToString();
                    // creating default labels for each class
                    for (int c = 0; c < layer.numclasses; c++)
                    {
                        classObj classobj = layer.getClass(c);
                        if (classobj.numlabels <= 0)
                        {
                            // adding an empty label to this class
                            classobj.addLabel(new labelObj());
                            labelObj label = classobj.getLabel(0);
                            MapUtils.SetDefaultLabel(label, layer.map);
                        }
                    }
                }

                if (textBoxLabelMaxScale.Text == "")
                    layer.labelmaxscaledenom = -1;
                else
                    layer.labelmaxscaledenom = double.Parse(textBoxLabelMaxScale.Text);

                if (textBoxLabelMinScale.Text == "")
                    layer.labelminscaledenom = -1;
                else
                    layer.labelminscaledenom = double.Parse(textBoxLabelMinScale.Text);

                if (checkBoxAutoStyle.Checked && (string.Compare(layer.styleitem, "AUTO", true) != 0))
                    layer.styleitem = "AUTO";
                else if (!checkBoxAutoStyle.Checked && (string.Compare(layer.styleitem, "AUTO", true) == 0))
                {
                    layer.styleitem = null;
                    // set default color (#4337)
                    //styleObj style = layer.getClass(0).getStyle(0);
                    //MapUtils.SetDefaultColor(layer.type, style);
                }

                if (checkBoxLabelCache.Checked)
                    layer.labelcache = mapscript.MS_ON;
                else
                    layer.labelcache = mapscript.MS_OFF;

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON &&
                    type != MS_LAYER_TYPE.MS_LAYER_POLYGON &&
                    layer.styleitem == null)
                {
                    // the type have been changed to polygon
                    styleObj style = layer.getClass(0).getStyle(0);
                    MapUtils.SetDefaultColor(layer.type, style);
                }

                if (textBoxSymbolScale.Text == "")
                    layer.symbolscaledenom = -1;
                else
                    layer.symbolscaledenom = double.Parse(textBoxSymbolScale.Text);

                // processing tab
                layer.clearProcessing();
                string[] processing = textBoxProcessing.Text.Split(new char[] { '\n', '\r' });
                for (int i = 0; i < processing.Length; i++)
                {
                    string[] directive = processing[i].Trim().Split(new char[] { '=' });
                    if (directive.Length > 1)
                        layer.setProcessingKey(directive[0], directive[1]); // don't add duplicates
                }

                if (layer.name != this.textBoxName.Text)
                    layer.name = this.textBoxName.Text;

                if (textBoxLink.Text.Length > 0)
                    layer.setMetaData("link", textBoxLink.Text);
                else
                {
                    // remove previous setting
                    string key2;
                    while ((key2 = MapUtils.FindMetadata(layer, "link")) != null)
                        layer.removeMetaData(key2);
                }

                if (target != null)
                    target.RaisePropertyChanged(this);
                SetDirty(false);
            }
            else
                CancelEditing();
        }
Example #48
0
        //���һ����ͼ�㵽mapfile
        public bool addLayer(string dataPath)
        {
            if (_Map == null)
            {
                if (ErrorOccured != null)
                    ErrorOccured(null, new MSErrorEventArgs("û�д�mapfile"));

                return false;
            }

            layerObj pLayer = new layerObj(_Map);
            pLayer.status = 1;

            string strName = Path.GetFileNameWithoutExtension(dataPath);
            pLayer.name = strName;
            pLayer.group = strName;

            string strExt = Path.GetExtension(dataPath).ToLower();
            //wanliyun:2009.05.06
            //add the mapinfo tab format support
            if ((strExt == ".shp") || (strExt == ".tab"))
            {
                IFeatureClass pFc = null;

                if (strExt == ".shp")
                {
                    IWorkspaceFactory pWsf = new ShapefileWorkspaceFactory();
                    IFeatureWorkspace pFws = pWsf.OpenFromFile(dataPath, 0) as IFeatureWorkspace;
                    pFc = pFws.OpenFeatureClass(strName);

                    pLayer.connectiontype = MS_CONNECTION_TYPE.MS_SHAPEFILE;
                    pLayer.data = dataPath;
                }
                else if (strExt == ".tab")
                {
                    IWorkspaceFactory pWsf = new OgrWorkspaceFactory();
                    IFeatureWorkspace pFws = pWsf.OpenFromFile(dataPath, 0) as IFeatureWorkspace;

                    pFc = pFws.OpenFeatureClass(strName);

                    pLayer.connectiontype = MS_CONNECTION_TYPE.MS_OGR;
                    pLayer.connection = dataPath;
                }

                IEnvelope pEnvelope = ((IGeoDataset)pFc).Extent;

                if (_Map.numlayers == 1)
                {
                    _Map.extent.minx = pEnvelope.XMin;
                    _Map.extent.miny = pEnvelope.YMin;
                    _Map.extent.maxx = pEnvelope.XMax;
                    _Map.extent.maxy = pEnvelope.YMax;
                }
                else
                {
                    //if the layer extents lager than the map extents
                    //reset the map extents
                    if (pEnvelope.XMin < _Map.extent.minx)
                        _Map.extent.minx = pEnvelope.XMin;
                    if (pEnvelope.YMin < _Map.extent.miny)
                        _Map.extent.miny = pEnvelope.YMin;
                    if (pEnvelope.XMax > _Map.extent.maxx)
                        _Map.extent.maxx = pEnvelope.XMax;
                    if (pEnvelope.YMax > _Map.extent.maxy)
                        _Map.extent.maxy = pEnvelope.YMax;

                }

                //rerecord the max extents
                m_MapMinx = _Map.extent.minx;
                m_MapMiny = _Map.extent.miny;
                m_MapMaxx = _Map.extent.maxx;
                m_MapMaxy = _Map.extent.maxy;

                classObj myClass = new classObj(pLayer);
                myClass.name = "random";

                styleObj myStyle = new styleObj(myClass);
                Color pRandomColor = GetRandomColor();
                myStyle.color.red = pRandomColor.R;
                myStyle.color.green = pRandomColor.G;
                myStyle.color.blue = pRandomColor.B;

                myStyle.opacity = 0;

                fmapGeometryType pGeomType = pFc.ShapeType;

                if ((pGeomType == fmapGeometryType.Point) ||
                    (pGeomType == fmapGeometryType.Point25D) ||
                    (pGeomType == fmapGeometryType.MultiPoint) ||
                    (pGeomType == fmapGeometryType.MultiPoint25D))
                {
                    pLayer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                }
                else if ((pGeomType == fmapGeometryType.LineString) ||
                        (pGeomType == fmapGeometryType.LineString) ||
                        (pGeomType == fmapGeometryType.MultiLineString) ||
                        (pGeomType == fmapGeometryType.MultiLineString25D))
                {
                    pLayer.type = MS_LAYER_TYPE.MS_LAYER_LINE;
                }
                else if ((pGeomType == fmapGeometryType.Polygon) ||
                        (pGeomType == fmapGeometryType.Polygon25D) ||
                        (pGeomType == fmapGeometryType.MultiPolygon) ||
                        (pGeomType == fmapGeometryType.MultiPolygon25D))
                {
                    pRandomColor = GetRandomColor();
                    myStyle.outlinecolor.red = pRandomColor.R;
                    myStyle.outlinecolor.green = pRandomColor.G;
                    myStyle.outlinecolor.blue = pRandomColor.B;

                    pLayer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                }
                else
                {
                    pLayer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                }

                if (pFc != null)
                    pFc.Dispose();
            }
            else if ((strExt == ".tif") || (strExt == ".img"))
            {
                pLayer.data = dataPath;
                pLayer.connectiontype = MS_CONNECTION_TYPE.MS_RASTER;
                pLayer.type = MS_LAYER_TYPE.MS_LAYER_RASTER;
            }
            else
                return false;

            if (OnLayerChanged != null)
                OnLayerChanged(null, new LayerChangedEventArgs(pLayer.index,strName, true));

            RecordLayersState();
            //Console.WriteLine(_Map.numlayers.ToString());

            return true;
        }
        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;
        }
Example #50
0
        private void UpdateStyleList()
        {
            string selectedName = style.symbolname;

            if (listView.SelectedItems.Count > 0)
            {
                selectedName = listView.SelectedItems[0].Text;
            }

            // populate the style listview
            listView.Items.Clear();
            imageList.Images.Clear();

            ListViewItem selected = null;

            if (comboBoxCategory.Text != "")
            {
                // Create "no symbol" entry
                styleObj nosymbolstyle = new styleObj(null);
                MapUtils.SetDefaultColor(layer.type, nosymbolstyle);
                ListViewItem nosymbolitem = AddListItem(nosymbolstyle, layer, "Default");
                if (selectedName == null)
                {
                    selected = nosymbolitem;
                }

                if (comboBoxCategory.Text == "Inline Symbols")
                {
                    for (int i = 0; i < map.symbolset.numsymbols; i++)
                    {
                        symbolObj symbol = map.symbolset.getSymbol(i);
                        if (symbol.inmapfile == mapscript.MS_TRUE &&
                            !StyleLibrary.HasSymbol(symbol.name))
                        {
                            styleObj libstyle = new styleObj(null);
                            //if (symbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_PATTERNMAP)
                            //    MapUtils.SetDefaultColor(MS_LAYER_TYPE.MS_LAYER_LINE, libstyle);
                            //else
                            MapUtils.SetDefaultColor(layer.type, libstyle);
                            libstyle.setSymbolByName(map, symbol.name);
                            libstyle.size = 8;
                            MS_LAYER_TYPE type = layer.type;
                            try
                            {
                                //STEPH: change layer passed to the list view to be consistent with the other symbol categories
                                //so that it uses a point layer to display the style in the list
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                                ListViewItem item = AddListItem(libstyle, layer, symbol.name);
                                if (selectedName == item.Text)
                                {
                                    selected = item;
                                }
                            }
                            finally
                            {
                                layer.type = type;
                            }
                        }
                    }
                }
                else
                {
                    // collect all fonts specified in the fontset file
                    Hashtable fonts = new Hashtable();
                    string    key   = null;
                    while ((key = map.fontset.fonts.nextKey(key)) != null)
                    {
                        fonts.Add(key, key);
                    }

                    mapObj   styles     = StyleLibrary.Styles;
                    layerObj stylelayer = styles.getLayerByName(comboBoxCategory.Text);
                    for (int i = 0; i < stylelayer.numclasses; i++)
                    {
                        classObj classobj    = stylelayer.getClass(i);
                        int      symbolIndex = classobj.getStyle(0).symbol;
                        if (symbolIndex >= 0)
                        {
                            string font = styles.symbolset.getSymbol(symbolIndex).font;
                            if (font != null && !fonts.ContainsKey(font))
                            {
                                continue; // this font cannot be found in fontset
                            }
                        }

                        ListViewItem item = AddListItem(classobj.getStyle(0), stylelayer, classobj.name);
                        if (selectedName == item.Text)
                        {
                            selected = item;
                        }
                    }
                }
            }

            if (selected != null)
            {
                selected.Selected = true;
                selected.EnsureVisible();
            }
        }
        /// <summary>
        /// Click event handler of the buttonEditDefaultStyle control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonEditDefaultStyle_Click(object sender, EventArgs e)
        {
            if (this.EditProperties != null)
            {
                // need to update the current changes
                if (IsDirty())
                {
                    UpdateValues();
                    UpdateControlState();
                }

                if (OriginalTarget.GetType() == typeof(styleObj))
                {
                    EditProperties(this, OriginalTarget);
                }
                else if (OriginalTarget.GetType() == typeof(classObj))
                {
                    classObj classobj = OriginalTarget;
                    if (classobj.numstyles <= 0)
                    {
                        // adding an empty style to this class
                        styleObj style = new styleObj(classobj);
                    }

                    EditProperties(this, new MapObjectHolder(classobj.getStyle(0), OriginalTarget));
                }
                else
                {
                    classObj classobj = layer.getClass(0);
                    if (classobj.numstyles <= 0)
                    {
                        // adding an empty style to this class
                        styleObj style = new styleObj(classobj);
                    }

                    EditProperties(this, new MapObjectHolder(classobj.getStyle(0),
                    new MapObjectHolder(classobj, target)));
                }
            }
        }
Example #52
0
        public static void ExpandFontStyles()
        {
            string        symbolSetFileContents = File.ReadAllText(symbolsetFileName);
            string        fontSetFileContents   = File.ReadAllText(fontsetFileName);
            StringBuilder newSymbols            = new StringBuilder();
            StringBuilder newFonts = new StringBuilder();

            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);
                if (MapUtils.HasMetadata(layer, "character-count"))
                {
                    string charcount = layer.getMetaData("character-count");
                    int    num;
                    if (layer.numclasses == 1 && charcount != null && int.TryParse(charcount, out num))
                    {
                        classObj classobj = layer.getClass(0);
                        if (!fontSetFileContents.Contains(classobj.name))
                        {
                            throw new Exception("Invalid font reference in mmstyles.map: " + classobj.name + ". The fontset file should contain an entry for this font name.");
                        }
                        for (int c = 33; c < 33 + num; c++)
                        {
                            string symbolname = classobj.name + "-" + c.ToString();

                            if (!symbolSetFileContents.Contains(symbolname))
                            {
                                symbolObj sym = new symbolObj(symbolname, null);
                                sym.character = "&#" + c.ToString() + ";";
                                sym.antialias = mapscript.MS_TRUE;
                                sym.type      = (int)MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE;
                                sym.font      = classobj.name;
                                sym.inmapfile = 0;
                                map.symbolset.appendSymbol(sym);
                                newSymbols.Append(String.Format("SYMBOL{0}  NAME \"{1}\"{0}  TYPE TRUETYPE{0}  ANTIALIAS TRUE{0}  CHARACTER \"{2}\"{0}  FONT \"{3}\"{0}END{0}", Environment.NewLine, symbolname, sym.character, sym.font));
                            }
                            if (c > 33)
                            {
                                // the first class is already inserted
                                classObj class2 = classobj.clone();
                                class2.name = symbolname;
                                styleObj style2 = class2.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                                layer.insertClass(class2, -1);
                            }
                            else
                            {
                                styleObj style2 = classobj.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                            }
                        }
                        if (!classobj.name.EndsWith("-33"))
                        {
                            classobj.name += "-33";
                        }
                    }
                    layer.removeMetaData("character-count");
                }
            }
            if (newSymbols.Length > 0)
            {
                // writing the new symbols to the symbolset file
                int lastpos = symbolSetFileContents.LastIndexOf("END", StringComparison.InvariantCultureIgnoreCase);
                symbolSetFileContents = symbolSetFileContents.Substring(0, lastpos) + newSymbols.ToString() + "END";
                File.WriteAllText(symbolsetFileName, symbolSetFileContents);
            }
            if (newFonts.Length > 0)
            {
                // writing the new fonts to the fontset file
                File.WriteAllText(fontsetFileName, fontSetFileContents + newFonts.ToString());
            }
        }
Example #53
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (style == null)
            {
                return;
            }
            //STEPH: set first load flag to make sure values are not updated by listView_SelectedIndexChanged event
            firstLoad = true;
            checkBoxAntialias.Checked = (style.antialias == mapscript.MS_TRUE);

            if (style.size < 0) // set default size (#4339)
            {
                textBoxSize.Text = "8";
            }
            else
            {
                textBoxSize.Text = style.size.ToString();
            }
            styleBindingControllerSize.InitializeBinding(target);

            textBoxMinSize.Text = style.minsize.ToString();
            textBoxMaxSize.Text = style.maxsize.ToString();
            textBoxWidth.Text   = style.width.ToString();
            styleBindingControllerWidth.InitializeBinding(target);
            textBoxAngle.Text = style.angle.ToString();
            styleBindingControllerAngle.InitializeBinding(target);
            textBoxMinWidth.Text = style.minwidth.ToString();
            textBoxMaxWidth.Text = style.maxwidth.ToString();
            textBoxOffsetX.Text  = style.offsetx.ToString();
            textBoxOffsetY.Text  = style.offsety.ToString();

            this.colorPickerColor.SetColor(style.color);
            styleBindingControllerColor.InitializeBinding(target);
            this.colorPickerBackColor.SetColor(style.backgroundcolor);
            this.colorPickerOutlineColor.SetColor(style.outlinecolor);
            styleBindingControllerOutlineColor.InitializeBinding(target);
            trackBarOpacity.Value    = style.opacity;
            labelOpacityPercent.Text = trackBarOpacity.Value + "%";

            checkBoxAutoAngle.Checked = (style.autoangle == mapscript.MS_TRUE);

            comboBoxGeomTransform.Items.Clear();
            if (isLabelStyle)
            {
                comboBoxGeomTransform.Items.AddRange(new string[] { "labelpnt", "labelpoly" });
            }
            else
            {
                comboBoxGeomTransform.Items.AddRange(new string[] { "start", "end", "vertices", "bbox", "centroid" });
            }

            comboBoxGeomTransform.Text = style.getGeomTransform();
            textBoxGap.Text            = style.gap.ToString();

            textBoxPattern.Text = GetPattenString(style.pattern);

            if (style.minscaledenom >= 0)
            {
                textBoxMinZoom.Text = style.minscaledenom.ToString();
            }
            else
            {
                textBoxMinZoom.Text = "";
            }
            if (style.maxscaledenom >= 0)
            {
                textBoxMaxZoom.Text = style.maxscaledenom.ToString();
            }
            else
            {
                textBoxMaxZoom.Text = "";
            }

            // populate the category combo
            mapObj styles           = StyleLibrary.Styles;
            string selectedCategory = null;
            bool   isStyleSelected  = false;

            for (int i = styles.numlayers - 1; i > -1; i--)
            {
                layerObj stylelayer = styles.getLayer(i);
                if (isLabelStyle)
                {
                    // for label styles add polygon and point categories
                    if (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                        stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                    {
                        comboBoxCategory.Items.Add(stylelayer.name);
                    }
                    if (selectedCategory == null && ((stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON && style.getGeomTransform().Contains("labelpoly")) ||
                                                     (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT && style.getGeomTransform().Contains("labelpnt"))))
                    {
                        selectedCategory = stylelayer.name; // for label style select default
                    }
                }
                else if ((layer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                          layer.type == MS_LAYER_TYPE.MS_LAYER_CIRCLE) &&
                         (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                          stylelayer.type == MS_LAYER_TYPE.MS_LAYER_LINE))
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for polygon layers select default
                    }
                }
                else if (layer.type == MS_LAYER_TYPE.MS_LAYER_LINE &&
                         stylelayer.type == MS_LAYER_TYPE.MS_LAYER_LINE)
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for line layers select default
                    }
                }
                else if (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for point layers select default
                    }
                }

                // select the style
                if (style.symbolname != null)
                {
                    for (int c = 0; c < stylelayer.numclasses; c++)
                    {
                        classObj styleclass = stylelayer.getClass(c);
                        styleObj libstyle   = styleclass.getStyle(0);

                        if (style.symbolname == libstyle.symbolname)
                        {
                            selectedCategory = stylelayer.name;
                            isStyleSelected  = true;
                            break;
                        }
                    }
                }
            }
            // check if we have inline symbols added to the map file
            bool inlineAdded = false;

            for (int i = 0; i < map.symbolset.numsymbols; i++)
            {
                symbolObj symbol = map.symbolset.getSymbol(i);
                if (symbol.inmapfile == mapscript.MS_TRUE &&
                    !StyleLibrary.HasSymbol(symbol.name))
                {
                    if (!inlineAdded)
                    {
                        comboBoxCategory.Items.Add("Inline Symbols");
                        inlineAdded = true;
                    }
                    if (!isStyleSelected && style.symbolname == symbol.name)
                    {
                        selectedCategory = "Inline Symbols";
                    }
                }
            }

            if (selectedCategory != null)
            {
                comboBoxCategory.SelectedItem = selectedCategory;
            }
            else if (comboBoxCategory.Items.Count > 0)
            {
                comboBoxCategory.SelectedIndex = 0;
            }

            SetDirty(false);
        }
Example #54
0
	public void testInsertStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,-1);
		
		assert(newStyle.refcount == 2, "testInsertStyleObj precondition");
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 2, "testInsertStyleObj");
	}
Example #55
0
        /// <summary>
        /// EditProperties Event handler for the layerControlStyles object.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">Event parameters.</param>
        private void layerControlStyles_EditProperties(object sender, MapObjectHolder target)
        {
            try
            {
                MapPropertyEditorForm mapPropertyEditor;
                if (target.GetType() == typeof(classObj))
                {
                    classObj classobj = target;

                    if (classobj.numstyles <= 0)
                    {
                        // adding an empty style to this class
                        styleObj style = new styleObj(classobj);
                    }

                    mapPropertyEditor = new MapPropertyEditorForm(
                        new MapObjectHolder(classobj.getStyle(0), target), new StyleLibraryPropertyEditor());
                }
                else if (target.GetType() == typeof(styleObj))
                    mapPropertyEditor = new MapPropertyEditorForm(target, new StyleLibraryPropertyEditor());
                else
                    return;
                propertyChanged = false;
                target.PropertyChanged += new EventHandler(target_PropertyChanged);
                mapPropertyEditor.ShowDialog(this);
                if (propertyChanged)
                    layerControlStyles.RefreshView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #56
0
	public void testInsertStyleObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,0);
		styleObj reference = classobj.getStyle(0);
		
		assert(newStyle.refcount == 3, "testInsertStyleObjDestroy precondition");
		newStyle.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; classobj=null; newStyle=null;
		gc();
		assert(reference.refcount == 2, "testInsertStyleObjDestroy");
	}
Example #57
0
        /// <summary>
        /// Update the style object according to the current Editor state.
        /// </summary>
        /// <param name="style">The object to be updated.</param>
        private void Update(styleObj style)
        {
            // general tab
            style.size = double.Parse(textBoxSize.Text);
            styleBindingControllerSize.ApplyBinding();
            style.minsize = double.Parse(textBoxMinSize.Text);
            style.maxsize = double.Parse(textBoxMaxSize.Text);
            style.width   = double.Parse(textBoxWidth.Text);
            styleBindingControllerWidth.ApplyBinding();
            style.angle = double.Parse(textBoxAngle.Text);
            styleBindingControllerAngle.ApplyBinding();
            style.minwidth = double.Parse(textBoxMinWidth.Text);
            style.maxwidth = double.Parse(textBoxMaxWidth.Text);
            // display tab
            this.colorPickerColor.ApplyTo(style.color);
            styleBindingControllerColor.ApplyBinding();
            this.colorPickerBackColor.ApplyTo(style.backgroundcolor);
            this.colorPickerOutlineColor.ApplyTo(style.outlinecolor);
            styleBindingControllerOutlineColor.ApplyBinding();
            style.offsetx = int.Parse(textBoxOffsetX.Text);
            style.offsety = int.Parse(textBoxOffsetY.Text);
            style.opacity = trackBarOpacity.Value;
            // set up alpha values according to opacity
            int alpha = Convert.ToInt32(style.opacity * 2.55);

            style.color.alpha           = alpha;
            style.outlinecolor.alpha    = alpha;
            style.backgroundcolor.alpha = alpha;
            style.mincolor.alpha        = alpha;
            style.maxcolor.alpha        = alpha;

            if (checkBoxAntialias.Checked)
            {
                style.antialias = mapscript.MS_TRUE;
            }
            else
            {
                style.antialias = mapscript.MS_FALSE;
            }

            if (checkBoxAutoAngle.Checked)
            {
                style.autoangle = mapscript.MS_TRUE;
            }
            else
            {
                style.autoangle = mapscript.MS_FALSE;
            }

            if (comboBoxGeomTransform.Text != "")
            {
                style.setGeomTransform(comboBoxGeomTransform.Text);
            }
            else
            {
                style.setGeomTransform(null);
            }

            style.gap = double.Parse(textBoxGap.Text);

            string[] values = textBoxPattern.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length > 0)
            {
                double[] result = new double[values.Length];
                for (int i = 0; i < values.Length; i++)
                {
                    result[i] = double.Parse(values[i], ni);
                }
                style.pattern = result;
            }
            else
            {
                style.patternlength = 0;
            }

            if (textBoxMaxZoom.Text == "")
            {
                style.maxscaledenom = -1;
            }
            else
            {
                style.maxscaledenom = double.Parse(textBoxMaxZoom.Text);
            }

            if (textBoxMinZoom.Text == "")
            {
                style.minscaledenom = -1;
            }
            else
            {
                style.minscaledenom = double.Parse(textBoxMinZoom.Text);
            }
        }
Example #58
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);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Update the style object according to the current Editor state.
        /// </summary>
        /// <param name="style">The object to be updated.</param>
        private void Update(styleObj style)
        {
            // general tab
            style.size = double.Parse(textBoxSize.Text);
            style.width = double.Parse(textBoxWidth.Text);
            style.angle = double.Parse(textBoxAngle.Text);
            // display tab
            this.colorPickerColor.ApplyTo(style.color);
            this.colorPickerBackColor.ApplyTo(style.backgroundcolor);
            this.colorPickerOutlineColor.ApplyTo(style.outlinecolor);

            style.gap = double.Parse(textBoxGap.Text);

            string[] values = textBoxPattern.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length > 0)
            {
                double[] result = new double[values.Length];
                for (int i = 0; i < values.Length; i++)
                    result[i] = double.Parse(values[i], ni);
                style.pattern = result;
            }
            else
                style.patternlength = 0;

            if (comboBoxSymbol.SelectedIndex > 0)
                style.setSymbolByName(map, comboBoxSymbol.SelectedItem.ToString());
            else
            {
                // no symbol selected
                style.symbol = 0;
                style.symbolname = null;
            }
        }