예제 #1
0
        /// <summary>
        /// Triggers a Zoom Chnaged event
        /// </summary>
        private void RaiseZoomChanged()
        {
            MS_UNITS mapunits = map.units;

            int unitPrecision = MapUtils.GetUnitPrecision(mapunits);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }
            target.RaiseZoomChanged(this, Math.Round(zoom, unitPrecision), map.scaledenom);
        }
예제 #2
0
        /// <summary>
        /// Click event handler of the buttonProjection control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonProjection_Click(object sender, EventArgs e)
        {
            if (projDialog == null)
            {
                projDialog = new ProjectionBrowserDialog();
            }

            projDialog.HelpRequested += new HelpEventHandler(MapPropertyEditor_HelpRequested);
            projDialog.Projection     = textBoxProjection.Text;
            if (projDialog.ShowDialog(this) == DialogResult.OK)
            {
                textBoxProjection.Text     = projDialog.Projection;
                textBoxProjection.Tag      = projDialog.ProjectionNative;
                comboBoxUnits.SelectedItem = MapUtils.GetMapUnitFromProj4(textBoxProjection.Tag.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// Validating event handler of the textBoxZoomWidth control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void textBoxZoomWidth_Validating(object sender, CancelEventArgs e)
        {
            double result;

            if (!double.TryParse(((TextBoxBase)sender).Text, out result) || result <= 0)
            {
                MessageBox.Show("Invalid zoom width or wrong number", "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }

            if (mapunits != map.units)
            {
                result = result * MapUtils.InchesPerUnit(mapunits) / MapUtils.InchesPerUnit(map.units);
            }

            zoomFactor        = result / (map.extent.maxx - map.extent.minx);
            textBoxScale.Text = Convert.ToString(Convert.ToInt32(map.scaledenom * zoomFactor));
        }
예제 #4
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            mapunits = map.units;

            unitPrecision     = MapUtils.GetUnitPrecision(mapunits);
            textBoxX.Text     = Convert.ToString(Math.Round((map.extent.maxx + map.extent.minx) / 2, unitPrecision));
            textBoxY.Text     = Convert.ToString(Math.Round((map.extent.maxy + map.extent.miny) / 2, unitPrecision));
            labelUnit2.Text   = MapUtils.GetUnitName(mapunits);
            textBoxScale.Text = Convert.ToString(Convert.ToInt32(map.scaledenom));

            labelUnit1.Text = MapUtils.GetUnitName(mapunits);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            textBoxZoomWidth.Text = Convert.ToString(Math.Round(zoom, unitPrecision));
        }
예제 #5
0
        /// <summary>
        /// Validating event handler of the textBoxScale control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void textBoxScale_Validating(object sender, CancelEventArgs e)
        {
            double result;

            if (!double.TryParse(((TextBoxBase)sender).Text, out result) || result <= 0)
            {
                MessageBox.Show("Invalid scale or wrong number", "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }
            zoomFactor = result / map.scaledenom;

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            textBoxZoomWidth.Text = Convert.ToString(Math.Round((zoom) * zoomFactor, unitPrecision));
        }
예제 #6
0
        /// <summary>
        /// Click event handler of the buttonApply control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonApply_Click(object sender, EventArgs e)
        {
            double deltaX  = (map.extent.maxx - map.extent.minx) * zoomFactor / 2;
            double deltaY  = (map.extent.maxy - map.extent.miny) * zoomFactor / 2;
            double centerX = double.Parse(textBoxX.Text);
            double centerY = double.Parse(textBoxY.Text);

            map.setExtent(centerX - deltaX, centerY - deltaY, centerX + deltaX, centerY + deltaY);

            target.RaisePropertyChanged(this);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            target.RaiseZoomChanged(this, Math.Round(zoom, unitPrecision), map.scaledenom);

            zoomFactor = 1.0;
        }
예제 #7
0
        public Color GetColorAtValue(double percent)
        {
            if (Value.Text == "Random values")
            {
                return(Color.FromArgb(MapUtils.GetRandomValue(256),
                                      MapUtils.GetRandomValue(256),
                                      MapUtils.GetRandomValue(256)));
            }

            // searching for the corresponding value
            int i;

            for (i = 0; i < Value.Count; i++)
            {
                if (Value.Keys[i] > percent)
                {
                    ++i;
                    break;
                }
            }

            // calculate color
            if (i > 0)
            {
                if (i < 2 || Value.Style == ColorRampStyle.Discrete)
                {
                    return(Value.Values[i - 1]);
                }
                else
                {
                    return(GetInterpolatedColor(Value.Values[i - 2], Value.Values[i - 1], percent / 100));
                }
            }
            else
            {
                return(Color.Empty);
            }
        }
예제 #8
0
        /// <summary>
        /// Click event handler of the buttonOK control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            // construct layer definition
            StringBuilder s = new StringBuilder(layerdef);

            s.Replace("%name%", MapUtils.GetUniqueLayerName(map, "grid", 0));

            s.Replace("%labelformat%", textBoxLabelFormat.Text);
            s.Replace("%labelcolorR%", colorPickerLabelColor.Value.R.ToString());
            s.Replace("%labelcolorG%", colorPickerLabelColor.Value.G.ToString());
            s.Replace("%labelcolorB%", colorPickerLabelColor.Value.B.ToString());
            s.Replace("%colorR%", colorPickerLineColor.Value.R.ToString());
            s.Replace("%colorG%", colorPickerLineColor.Value.G.ToString());
            s.Replace("%colorB%", colorPickerLineColor.Value.B.ToString());

            if (textBoxLabelSize.Text.Trim() != "")
            {
                s.Replace("%labelsize%", textBoxLabelSize.Text.ToString());
            }
            else
            {
                s.Replace("%labelsize%", "8");
            }

            if (textBoxLineWidth.Text.Trim() != "")
            {
                s.Replace("%linewidth%", textBoxLineWidth.Text.ToString());
            }
            else
            {
                s.Replace("%linewidth%", "2");
            }

            // optional parameters
            if (textBoxMinArcs.Text.Trim() != "")
            {
                s.Replace("%minarcs%", "MINARCS " + textBoxMinArcs.Text.ToString());
            }
            else
            {
                s.Replace("%minarcs%", "");
            }

            if (textBoxMaxArcs.Text.Trim() != "")
            {
                s.Replace("%maxarcs%", "MAXARCS " + textBoxMaxArcs.Text.ToString());
            }
            else
            {
                s.Replace("%maxarcs%", "");
            }

            if (textBoxMinInterval.Text.Trim() != "")
            {
                s.Replace("%mininterval%", "MININTERVAL " + textBoxMinInterval.Text.ToString());
            }
            else
            {
                s.Replace("%mininterval%", "");
            }

            if (textBoxMaxInterval.Text.Trim() != "")
            {
                s.Replace("%maxinterval%", "MAXINTERVAL " + textBoxMaxInterval.Text.ToString());
            }
            else
            {
                s.Replace("%maxinterval%", "");
            }

            if (textBoxMinSubdivide.Text.Trim() != "")
            {
                s.Replace("%minsubdivide%", "MINSUBDIVIDE " + textBoxMinSubdivide.Text.ToString());
            }
            else
            {
                s.Replace("%minsubdivide%", "");
            }

            if (textBoxMaxSubdivide.Text.Trim() != "")
            {
                s.Replace("%maxsubdivide%", "MAXSUBDIVIDE " + textBoxMaxSubdivide.Text.ToString());
            }
            else
            {
                s.Replace("%maxsubdivide%", "");
            }

            if (textBoxProjection.Tag != null)
            {
                s.Replace("%projection%", textBoxProjection.Tag.ToString());
            }
            else
            {
                s.Replace("%projection%", "init=epsg:4326");
            }

            // create layer
            layerObj layer = new layerObj(map);

            try
            {
                layer.updateFromString(s.ToString());

                DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                map.removeLayer(layer.index);
            }
        }
예제 #9
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 StyleLibrary.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.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());
            }
        }
예제 #10
0
 public static bool HasSymbol(string name)
 {
     return(MapUtils.FindSymbol(map.symbolset, name) != null);
 }
예제 #11
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)));
        }
