Exemplo n.º 1
0
        public GroupMenuItem(ITOCElement elem, System.EventHandler evHander)
        {
            _element = elem;

            string path = "<root>";

            if (_element != null)
            {
                if (_element.ElementType != TOCElementType.ClosedGroup &&
                    _element.ElementType != TOCElementType.OpenedGroup)
                {
                    return;
                }

                path = _element.Name;
                ITOCElement parent = _element;
                while ((parent = parent.ParentGroup) != null)
                {
                    path = parent.Name + "/" + path;
                }
            }
            base.Text = path;

            if (evHander != null)
            {
                base.Click += evHander;
            }
        }
Exemplo n.º 2
0
        async public override Task <bool> Match(IExplorerObject exObject)
        {
            bool match = await base.Match(exObject);

            // Grouplayer nicht...
            if (exObject is IExplorerParentObject)
            {
                return(false);
            }

            var instance = await exObject?.GetInstanceAsync();

            if (match && instance is ITOCElement && _geomType != geometryType.Unknown)
            {
                ITOCElement tocElement = instance as ITOCElement;
                if (tocElement.Layers != null)
                {
                    foreach (ILayer layer in tocElement.Layers)
                    {
                        if (layer is IFeatureLayer && ((IFeatureLayer)layer).FeatureClass != null)
                        {
                            return(((IFeatureLayer)layer).FeatureClass.GeometryType == _geomType);
                        }
                    }
                }
            }
            //if (match && _geomType != geometryType.Unknown && exObject.Object is IFeatureLayer && ((IFeatureLayer)exObject.Object).FeatureClass != null)
            //{
            //    return ((IFeatureLayer)exObject.Object).FeatureClass.GeometryType == _geomType;
            //}

            return(match);
        }
Exemplo n.º 3
0
        void ContextMenuButton_Click(object sender, RoutedEventArgs e)
        {
            if (_doc == null || Tool == null || _contextType == null)
            {
                return;
            }

            if (_contextType.ContextObject is IMap)
            {
                Tool.OnEvent(_contextType.ContextObject, _doc);
            }
            else if (_contextType.ContextObject is ITOCElement && ((ITOCElement)_contextType.ContextObject).Layers != null)
            {
                ITOCElement tocElement = (ITOCElement)_contextType.ContextObject;

                foreach (var layer in tocElement.Layers)
                {
                    if (layer.Class == null || layer.Class.Dataset == null)
                    {
                        continue;
                    }

                    Tool.OnEvent(layer, layer.Class.Dataset);
                }
            }
        }
Exemplo n.º 4
0
        public override bool Match(IExplorerObject exObject)
        {
            bool match = base.Match(exObject);

            // Grouplayer nicht...
            if (exObject is IExplorerParentObject)
            {
                return(false);
            }

            if (match && exObject != null && exObject.Object is ITOCElement && _geomType != geometryType.Unknown)
            {
                ITOCElement tocElement = exObject.Object as ITOCElement;
                if (tocElement.Layers != null)
                {
                    foreach (ILayer layer in tocElement.Layers)
                    {
                        if (layer is IFeatureLayer && ((IFeatureLayer)layer).FeatureClass != null)
                        {
                            return(((IFeatureLayer)layer).FeatureClass.GeometryType == _geomType);
                        }
                    }
                }
            }
            //if (match && _geomType != geometryType.Unknown && exObject.Object is IFeatureLayer && ((IFeatureLayer)exObject.Object).FeatureClass != null)
            //{
            //    return ((IFeatureLayer)exObject.Object).FeatureClass.GeometryType == _geomType;
            //}

            return(match);
        }
        public object PropertyPanel(IFeatureLayerJoin join, Framework.UI.IMapDocument mapDocument)
        {
            if (join is FeatureLayerJoin)
            {
                _join = (FeatureLayerJoin)join;

                foreach (IDatasetElement element in mapDocument.FocusMap.MapElements)
                {
                    if (/*element == layer ||*/ !(element.Class is ITableClass))
                    {
                        continue;
                    }

                    ITOCElement tocElement = mapDocument.FocusMap.TOC.GetTOCElement(element as ILayer);
                    string      alias      = tocElement != null ? tocElement.Name : element.Title;
                    cmbJoinedLayer.Items.Add(new DatasetElementItem(element, alias));

                    if (_join.FeatureLayer != null && element.ID == _join.FeatureLayer.ID)
                    {
                        cmbJoinedLayer.SelectedIndex = cmbJoinedLayer.Items.Count - 1;
                    }
                }

                cmbJoinedFeatureLayerJoinField.SelectedItem = _join.JoinField;
            }
            return(this);
        }
Exemplo n.º 6
0
 internal TOCElementExplorerObject(IExplorerObject parent, ITOCElement element)
     : base(parent, typeof(ITOCElement), 2)
 {
     _parent  = parent;
     _element = element;
     _icon    = new MapDocumentExploererIcon(2);
 }
