Exemplo n.º 1
0
        public void CreateLayerPanels()
        {
            // Delete any existing panel
            foreach (var panel in _layersMap)
            {
                Destroy(panel.Value.gameObject);
            }
            _layersMap.Clear();

            // appState.layers are actually Layer script (Component)
            AppState.instance.layers.ForEach(comp =>
            {
                IVirgisLayer layer = (IVirgisLayer)comp;
                Debug.Log($"CreateLayerPanels: layer {layer.GetMetadata().Id ?? ""}, {layer.GetMetadata().DisplayName ?? ""}");
                // create a view panel for this particular layer
                GameObject newLayerPanel = Instantiate(layerPanelPrefab, transform);
                // obtain the panel script
                LayerUIPanel panelScript         = newLayerPanel.GetComponentInChildren <LayerUIPanel>();
                LayerUIContainer containerScript = newLayerPanel.GetComponentInChildren <LayerUIContainer>();
                containerScript._layersMap       = _layersMap;
                // set the layer in the panel
                containerScript.layer = layer;

                containerScript.viewLayerToggle.isOn = layer.IsVisible();

                _layersMap.Add(Guid.NewGuid(), panelScript);
                newLayerPanel.transform.SetParent(layersScrollView.transform, false);
            });
            LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
        }
Exemplo n.º 2
0
        private void CreateLayerPanels()
        {
            GameObject newLayerPanel;

            // appState.layers are actually Layer script (Component)
            _appState.layers.ForEach(comp =>
            {
                // obtain the actual Layer object
                //                ILayer layer = comp.GetComponentInChildren<ILayer>();
                IVirgisLayer layer = (IVirgisLayer)comp;
                print($"CreateLayerPanels: layer {layer.GetMetadata().Id ?? ""}, {layer.GetMetadata().DisplayName ?? ""}");
                // create a view panel for this particular layer
                newLayerPanel = (GameObject)Instantiate(layerPanelPrefab, transform);
                // obtain the panel script
                LayerUIPanel panelScript = newLayerPanel.GetComponentInChildren <LayerUIPanel>();
                // set the layer in the panel
                panelScript.layer = layer;
                // listens to panel's edit selected event
                panelScript.AddEditSelectedListener(OnLayerPanelEditSelected);
                if (layer.IsEditable())
                {
                    panelScript.editLayerToggle.isOn = true;
                }
                panelScript.viewLayerToggle.isOn = layer.IsVisible();
                // when the Layers Menu screen is first displayed,
                // edit session could already be active
                if (_appState.editSession.IsActive())
                {
                    // in edit session, layer can be set to edit
                    panelScript.editLayerToggle.interactable = true;
                }
                else
                {
                    // not in edit session, layer cannot be set to edit
                    panelScript.editLayerToggle.interactable = false;
                }
                _layersMap.Add(layer.GetId(), panelScript);
                newLayerPanel.transform.SetParent(layersScrollView.transform, false);
            });
            printEditStatus();
        }
Exemplo n.º 3
0
        private void OnTriggerDoublePress()
        {
            if (_appState.editSession.IsActive())
            {
                IVirgisLayer      editableLayer = _appState.editSession.editableLayer;
                RecordSetDataType dataType      = editableLayer.GetMetadata().DataType;
                switch (dataType)
                {
                case RecordSetDataType.Line:
                    if (_newFeature != null)
                    {
                        VirgisFeature temp = _lastVertex[0];
                        _lastVertex.Clear();
                        temp.UnSelected(SelectionTypes.SELECT);
                        // if edit mode is snap to anchor and start and end vertexes are at the same position
                        if (_appState.editSession.mode == EditSession.EditMode.SnapAnchor &&
                            _firstVertex.transform.position == temp.transform.position)
                        {
                            (_newFeature as Dataline).MakeLinearRing();
                        }
                        // complete adding line feature
                        _newFeature = null;
                    }
                    break;

                case RecordSetDataType.Polygon:
                    if (_newFeature != null)
                    {
                        // complete adding polygon feature
                        _newFeature = null;
                        VirgisFeature temp = _lastVertex[0];
                        _lastVertex.Clear();
                        temp.UnSelected(SelectionTypes.SELECT);
                    }
                    break;
                }
            }
        }
Exemplo n.º 4
0
        private void OnTriggerSinglePress(Vector3 posWhenSinglePress)
        {
            if (_appState.editSession.IsActive())
            {
                IVirgisLayer      editableLayer = _appState.editSession.editableLayer;
                RecordSetDataType dataType      = editableLayer.GetMetadata().DataType;
                Datapoint[]       vertexes;
                switch (dataType)
                {
                case RecordSetDataType.Point:
                    VirgisFeature point = editableLayer.AddFeature(new Vector3[1] {
                        posWhenSinglePress
                    });
                    point.UnSelected(SelectionTypes.SELECT);
                    break;

                case RecordSetDataType.Line:
                    //Debug.Log($"ShapeAdder add Vertex");
                    if (_newFeature != null)
                    {
                        _newFeature.AddVertex(posWhenSinglePress);
                    }
                    else
                    {
                        _newFeature = editableLayer.AddFeature(new Vector3[2] {
                            posWhenSinglePress, posWhenSinglePress + Vector3.one * Single.Epsilon
                        });
                        // get the last vertex
                        vertexes     = (_newFeature as Dataline).GetVertexes();
                        _firstVertex = vertexes[0];
                        _lastVertex.Add(vertexes[1]);
                        _firstVertex.UnSelected(SelectionTypes.SELECT);
                    }
                    break;

                case RecordSetDataType.Polygon:
                    if (_newFeature != null)
                    {
                        if (_lastVertex.Count == 1)
                        {
                            _newFeature.transform.GetComponentInChildren <Dataline>().AddVertex(posWhenSinglePress);
                        }
                        else
                        {
                            _lastVertex[0].UnSelected(SelectionTypes.SELECT);
                            _lastVertex.RemoveAt(0);
                        }
                    }
                    else
                    {
                        _newFeature = editableLayer.AddFeature(new Vector3[4] {
                            posWhenSinglePress, posWhenSinglePress + Vector3.right * 0.01f, posWhenSinglePress + Vector3.up * 0.01f, posWhenSinglePress
                        });
                        vertexes     = (_newFeature as Datapolygon).GetVertexes();
                        _firstVertex = vertexes[0];
                        _lastVertex.Add(vertexes[1]);
                        _lastVertex.Add(vertexes[2]);
                    }
                    break;
                }
            }
        }