Beispiel #1
0
        internal static SharpMap.Map InitializeMap(float angle, string[] filenames)
        {
            var map = new SharpMap.Map();

            try
            {
                foreach (var filename in filenames)
                {
                    var connectionString = string.Format("Data Source={0}", filename);
                    foreach (var provider in SharpMap.Data.Providers.SpatiaLite.GetSpatialTables(connectionString))
                    {
                        map.Layers.Add(
                            new SharpMap.Layers.VectorLayer(
                                string.Format("{0} - {1}", provider.Table, provider.GeometryColumn), provider)
                        {
                            Style = LayerTools.GetRandomVectorStyle()
                        });
                    }
                }
                if (map.Layers.Count > 0)
                {
                    map.ZoomToExtents();

                    System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                    mat.RotateAt(angle, map.WorldToImage(map.Center));
                    map.MapTransform = mat;
                    return(map);
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            return(null);
        }
        private void InitDisplayPnl()
        {
            if (displayPnl == null)
            {
                if (displayCanvas == null)
                {
                    displayCanvas            = new GameObject("VideoDisplayCanvas").AddComponent <Canvas>();
                    displayCanvas.renderMode = RenderMode.ScreenSpaceCamera;

                    var scale = displayCanvas.gameObject.AddComponent <CanvasScaler>();
                    scale.matchWidthOrHeight  = Framework.UIModule.DefaultMatchRatio(false);
                    scale.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
                    scale.referenceResolution = Framework.Driver.Instance.Config._uiResolution;

                    LayerTools.SetLayer(displayCanvas.gameObject, (int)canvasLayer);
                }

                displayPnl = new GameObject("VideoDisplayPnl").AddComponent <DisplayUGUI>();
                displayPnl.transform.SetParent(displayCanvas.transform, false);
                LayerTools.SetLayer(displayPnl.gameObject, (int)canvasLayer);

                ResetDisplayPnl();
                displayPnl.raycastTarget = false;
                displayPnl._scaleMode    = ScaleMode.ScaleAndCrop;

                displayPnl._noDefaultDisplay = defaultTexture == null;
                if (defaultTexture != null)
                {
                    displayPnl._defaultTexture = defaultTexture;
                    displayPnl.enabled         = false;
                }
            }

            displayPnl._mediaPlayer = CurMediaPlayer;
        }
Beispiel #3
0
    protected virtual void ApplyAfterLayerCheck(GameObject other)
    {
        if (LayerTools.IsLayerInMask(LayerMask, other.layer) == false)
        {
            return;
        }

        Apply(other.gameObject);
    }
Beispiel #4
0
    protected override void OnTriggerStay(Collider other)
    {
        if (LayerTools.IsLayerInMask(LayerMask, other.gameObject.layer) == false)
        {
            return;
        }


        Apply(other.gameObject);
    }
 private void OnTriggerExit2D(Collider2D other)
 {
     if (!other.isTrigger)
     {
         if (LayerTools.IsInLayerMask(m_whatIsGround, other.gameObject.layer))
         {
             --m_collisionCounter;
         }
     }
 }
Beispiel #6
0
    protected virtual void OnTriggerEnter(Collider other)
    {
        if (LayerTools.IsLayerInMask(Mask, other.gameObject.layer) == false)
        {
            return;
        }

        DeployEffectZone();

        HandlePenetration();
    }
Beispiel #7
0
        /// <summary>
        /// 暂时保存编辑内容,将正在编辑的要素保存到原有要素,并计算地理坐标
        /// </summary>
        public void TmpSaveEdit()
        {
            if (_IsEditing)
            {
                if (_EditingLayer.GeoType == typeof(PointD))
                {
                    foreach (DataRow sRow in _EditingLayer.EditingRecord)
                    {
                        if (!Convert.IsDBNull(sRow[2]))
                        {
                            sRow[1] = _PrjSystem.ToLngLat((PointD)sRow[2]);
                            sRow[3] = ((PointD)sRow[2]).Clone();
                        }
                        else
                        {
                            sRow[1] = null;
                        }
                    }
                }
                else if (_EditingLayer.GeoType == typeof(MultiPolyLine))
                {
                    foreach (DataRow sRow in _EditingLayer.EditingRecord)
                    {
                        if (!Convert.IsDBNull(sRow[2]))
                        {
                            sRow[1] = _PrjSystem.ToLngLat((MultiPolyLine)sRow[2]);
                            sRow[3] = LayerTools.GetCenterPoint((MultiPolyLine)sRow[2]);
                        }
                        else
                        {
                            sRow[1] = null;
                        }
                    }
                }
                else if (_EditingLayer.GeoType == typeof(MultiPolygon))
                {
                    foreach (DataRow sRow in _EditingLayer.EditingRecord)
                    {
                        if (!Convert.IsDBNull(sRow[2]))
                        {
                            sRow[1] = _PrjSystem.ToLngLat((MultiPolygon)sRow[2]);
                            sRow[3] = LayerTools.GetCenterPoint((MultiPolygon)sRow[2]);
                        }
                        else
                        {
                            sRow[1] = null;
                        }
                    }
                }

                _EditingLayer.EditingRecord.Clear();
            }
        }
Beispiel #8
0
        /// <summary>
        ///  显示edge的详细信息
        /// </summary>
        /// <param name="eid">edge id</param>
        public void showEdgeInfo(int eid)
        {
            Edge e = graph.Edges[eid];

            if (e != null)
            {
                double length = LayerTools.GetDistance(e.Start.Point, e.End.Point);
                //double cost = e.Cost;
                double cost = 0;
                MessageBox.Show(string.Format("{0} --> {1} : {2}m\nCost:{3},Length/Cost:{4}", e.Start.ID, e.End.ID, length, cost, length / cost));
            }
        }
Beispiel #9
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (LayerTools.IsLayerInMask(bounceLayer, other.gameObject.layer) == false)
        {
            return;
        }

        ActivateBounce();

        //if (myBody.velocity.magnitude >= 5f)
        //    bounceForce = startingForce;
    }
Beispiel #10
0
    protected override void OnTriggerStay(Collider other)
    {
        if (LayerTools.IsLayerInMask(LayerMask, other.gameObject.layer) == false)
        {
            return;
        }

        if (CheckHitTargets(other.gameObject) == true)
        {
            Apply(other.gameObject);
        }
    }
Beispiel #11
0
 public void AddGeometry(Layer layer, List <Geometry> gList, Type geoType)
 {
     if (_IsEditing && !layer.ReadOnly)
     {
         if (gList != null && geoType == layer.GeoType)
         {
             foreach (Geometry geo in gList)
             {
                 layer.Records.Rows.Add(null, geo, _PrjSystem.ToProjCo(geo), LayerTools.GetCenterPoint(geo));
             }
         }
     }
 }
Beispiel #12
0
    private void OnCollisionEnter(Collision other)
    {
        if (LayerTools.IsLayerInMask(groundLayer, other.gameObject.layer) == false)
        {
            return;
        }

        //Debug.Log("Collided with ground");

        if (onCollideWithGround != null)
        {
            onCollideWithGround();
        }
    }
Beispiel #13
0
    private void SetDestination()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            if (hit.collider != null)
            {
                if (LayerTools.IsLayerInMask(walkableArea, hit.collider.gameObject.layer))
                {
                    navMeshAgent.SetDestination(hit.point);
                }
            }
        }
    }