Exemplo n.º 7
0
        public UnlockLayerMenuItem(TOCControl control, ITOCElement element, Image image)
        {
            _control = control;
            _element = element;

            this.Text  = element.Name;
            this.Image = image;

            this.Click += new EventHandler(UnlockLayerMenuItem_Click);
        }
        private string TocElementFullname(ITOCElement tocElement)
        {
            string name = tocElement.Name;

            while (tocElement.ParentGroup != null)
            {
                name       = tocElement.ParentGroup.Name + "/" + name;
                tocElement = tocElement.ParentGroup;
            }

            return(name);
        }
Exemplo n.º 9
0
        private void SetLayernameAndScales(XmlNode layerNode, IFeatureLayer fLayer)
        {
            if (_doc != null && _doc.FocusMap != null && _doc.FocusMap.TOC != null)
            {
                ITOCElement tocElement = _doc.FocusMap.TOC.GetTOCElement(fLayer);
                tocElement.Name = layerNode.Attributes["name"].Value;
                if (layerNode.Attributes["visible"] != null)
                {
                    tocElement.LayerVisible = Convert.ToBoolean(layerNode.Attributes["visible"].Value);
                }
            }

            if (layerNode.Attributes["minscale"] != null)
            {
                string[] s = layerNode.Attributes["minscale"].Value.Split(':');
                double   o;
                if (s.Length == 2)
                {
                    if (double.TryParse(s[1].Replace(".", ","), out o))
                    {
                        fLayer.MinimumScale = o;
                    }
                }
                else
                {
                    if (double.TryParse(s[1].Replace(".", ","), out o))
                    {
                        fLayer.MinimumScale = o * (96.0 / 0.254);
                    }
                }
            }
            if (layerNode.Attributes["maxscale"] != null)
            {
                string[] s = layerNode.Attributes["maxscale"].Value.Split(':');
                double   o;
                if (s.Length == 2)
                {
                    if (double.TryParse(s[1].Replace(".", ","), out o))
                    {
                        fLayer.MaximumScale = o;
                    }
                }
                else
                {
                    if (double.TryParse(s[1].Replace(".", ","), out o))
                    {
                        fLayer.MaximumScale = o * (96.0 / 0.254);
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void FormSolveConflicts_Load(object sender, EventArgs e)
        {
            if (_doc == null || _doc.FocusMap == null)
            {
                this.Close();
                return;
            }

            tvConflicts.Nodes.Add(_rootNode);

            foreach (IDatasetElement element in _doc.FocusMap.MapElements)
            {
                if (element == null || !(element.Class is IFeatureClass))
                {
                    continue;
                }

                List <Guid> guids = Replication.FeatureClassConflictsParentGuids(element.Class as IFeatureClass);
                if (guids == null || guids.Count == 0)
                {
                    continue;
                }

                string title = element.Title;
                if (_doc.FocusMap.TOC != null && element is ILayer)
                {
                    ITOCElement tocElement = _doc.FocusMap.TOC.GetTOCElement((ILayer)element);
                    if (tocElement != null)
                    {
                        title = tocElement.Name;
                    }
                }
                FeatureClassNode fcNode = new FeatureClassNode(element.Class as IFeatureClass, title);
                _rootNode.Nodes.Add(fcNode);

                foreach (Guid guid in guids)
                {
                    fcNode.Nodes.Add(new GuidTreeNode(guid));
                }
                fcNode.Expand();
            }

            _rootNode.ExpandAll();

            if (_rootNode.Nodes.Count == 0)
            {
                MessageBox.Show("No conflicts in current map detected.");
                this.Close();
            }
        }
Exemplo n.º 11
0
        private static string ParentGroupName(ITOCElement element)
        {
            if (element == null || element.ParentGroup == null)
            {
                return(String.Empty);
            }

            string group = String.Empty;

            while ((element = element.ParentGroup) != null)
            {
                group = element.Name + ((group != "") ? "/" + group : "");
            }
            return(group);
        }
Exemplo n.º 12
0
        public void OnEvent(object element, object dataset)
        {
            if (!(element is IDatasetElement) || !(dataset is IDataset))
            {
                return;
            }

            TOC toc = _doc.FocusMap.TOC as TOC;

            if (toc == null)
            {
                return;
            }

            ITOCElement tocElement = toc.GetTOCElement(((IDatasetElement)element).Class);

            if (tocElement == null)
            {
                return;
            }

            ILayer newLayer = LayerFactory.Create(((IDatasetElement)element).Class);

            if (newLayer is IFeatureLayer && element is IFeatureLayer)
            {
                if (((IFeatureLayer)element).Joins != null)
                {
                    ((IFeatureLayer)newLayer).Joins = ((IFeatureLayer)element).Joins.Clone() as FeatureLayerJoins;
                }
                if (((IFeatureLayer)element).FilterQuery != null)
                {
                    QueryFilter filter = new QueryFilter();
                    filter.WhereClause = ((IFeatureLayer)element).FilterQuery.WhereClause;
                    ((IFeatureLayer)newLayer).FilterQuery = filter;
                }
            }
            if (newLayer == null)
            {
                return;
            }

            _doc.FocusMap.AddLayer(newLayer);

            if (_doc.Application is IMapApplication)
            {
                ((IMapApplication)_doc.Application).RefreshActiveMap(Framework.Carto.DrawPhase.All);
            }
        }
Exemplo n.º 13
0
        static public bool IsHidden(this ITOCElement tocElement)
        {
            var parent = tocElement.ParentGroup;

            while (parent != null)
            {
                IGroupLayer groupLayer = parent.Layers.FirstOrDefault() as IGroupLayer;
                if (groupLayer != null && groupLayer.MapServerStyle == MapServerGrouplayerStyle.Checkbox)
                {
                    return(true);
                }
                parent = parent.ParentGroup;
            }

            return(false);
        }
Exemplo n.º 14
0
        public LayerItem(IMap map, ILayer layer)
        {
            _layer = layer;
            if (_layer == null)
            {
                return;
            }
            _text = _layer.Title;

            if (map != null && map.TOC != null)
            {
                ITOCElement tocelement = map.TOC.GetTOCElement(layer);
                if (tocelement != null)
                {
                    _text = tocelement.Name;
                }
            }
        }
Exemplo n.º 15
0
        internal void Refresh()
        {
            if (_doc == null || _doc.FocusMap == null)
            {
                return;
            }
            if (!_combo.Visible)
            {
                return;
            }

            _combo.Items.Clear();
            foreach (IDatasetElement element in _doc.FocusMap.MapElements)
            {
                if (element == null)
                {
                    continue;
                }
                if (Replication.FeatureClassHasConflicts(element.Class as IFeatureClass))
                {
                    if (_doc.FocusMap.TOC != null && element is ILayer)
                    {
                        ITOCElement tocElement = _doc.FocusMap.TOC.GetTOCElement((ILayer)element);
                        if (tocElement != null)
                        {
                            _combo.Items.Add(new ComboItem(element.Class as IFeatureClass, tocElement));
                        }
                        else
                        {
                            _combo.Items.Add(new ComboItem(element.Class as IFeatureClass));
                        }
                    }
                    else
                    {
                        _combo.Items.Add(new ComboItem(element.Class as IFeatureClass));
                    }
                }
            }

            if (_combo.Items.Count > 0)
            {
                _combo.SelectedIndex = 0;
            }
        }
Exemplo n.º 16
0
        public ContextMenuButton(IContextMenuTool tool, IContextType contextType, IMapDocument mapDocument)
        {
            this.Tool    = tool;
            _contextType = contextType;
            _doc         = mapDocument;

            base.Header = LocalizedResources.GetResString(tool.Name, tool.Name);
            base.Icon   = base.LargeIcon = ImageFactory.FromBitmap(tool.Image as System.Drawing.Image);

            base.Click += new RoutedEventHandler(ContextMenuButton_Click);

            bool visible = false, enable = false;

            if (_contextType.ContextObject is IMap)
            {
                enable  = tool.Enable(contextType.ContextObject);
                visible = tool.Visible(contextType.ContextObject);
            }
            else if (_contextType.ContextObject is ITOCElement && ((ITOCElement)_contextType.ContextObject).Layers != null)
            {
                ITOCElement tocElement = (ITOCElement)_contextType.ContextObject;

                foreach (var layer in tocElement.Layers)
                {
                    if (visible == true && enable == true)
                    {
                        break;
                    }

                    if (!enable)
                    {
                        enable = tool.Enable(layer);
                    }
                    if (!visible)
                    {
                        visible = tool.Visible(layer);
                    }
                }
            }

            base.IsEnabled  = enable;
            base.Visibility = visible == false ? Visibility.Collapsed : Visibility.Visible;
        }
        public SelectionTOCLayerNode(IMapDocument mapDocument, ITOCElement element, bool check)
        {
            if (element == null)
            {
                return;
            }
            _element = element;

            base.Checked = check;
            RefreshText();

            //if (mapDocument != null && mapDocument.TableRelations != null)
            //{
            //    foreach (ILayer layer in element.Layers)
            //    {
            //        foreach (ITableRelation tableRelation in mapDocument.TableRelations.GetRelations(layer))
            //        {
            //            base.Nodes.Add(new SelectionRelationTreeNode(tableRelation, layer));
            //        }
            //    }
            //}
        }
Exemplo n.º 18
0
        public FormSplitLayerWithFilter(IMapDocument doc, ILayer layer)
        {
            InitializeComponent();

            if (!(layer.Class is IFeatureClass))
            {
                return;
            }
            _layer = layer;

            cmbOperator.SelectedIndex = 0;

            foreach (IField field in ((IFeatureClass)layer.Class).Fields.ToEnumerable())
            {
                if (field == null)
                {
                    continue;
                }
                cmbFilterField.Items.Add(new FieldItem(field));
            }
            if (cmbFilterField.Items.Count > 0)
            {
                cmbFilterField.SelectedIndex = 0;
            }

            string title = _layer.Title;

            if (doc != null && doc.FocusMap != null && doc.FocusMap.TOC != null)
            {
                ITOCElement tocElement = doc.FocusMap.TOC.GetTOCElement(_layer);
                if (tocElement != null)
                {
                    title = tocElement.Name;
                }
            }
            txtTemplate.Text = title + " [VALUE]";
        }
Exemplo n.º 19
0
 public TOCElementItem(ITOCElement element)
 {
     _element = element;
 }
Exemplo n.º 20
0
 public TocElementListViewitem(ITOCElement tocElement, string[] subItems)
     : base(subItems)
 {
     this.TOCElement = tocElement;
 }
Exemplo n.º 21
0
        async public Task <IBitmap> Legend()
        {
            ITOC toc = _toc.Clone(this) as ITOC;

            #region WebServiceLayer
            List <IWebServiceLayer> webServices;
            if (this.TOC != null)
            {
                webServices = ListOperations <IWebServiceLayer> .Swap(this.TOC.VisibleWebServiceLayers);
            }
            else
            {
                webServices = new List <IWebServiceLayer>();
                foreach (IDatasetElement layer in this.MapElements)
                {
                    if (!(layer is IWebServiceLayer))
                    {
                        continue;
                    }

                    if (((ILayer)layer).Visible)
                    {
                        webServices.Add((IWebServiceLayer)layer);
                    }
                }
            }
            foreach (IWebServiceLayer element in webServices)
            {
                if (!(element is ILayer))
                {
                    continue;
                }

                if (!element.Visible)
                {
                    continue;
                }

                IWebServiceLayer wsLayer = LayerFactory.Create(element.WebServiceClass.Clone() as IClass, element) as IWebServiceLayer;
                if (wsLayer == null || wsLayer.WebServiceClass == null)
                {
                    continue;
                }

                if (BeforeRenderLayers != null)
                {
                    // layer im geklonten TOC austauschen...
                    // Besser layer als layer.Class verwendenden, weil Class von mehrerenen Layern
                    // verwendet werden kann zB bei gesplitteten Layern...
                    //ITOCElement tocElement = toc.GetTOCElement(element.Class);
                    ITOCElement tocElement = toc.GetTOCElement(element);
                    tocElement.RemoveLayer(element);
                    tocElement.AddLayer(wsLayer);

                    List <ILayer> modLayers = new List <ILayer>();
                    foreach (IWebServiceTheme theme in wsLayer.WebServiceClass.Themes)
                    {
                        if (theme is ILayer)
                        {
                            modLayers.Add(theme);
                        }
                    }
                    BeforeRenderLayers(this, modLayers);
                }
            }
            #endregion

            List <ILayer> layers = new List <ILayer>();
            if (this.TOC != null)
            {
                if (this.GetType().Equals(typeof(ServiceMap)))
                {
                    layers = ListOperations <ILayer> .Swap(this.TOC.Layers);
                }
                else
                {
                    layers = ListOperations <ILayer> .Swap(this.TOC.VisibleLayers);
                }
            }
            else
            {
                layers = new List <ILayer>();
                foreach (IDatasetElement layer in this.MapElements)
                {
                    if (!(layer is ILayer))
                    {
                        continue;
                    }

                    if (((ILayer)layer).Visible)
                    {
                        layers.Add((ILayer)layer);
                    }
                }
            }

            if (BeforeRenderLayers != null)
            {
                //
                // Kopie der Original Layer erstellen
                // ACHTUNG: Renderer werden nicht kopiert!
                // dürfen in BeforeRenderLayers nicht verändert werden...
                // Eine zuweisung eines neuen Renderers ist jedoch legitim.
                //
                List <ILayer> modLayers = new List <ILayer>();
                foreach (IDatasetElement element in layers)
                {
                    if (!(element is ILayer) || element is IWebServiceTheme)
                    {
                        continue;
                    }

                    ILayer layer = (ILayer)element;
                    if (layer.MinimumScale > 1 && layer.MinimumScale > this.mapScale)
                    {
                        continue;
                    }

                    if (layer.MaximumScale > 1 && layer.MaximumScale < this.mapScale)
                    {
                        continue;
                    }

                    ILayer newLayer = null;
                    modLayers.Add(newLayer = LayerFactory.Create(layer.Class, layer));

                    // layer im geklonten TOC austauschen...
                    if (element is ILayer && newLayer != null)
                    {
                        // Besser layer als layer.Class verwendenden, weil Class von mehrerenen Layern
                        // verwendet werden kann zB bei gesplitteten Layern...
                        //ITOCElement tocElement = toc.GetTOCElement(layer.Class);
                        ITOCElement tocElement = toc.GetTOCElement(layer);
                        tocElement.RemoveLayer(element as ILayer);
                        tocElement.AddLayer(newLayer);
                    }
                }
                BeforeRenderLayers(this, modLayers);
                layers = modLayers;
            }

            return(await toc.Legend());
        }
Exemplo n.º 22
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (_parent == null || _parent.MapDocument == null ||
                    _parent.MapDocument.FocusMap == null ||
                    _parent.MapDocument.FocusMap.Display == null)
                {
                    return;
                }

                ISpatialReference sRef =
                    (_parent.MapDocument.FocusMap.Display.SpatialReference != null) ?
                    _parent.MapDocument.FocusMap.Display.SpatialReference.Clone() as ISpatialReference :
                    null;

                StartProgress();

                List <IDatasetElement> elements = e.Argument as List <IDatasetElement>;
                if (elements == null)
                {
                    return;
                }

                foreach (IDatasetElement element in elements)
                {
                    if (!(element is IFeatureLayer))
                    {
                        continue;
                    }
                    IFeatureLayer layer = element as IFeatureLayer;
                    if (!(element.Class is IFeatureClass))
                    {
                        continue;
                    }
                    IFeatureClass fc = element.Class as IFeatureClass;
                    if (fc.Fields == null)
                    {
                        continue;
                    }

                    string val  = _queryVal.Replace("*", "%");
                    string sval = _useWildcards ? AppendWildcards(val) : val;

                    //
                    // Collect Fields
                    //
                    Fields queryFields = new Fields();
                    foreach (IField field in fc.Fields.ToEnumerable())
                    {
                        if (field.type == FieldType.binary || field.type == FieldType.Shape)
                        {
                            continue;
                        }
                        if (field.name.Contains(":"))
                        {
                            continue;                            // No Joined Fields
                        }
                        if (_searchType == SearchType.allfields)
                        {
                            queryFields.Add(field);
                        }
                        else if (_searchType == SearchType.field)
                        {
                            if (field.aliasname == _queryField)
                            {
                                queryFields.Add(field);
                            }
                        }
                        else if (_searchType == SearchType.displayfield)
                        {
                        }
                    }
                    if (queryFields.Count == 0)
                    {
                        continue;
                    }

                    //
                    // Build SQL Where Clause
                    //
                    StringBuilder sql = new StringBuilder();
                    foreach (IField field in queryFields.ToEnumerable())
                    {
                        switch (field.type)
                        {
                        case FieldType.character:
                        case FieldType.String:
                            if (sql.Length > 0)
                            {
                                sql.Append(" OR ");
                            }
                            sql.Append(field.name);
                            sql.Append(sval.IndexOf("%") == -1 ? "=" : " like ");
                            sql.Append("'" + sval + "'");
                            break;

                        case FieldType.integer:
                        case FieldType.smallinteger:
                        case FieldType.biginteger:
                        case FieldType.Double:
                        case FieldType.Float:
                            if (IsNumeric(val))
                            {
                                if (sql.Length > 0)
                                {
                                    sql.Append(" OR ");
                                }
                                sql.Append(field.name + "=" + val);
                            }
                            break;
                        }
                    }
                    if (sql.Length == 0)
                    {
                        continue;
                    }

                    if (!_cancelTracker.Continue)
                    {
                        return;
                    }
                    string title = fc.Name;
                    if (_focusMap != null && _focusMap.TOC != null)
                    {
                        ITOCElement tocElement = _focusMap.TOC.GetTOCElement(element as ILayer);
                        if (tocElement != null)
                        {
                            title = tocElement.Name;
                        }
                    }
                    //
                    // Query
                    //
                    QueryFilter filter = new QueryFilter();
                    filter.SubFields               = "*";
                    filter.WhereClause             = sql.ToString();
                    filter.FeatureSpatialReference = _parent.MapDocument.FocusMap.Display.SpatialReference;

                    SetMsgText("Query Table " + title, 1);
                    SetMsgText("", 2);
                    using (IFeatureCursor cursor = fc.Search(filter) as IFeatureCursor)
                    {
                        if (cursor == null)
                        {
                            continue;
                        }

                        int             counter = 0;
                        IFeature        feature;
                        List <IFeature> features = new List <IFeature>();
                        while ((feature = cursor.NextFeature) != null)
                        {
                            if (!_cancelTracker.Continue)
                            {
                                return;
                            }
                            //this.AddFeature(feature, fc.SpatialReference, title);
                            features.Add(feature);
                            counter++;
                            if (counter % 100 == 0)
                            {
                                SetMsgText(counter + " Features...", 2);
                                this.AddFeature(features, sRef, layer, title, null, null, null);
                                features = new List <IFeature>();
                            }
                        }
                        if (features.Count > 0)
                        {
                            this.AddFeature(features, sRef, layer, title, null, null, null);
                        }

                        if (_mode == IdentifyMode.topmost && counter > 0)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                StopProgress();
            }
        }
Exemplo n.º 23
0
        void worker2_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_theme == null || _theme.Nodes == null || _theme.Nodes.Count == 0 || _userdefValues == null)
            {
                return;
            }

            if (_parent == null || _parent.MapDocument == null ||
                _parent.MapDocument.FocusMap == null ||
                _parent.MapDocument.FocusMap.Display == null)
            {
                return;
            }

            ISpatialReference sRef =
                (_parent.MapDocument.FocusMap.Display.SpatialReference != null) ?
                _parent.MapDocument.FocusMap.Display.SpatialReference.Clone() as ISpatialReference :
                null;

            try
            {
                StartProgress();

                foreach (QueryThemeTable table in _theme.Nodes)
                {
                    if (table.QueryFieldDef == null)
                    {
                        continue;
                    }

                    IFeatureLayer layer = table.GetLayer(_parent._doc) as  IFeatureLayer;
                    if (layer == null || !(layer.Class is IFeatureClass))
                    {
                        continue;
                    }
                    IFeatureClass fc = layer.Class as IFeatureClass;

                    #region SQL
                    StringBuilder sql         = new StringBuilder();
                    int           actPromptID = -99;
                    foreach (DataRow fieldDef in table.QueryFieldDef.Select("", "Prompt"))
                    {
                        string logic = " OR ";
                        if ((int)fieldDef["Prompt"] != actPromptID)
                        {
                            actPromptID = (int)fieldDef["Prompt"];
                            logic       = ") AND (";
                        }

                        string val = "";
                        if (!_userdefValues.TryGetValue((int)fieldDef["Prompt"], out val))
                        {
                            continue;
                        }
                        if (val == "")
                        {
                            continue;
                        }

                        val = val.Replace("*", "%");

                        IField field = fc.FindField(fieldDef["Field"].ToString());
                        if (field == null)
                        {
                            continue;
                        }

                        switch (field.type)
                        {
                        case FieldType.biginteger:
                        case FieldType.Double:
                        case FieldType.Float:
                        case FieldType.smallinteger:
                        case FieldType.integer:
                            if (IsNumeric(val))
                            {
                                if (sql.Length > 0)
                                {
                                    sql.Append(logic);
                                }
                                sql.Append(field.name + fieldDef["Operator"] + val);
                            }
                            break;

                        case FieldType.String:
                            string op = fieldDef["Operator"].ToString();
                            string v  = val;
                            if (v.IndexOf("%") != -1)
                            {
                                op = " like ";
                            }
                            else if (op.ToLower() == " like ")
                            {
                                v += "%";
                            }
                            if (sql.Length > 0)
                            {
                                sql.Append(logic);
                            }
                            sql.Append(field.name + op + "'" + v + "'");
                            break;
                        }
                    }
                    if (sql.Length == 0)
                    {
                        continue;
                    }
                    sql.Insert(0, "(");
                    sql.Append(")");
                    #endregion

                    if (!_cancelTracker.Continue)
                    {
                        return;
                    }

                    #region Layer Title
                    string title = fc.Name;
                    if (_focusMap != null && _focusMap.TOC != null)
                    {
                        ITOCElement tocElement = _focusMap.TOC.GetTOCElement(layer);
                        if (tocElement != null)
                        {
                            title = tocElement.Name;
                        }
                    }
                    #endregion

                    #region Fields
                    Fields fields = null;
                    IField primaryDisplayField = null;

                    if (layer != null && layer.Fields != null && table.VisibleFieldDef != null && table.VisibleFieldDef.UseDefault == false)
                    {
                        fields = new Fields();

                        foreach (IField field in layer.Fields.ToEnumerable())
                        {
                            if (table.VisibleFieldDef.PrimaryDisplayField == field.name)
                            {
                                primaryDisplayField = field;
                            }

                            DataRow [] r = table.VisibleFieldDef.Select("Visible=true AND Name='" + field.name + "'");
                            if (r.Length == 0)
                            {
                                continue;
                            }

                            Field f = new Field(field);
                            f.visible   = true;
                            f.aliasname = (string)r[0]["Alias"];
                            fields.Add(f);
                        }
                    }
                    #endregion

                    #region QueryFilter
                    QueryFilter filter = new QueryFilter();
                    if (fields == null)
                    {
                        filter.SubFields = "*";
                    }
                    else
                    {
                        foreach (IField field in fields.ToEnumerable())
                        {
                            if (!field.visible)
                            {
                                continue;
                            }
                            filter.AddField(field.name);
                        }
                        if (primaryDisplayField != null)
                        {
                            filter.AddField(primaryDisplayField.name);
                        }
                        if (layer is IFeatureLayer && ((IFeatureLayer)layer).FeatureClass != null)
                        {
                            filter.AddField(((IFeatureLayer)layer).FeatureClass.ShapeFieldName);
                        }
                    }

                    filter.WhereClause             = sql.ToString();
                    filter.FeatureSpatialReference = _parent.MapDocument.FocusMap.Display.SpatialReference;
                    #endregion

                    SetMsgText("Query Table " + title, 1);
                    SetMsgText("", 2);

                    #region Query
                    using (IFeatureCursor cursor = fc.Search(filter) as IFeatureCursor)
                    {
                        if (cursor == null)
                        {
                            continue;
                        }

                        int             counter = 0;
                        IFeature        feature;
                        List <IFeature> features = new List <IFeature>();
                        while ((feature = cursor.NextFeature) != null)
                        {
                            if (!_cancelTracker.Continue)
                            {
                                return;
                            }
                            //this.AddFeature(feature, fc.SpatialReference, title);
                            features.Add(feature);
                            counter++;
                            if (counter % 100 == 0)
                            {
                                SetMsgText(counter + " Features...", 2);
                                ManualResetEvent resetEvent = new ManualResetEvent(false);

                                this.AddFeature(features, sRef, layer, title, fields, primaryDisplayField, resetEvent);
                                features = new List <IFeature>();

                                resetEvent.WaitOne();
                            }
                        }
                        if (features.Count > 0)
                        {
                            this.AddFeature(features, sRef, layer, title, fields, primaryDisplayField, null);
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                StopProgress();
            }
        }
Exemplo n.º 24
0
        public static List <Layers> MapLayers(IServiceMap map, bool useTOC)
        {
            if (useTOC)
            {
                return(MapLayersFromTOC(map));
            }

            List <Layers> layersList = new List <Layers>();

            foreach (IDatasetElement element in map.MapElements)
            {
                if (!(element is ILayer))
                {
                    continue;
                }
                ILayer layer = element as ILayer;

                if (layer.Class is IWebServiceClass)
                {
                    foreach (IWebServiceTheme theme in ((IWebServiceClass)layer.Class).Themes)
                    {
                        if (!(theme is ILayer))
                        {
                            continue;
                        }

                        string title = layer.Title;
                        string group = String.Empty;
                        if (map.TOC != null)
                        {
                            //ITOCElement tocElement = map.TOC.GetTOCElement(theme.Class);
                            // Besser layer als layer.Class verwendenden, weil Class von mehrerenen Layern
                            // verwendet werden kann zB bei gesplitteten Layern...
                            ITOCElement tocElement = map.TOC.GetTOCElement((ILayer)theme);
                            if (tocElement != null)
                            {
                                title = tocElement.Name;
                                group = ParentGroupName(tocElement);
                            }
                        }
                        if (!String.IsNullOrEmpty(layer.Namespace))
                        {
                            title = layer.Namespace + ":" + title;
                        }

                        layersList.Add(new Layers(theme));
                        layersList[layersList.Count - 1].Title     = title;
                        layersList[layersList.Count - 1].GroupName = group;
                    }
                }
                else
                {
                    string title = layer.Title;
                    string group = String.Empty;
                    if (map.TOC != null)
                    {
                        //ITOCElement tocElement = map.TOC.GetTOCElement(layer.Class);
                        // Besser layer als layer.Class verwendenden, weil Class von mehrerenen Layern
                        // verwendet werden kann zB bei gesplitteten Layern...
                        ITOCElement tocElement = map.TOC.GetTOCElement(layer);
                        if (tocElement != null)
                        {
                            title = tocElement.Name;
                            group = ParentGroupName(tocElement);
                        }
                    }
                    if (!String.IsNullOrEmpty(layer.Namespace))
                    {
                        title = layer.Namespace + ":" + title;
                    }

                    layersList.Add(new Layers(layer));
                    layersList[layersList.Count - 1].Title     = title;
                    layersList[layersList.Count - 1].GroupName = group;
                }
            }
            return(layersList);
        }
Exemplo n.º 25
0
 public ComboItem(IFeatureClass fc, ITOCElement tocElement) : this(fc)
 {
     _tocElement = tocElement;
 }
Exemplo n.º 26
0
 public LayerItem(ITOCElement element)
 {
     _element = element;
 }
Exemplo n.º 27
0
        public void OnEvent(object element, object dataset)
        {
            if (!(element is IDatasetElement) || !(dataset is IDataset))
            {
                return;
            }

            TOC toc = _doc.FocusMap.TOC as TOC;

            if (toc == null)
            {
                return;
            }

            ITOCElement tocElement = toc.GetTOCElement(((IDatasetElement)element).Class);

            if (tocElement == null)
            {
                return;
            }
            ITOCElement parentTocElement = tocElement.ParentGroup;

            //IDatasetElement e = ((IDataset)dataset)[((IDatasetElement)element).Title];
            //if (e == null) return;

            if (!(element is ILayer))
            {
                return;
            }
            FormSplitLayerWithFilter dlg = new FormSplitLayerWithFilter(_doc, element as ILayer);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                foreach (FormSplitLayerWithFilter.FilterExpessionItem expression in dlg.FilterExpressions)
                {
                    ILayer newLayer = LayerFactory.Create(((IDatasetElement)element).Class);
                    if (newLayer is IFeatureLayer &&
                        element is IFeatureLayer && ((IFeatureLayer)element).Joins != null)
                    {
                        ((IFeatureLayer)newLayer).Joins = ((IFeatureLayer)element).Joins.Clone() as FeatureLayerJoins;
                    }

                    if (newLayer is IFeatureLayer)
                    {
                        QueryFilter filter = new QueryFilter();
                        filter.WhereClause = expression.Filter;
                        ((IFeatureLayer)newLayer).FilterQuery = filter;

                        _doc.FocusMap.AddLayer(newLayer);
                        tocElement      = toc.GetTOCElement(newLayer);
                        tocElement.Name = expression.Text;
                        toc.Add2Group(tocElement, parentTocElement);
                    }
                }

                if (_doc.Application is IMapApplication)
                {
                    ((IMapApplication)_doc.Application).RefreshActiveMap(Framework.Carto.DrawPhase.All);
                }
            }
        }
Exemplo n.º 28
0
 internal TOCGroupElementExplorerObject(IExplorerObject parent, ITOCElement element)
 {
     _parent  = parent;
     _element = element;
     _icon    = new MapDocumentExploererIcon(3);
 }
Exemplo n.º 29
0
 public GroupItem(ITOCElement element)
 {
     _element = element;
 }
        private void btnStart_Click(object sender, EventArgs e)
        {
            txtMap.Text = txtMap.Text.ToUpper().Replace(" ", "_").Replace("Ä", "AE").Replace("Ö", "OE").Replace("Ü", "UE").Replace("ß", "SS");

            _filter = ((ExportMethodItem)cmbExport.SelectedItem).QueryFilter;

            Map migMap = new Map();

            migMap.Name                     = txtMap.Text;
            migMap.Display.refScale         = _map.Display.refScale;
            migMap.Display.MapUnits         = _map.Display.MapUnits;
            migMap.Display.DisplayUnits     = _map.Display.DisplayUnits;
            migMap.Display.SpatialReference = _map.Display.SpatialReference;

            _doc.AddMap(migMap);
            _doc.FocusMap = migMap;
            migMap.Display.ZoomTo(_map.Display.Envelope);

            List <string> migratedClassNames = new List <string>();

            foreach (IDatasetElement element in _map.MapElements)
            {
                if (!(element is IFeatureLayer) || element.Class == null)
                {
                    continue;
                }

                try
                {
                    if (element.Class is IFeatureClass)
                    {
                        IFeatureClass fc = (IFeatureClass)element.Class;
                        if (!migratedClassNames.Contains(fc.Name))
                        {
                            ExportDatasetObject(fc);
                            migratedClassNames.Add(fc.Name);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show(ex.Message + "\n\nDo you want to continue?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) != DialogResult.OK)
                    {
                        break;
                    }
                }
                IDatasetElement destDatasetElement = _dataset[(txtMap.Text + "_" + element.Class.Name).Replace(".", "_")];

                if (destDatasetElement != null)
                {
                    IFeatureLayer sourceLayer = (IFeatureLayer)element;

                    IFeatureLayer layer = LayerFactory.Create(destDatasetElement.Class) as IFeatureLayer;
                    if (layer != null)
                    {
                        if (sourceLayer.FeatureRenderer != null)
                        {
                            layer.FeatureRenderer = sourceLayer.FeatureRenderer.Clone(migMap.Display) as IFeatureRenderer;
                        }
                        if (sourceLayer.LabelRenderer != null)
                        {
                            layer.LabelRenderer = sourceLayer.LabelRenderer.Clone(migMap.Display) as ILabelRenderer;
                        }
                        if (sourceLayer.SelectionRenderer != null)
                        {
                            layer.SelectionRenderer = sourceLayer.SelectionRenderer.Clone(migMap.Display) as IFeatureRenderer;
                        }

                        layer.MinimumLabelScale = sourceLayer.MinimumLabelScale;
                        layer.MaximumLabelScale = sourceLayer.MaximumLabelScale;
                        layer.MinimumScale      = sourceLayer.MinimumScale;
                        layer.MaximumScale      = sourceLayer.MaximumScale;
                        layer.Visible           = sourceLayer.Visible;
                    }
                    layer.SID = sourceLayer.SID;

                    migMap.AddLayer(layer);

                    ITOCElement tocElement       = migMap.TOC.GetTOCElement(layer);
                    ITOCElement sourceTocElement = _map.TOC.GetTOCElement(sourceLayer);
                    if (tocElement != null && sourceTocElement != null)
                    {
                        tocElement.Name = sourceTocElement.Name;
                    }
                }
            }

            if (_doc.Application is IMapApplication)
            {
                ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
            }
        }