示例#1
0
        /// <summary>
        /// Constructs a new ThemeWizardForm object.
        /// </summary>
        /// <param name="target">The object that this Wizard operates on.</param>
        public ThemeWizardForm(MapObjectHolder target)
        {
            InitializeComponent();

            this.target = target;

            ListViewItem item = new ListViewItem();

            item.Text = "Individual Values";
            IndividualValuesTheme theme = new IndividualValuesTheme();

            theme.Visible = false;
            item.Tag      = theme;
            listViewThemes.Items.Add(item);

            item      = new ListViewItem();
            item.Text = "Value Ranges";
            RangeTheme theme2 = new RangeTheme();

            theme2.Visible = false;
            item.Tag       = theme2;
            listViewThemes.Items.Add(item);

            buttonBack.Enabled = false;
            buttonNext.Enabled = false;
            pageIndex          = 1;
        }
示例#2
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);
            }
        }
示例#3
0
        public static void Load(string fileName)
        {
            styles           = MapUtils.OpenMap(fileName);
            map              = styles;
            styleLibFileName = fileName;

            // get symbolset file name
            string styleDir = Path.GetDirectoryName(fileName);

            if (File.Exists(map.symbolset.filename))
            {
                symbolsetFileName = map.symbolset.filename;
            }
            else
            {
                throw new Exception("Cannot load Symbolset file." + map.symbolset.filename);
            }

            if (File.Exists(map.fontset.filename))
            {
                fontsetFileName = map.fontset.filename;
            }
            else
            {
                throw new Exception("Cannot load Fontset file. " + map.fontset.filename);
            }

            ExpandFontStyles();
        }
示例#4
0
        public ScriptConsoleForm(MapObjectHolder mapH)
        {
            InitializeComponent();
            this.mapH = mapH;
            this.map = mapH;

            ListSupportedLanguages();
        }
示例#5
0
 /// <summary>
 /// Constructs a new AddWMSLayerForm class.
 /// </summary>
 public AddWMSLayerForm(MapObjectHolder target)
 {
     InitializeComponent();
     if (target.GetType() != typeof(mapObj))
         throw new ApplicationException("Invalid object type.");
     this.map = target;
     this.target = target;
     UpdateControls();
 }
示例#6
0
 /// <summary>
 /// Constructs a new AddWMSLayerForm class.
 /// </summary>
 public AddWMSLayerForm(MapObjectHolder target)
 {
     InitializeComponent();
     if (target.GetType() != typeof(mapObj))
     {
         throw new ApplicationException("Invalid object type.");
     }
     this.map    = target;
     this.target = target;
     UpdateControls();
 }
示例#7
0
 /// <summary>
 /// Constructs a new ChangeViewForm class.
 /// </summary>
 public StyleLibraryForm(MapObjectHolder target)
 {
     InitializeComponent();
     isTextValidating = false;
     refresh = new RefreshDelegate(this.Refresh);
     isInit = true;
     isInitStyleLibText = true;
     // saving the reference to the base mapObj
     // In certain cases we require to reload the modified symbolset on the base mapfile too.
     this.target = target;
     this.map = target;
 }
示例#8
0
 /// <summary>
 /// Constructs a new ChangeViewForm class.
 /// </summary>
 public StyleLibraryForm(MapObjectHolder target)
 {
     InitializeComponent();
     isTextValidating   = false;
     refresh            = new RefreshDelegate(this.Refresh);
     isInit             = true;
     isInitStyleLibText = true;
     // saving the reference to the base mapObj
     // In certain cases we require to reload the modified symbolset on the base mapfile too.
     this.target = target;
     this.map    = target;
 }
 /// <summary>
 /// EditProperties event handler of the layerControl control
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="target">The target object to be edited.</param>
 void layerControl_EditProperties(object sender, MapObjectHolder target)
 {
     try
     {
         MapPropertyEditorForm mapPropertyEditor = new MapPropertyEditorForm(target);
         mapPropertyEditor.ShowDialog(this);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
示例#10
0
 /// <summary>
 /// Event handled to edit a sub-object.
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="target">The object to be edited.</param>
 void editor_EditProperties(object sender, MapObjectHolder target)
 {
     try
     {
         MapPropertyEditorForm mapPropertyEditor = new MapPropertyEditorForm(target);
         mapPropertyEditor.HelpRequested += new HelpEventHandler(mapPropertyEditor_HelpRequested);
         mapPropertyEditor.ShowDialog(this);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
示例#11
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);
            }
        }
示例#12
0
        /// <summary>
        /// Constructs a new ThemeWizardForm object.
        /// </summary>
        /// <param name="target">The object that this Wizard operates on.</param>
        public ThemeWizardForm(MapObjectHolder target)
        {
            InitializeComponent();

            this.target = target;

            ListViewItem item = new ListViewItem();
            item.Text = "Individual Values";
            IndividualValuesTheme theme = new IndividualValuesTheme();
            theme.Visible = false;
            item.Tag = theme;
            listViewThemes.Items.Add(item);

            item = new ListViewItem();
            item.Text = "Value Ranges";
            RangeTheme theme2 = new RangeTheme();
            theme2.Visible = false;
            item.Tag = theme2;
            listViewThemes.Items.Add(item);

            buttonBack.Enabled = false;
            buttonNext.Enabled = false;
            pageIndex = 1;
        }
示例#13
0
 /// <summary>
 /// ItemSelect 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_ItemSelect(object sender, MapObjectHolder target)
 {
     selectedItem = target;
     UpdateSample(target);
 }
示例#14
0
 /// <summary>
 /// EditProperties event handler of the layerControl control
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="target">The target object to be edited.</param>
 void layerControl_EditProperties(object sender, MapObjectHolder target)
 {
     try
     {
         MapPropertyEditorForm mapPropertyEditor = new MapPropertyEditorForm(target);
         mapPropertyEditor.ShowDialog(this);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
 /// <summary>
 /// Constructs a new MapPropertyEditorForm object.
 /// </summary>
 /// <param name="target">The target object to be edited.</param>
 public MapPropertyEditorForm(MapObjectHolder target)
     : this(target, null)
 {
 }
示例#16
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)resolver.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)resolver.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", resolver.ProxyType);
                cred = (NetworkCredential)resolver.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", wms_server_version);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                    colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0);
                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);
        }
