private Task UpdateForActiveMap(bool activeMapChanged = true, Dictionary <MapMember, List <long> > mapSelection = null)
        {
            return(QueuedTask.Run(() =>
            {
                SelectedLayerInfo selectedLayerInfo = null;
                if (!_selectedLayerInfos.ContainsKey(_activeMap))
                {
                    selectedLayerInfo = new SelectedLayerInfo();
                    _selectedLayerInfos.Add(_activeMap, selectedLayerInfo);
                }
                else
                {
                    selectedLayerInfo = _selectedLayerInfos[_activeMap];
                }

                if (activeMapChanged)
                {
                    RefreshLayerCollection();

                    SetProperty(ref _selectedLayer, (selectedLayerInfo.SelectedLayer != null) ? selectedLayerInfo.SelectedLayer : Layers.FirstOrDefault(), () => SelectedLayer);
                    if (_selectedLayer == null)
                    {
                        FrameworkApplication.SetCurrentToolAsync("esri_mapping_exploreTool");
                        return;
                    }
                    selectedLayerInfo.SelectedLayer = SelectedLayer;
                }

                if (SelectedLayer == null)
                {
                    RefreshSelectionOIDs(new List <long>());
                }
                else
                {
                    List <long> oids = new List <long>();
                    if (mapSelection != null)
                    {
                        if (mapSelection.ContainsKey(SelectedLayer))
                        {
                            oids.AddRange(mapSelection[SelectedLayer]);
                        }
                    }
                    else
                    {
                        oids.AddRange(SelectedLayer.GetSelection().GetObjectIDs());
                    }
                    RefreshSelectionOIDs(oids);
                }

                SetProperty(ref _selectedOID, (selectedLayerInfo.SelectedOID != null && LayerSelection.Contains(selectedLayerInfo.SelectedOID)) ? selectedLayerInfo.SelectedOID : LayerSelection.FirstOrDefault(), () => SelectedOID);
                selectedLayerInfo.SelectedOID = SelectedOID;
                ShowAttributes();
            }));
        }
Exemplo n.º 2
0
        public void DoLayout(SVGLayer[] layers, LayerSelection layerSelection)
        {
            if (layers == null)
            {
                return;
            }

            float width  = EditorGUIUtility.currentViewWidth - 55f;
            float height = itemHeight * Mathf.Min(layers.Length, maxVisibleItems);

            Rect rect = GUILayoutUtility.GetRect(width, height);

            rect.width = width;
            Rect finRect = new Rect(rect.position.x - rect.width * 0.5f, rect.position.y - itemHeight * 0.5f, rect.width, itemHeight);

            int layersLength = scrollIndex + Mathf.Clamp(layers.Length - scrollIndex, 0, maxVisibleItems);
            int index        = 0;

            if (rect.Contains(Event.current.mousePosition))
            {
                hilightedLayer = Mathf.Clamp(Mathf.FloorToInt((Event.current.mousePosition.y - rect.y) / itemHeight), 0, layers.Length);
                if (Event.current.type == EventType.ScrollWheel)
                {
                    scrollIndex = Mathf.Clamp(scrollIndex + (int)Mathf.Sign(Event.current.delta.y), 0, layers.Length);
                    Event.current.Use();
                }
            }
            else
            {
                hilightedLayer = -1;
            }

            bool selected;
            bool lastSelected;

            for (int i = scrollIndex; i < layersLength; i++)
            {
                finRect.x = rect.x;
                finRect.y = rect.y + index * itemHeight;

                lastSelected = layerSelection.Contains(i);
                selected     = GUI.Toggle(finRect, layerSelection.Contains(i), GUIContent.none);
                if (selected != lastSelected)
                {
                    if (selected)
                    {
                        layerSelection.Add(i);
                    }
                    else
                    {
                        layerSelection.Remove(i);
                    }
                }

                finRect.x += itemHeight;
                GUI.Label(finRect, i + " " + layers[i].name);
                index++;
            }

            if (layers.Length > maxVisibleItems)
            {
                finRect.x      = width + 20;
                finRect.y      = rect.y;
                finRect.width  = 35f;
                finRect.height = rect.height;
                scrollIndex    = Mathf.Clamp((int)GUI.VerticalScrollbar(finRect, scrollIndex, maxVisibleItems, 0f, layers.Length), 0, layers.Length);
            }
            else
            {
                scrollIndex = 0;
            }
        }