Exemple #1
0
        private RaycastMapResult RayCastToMap(Point startPoint)
        {
            RayHitTestResult rayHitTestResult = VisualTreeHelper.HitTest(viewport, startPoint) as RayHitTestResult;

            if (rayHitTestResult != null)
            {
                Point3D hitPoint = rayHitTestResult.PointHit;
                // Convert to tile coords
                var hitPointOnTile = new Vector2 <double>(hitPoint.X - rayHitTestResult.ModelHit.Bounds.X, -(rayHitTestResult.ModelHit.Bounds.Y - hitPoint.Y));
                hitPointOnTile.X = 4096 - hitPointOnTile.X;
                hitPointOnTile   = hitPointOnTile.Multiply(2);

                Projection projection = CalculateProjection();
                var        hitTile    = new Vector2 <double>(hitPoint.X, hitPoint.Y).Divide(4096).ToVectorInt().Multiply(4096);

                double startPosX = (int)Math.Floor((hitTile.X - (projection.Bottom / 2)) / 4096) + 1;
                double startPosY = (int)Math.Floor((hitTile.Y - (projection.Left / 2)) / 4096) + 1;

                double           cZoom = dataController.ConvertToMapZoom(zoom);
                Vector2 <double> startTileCoordinations = MercatorProjection.LatLngToTile(Settings.startPosition, cZoom);
                LatLng           tileLatLng             = MercatorProjection.TileToLatLng(new Vector2 <double>(startTileCoordinations.X - startPosX, startTileCoordinations.Y + startPosY), cZoom);
                //LatLng pointLatLng = MercatorProjection.TileToLatLng(, cZoom);

                Vector2 <double> tile  = MercatorProjection.LatLngToTile(tileLatLng, cZoom).Floor();
                Graph            graph = dataController.GetRoads(new Vector3 <double>(tile.X, tile.Y, cZoom));
                help.Content = graph.FindNearest(hitPointOnTile);

                return(new RaycastMapResult(tileLatLng, hitPointOnTile, hitPoint));
            }

            return(null);
        }
        public void TestMercatorProjection()
        {
            LatLng startPosition = new LatLng(48.464717, 35.046183);

            Vector2 <double> tile    = MercatorProjection.LatLngToTile(startPosition, 13);
            LatLng           latLng  = MercatorProjection.TileToLatLng(tile, 13);
            LatLng           latLng1 = MercatorProjection.TileToLatLng(tile.X, tile.Y, 13);

            Assert.IsTrue(startPosition.IsEquals(latLng.Round(6)) && startPosition.IsEquals(latLng1.Round(6)));
        }