示例#17
0
        public override void InitializeBinding(MapObjectHolder target)
        {
            this.target = target;

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

            layerObj layer = target.GetParent().GetParent();
            styleObj style = target;
            if (itemList == null)
            {
                itemList = new ComboBox();
                itemList.Width = targetControl.Width;
                itemList.Height = targetControl.Height;
                itemList.Location = targetControl.Location;
                itemList.DropDownStyle = ComboBoxStyle.DropDownList;
                itemList.SelectedIndexChanged += new EventHandler(itemList_SelectedIndexChanged);
                targetControl.Parent.Controls.Add(itemList);
                itemList.BringToFront();
                Bitmap bmp = Resources.DataConnection;
                bmp.MakeTransparent(Color.Magenta);
                pbox = new PictureBox();
                pbox.Image = bmp;
                pbox.SizeMode = PictureBoxSizeMode.AutoSize;
                pbox.Location = new System.Drawing.Point(targetControl.Location.X + targetControl.Width + 2,
                    targetControl.Location.Y + (targetControl.Height - pbox.Image.Height) / 2);
                targetControl.Parent.Controls.Add(pbox);
                pbox.BringToFront();
            }

            BindingState = false;

            itemList.Items.Clear();
            layer.open();
            for (int i = 0; i < layer.numitems; i++)
                itemList.Items.Add(layer.getItem(i));
            if (layer.getResults() == null)
                layer.close(); // close only is no query results

            if (layer.connectiontype == MS_CONNECTION_TYPE.MS_OGR)
            {
                itemList.Items.Add("OGR:LabelFont");
                itemList.Items.Add("OGR:LabelSize");
                itemList.Items.Add("OGR:LabelText");
                itemList.Items.Add("OGR:LabelAngle");
                itemList.Items.Add("OGR:LabelFColor");
                itemList.Items.Add("OGR:LabelBColor");
                itemList.Items.Add("OGR:LabelPlacement");
                itemList.Items.Add("OGR:LabelAnchor");
                itemList.Items.Add("OGR:LabelDx");
                itemList.Items.Add("OGR:LabelDy");
                itemList.Items.Add("OGR:LabelPerp");
                itemList.Items.Add("OGR:LabelBold");
                itemList.Items.Add("OGR:LabelItalic");
                itemList.Items.Add("OGR:LabelUnderline");
                itemList.Items.Add("OGR:LabelPriority");
                itemList.Items.Add("OGR:LabelStrikeout");
                itemList.Items.Add("OGR:LabelStretch");
                itemList.Items.Add("OGR:LabelAdjHor");
                itemList.Items.Add("OGR:LabelAdjVert");
                itemList.Items.Add("OGR:LabelHColor");
                itemList.Items.Add("OGR:LabelOColor");
            }

            string binding = style.getBinding((int)styleBinding);
            if (binding != null)
            {
                itemList.SelectedItem = binding;
                BindingState = true;
            }
            else
            {
                if (itemList.Items.Count > 0)
                    itemList.SelectedIndex = 0;
            }
        }
示例#18
0
 public virtual void InitializeBinding(MapObjectHolder target)
 {
 }
示例#19
0
 /// <summary>
 /// Raises an ItemSelect event
 /// </summary>
 private void RaiseItemSelect(MapObjectHolder selected)
 {
     if (this.ItemSelect != null && enableItemSelect)
         ItemSelect(this, selected);
 }
示例#20
0
 /// <summary>
 /// EditProperties event handler of the propertyEditor control
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="target">The object to be edited.</param>
 void propertyEditor_EditProperties(object sender, MapObjectHolder target)
 {
     if (EditProperties != null)
         EditProperties(this, target);
 }
示例#21
0
        /// <summary>
        /// Opens a vector layer.
        /// </summary>
        /// <param name="fileName">The name of the file to be opened.</param>
        private void OpenVectorLayer(string fileName)
        {
            layerObj layer = null;

            try
            {
                // trying to open the layer
                layer = CreateNewLayer();

                layer.connection = fileName;

                layer.connectiontype = MS_CONNECTION_TYPE.MS_OGR;
                layer.name = MapUtils.GetUniqueLayerName(map, Path.GetFileNameWithoutExtension(fileName), 0);
                layer.setProjection("+AUTO");
                layer.data = null;
                layer.status = mapscript.MS_ON;
                layer.template = "query.html";

                MapUtils.CreateRandomClass(layer);
                //MapUtils.InitializeDefaultLabel(layer);

                layer.open();
                layer.close();
                // try to find out the shape type using OGR
                Ogr.RegisterAll();
                DataSource ds = Ogr.Open(layer.connection, 0);
                if (ds != null)
                {
                    if (ds.GetLayerCount() > 0)
                    {
                        Layer ogrLayer;
                        if (layer.data != null)
                            ogrLayer = ds.GetLayerByName(layer.data);
                        else
                            ogrLayer = ds.GetLayerByIndex(0);
                        wkbGeometryType gType = ogrLayer.GetLayerDefn().GetGeomType();
                        // reading the first feature to detect the type, if necessary
                        Feature feat;
                        while (gType == wkbGeometryType.wkbUnknown  && (feat = ogrLayer.GetNextFeature()) != null)
                        {
                            Geometry geom = feat.GetGeometryRef();
                            if (geom != null)
                                gType = geom.GetGeometryType();
                            feat.Dispose();
                        }
                        layer.type = MapUtils.GetLayerType(gType);
                        //ds.ReleaseResultSet(ogrLayer);
                    }
                    ds.Dispose();
                }
                if (layer.styleitem != "AUTO")
                {
                    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 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;
                            }
                        }
                    }

                    // setting the default color
                    styleObj style = layer.getClass(0).getStyle(0);
                    MapUtils.SetDefaultColor(layer.type, style);
                }

                // setting up the selected layer
                selected = new MapObjectHolder(layer, target.GetParent());
            }
            catch(Exception ex)
            {
                MessageBox.Show("Unable to open layer, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (layer != null)
                {
                    if (layer.map != null)
                        layer.map.removeLayer(layer.index);
                    layer = null;
                }
            }

            if (layer != null)
            {
                // trying to find out the projname
                string proj = layer.getProjection().Trim();
                string proj4;
                int epsg;
                string proj_name = MapUtils.FindProjection(proj, out proj4, out epsg);
                if (proj4.Trim().StartsWith("+"))
                {
                    if (proj != proj4.Trim())
                        layer.setProjection(proj4);

                    layer.setMetaData("coordsys_name", proj_name);
                }

                // if this is the first layer or the map projection hasn't been set zoom to this extent
                if (map.numlayers == 1 || map.getProjection().Trim().Length == 0)
                {
                    ZoomToLayerExtent(layer);
                    if (InitialExtentSet != null)
                        InitialExtentSet(this, null);

                    // setting the projection of the map according to the layer projection
                    if (map.getProjection().Trim().Length == 0 && proj.Length > 0 && proj != "+AUTO")
                    {
                        map.setProjection(layer.getProjection());
                        map.setMetaData("coordsys_name", proj_name);
                        // setting up the default unit
                        if (proj.Contains("+proj=longlat"))
                            map.units = MS_UNITS.MS_DD;
                        else
                            map.units = MS_UNITS.MS_METERS;
                    }
                }
            }
        }