예제 #12
0
        /// <summary>
        /// Adding the selected layer to map
        /// </summary>
        void AddLayerToMap()
        {
            // trying to open the layer
            layerObj layer = new layerObj(map);

            layer.connection     = textBoxServer.Text.Trim();
            layer.connectiontype = MS_CONNECTION_TYPE.MS_WMS;
            layer.type           = MS_LAYER_TYPE.MS_LAYER_RASTER;
            layer.status         = mapscript.MS_ON;

            // set up authentication
            NetworkCredential cred = (NetworkCredential)ViewModel.XmlProxyUrlResolver.GetCredentials();

            if (cred != null)
            {
                layer.metadata.set("wms_auth_username", cred.UserName);
                layer.metadata.set("wms_auth_password", cred.Password);
                layer.metadata.set("wms_auth_type", "any");
            }
            WebProxy proxy = (WebProxy)ViewModel.XmlProxyUrlResolver.Proxy;

            if (proxy != null)
            {
                layer.metadata.set("wms_proxy_host", proxy.Address.Host);
                layer.metadata.set("wms_proxy_port", proxy.Address.Port.ToString());
                layer.metadata.set("wms_proxy_auth_type", "any");
                layer.metadata.set("wms_proxy_type", ViewModel.XmlProxyUrlResolver.ProxyType);
                cred = (NetworkCredential)ViewModel.XmlProxyUrlResolver.GetProxyCredentials();
                if (cred != null)
                {
                    layer.metadata.set("wms_proxy_username", cred.UserName);
                    layer.metadata.set("wms_proxy_password", cred.Password);
                }
            }

            // setting up the selected layer
            selected = new MapObjectHolder(layer, target);

            // set queryable flag
            if (wms_queryable == "1")
            {
                layer.template = "query.html";
            }

            // setting up the layer metadata section
            layer.metadata.set("wms_name", wms_name);
            layer.metadata.set("wms_format", comboBoxImageFormat.Text.Trim());

            layer.metadata.set("wms_server_version", ViewModel.ServerVersion);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                                              colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 255);
                layer.metadata.set("wms_bgcolor", "0x" + color.toHex().Substring(1));
            }

            if (!checkBoxTransparent.Checked)
            {
                layer.metadata.set("wms_transparent", "FALSE");
            }

            // wms_style
            if (comboBoxStyle.Text != "")
            {
                layer.metadata.set("wms_style", comboBoxStyle.Text);
            }

            // title
            if (wms_title != null)
            {
                layer.name = MapUtils.GetUniqueLayerName(map, wms_title, 0);
            }
            else
            {
                layer.name = MapUtils.GetUniqueLayerName(map, "Layer", 0);
            }

            // scale denom
            if (wms_maxscaledenom > 0)
            {
                layer.maxscaledenom = wms_maxscaledenom;
            }
            if (wms_minscaledenom > 0)
            {
                layer.maxscaledenom = wms_minscaledenom;
            }

            // get bbox parameters
            if (wms_bbox != null && map.numlayers == 1)
            {
                // this is the first layer, set the extent of the map
                map.setExtent(wms_bbox.minx, wms_bbox.miny, wms_bbox.maxx, wms_bbox.maxy);
            }

            // setting up the selected projection
            KeyValuePair <string, string> current = (KeyValuePair <string, string>)bs.Current;
            string wms_srs = current.Key;

            // mapping not EPSG systems to the EPSG variants
            if (string.Compare(wms_srs, "CRS:84", true) == 0)
            {
                wms_srs = "EPSG:4326";
            }
            else if (string.Compare(wms_srs, "CRS:83", true) == 0)
            {
                wms_srs = "EPSG:4369";
            }
            else if (string.Compare(wms_srs, "CRS:27", true) == 0)
            {
                wms_srs = "EPSG:4267";
            }

            if (wms_srs.StartsWith("EPSG", StringComparison.InvariantCultureIgnoreCase))
            {
                layer.metadata.set("wms_srs", wms_srs);
            }
            layer.setProjection(wms_srs);
        }
