Пример #1
0
        /// <summary>
        /// Update the preview according to the current Editor state.
        /// In case of the preview a temporary object will only be updated.
        /// </summary>
        public void UpdateValues()
        {
            if (style == null)
            {
                return;
            }
            if (dirtyFlag)
            {
                Update(this.style);

                // copy symbol to the map if needed
                if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default")
                {
                    // try to find symbol
                    int    symbolIndex;
                    string symbolName = listView.SelectedItems[0].Text;
                    for (symbolIndex = 0; symbolIndex < map.symbolset.numsymbols; symbolIndex++)
                    {
                        if (map.symbolset.getSymbol(symbolIndex).name == symbolName)
                        {
                            break;
                        }
                    }
                    if (symbolIndex == map.symbolset.numsymbols &&
                        comboBoxCategory.Text != "Inline Symbols")
                    {
                        // copy symbol from style library
                        mapObj sourceMap = StyleLibrary.Styles;
                        // removing the embedded scalebar symbol from top (should be fixed in mapserver)
                        string lastsymbolName = map.symbolset.getSymbol(map.symbolset.numsymbols - 1).name;
                        if (lastsymbolName == "scalebar" || lastsymbolName == "legend")
                        {
                            map.symbolset.removeSymbol(map.symbolset.numsymbols - 1);
                        }
                        lastsymbolName = map.symbolset.getSymbol(map.symbolset.numsymbols - 1).name;
                        if (lastsymbolName == "scalebar" || lastsymbolName == "legend")
                        {
                            map.symbolset.removeSymbol(map.symbolset.numsymbols - 1);
                        }
                        symbolIndex = map.symbolset.appendSymbol(MapUtils.CloneSymbol(
                                                                     sourceMap.symbolset.getSymbolByName(symbolName)));
                    }
                    style.symbolname = symbolName;
                    style.symbol     = symbolIndex;
                }
                else
                {
                    // remove symbol
                    style.symbol     = 0;
                    style.symbolname = null;
                }

                SetDirty(false);
                if (target != null)
                {
                    target.RaisePropertyChanged(this);
                }
            }
        }
Пример #2
0
        /// <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)));
        }
Пример #3
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)));
        }