示例#22
0
        /// <summary>
        /// Opens a tile index layer.
        /// </summary>
        /// <param name="fileName">The name of the file to be opened.</param>
        private void OpenTileIndexLayer(string fileName)
        {
            layerObj layer = null;

            try
            {
                // trying to open the layer
                layer = CreateNewLayer();

                layer.connection = fileName;

                layer.connectiontype = MS_CONNECTION_TYPE.MS_OGR;
                layer.name = MapUtils.GetUniqueLayerName(map, Path.GetFileNameWithoutExtension(fileName), 0);
                layer.setProjection("+AUTO");
                layer.data = null;
                layer.status = mapscript.MS_OFF;
                layer.template = "query.html";

                MapUtils.CreateRandomClass(layer);
                //MapUtils.InitializeDefaultLabel(layer);

                // setting auto style for the mapinfo layers
                string ext = Path.GetExtension(fileName).Trim().ToLower();
                if (ext == ".tab" || ext == ".mif")
                    layer.styleitem = "AUTO";

                layer.open();
                layer.close();
                // try to find out the shape type using OGR
                Ogr.RegisterAll();
                DataSource ds = Ogr.Open(layer.connection, 0);
                if (ds != null)
                {
                    if (ds.GetLayerCount() > 0)
                    {
                        Layer ogrLayer;
                        if (layer.data != null)
                            ogrLayer = ds.GetLayerByName(layer.data);
                        else
                            ogrLayer = ds.GetLayerByIndex(0);
                        wkbGeometryType gType = ogrLayer.GetLayerDefn().GetGeomType();
                        if (gType != wkbGeometryType.wkbUnknown)
                            layer.type = MapUtils.GetLayerType(gType);

                        int tileFieldIndex = ogrLayer.GetLayerDefn().GetFieldIndex("location");
                        if (tileFieldIndex < 0)
                        {
                            // Prompt for the index
                            FieldSelectionForm form = new FieldSelectionForm(layer, "Select the field for the file locations");
                            if (form.ShowDialog(this) == DialogResult.OK)
                            {
                                tileFieldIndex = ogrLayer.GetLayerDefn().GetFieldIndex(form.SelectedItem);
                                layer.tileitem = form.SelectedItem;
                            }
                        }
                        Feature feat;
                        while ((feat = ogrLayer.GetNextFeature()) != null)
                        {
                            string basePath = "";
                            string tileFile = feat.GetFieldAsString(tileFieldIndex);
                            // separate source and layer
                            string[] src = tileFile.Split(new char[] { ',' });

                            if (!File.Exists(src[0]))
                            {
                                if (map.shapepath != "" && File.Exists(map.shapepath + "\\" + src[0]))
                                    basePath = map.shapepath + "\\";
                                else if (map.mappath != "" && File.Exists(map.mappath + "\\" + src[0]))
                                    basePath = map.mappath + "\\";
                                else
                                    throw new Exception("File fot found: " + src[0] + ". If your tile file contains relative pathes try to set SHAPEPATH to the base directory.");
                            }
                            // trying to open as vector data source
                            DataSource ds2 = Ogr.Open(basePath + src[0], 0);
                            if (ds2 == null)
                            {
                                // trying to open as raster data source
                                Dataset ds3 = Gdal.Open(basePath + src[0], Access.GA_ReadOnly);
                                if (ds3 == null)
                                    throw new Exception("Can't open data source: " + src[0] + ".");

                                // successfully opened
                                layer.type = MS_LAYER_TYPE.MS_LAYER_RASTER;
                                layer.styleitem = null;
                                // TODO: check for SRS entry (if upgrading to Mapserver 6.4)
                                ds3.Dispose();
                            }
                            else
                            {
                                try
                                {
                                    // find out geometry type
                                    if (gType == wkbGeometryType.wkbUnknown)
                                    {
                                        Geometry geom = feat.GetGeometryRef();
                                        if (geom != null)
                                            gType = geom.GetGeometryType();
                                        layer.type = MapUtils.GetLayerType(gType);
                                    }
                                    feat.Dispose();

                                    Layer l;
                                    if (src.Length == 2)
                                    {
                                        int layerIndex;
                                        if (int.TryParse(src[1], out layerIndex))
                                            l = ds2.GetLayerByIndex(layerIndex);
                                        else
                                            l = ds2.GetLayerByName(src[1]);
                                    }
                                    else
                                        l = ds2.GetLayerByIndex(0);
                                    if (l == null)
                                    {
                                        throw new Exception("Can't open layer: " + tileFile + ".");
                                    }
                                    else
                                        l.Dispose();
                                }
                                finally
                                {
                                    ds2.Dispose();
                                }
                            }
                        }
                    }
                    ds.Dispose();
                }
                if (layer.styleitem != "AUTO")
                {
                    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 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;
                            }
                        }
                    }

                    // setting the default color
                    styleObj style = layer.getClass(0).getStyle(0);
                    MapUtils.SetDefaultColor(layer.type, style);
                }

                // setting up the selected layer
                selected = new MapObjectHolder(layer, target.GetParent());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to open layer, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (layer != null)
                {
                    if (layer.map != null)
                        layer.map.removeLayer(layer.index);
                    layer = null;
                }
            }

            if (layer != null)
            {
                // set up layer extent, we still need to open the layer as a vector layer to get extent

                // trying to find out the projname
                string proj = layer.getProjection().Trim();
                string proj4;
                int epsg;
                string proj_name = MapUtils.FindProjection(proj, out proj4, out epsg);
                if (proj4.Trim().StartsWith("+"))
                {
                    if (proj != proj4.Trim())
                        layer.setProjection(proj4);

                    layer.setMetaData("coordsys_name", proj_name);
                }

                // if this is the first layer or the map projection hasn't been set zoom to this extent
                if (map.numlayers == 1 || map.getProjection().Trim().Length == 0)
                {
                    ZoomToLayerExtent(layer);
                    if (InitialExtentSet != null)
                        InitialExtentSet(this, null);

                    // setting the projection of the map according to the layer projection
                    if (map.getProjection().Trim().Length == 0 && proj.Length > 0 && proj != "+AUTO")
                    {
                        map.setProjection(layer.getProjection());
                        map.setMetaData("coordsys_name", proj_name);
                        // setting up the default unit
                        if (proj.Contains("+proj=longlat"))
                            map.units = MS_UNITS.MS_DD;
                        else
                            map.units = MS_UNITS.MS_METERS;
                    }
                }
                // set up tile index
                layer.tileindex = layer.connection;
                if (layer.type == MS_LAYER_TYPE.MS_LAYER_RASTER)
                {
                    // switch to raster layer, modify vtable
                    layer.setConnectionType((int)MS_CONNECTION_TYPE.MS_RASTER, null);
                }
                // tile index layer doesn't use connection parameter
                layer.connection = null;
            }
        }
