Beispiel #1
0
        /// <summary>
        /// Click event handler of the replaceToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void checkMapFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MapfileConverter c = new MapfileConverter();
            try
            {
                c.Parse(scintillaControl.Text, true);
                MapObjectHolder mapH;
                mapObj map;
                if (c.HasToConvert())
                {
                    MapFileConvertForm form = new MapFileConvertForm(c.GetChangeLog());

                    if (form.ShowDialog(this) == DialogResult.Yes)
                    {
                        scintillaControl.Text = c.GetMapFile();
                    }
                }
                else
                {
                    MessageBox.Show("Map file check was successful.",
                    "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                    "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Opening a map by showing a FileOpen dialog box.
        /// </summary>
        /// <param name="file">The name of the map file to open.</param>
        /// <returns>True if the file have been opened, otherwise false</returns>
        private bool OpenMap(string file, bool isTemplate)
        {
            // check if a Tile Manager window is open and close it if it is
            if (tileManagerForm != null) tileManagerForm.Close();
            tileManagerForm = null;

            if (dirtyFlag || buttonApply.Enabled)
            {
                DialogResult result = MessageBox.Show("The map has been edited, would you like to save the changes?", "MapManager",
                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                    SaveMap();
                else if (result == DialogResult.Cancel)
                    return false;
            }

            buttonApply.Enabled = false;

            fileName = file;

            this.isTemplate = isTemplate;

            scrollPos = 0;
            MapfileConverter c = new MapfileConverter();
            try
            {
                c.Parse(File.ReadAllText(file, Encoding.Default), false);
                MapObjectHolder mapH;
                mapObj map;
                if (c.HasToConvert())
                {
                    MapFileConvertForm form = new MapFileConvertForm(c.GetChangeLog());

                    if (form.ShowDialog(this) == DialogResult.Yes)
                    {
                        map = mapscript.msLoadMapFromString(c.GetMapFile(), null);
                        mapH = new MapObjectHolder(map, null);
                    }
                    else
                        throw new Exception ("Map file conversion aborted");
                }
                else
                {
                    mapH = MapUtils.OpenMap(file);
                    map = mapH;
                }

                if (map.extent.maxx == -1 && map.extent.minx == -1 && map.extent.maxy == -1 && map.extent.miny == -1)
                    map.setExtent(0, 0, 10, 10);

                mapH.PropertyChanged += new System.EventHandler(this.MainForm_PropertyChanged);
                mapH.PropertyChanging += new EventHandler(MainForm_PropertyChanging);
                mapH.SelectionChanged += new EventHandler(MainForm_SelectionChanged);
                mapH.ZoomChanged += new MapObjectHolder.ZoomChangedEventHandler(MainForm_ZoomChanged);

                mapControl.Target = mapH;
                layerControl_ItemSelect(this, null);
                layerControl.Target = mapControl.Target;
                selectListForm.selectList.Target = mapControl.Target;

                LoadTextContents();
                SetDirty(false);

                if (c.HasToConvert())
                    SetDirty(true); // conversion happened

                if (map.symbolset.filename != null && !File.Exists(map.symbolset.filename))
                {
                    // override the symbolset if that points to incorrect location
                    map.setSymbolSet(Application.StartupPath + "\\templates\\symbols.sym");
                }

                if (map.fontset.filename != null && !File.Exists(map.fontset.filename))
                {
                    // override the fontset if that points to incorrect location
                    map.setFontSet(Application.StartupPath + "\\templates\\font.list");
                }

                if (MapUtils.RenameDuplicatedNames(map))
                {
                    MessageBox.Show("Duplicated layer names detected in this mapfile, which is not supported by IntraMaps. The layers will be renamed to unique names.", "MapManager",
                               MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    layerControl.RefreshView();
                    SetDirty(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ". Please correct the issue in the text tab.", "MapManager",
                               MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetDirty(false);
                mapControl.Target = null;
                layerControl_ItemSelect(this, null);
                layerControl.Target = null;
                selectListForm.selectList.Target = null;

                if (c.HasToConvert())
                    scintillaControl.Text = c.GetMapFile();
                else
                    scintillaControl.Text = File.ReadAllText(fileName, Encoding.Default);
                SetMargins();
                tabControlContents.SelectedIndex = 1;
            }

            if (!isTemplate)
                settings.AddToMRU(fileName); // template is not added to MRU (#4423)
            UpdateMRU();

            UpdateMenuState();

            UpdateFileMonitor();

            // clear the undo buffer of the control
            scintillaControl.UndoRedo.EmptyUndoBuffer();

            return true;
        }