/// <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)));
        }
Exemple #2
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (layer == null)
            {
                return;
            }

            shapeObj shape;

            layer.open();

            // Get layer statistics
            maxvalue   = new double[layer.numitems];
            minvalue   = new double[layer.numitems];
            fieldName  = new string[layer.numitems];
            isNumber   = new bool[layer.numitems];
            isInteger  = new bool[layer.numitems];
            valueCount = new int[layer.numitems];
            int i;

            for (i = 0; i < layer.numitems; i++)
            {
                isNumber[i]   = true;
                isInteger[i]  = true;
                valueCount[i] = 0;
                fieldName[i]  = layer.getItem(i);
            }

            layer.whichShapes(layer.getExtent());

            NumberFormatInfo ni = new NumberFormatInfo();

            ni.NumberDecimalSeparator = ".";

            double val;

            while ((shape = layer.nextShape()) != null)
            {
                for (i = 0; i < layer.numitems; i++)
                {
                    if (isNumber[i])
                    {
                        string v = shape.getValue(i);
                        if (v != "" && Double.TryParse(v, NumberStyles.Any, ni, out val))
                        {
                            if (val % 1 != 0)
                            {
                                isInteger[i] = false;
                            }

                            if (valueCount[i] == 0)
                            {
                                maxvalue[i] = val;
                                minvalue[i] = val;
                            }
                            else
                            {
                                if (maxvalue[i] < val)
                                {
                                    maxvalue[i] = val;
                                }
                                if (minvalue[i] > val)
                                {
                                    minvalue[i] = val;
                                }
                            }
                            ++valueCount[i];
                        }
                        else
                        {
                            isNumber[i]  = false;
                            isInteger[i] = false;
                        }
                    }
                }
            }

            for (i = 0; i < layer.numitems; i++)
            {
                if (isNumber[i])
                {
                    comboBoxColumns.Items.Add(fieldName[i]);
                }
            }
            if (comboBoxColumns.Items.Count > 0)
            {
                comboBoxColumns.SelectedIndex = 0;
            }

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