예제 #13
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();
            }
        }
예제 #14
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            listView.Items.Clear();

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

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

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

                    try
                    {
                        for (int i = 0; i < map.numlayers; i++)
                        {
                            layerObj layer = map.getLayer(i);
                            if (layer.status != mapscript.MS_OFF)
                            {
                                resultObj res;
                                shapeObj  feature;
                                using (resultCacheObj results = layer.getResults())
                                {
                                    if (results != null && results.numresults > 0)
                                    {
                                        // extracting the features found
                                        for (int j = 0; j < results.numresults; j++)
                                        {
                                            res     = results.getResult(j);
                                            feature = layer.getShape(res);
                                            if (feature != null)
                                            {
                                                if (layerIndex != layer.index || classIndex != res.classindex)
                                                {
                                                    layerIndex = layer.index;
                                                    classIndex = res.classindex;
                                                    if (classIndex < 0)
                                                    {
                                                        classIndex = 0;
                                                    }
                                                    // creating the icon for this class
                                                    using (classObj def_class = new classObj(null)) // for drawing legend images
                                                    {
                                                        using (imageObj image = def_class.createLegendIcon(map, layer, 30, 20))
                                                        {
                                                            // drawing the class icons
                                                            if (layer.numclasses > classIndex)
                                                            {
                                                                layer.getClass(classIndex).drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                                            }
                                                            byte[] img = image.getBytes();
                                                            using (MemoryStream ms = new MemoryStream(img))
                                                            {
                                                                imageList.Images.Add(Image.FromStream(ms));
                                                            }
                                                        }
                                                    }
                                                }

                                                ListViewItem item = new ListViewItem(layer.name, imageList.Images.Count - 1);
                                                item.SubItems.Add(feature.index.ToString());
                                                item.SubItems.Add(MapUtils.GetShapeTypeName((MS_SHAPE_TYPE)feature.type));
                                                listView.Items.Add(item);

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

                    listView.SmallImageList = imageList;
                }
                if (listView.Items.Count > 0)
                {
                    listView.Items[0].Selected = true;
                }
                else
                {
                    richTextBox.Text = "";
                }
            }
        }
예제 #15
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)));
        }