示例#23
0
        /// <summary>
        /// Opens a raster layer
        /// </summary>
        /// <param name="fileName">The name of the file to be opened.</param>
        private void OpenRasterLayer(string fileName)
        {
            layerObj layer = null;
            try
            {
                // trying to open the layer
                layer = CreateNewLayer();
                layer.connectiontype = MS_CONNECTION_TYPE.MS_RASTER;
                layer.type = MS_LAYER_TYPE.MS_LAYER_RASTER;
                layer.name = MapUtils.GetUniqueLayerName(map, Path.GetFileNameWithoutExtension(fileName), 0);
                layer.setProjection("AUTO");
                layer.data = fileName;
                layer.status = mapscript.MS_ON;

                // setting up the selected layer
                selected = new MapObjectHolder(layer, target.GetParent());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to open layer, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (layer != null)
                {
                    if (layer.map != null)
                        layer.map.removeLayer(layer.index);
                    layer = null;
                }
            }

            // calculating the extent of this layer
            Gdal.AllRegister();
            Dataset ds = Gdal.Open(fileName, Access.GA_ReadOnly);
            if (ds != null)
            {
                double[] adfGeoTransform = new double[6];
                double minx, miny, maxx, maxy;
                ds.GetGeoTransform(adfGeoTransform);
                minx = adfGeoTransform[0];
                miny = adfGeoTransform[3];
                maxx = adfGeoTransform[0] + adfGeoTransform[1] * ds.RasterXSize + adfGeoTransform[2] * ds.RasterYSize;
                maxy = adfGeoTransform[3] + adfGeoTransform[4] * ds.RasterXSize + adfGeoTransform[5] * ds.RasterYSize;
                if (minx != maxx || miny != maxy)
                {
                    layer.setExtent(Math.Min(minx, maxx), Math.Min(miny, maxy), Math.Max(minx, maxx), Math.Max(miny, maxy));
                }

                // try to find out the projection and use that explicitly
                string wkt = ds.GetProjection();
                if (wkt != "")
                {
                    SpatialReference srs = new SpatialReference(wkt);
                    string proj4;
                    srs.ExportToProj4(out proj4);
                    if (proj4 != null || proj4 != "")
                    {
                        string proj4_out;
                        int epsg;
                        string projName = MapUtils.FindProjection(proj4, out proj4_out, out epsg);
                        if (proj4_out.StartsWith("+"))
                        {
                            layer.setProjection(proj4_out);
                            layer.setMetaData("coordsys_name", projName);
                        }
                    }
                }
            }

            // if this is the first layer zoom to this extent
            if (layer != null && map.numlayers == 1)
            {
                ZoomToLayerExtent(layer);
                if (InitialExtentSet != null)
                    InitialExtentSet(this, null);

                // setting the projection of the map according to the layer projection
                string proj = layer.getProjection().Trim();
                if (map.getProjection().Trim().Length == 0 && proj.Length > 0 && proj != "+AUTO")
                {
                    map.setProjection(proj);
                    // setting up the default unit
                    if (proj.Contains("+proj=longlat"))
                        map.units = MS_UNITS.MS_DD;
                    else
                        map.units = MS_UNITS.MS_METERS;
                }
            }
        }
示例#24
0
        /// <summary>
        /// Click event handler of the addWMSLayerToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void addWMSLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode source = CurrentTree.SelectedNode;
            if (source != null && source.Tag != null)
                RaiseItemSelect((MapObjectHolder)source.Tag);

            int numlayers = map.numlayers;

            AddWMSLayerForm form = new AddWMSLayerForm(target);
            if (form.ShowDialog(this) == DialogResult.OK)
            {
                this.selected = form.GetSelectedLayer();
                layerObj layer = selected;

                // if this is the first layer zoom to this extent
                if (layer != null && numlayers == 0)
                {
                    ZoomToLayerExtent(layer);
                    if (InitialExtentSet != null)
                        InitialExtentSet(this, null);

                    // setting the projection of the map according to the layer projection
                    string proj = layer.getProjection().Trim();
                    if (map.getProjection().Trim().Length == 0 && proj.Length > 0 && proj != "+AUTO")
                    {
                        map.setProjection(proj);
                        // setting up the default unit
                        if (proj.Contains("+proj=longlat"))
                            map.units = MS_UNITS.MS_DD;
                        else
                            map.units = MS_UNITS.MS_METERS;
                    }
                }

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

                RefreshView();
            }
        }
示例#25
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;
            }
        }
示例#26
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;
        }
示例#27
0
        /// <summary>
        /// Updates the expanded and the selected state of the nodes in the collection according to the node type
        /// </summary>
        /// <param name="source">The source (sample) treeView</param>
        /// <param name="destination">The destination treeView which should be updated</param>
        /// <param name="destnodes">The node collection which should be updated</param>
        private void UpdateNodeState(TreeView source, TreeView destination, TreeNodeCollection destnodes)
        {
            foreach (TreeNode node in destnodes)
            {
                TreeNode n = FindNode(source.Nodes, node);
                if (n == null)
                    n = FindNodeByName(source.Nodes, node);

                if (n != null)
                {
                    if (n.IsExpanded || n.Parent == null)
                        node.Expand();
                    if (n.IsSelected)
                        destination.SelectedNode = node;
                    if (n.Equals(source.TopNode))
                        topNode = node;  // preserve the top node
                }
                else
                {
                    MapObjectHolder h = (MapObjectHolder)node.Tag;
                    if (h.GetType() == typeof(mapObj))
                    {
                        // expand the map and layer nodes by default
                        node.Expand();
                    }
                }

                // pre select the desired node
                if (selected != null)
                {
                    if (selected.Equals(node.Tag))
                    {
                        destination.SelectedNode = node;
                        source.SelectedNode = null; // remove the previous selection
                        selected = null;
                    }
                }

                UpdateNodeState(source, destination, node.Nodes);
            }
        }