Beispiel #14
0
    protected virtual void ApplyAfterLayerCheck(GameObject other, bool checkHits = false)
    {
        if (LayerTools.IsLayerInMask(LayerMask, other.layer) == false)
        {
            return;
        }

        if (checkHits == true)
        {
            if (CheckHitTargets(other) == false)
            {
                return;
            }
        }

        Apply(other.gameObject);
    }
Beispiel #15
0
    private GameObject TryToDetect(GameObject other)
    {
        Vector2      direction = other.transform.position - transform.position;
        RaycastHit2D hit       = Physics2D.Raycast(transform.position, direction.normalized, detectionDistance);

        if (hit.collider != null)
        {
            //Debug.Log(hit.collider.gameObject.name + " is seen");
            if (LayerTools.IsLayerInMask(targetLayers, hit.collider.gameObject.layer) == true)
            {
                //Debug.Log(hit.collider.gameObject.name + " is seen");
                return(hit.collider.gameObject);
            }
        }

        return(null);
    }
Beispiel #16
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            var providers = new SharpMap.Data.Providers.Ogr[filenames.Length];

            for (int i = 0; i < filenames.Length; i++)
            {
                providers[i] = new Ogr(filenames[i]);
            }

            var map = LayerTools.GetMapForProviders(providers);

            Matrix mat = new Matrix();

            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;
            map.ZoomToExtents();
            return(map);
        }
