Exemple #1
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;
                }
            }
        }
Exemple #2
0
        protected override void _draw()
        {
            Dictionary <string, Unit> symbology = new Dictionary <string, Unit>();
            float displacement = 1.0f;

            if (layer.Properties.ContainsKey("Units"))
            {
                symbology = layer.Properties["Units"] as Dictionary <string, Unit>;
                if (symbology.ContainsKey("point") && symbology["point"].ContainsKey("Shape"))
                {
                    Shapes shape = symbology["point"].Shape;
                    switch (shape)
                    {
                    case Shapes.Spheroid:
                        PointPrefab = SpherePrefab;
                        break;

                    case Shapes.Cuboid:
                        PointPrefab = CubePrefab;
                        break;

                    case Shapes.Cylinder:
                        PointPrefab  = CylinderPrefab;
                        displacement = 1.5f;
                        break;

                    default:
                        PointPrefab = SpherePrefab;
                        break;
                    }
                }
                else
                {
                    PointPrefab = SpherePrefab;
                }
            }
            if (layer.Properties.ContainsKey("lat") && features[0].ContainsKey(layer.Properties["lat"] as string) &&
                layer.Properties.ContainsKey("lon") && features[0].ContainsKey(layer.Properties["lon"] as string))
            {
                foreach (CSVRow feature in features)
                {
                    Position position = new Position((double)feature[layer.Properties["lat"] as string], (double)feature[layer.Properties["lon"] as string]);


                    //instantiate the prefab with coordinates defined above
                    GameObject dataPoint = Instantiate(PointPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                    dataPoint.transform.parent = gameObject.transform;

                    // add the gis data from geoJSON
                    Datapoint com = dataPoint.GetComponent <Datapoint>();
                    com.gisProperties = feature;

                    //Set the symbology
                    if (symbology.ContainsKey("point"))
                    {
                        dataPoint.SendMessage("SetColor", (Color)symbology["point"].Color);
                        dataPoint.transform.localScale    = symbology["point"].Transform.Scale;
                        dataPoint.transform.localRotation = symbology["point"].Transform.Rotate;
                        dataPoint.transform.localPosition = symbology["point"].Transform.Position;
                        dataPoint.transform.position      = position.Vector3();
                    }

                    //Set the label
                    GameObject labelObject = Instantiate(LabelPrefab, Vector3.zero, Quaternion.identity);
                    labelObject.transform.parent        = dataPoint.transform;
                    labelObject.transform.localPosition = Vector3.up * displacement;
                    Text labelText = labelObject.GetComponentInChildren <Text>();

                    if (symbology.ContainsKey("point") && symbology["point"].ContainsKey("Label") && symbology["point"].Label != null && feature.ContainsKey(symbology["point"].Label))
                    {
                        labelText.text = (string)feature[symbology["point"].Label];
                    }
                }
            }
        }