示例#28
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)resolver.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)resolver.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", resolver.ProxyType);
                cred = (NetworkCredential)resolver.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", wms_server_version);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                                              colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0);
                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);
        }
示例#29
0
        /// <summary>
        /// Adding a new classObj to the corresponding layerObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="classHolder">Wrapper class containing the classObj and the parent object</param>
        /// /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param>
        private void AddClassNode(TreeNodeCollection nodes, MapObjectHolder classHolder, ImageList imageList)
        {
            layerObj layer = classHolder.GetParent();
            classObj layerclass = classHolder;

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

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

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

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

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

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

                            if (layerclass.numlabels > 1)
                            {
                                AddLabelNode(nodes, new MapObjectHolder(classLabel, classHolder), imageList, l);
                            }
                        }
                    }
                }
            }
        }
示例#30
0
        /// <summary>
        /// Creating a sample (preview) based on a classObj, styleObj or labelObj.
        /// </summary>
        /// <param name="original">The wrapper holding the original object.</param>
        private void CreateSampleMap(MapObjectHolder original)
        {
            MapObjectHolder originalMap = null;
            MapObjectHolder originalLayer = null;
            MapObjectHolder originalClass = null;
            // create a sample map to render a preview of the given object
            if (original.GetType() == typeof(classObj))
            {
                // tracking down the whole object tree
                originalLayer = original.GetParent();
                if (originalLayer != null)
                    originalMap = originalLayer.GetParent();
                // creating a new compatible map object
                if (originalMap != null)
                {
                    layerObj layer = InitializeDefaultLayer(originalMap, originalLayer);
                    layer.insertClass(((classObj)original).clone(), -1);
                    // bindings are not supported with sample maps
                    classObj classobj = layer.getClass(0);
                    for (int i = 0; i < classobj.numstyles; i++)
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(i));
                    for (int i = 0; i < classobj.numlabels; i++)
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(i));
                    classobj.setText("Sample text");
                    classobj.setExpression(""); // remove expression to have the class shown

                    this.target = new MapObjectHolder(classobj, original.GetParent());
                }
            }
            else if (original.GetType() == typeof(styleObj))
            {
                // tracking down the whole object tree
                if (original.GetParent().GetType() == typeof(labelObj))
                    originalClass = original.GetParent().GetParent();
                else
                    originalClass = original.GetParent();
                if (originalClass != null)
                    originalLayer = originalClass.GetParent();
                if (originalLayer != null)
                    originalMap = originalLayer.GetParent();
                // creating a new compatible map object
                if (originalMap != null)
                {
                    layerObj layer = InitializeDefaultLayer(originalMap, originalLayer);
                    classObj classobj = new classObj(layer);
                    classobj.name = MapUtils.GetClassName(layer);
                    styleObj style;
                    if (original.GetParent().GetType() == typeof(labelObj))
                    {

                        classobj.addLabel(new labelObj());
                        labelObj label = classobj.getLabel(classobj.numlabels - 1);
                        MapUtils.SetDefaultLabel(label, layer.map);
                        label.insertStyle(((styleObj)original).clone(), -1);
                        style = label.getStyle(0);
                    }
                    else
                    {
                        classobj.insertStyle(((styleObj)original).clone(), -1);
                        style = classobj.getStyle(0);
                    }

                    // bindings are not supported with sample maps
                    StyleBindingController.RemoveAllBindings(style);
                    classobj.setText("Sample text");
                    this.target = new MapObjectHolder(style, original.GetParent());
                }
            }
            else if (original.GetType() == typeof(labelObj))
            {
                // tracking down the whole object tree
                originalClass = original.GetParent();
                if (originalClass != null)
                {
                    if (originalClass.GetType() == typeof(classObj))
                    {
                        originalLayer = originalClass.GetParent();
                        if (originalLayer != null)
                            originalMap = originalLayer.GetParent();
                    }
                    else if (originalClass.GetType() == typeof(scalebarObj))
                    {
                        originalMap = originalClass.GetParent();
                    }
                }

                // creating a new compatible map object
                if (originalMap != null)
                {
                    layerObj layer = InitializeDefaultLayer(originalMap, originalLayer);
                    classObj classobj = new classObj(layer);
                    classobj.name = MapUtils.GetClassName(layer);
                    labelObj label = new labelObj();

                    if (originalClass.GetType() == typeof(classObj))
                    {
                        // copy settings
                        label.updateFromString(((labelObj)original).convertToString());
                    }
                    classobj.addLabel(label);

                    this.target = new MapObjectHolder(layer.getClass(0).getLabel(0), original.GetParent());
                }
            }
            else
                throw new Exception("Invalid target type: " + original.GetType());
        }
示例#31
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);
        }
示例#32
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);
            }
        }