예제 #16
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (map == null)
            {
                return;
            }
            // general tab
            this.textBoxName.Text      = map.name;
            this.textBoxShapePath.Text = map.shapepath;
            this.textBoxImagepath.Text = map.web.imagepath;
            this.textBoxSymbolset.Text = map.symbolset.filename;
            this.textBoxFontset.Text   = map.fontset.filename;
            // image details tab
            this.colorPickerBackColor.SetColor(map.imagecolor);
            comboBoxImageType.Items.Clear();
            comboBoxImageType.Items.AddRange(new object[] { "png", "jpeg", "gif", "png8", "png24", "pdf", "svg", "cairopng"
                                                            , "GTiff", "kml", "kmz" });

            for (int i = 0; i < map.numoutputformats; i++)
            {
                outputFormatObj format = map.getOutputFormat(i);
                if (!comboBoxImageType.Items.Contains(format.name))
                {
                    comboBoxImageType.Items.Add(format.name);
                }
            }

            //outputFormatObj[] formats = map.outputformatlist;
            //for (int i = 0; i < formats.Length; i++)
            //{
            //    if (!comboBoxImageType.Items.Contains(formats[i].name))
            //        comboBoxImageType.Items.Add(formats[i].name);
            //}
            comboBoxImageType.SelectedItem = map.imagetype;
            this.textBoxResolution.Text    = map.resolution.ToString();

            // setting up the projection information
            this.textBoxProjection.Tag  = map.getProjection();
            this.textBoxProjection.Text = "";
            string key = map.getFirstMetaDataKey();

            while (key != null)
            {
                if (key == "coordsys_name")
                {
                    this.textBoxProjection.Text = map.getMetaData("coordsys_name");
                    break;
                }
                key = map.getNextMetaDataKey(key);
            }
            if (this.textBoxProjection.Text == "")
            {
                string proj4;
                int    epsg;
                this.textBoxProjection.Text = MapUtils.FindProjection(this.textBoxProjection.Tag.ToString(), out proj4, out epsg);
            }

            comboBoxUnits.DataSource   = Enum.GetValues(typeof(MS_UNITS));
            comboBoxUnits.SelectedItem = (MS_UNITS)map.units;

            checkBoxTransparent.Checked = (map.outputformat.transparent == mapscript.MS_TRUE && map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA);
            checkBoxTransparent.Enabled = (map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGB || map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA);

            // extent tab
            UpdateExtentValues();

            SetDirty(false);
        }