Beispiel #17
0
        private void mbMap_GeometryDefined(IGeometry geometry)
        {
            double length = 0;

            if (geometry.GetType() == typeof(LineString) && ruler)
            {
                geometry = GeometryTransform.TransformGeometry(geometry, LayerTools.GoogleMercatorToWgs84.MathTransform, geofactory);
                length   = LayerTools.GetLength(geometry as LineString);
                MessageBox.Show("Length:" + length + "m.");
                ruler = false;
            }
            else
            {
                outputProvider.Geometries.Add(geometry);
            }
            mbMap.ActiveTool = MapBox.Tools.Pan;
            RefreshMap();
        }
Beispiel #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputfile"></param>
        /// <param name="file"></param>
        /// <param name="stdFile"></param>
        //private void cmpFile(string inputfile, string file, string stdFile)
        //{
        //    StreamReader inSr = new StreamReader(inputfile);
        //    StreamReader sr = new StreamReader(file);
        //    StreamReader stdSr = new StreamReader(stdFile);
        //    int lineNumber = 0;
        //    int correctNumber = 0;
        //    String line, stdLine, inLine;
        //    List<Record> list = new List<Record>();
        //    while (!sr.EndOfStream && !stdSr.EndOfStream)
        //    {

        //        inLine = inSr.ReadLine();
        //        line = sr.ReadLine();
        //        stdLine = stdSr.ReadLine();
        //        lineNumber++;
        //        Record rec = new Record();
        //        String[] fields = inLine.Split(',');
        //        rec.Time = int.Parse(fields[0]);
        //        rec.Lat = double.Parse(fields[1]);
        //        rec.Lng = double.Parse(fields[2]);
        //        //output
        //        fields = line.Split(',');
        //        int time = int.Parse(fields[0]);
        //        if (time != rec.Time)
        //        {
        //            MessageBox.Show(String.Format("time fields at Line {0} in the input file and the output file should be the same.", lineNumber));
        //            return;
        //        }
        //        rec.EdgeId = int.Parse(fields[1]);
        //        rec.Confidence = double.Parse(fields[2]);
        //        //stdoutput
        //        fields = stdLine.Split(',');
        //        time = int.Parse(fields[0]);
        //        if (time != rec.Time)
        //        {
        //            MessageBox.Show(String.Format("time fields at Line {0} in the input file and the stdoutput file should be the same.", lineNumber));
        //            return;
        //        }
        //        rec.StdEdgeId = int.Parse(fields[1]);
        //        if (rec.EdgeId == rec.StdEdgeId)
        //        {
        //            rec.Correct = true;
        //            correctNumber++;
        //        }
        //        else
        //        {
        //            rec.Correct = false;
        //        }
        //        if (lineNumber > 1)
        //        {
        //            Record prev = list[lineNumber - 2];
        //            rec.Distance = LayerTools.GetDistance(rec.Lng, rec.Lat, prev.Lng, prev.Lat);
        //        }
        //        else
        //        {
        //            rec.Distance = 0;
        //        }
        //        list.Add(rec);
        //    }
        //    inSr.Close();
        //    sr.Close();
        //    stdSr.Close();

        //    //显示正确率
        //    lbCorrectRate.Text = (correctNumber * 1.0 / lineNumber).ToString();

        //    dgvCmp.AutoGenerateColumns = true;
        //    dgvCmp.DataSource = list;
        //    //更改背景颜色
        //    DataGridViewRowCollection rows = dgvCmp.Rows;
        //    //int correct_idx = dgvCmp.Columns.Count - 2;
        //    int correct_idx = dgvCmp.Columns["Correct"].Index;
        //    for (int i = 0; i < rows.Count; i++)
        //    {
        //        bool correct = (bool)rows[i].Cells[correct_idx].Value;
        //        if (!correct)
        //        {
        //            rows[i].DefaultCellStyle.BackColor = Color.Red;
        //        }
        //    }
        //    dgvCmp.Columns["Time"].Width = 50;
        //    dgvCmp.Columns["Lat"].Width = 100;
        //    dgvCmp.Columns["Lng"].Width = 100;
        //    dgvCmp.Columns["EdgeId"].Width = 60;
        //    dgvCmp.Columns["StdEdgeId"].Width = 60;
        //    dgvCmp.Columns["Distance"].Width = 60;
        //    dgvCmp.Columns["Confidence"].Width = 30;
        //    dgvCmp.Columns["Correct"].Width = 40;
        //    dgvCmp.Refresh();
        //}

        /// <summary>
        /// Read the matched trajectory file
        /// </summary>
        /// <param name="inputfile"></param>
        private void cmpFile(string inputfile)
        {
            StreamReader  inSr       = new StreamReader(inputfile);
            int           lineNumber = 0;
            String        inLine;
            List <Record> list = new List <Record>();

            while (!inSr.EndOfStream)
            {
                inLine = inSr.ReadLine();
                lineNumber++;
                Record   rec    = new Record();
                String[] fields = inLine.Split(',');
                rec.Time = fields[0];
                //rec.Time = int.Parse(fields[0]);
                rec.Lat    = double.Parse(fields[1]);
                rec.Lng    = double.Parse(fields[2]);
                rec.EdgeId = int.Parse(fields[3]);
                if (lineNumber > 1)
                {
                    Record prev = list[lineNumber - 2];
                    rec.Distance = LayerTools.GetDistance(rec.Lng, rec.Lat, prev.Lng, prev.Lat);
                }
                else
                {
                    rec.Distance = 0;
                }
                list.Add(rec);
            }
            inSr.Close();

            dgvCmp.AutoGenerateColumns        = true;
            dgvCmp.DataSource                 = list;
            dgvCmp.Columns["Time"].Width      = 100;
            dgvCmp.Columns["Lat"].Width       = 100;
            dgvCmp.Columns["Lng"].Width       = 100;
            dgvCmp.Columns["EdgeId"].Width    = 60;
            dgvCmp.Columns["StdEdgeId"].Width = 60;
            dgvCmp.Columns["Distance"].Width  = 60;
            //dgvCmp.Columns["Confidence"].Width = 30;
            dgvCmp.Columns["Correct"].Width = 40;
            dgvCmp.Refresh();
        }
