Пример #1
0
        private TriangulationList <Vector3> CreateScaleBar(float modelSize4326, float modelSizeProjected, float radius = 10f)
        {
            int          nSteps    = 4;
            ScaleBarInfo scaleInfo = GetScaleBarWidth(modelSize4326, modelSizeProjected, scaleBarSizeRelativeToModel: 0.5f, nSteps);

            Vector3 currentPosition = Vector3.Zero;
            TriangulationList <Vector3> triangulation = new TriangulationList <Vector3>();

            for (int i = 0; i < nSteps; i++)
            {
                currentPosition.Z = scaleInfo.StepSizeProjected * i;

                triangulation += _meshService.CreateCylinder(currentPosition, radius, scaleInfo.StepSizeProjected
                                                             , color: i % 2 == 0 ? VectorsExtensions.CreateColor(0, 0, 0) : VectorsExtensions.CreateColor(255, 255, 255));
            }

            // scale units (m or km ?)
            string scaleLabel = (scaleInfo.TotalSize / 1000f > 1) ? $"{scaleInfo.TotalSize / 1000:F0} km" : $"{scaleInfo.TotalSize} m";

            triangulation += CreateText(scaleLabel, color: VectorsExtensions.CreateColor(255, 255, 255))
                             .Scale(radius / 5)
                             .RotateY((float)Math.PI / 2)
                             .RotateZ((float)Math.PI / 2)
                             .Translate(new Vector3(radius * 5, -radius, scaleInfo.TotalSizeProjected / 2));

            return(triangulation);
        }
Пример #2
0
        public TriangulationList <Vector3> CreateModelAdornments(DEMDataSet dataset, ImageryProvider imageryProvider, BoundingBox bboxDemSpace, BoundingBox bboxModelSpace)
        {
            var width = (float)new GeoPoint(latitude: bboxDemSpace.Center[1],
                                            longitude: bboxDemSpace.Center[0] - bboxDemSpace.Width / 2f)
                        .DistanceTo(
                new GeoPoint(latitude: bboxDemSpace.Center[1],
                             longitude: bboxDemSpace.Center[0] + bboxDemSpace.Width / 2f)
                );

            // bbox size
            float projHeight      = (float)bboxModelSpace.Height;
            float arrowSizeFactor = projHeight / 3f;
            float zCenter         = (float)bboxModelSpace.Center[2];
            float projWidth       = (float)bboxModelSpace.Width;
            //
            float PI = (float)Math.PI;

            // Arrow
            TriangulationList <Vector3> adornments = _meshService.CreateArrow().ToGlTFSpace()
                                                     .Scale(arrowSizeFactor)
                                                     .Translate(new Vector3(-projWidth * 0.55f, 0, zCenter));

            // North text 'N'
            adornments += this.CreateText("N", VectorsExtensions.CreateColor(255, 255, 255)).ToGlTFSpace()
                          .Scale(projHeight / 200f / 5f)
                          .RotateX(-PI / 2)
                          .Translate(new Vector3(-projWidth * 0.55f, arrowSizeFactor * 1.1f, zCenter));

            // Scale bar
            var scaleBar     = this.CreateScaleBar(width, projWidth, radius: projHeight / 200f).ToGlTFSpace();
            var scaleBarSize = scaleBar.GetBoundingBox().Height;

            adornments += scaleBar
                          .RotateZ(PI / 2f)
                          .Translate(new Vector3(projWidth / 2, -projHeight / 2 - projHeight * 0.05f, zCenter));

            var text = $"{dataset.Attribution.Subject}: {dataset.Attribution.Text}";

            if (imageryProvider != null)
            {
                text = string.Concat(text, $"{Environment.NewLine}{imageryProvider.Attribution.Subject}: {imageryProvider.Attribution.Text}");
            }
            var text3D    = this.CreateText(text, VectorsExtensions.CreateColor(255, 255, 255)).ToGlTFSpace();
            var textWidth = (float)text3D.GetBoundingBox().Width;
            var scale     = (float)(((projWidth - scaleBarSize) * 0.9f) / textWidth);

            text3D = text3D.Scale((float)scale)
                     .RotateX(-PI / 2)
                     .Translate(new Vector3((-projWidth + textWidth * scale) / 2f, -projHeight * 0.55f, zCenter));
            adornments += text3D;

            return(adornments);
        }