示例#33
0
 /// <summary>
 /// Applying the text contents based on the current map configuration
 /// </summary>
 public static void ApplyTextContents(string text)
 {
     map    = mapscript.msLoadMapFromString(text, null);
     styles = new MapObjectHolder(map, null);
 }
 /// <summary>
 /// Event handled to edit a sub-object.
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="target">The object to be edited.</param>
 void editor_EditProperties(object sender, MapObjectHolder target)
 {
     try
     {
         MapPropertyEditorForm mapPropertyEditor = new MapPropertyEditorForm(target);
         mapPropertyEditor.HelpRequested += new HelpEventHandler(mapPropertyEditor_HelpRequested);
         mapPropertyEditor.ShowDialog(this);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
示例#35
0
 /// <summary>
 /// Constructs a new MapPropertyEditorForm object.
 /// </summary>
 /// <param name="target">The target object to be edited.</param>
 public MapPropertyEditorForm(MapObjectHolder target) : this(target, null)
 {
 }
        /// <summary>
        /// Constructs a new MapPropertyEditorForm object.
        /// </summary>
        /// <param name="target">The target object to be edited.</param>
        /// <param name="editor">The editor to be used.</param>
        public MapPropertyEditorForm(MapObjectHolder target, IPropertyEditor editor)
        {
            InitializeComponent();
            this.SuspendLayout();
            if (target.GetType() == typeof(mapObj))
            {
                if (editor == null)
                {
                    editor = new MapPropertyEditor();
                    ((MapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Map Properties";
                mapObj map = (mapObj)target;
                if (map.name != "")
                this.Text += " (" + map.name + ")";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(layerObj))
            {
                if (editor == null)
                {
                    editor = new LayerPropertyEditor();
                    ((LayerPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Layer Properties";
                layerObj layer = (layerObj)target;
                if (layer.name != "")
                    this.Text += " (" + layer.name + ")";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(classObj))
            {
                if (editor == null)
                {
                    editor = new ClassPropertyEditor();
                    ((ClassPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Class Properties";
                classObj classObject = (classObj)target;

                StringBuilder scaledomain = new StringBuilder("");
                if (classObject.minscaledenom >= 0)
                {
                    if (classObject.maxscaledenom >= 0)
                        scaledomain.Append(" 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    else
                        scaledomain.Append(" from 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }
                if (classObject.maxscaledenom >= 0)
                {
                    scaledomain.Append(" to 1:" + classObject.maxscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }

                if (classObject.name != "")
                    this.Text += " (" + classObject.name + scaledomain + ")";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(styleObj))
            {
                if (editor == null)
                {
                    editor = new StylePropertyEditor();
                    ((StylePropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Style Properties";
                this.editor = editor;
            }

            else if (target.GetType() == typeof(labelObj))
            {
                if (editor == null)
                {
                    editor = new LabelPropertyEditor();
                    ((LabelPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Label Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(scalebarObj))
            {
                if (editor == null)
                {
                    editor = new ScalebarPropertyEditor();
                    ((ScalebarPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Scalebar Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(queryMapObj))
            {
                if (editor == null)
                {
                    editor = new QueryMapPropertyEditor();
                    ((QueryMapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Query Map Properties";
                this.editor = editor;
            }
            else
                throw new Exception("No editor have been implemented for this item");

            if (this.editor != null)
            {
                Control c = (Control)this.editor;
                c.Location = new System.Drawing.Point(3, 4);
                c.TabIndex = 0;

                editor.Target = target;
                this.Controls.Add(c);
                target.PropertyChanging += new EventHandler(target_PropertyChanging);
                editor.EditProperties += new EditPropertiesEventHandler(editor_EditProperties);

                buttonOK.Top = c.Bottom + 8;
                buttonCancel.Top = c.Bottom + 8;
                buttonApply.Top = c.Bottom + 8;
            }

            UpdateButtonState();

            this.ResumeLayout(false);
        }
示例#37
0
 public virtual void InitializeBinding(MapObjectHolder target)
 {
 }
示例#38
0
 /// <summary>
 /// Constructs a new MapObjectHolder object
 /// </summary>
 /// <param name="target">The MapScript object to be stored.</param>
 /// <param name="parent">The wrapper of the parent object.</param>
 public MapObjectHolder(object target, MapObjectHolder parent)
 {
     this.target = target;
     this.parent = parent;
 }
示例#39
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);
        }
示例#40
0
        /// <summary>
        /// Adding a new mapObj to the treeView.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the treeView object.</param>
        /// <param name="mapHolder">Wrapper class containing the mapObj and the parent object.</param>
        /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param> 
        /// <param name="imageList">The imagelist of the treeview.</param>
        private void AddMapNode(TreeNodeCollection nodes, MapObjectHolder mapHolder, bool showRoot, ImageList imageList)
        {
            TreeNode current = null;
            using (intarray ar = map.getLayersDrawingOrder())
            {
                if (showRoot)
                {
                    if (IsStyleLibraryControl)
                    {
                        imageList.Images.Add(global::MapLibrary.Properties.Resources.Map_Legend_Big);
                    }
                    else
                    {
                        imageList.Images.Add(global::MapLibrary.Properties.Resources.Map_Legend);
                    }
                    current = new TreeNode(map.name, imageList.Images.Count - 1, imageList.Images.Count - 1);
                    current.Checked = true;
                    current.Tag = target; // wire up the map into the node
                    nodes.Add(current);
                    nodes = current.Nodes;
                }
                for (int i = 0; i < map.numlayers; i++)
                {
                    layerObj layer = map.getLayer(ar.getitem(i));
                    if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend")
                        continue;

                    AddLayerNode(nodes, new MapObjectHolder(layer, mapHolder), true, imageList);
                }
            }
        }
示例#41
0
        /// <summary>
        /// Click event handler of the addMSSQLSpatialLayerToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void addMSSQLSpatialLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode source = CurrentTree.SelectedNode;
            if (source != null && source.Tag != null)
                RaiseItemSelect((MapObjectHolder)source.Tag);

            int numlayers = map.numlayers;

            SqlConnectionDialog form = new SqlConnectionDialog();
            if (form.ShowDialog(this) == DialogResult.OK)
            {
                layerObj layer = null;
                try
                {
                    // trying to open the layer
                    MapUtils.TestMSSQLConnection(form.GetConnectionString(), form.GetDataString());

                    layer = CreateNewLayer();
                    layer.connectiontype = MS_CONNECTION_TYPE.MS_PLUGIN;
                    layer.plugin_library = layer.plugin_library_original = "msplugin_mssql2008.dll";

                    layer.connection = form.GetConnectionString();
                    layer.data = form.GetDataString();

                    switch (form.GeometryType)
                    {
                        case "Point":
                        case "MultiPoint":
                            layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            break;
                        case "LineString":
                        case "MultiLineString":
                            layer.type = MS_LAYER_TYPE.MS_LAYER_LINE;
                            break;
                        case "Polygon":
                        case "MultiPolygon":
                            layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            break;
                        default:
                            layer.type = MS_LAYER_TYPE.MS_LAYER_LINE;
                            break;
                    }

                    MapUtils.CreateRandomClass(layer);
                    MapUtils.InitializeDefaultLabel(layer);

                    layer.name = MapUtils.GetUniqueLayerName(map, form.TableName, 0);
                    string projName;
                    string proj4text;
                    int epsg;

                    if (form.GetProj4Text() != null)
                    {
                        projName = MapUtils.FindProjection(form.GetProj4Text(), out proj4text, out epsg);
                        layer.setProjection(form.GetProj4Text());
                        layer.setMetaData("coordsys_name", projName);
                    }
                    else if (form.GetSRText() != null && form.GetSRText() != "")
                    {
                        SpatialReference srs = new SpatialReference(form.GetSRText());
                        string proj4;
                        srs.ExportToProj4(out proj4);
                        if (proj4 != null || proj4 != "")
                        {
                            projName = MapUtils.FindProjection(proj4, out proj4text, out epsg);
                            //Steph: looks like there was a copy and paste error, I have replaced form.GetProj4Text() with proj4text
                            layer.setProjection(proj4text);
                            layer.setMetaData("coordsys_name", projName);
                        }
                    }
                    else
                        layer.setProjection("AUTO");

                    layer.status = mapscript.MS_ON;

                    // setting up the selected layer
                    selected = new MapObjectHolder(layer, target.GetParent());
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to open layer, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (layer != null)
                    {
                        if (layer.map != null)
                            layer.map.removeLayer(layer.index);
                        layer = null;
                    }
                    return;
                }

                // if this is the first layer or the map projection hasn't been set zoom to this extent
                if (map.numlayers == 1 || map.getProjection().Trim().Length == 0)
                {
                    ZoomToLayerExtent(layer);
                    if (InitialExtentSet != null)
                        InitialExtentSet(this, null);

                    // setting the projection of the map according to the layer projection
                    string proj = layer.getProjection().Trim();
                    if (proj.Length > 0 && proj != "+AUTO")
                    {
                        map.setProjection(proj);
                        // setting up the default unit
                        if (proj.Contains("+proj=longlat"))
                            map.units = MS_UNITS.MS_DD;
                        else
                            map.units = MS_UNITS.MS_METERS;
                    }
                }

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

                TreeNode src = CurrentTree.SelectedNode;
                if (src != null && src.Tag != null)
                    RaiseItemSelect((MapObjectHolder)src.Tag);
                UpdateToolbar();
            }
        }
示例#42
0
        /// <summary>
        /// Adding a new labelObj to the corresponding classObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="labelHolder">Wrapper class containing the labelObj and the parent object</param>
        /// <param name="imageList">The image list where the label image should be stored.</param>
        /// <param name="index">The current index of the label object.</param>
        private void AddLabelNode(TreeNodeCollection nodes, MapObjectHolder labelHolder, ImageList imageList, int index)
        {
            layerObj layer = labelHolder.GetParent().GetParent();
            classObj layerclass = labelHolder.GetParent();
            labelObj classLabel = labelHolder;

            classObj labelclass = new classObj(null);
            labelclass.name = MapUtils.GetClassName(layer);
            labelclass.addLabel(classLabel);
            // creating the treeicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                map, layer, legendIconSize.Width, legendIconSize.Height))
                {
                    MS_LAYER_TYPE layertype = layer.type;
                    layer.type = MS_LAYER_TYPE.MS_LAYER_ANNOTATION;
                    labelclass.drawLegendIcon(map, layer,
                        legendDrawingSize.Width, legendDrawingSize.Height, image2,
                        LegendIconPadding.Left, LegendIconPadding.Top);
                    layer.type = layertype;
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    TreeNode labelNode = new TreeNode("Label (" + index + ")",
                        imageList.Images.Count - 1, imageList.Images.Count - 1);
                    labelNode.Tag = labelHolder;
                    labelNode.Checked = true;
                    nodes.Add(labelNode);
                }
            }
        }
示例#43
0
        /// <summary>
        /// Adding a new styleObj to the corresponding classObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="styleHolder">Wrapper class containing the styleObj and the parent object</param>
        /// /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param>
        private void AddStyleNode(TreeNodeCollection nodes, MapObjectHolder styleHolder, ImageList imageList)
        {
            layerObj layer = styleHolder.GetParent().GetParent();
            classObj layerclass = styleHolder.GetParent();
            styleObj classStyle = styleHolder;

            classObj styleclass = new classObj(null);
            styleclass.name = MapUtils.GetClassName(layer);
            styleclass.insertStyle(classStyle, -1);
            // creating the treeicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                 map, layer, legendIconSize.Width, legendIconSize.Height))
                {
                    styleclass.drawLegendIcon(map, layer,
                        legendDrawingSize.Width, legendDrawingSize.Height, image2,
                        LegendIconPadding.Left, LegendIconPadding.Top);
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    TreeNode styleNode = new TreeNode("Style (" + nodes.Count + ")",
                        imageList.Images.Count - 1, imageList.Images.Count - 1);
                    styleNode.Tag = styleHolder;
                    styleNode.Checked = true;
                    nodes.Add(styleNode);
                }
            }
        }
示例#44
0
        /// <summary>
        /// Click event handler of the addLabelToolStripMenuItem control
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void addLabelToolStripMenuItem_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);

                // adding an empty label to this class
                classobj.addLabel(new labelObj());
                labelObj label = classobj.getLabel(classobj.numlabels - 1);
                MapUtils.SetDefaultLabel(label, layer.map);

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

                RefreshView();
                if (target != null)
                    target.RaisePropertyChanged(this);
            }
            else if (selected.GetType() == typeof(classObj))
            {
                layerObj layer = selected.GetParent();
                classobj = selected;

                // adding an empty label to this class
                classobj.addLabel(new labelObj());
                labelObj label = classobj.getLabel(classobj.numlabels - 1);
                MapUtils.SetDefaultLabel(label, layer.map);

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

                RefreshView();
                if (target != null)
                    target.RaisePropertyChanged(this);
            }
            else
                return;
        }
示例#45
0
        /// <summary>
        /// Adding a new layerObj to the mapObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object.</param>
        /// <param name="layerHolder">Wrapper class containing the layerObj and the parent object.</param>
        /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param>
        private void AddLayerNode(TreeNodeCollection nodes, MapObjectHolder layerHolder, bool showRoot, ImageList imageList)
        {
            layerObj layer = layerHolder;

            // adding the layer based on the icon of the first class
            if (showRoot)
            {
                TreeNode layerNode = new TreeNode(layer.name, imageList.Images.Count,
                    imageList.Images.Count);
                layerNode.Checked = (layer.status != mapscript.MS_OFF);
                layerNode.Tag = layerHolder; // wire up the layer into the node
                if (MapUtils.HasMetadata(layer, "link"))
                {
                    layerNode.NodeFont = new Font(treeView.Font, FontStyle.Underline | FontStyle.Italic);
                    layerNode.ForeColor = Color.Blue;
                }
                nodes.Insert(0, layerNode);
                nodes = layerNode.Nodes;

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_RASTER)
                    imageList.Images.Add(global::MapLibrary.Properties.Resources.raster);
            }

            for (int j = 0; j < layer.numclasses; j++)
            {
                classObj layerclass = layer.getClass(j);
                AddClassNode(nodes, new MapObjectHolder(layerclass, layerHolder), imageList);

                if (!showClasses || string.Compare(layer.styleitem, "AUTO", true) == 0)
                    break;
            }
        }
示例#46
0
        /// <summary>
        /// Constructs a new MapPropertyEditorForm object.
        /// </summary>
        /// <param name="target">The target object to be edited.</param>
        /// <param name="editor">The editor to be used.</param>
        public MapPropertyEditorForm(MapObjectHolder target, IPropertyEditor editor)
        {
            InitializeComponent();
            this.SuspendLayout();
            if (target.GetType() == typeof(mapObj))
            {
                if (editor == null)
                {
                    editor = new MapPropertyEditor();
                    ((MapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Map Properties";
                mapObj map = (mapObj)target;
                if (map.name != "")
                {
                    this.Text += " (" + map.name + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(layerObj))
            {
                if (editor == null)
                {
                    editor = new LayerPropertyEditor();
                    ((LayerPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Layer Properties";
                layerObj layer = (layerObj)target;
                if (layer.name != "")
                {
                    this.Text += " (" + layer.name + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(classObj))
            {
                if (editor == null)
                {
                    editor = new ClassPropertyEditor();
                    ((ClassPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Class Properties";
                classObj classObject = (classObj)target;

                StringBuilder scaledomain = new StringBuilder("");
                if (classObject.minscaledenom >= 0)
                {
                    if (classObject.maxscaledenom >= 0)
                    {
                        scaledomain.Append(" 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        scaledomain.Append(" from 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    }
                }
                if (classObject.maxscaledenom >= 0)
                {
                    scaledomain.Append(" to 1:" + classObject.maxscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }

                if (classObject.name != "")
                {
                    this.Text += " (" + classObject.name + scaledomain + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(styleObj))
            {
                if (editor == null)
                {
                    editor = new StylePropertyEditor();
                    ((StylePropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Style Properties";
                this.editor = editor;
            }

            else if (target.GetType() == typeof(labelObj))
            {
                if (editor == null)
                {
                    editor = new LabelPropertyEditor();
                    ((LabelPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Label Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(scalebarObj))
            {
                if (editor == null)
                {
                    editor = new ScalebarPropertyEditor();
                    ((ScalebarPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Scalebar Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(queryMapObj))
            {
                if (editor == null)
                {
                    editor = new QueryMapPropertyEditor();
                    ((QueryMapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Query Map Properties";
                this.editor = editor;
            }
            else
            {
                throw new Exception("No editor have been implemented for this item");
            }

            if (this.editor != null)
            {
                Control c = (Control)this.editor;
                c.Location = new System.Drawing.Point(3, 4);
                c.TabIndex = 0;

                editor.Target = target;
                this.Controls.Add(c);
                target.PropertyChanging += new EventHandler(target_PropertyChanging);
                editor.EditProperties   += new EditPropertiesEventHandler(editor_EditProperties);

                buttonOK.Top     = c.Bottom + 8;
                buttonCancel.Top = c.Bottom + 8;
                buttonApply.Top  = c.Bottom + 8;
            }

            UpdateButtonState();

            this.ResumeLayout(false);
        }
示例#47
0
        public override void InitializeBinding(MapObjectHolder target)
        {
            this.target = target;

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

            layerObj layer = target.GetParent().GetParent();
            styleObj style = target;

            if (itemList == null)
            {
                itemList                       = new ComboBox();
                itemList.Width                 = targetControl.Width;
                itemList.Height                = targetControl.Height;
                itemList.Location              = targetControl.Location;
                itemList.DropDownStyle         = ComboBoxStyle.DropDownList;
                itemList.SelectedIndexChanged += new EventHandler(itemList_SelectedIndexChanged);
                targetControl.Parent.Controls.Add(itemList);
                itemList.BringToFront();
                Bitmap bmp = Resources.DataConnection;
                bmp.MakeTransparent(Color.Magenta);
                pbox          = new PictureBox();
                pbox.Image    = bmp;
                pbox.SizeMode = PictureBoxSizeMode.AutoSize;
                pbox.Location = new System.Drawing.Point(targetControl.Location.X + targetControl.Width + 2,
                                                         targetControl.Location.Y + (targetControl.Height - pbox.Image.Height) / 2);
                targetControl.Parent.Controls.Add(pbox);
                pbox.BringToFront();
            }

            BindingState = false;

            itemList.Items.Clear();
            layer.open();
            for (int i = 0; i < layer.numitems; i++)
            {
                itemList.Items.Add(layer.getItem(i));
            }
            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
            if (layer.connectiontype == MS_CONNECTION_TYPE.MS_OGR)
            {
                itemList.Items.Add("OGR:LabelFont");
                itemList.Items.Add("OGR:LabelSize");
                itemList.Items.Add("OGR:LabelText");
                itemList.Items.Add("OGR:LabelAngle");
                itemList.Items.Add("OGR:LabelFColor");
                itemList.Items.Add("OGR:LabelBColor");
                itemList.Items.Add("OGR:LabelPlacement");
                itemList.Items.Add("OGR:LabelAnchor");
                itemList.Items.Add("OGR:LabelDx");
                itemList.Items.Add("OGR:LabelDy");
                itemList.Items.Add("OGR:LabelPerp");
                itemList.Items.Add("OGR:LabelBold");
                itemList.Items.Add("OGR:LabelItalic");
                itemList.Items.Add("OGR:LabelUnderline");
                itemList.Items.Add("OGR:LabelPriority");
                itemList.Items.Add("OGR:LabelStrikeout");
                itemList.Items.Add("OGR:LabelStretch");
                itemList.Items.Add("OGR:LabelAdjHor");
                itemList.Items.Add("OGR:LabelAdjVert");
                itemList.Items.Add("OGR:LabelHColor");
                itemList.Items.Add("OGR:LabelOColor");
            }

            string binding = style.getBinding((int)styleBinding);

            if (binding != null)
            {
                itemList.SelectedItem = binding;
                BindingState          = true;
            }
            else
            {
                if (itemList.Items.Count > 0)
                {
                    itemList.SelectedIndex = 0;
                }
            }
        }