Beispiel #19
0
        public void ShowInspector()
        {
            Main.Logger.LogDebug($"[BTDebug] Showing inspector");
            if (!inspectorPrefab)
            {
                inspectorPrefab = Main.BTDebugBundle.LoadAsset("BTDebugInspector") as GameObject;
                ApplySettings(inspectorPrefab);
            }

            if (!inspectorGO)
            {
                inspectorGO = MonoBehaviour.Instantiate(inspectorPrefab, Vector3.zero, Quaternion.identity);
            }
            if (!inspectorGO.activeSelf)
            {
                inspectorGO.SetActive(true);
            }
            LayerTools.SetLayerRecursively(inspectorGO, 17);
            IsInspectorShowing = true;
        }
Beispiel #20
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            if (filenames == null)
            {
                return(null);
            }

            Map map = new Map();

            try
            {
                foreach (string filename in filenames)
                {
                    string connectionString = string.Format("Data Source={0}", filename);
                    foreach (SpatiaLite provider in SpatiaLite.GetSpatialTables(connectionString))
                    {
                        map.Layers.Add(
                            new VectorLayer(
                                string.Format("{0} - {1}", provider.Table, provider.GeometryColumn), provider)
                        {
                            Style = LayerTools.GetRandomVectorStyle()
                        });
                    }
                }
                if (map.Layers.Count > 0)
                {
                    map.ZoomToExtents();

                    Matrix mat = new Matrix();
                    mat.RotateAt(angle, map.WorldToImage(map.Center));
                    map.MapTransform = mat;
                    return(map);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            return(null);
        }
Beispiel #21
0
    private void OnTriggerStay2D(Collider2D other)
    {
        if (LayerTools.IsLayerInMask(targetLayers, other.gameObject.layer) == false)
        {
            return;
        }

        GameObject target = TryToDetect(other.gameObject);

        if (target != null)
        {
            if (targets.AddUnique(target))
            {
                owner.Brain.TargetSpotted();
            }

            //if (targets.AddUnique(target))
            //{
            //    ((EntityEnemy)owner).Aggro();
            //}
        }
    }
Beispiel #22
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            if (filenames == null)
            {
                return(null);
            }

            var providers = new SharpMap.Data.Providers.ShapeFile[filenames.Length];

            for (int i = 0; i < filenames.Length; i++)
            {
                providers[i] = new ShapeFile(filenames[i], true);
                providers[i].Open();
            }

            var map = LayerTools.GetMapForProviders(providers);

            Matrix mat = new Matrix();

            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            return(map);
        }
Beispiel #23
0
        /// <summary>
        /// 添加图层
        /// </summary>
        /// <param name="layer">图层</param>
        public void AddLayer(Layer layer)
        {
            //计算投影
            if (layer.GeoType == typeof(PointD))
            {
                PointD sPoint;
                foreach (DataRow mRow in layer.Records.Rows)
                {
                    sPoint = mRow.Field <PointD>(1);
                    if (sPoint != null)
                    {
                        mRow[2] = _PrjSystem.ToProjCo(sPoint);
                    }
                }
            }
            else if (layer.GeoType == typeof(MultiPolyLine))
            {
                MultiPolyLine sMultiPolyLine;
                foreach (DataRow mRow in layer.Records.Rows)
                {
                    sMultiPolyLine = mRow.Field <MultiPolyLine>(1);
                    if (sMultiPolyLine != null)
                    {
                        mRow[2] = _PrjSystem.ToProjCo(sMultiPolyLine);
                    }
                }
            }
            else if (layer.GeoType == typeof(MultiPolygon))
            {
                MultiPolygon sMultiPolygon;
                foreach (DataRow mRow in layer.Records.Rows)
                {
                    sMultiPolygon = mRow.Field <MultiPolygon>(1);
                    if (sMultiPolygon != null)
                    {
                        mRow[2] = _PrjSystem.ToProjCo(sMultiPolygon);
                    }
                }
            }

            Geometry sGeo;

            foreach (DataRow mRow in layer.Records.Rows)
            {
                if (!Convert.IsDBNull(mRow[2]))
                {
                    sGeo    = (Geometry)mRow[2];
                    mRow[3] = LayerTools.GetCenterPoint(sGeo);
                }
            }
            if (layer.MBR == null)
            {
                layer.MBR = LayerTools.GetLayerGeoMBR(layer);
            }

            layer.PRJMBR = _PrjSystem.ToProjCo(layer.MBR);
            layer.Records.AcceptChanges(); //保存更改
            layer.GenerateIndex();         //计算地理索引

            //将地图数据锁住,不允许修改
            layer.ReadOnly = true;


            layer.VisiblityChanged += Layer_VisiblityChanged;
            layer.SymbolChanged    += Layer_SymbolChanged;
            layer.RecordsChanged   += Layer_RecordsChanged;

            _Layers.Insert(0, layer);
            if (_DataSet.Tables.Contains(layer.Name))
            {
                layer.Name += "_";
            }
            _DataSet.Tables.Add(layer.Records);
            _TreeNode.Nodes.Insert(0, layer.Node);

            LayerAdded?.Invoke(this, layer);    //通知外部已经添加了图层
            MapPerformaceChanged?.Invoke(this); //重绘一级地图
        }
Beispiel #24
0
        //投影信息改变了
        private void _PrjSystem_ProjectedSystemChanged(object sender)
        {
            foreach (Layer sLayer in _Layers)
            {
                //计算投影
                bool sRead = sLayer.ReadOnly;
                sLayer.ReadOnly = false;
                if (sLayer.GeoType == typeof(PointD))
                {
                    PointD sPoint;
                    foreach (DataRow mRow in sLayer.Records.Rows)
                    {
                        sPoint = mRow.Field <PointD>(1);
                        if (sPoint != null)
                        {
                            mRow[2] = _PrjSystem.ToProjCo(sPoint);
                        }
                    }
                }
                else if (sLayer.GeoType == typeof(MultiPolyLine))
                {
                    MultiPolyLine sMultiPolyLine;
                    foreach (DataRow mRow in sLayer.Records.Rows)
                    {
                        sMultiPolyLine = mRow.Field <MultiPolyLine>(1);
                        if (sMultiPolyLine != null)
                        {
                            mRow[2] = _PrjSystem.ToProjCo(sMultiPolyLine);
                        }
                    }
                }
                else if (sLayer.GeoType == typeof(MultiPolygon))
                {
                    MultiPolygon sMultiPolygon;
                    foreach (DataRow mRow in sLayer.Records.Rows)
                    {
                        sMultiPolygon = mRow.Field <MultiPolygon>(1);
                        if (sMultiPolygon != null)
                        {
                            mRow[2] = _PrjSystem.ToProjCo(sMultiPolygon);
                        }
                    }
                }

                Geometry sGeo;
                foreach (DataRow mRow in sLayer.Records.Rows)
                {
                    if (!Convert.IsDBNull(mRow[2]))
                    {
                        sGeo    = (Geometry)mRow[2];
                        mRow[3] = LayerTools.GetCenterPoint(sGeo);
                    }
                }

                sLayer.MBR    = LayerTools.GetLayerGeoMBR(sLayer);
                sLayer.PRJMBR = _PrjSystem.ToProjCo(sLayer.MBR);
                sLayer.Records.AcceptChanges();     //保存更改
                sLayer.GenerateIndex();             //计算地理索引
                MapPerformaceChanged?.Invoke(this); //重绘一级地图
                sLayer.ReadOnly = sRead;
            }
        }