当前位置: 首页>>代码示例>>C#>>正文


C# IProjection.ToZoomFactor方法代码示例

本文整理汇总了C#中IProjection.ToZoomFactor方法的典型用法代码示例。如果您正苦于以下问题:C# IProjection.ToZoomFactor方法的具体用法?C# IProjection.ToZoomFactor怎么用?C# IProjection.ToZoomFactor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProjection的用法示例。


在下文中一共展示了IProjection.ToZoomFactor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LayerOsm

        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        public LayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter, IProjection projection)
        {
            // build the zoom-level cutoffs.
            List<float> zoomLevelCutoffs = new List<float>();
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(18));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(16));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(14));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(12));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(10));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(8));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(0));

            _dataSource = dataSource;
            _styleSceneManager = new StyleSceneManager(styleInterpreter, zoomLevelCutoffs);
            //_styleSceneManager = new StyleSceneManager(styleInterpreter);
        }
开发者ID:robert-hickey,项目名称:OsmSharp,代码行数:21,代码来源:LayerOsm.cs

示例2: TranslateWay

        /// <summary>
        /// Translates a way.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="way"></param>
        /// <param name="relevantTags"></param>
        private bool TranslateWay(Scene2D scene, IProjection projection, CompleteWay way, TagsCollectionBase relevantTags)
        {
            // build the rules.
            List<MapCSSRuleProperties> rules = null;
            if (!_succesfullWays.TryGetValue(relevantTags, out rules))
            {
                rules = this.BuildRules(new MapCSSObject(way));
                _succesfullWays.Add(relevantTags, rules);
            }

            // validate what's there.
            if (rules.Count == 0)
            {
                return false;
            }

            bool success = false;

            // get x/y.
            double[] x = null, y = null;
            if (x == null)
            { // pre-calculate x/y.
                x = new double[way.Nodes.Count];
                y = new double[way.Nodes.Count];
                for (int idx = 0; idx < way.Nodes.Count; idx++)
                {
                    x[idx] = projection.LongitudeToX(
                        way.Nodes[idx].Coordinate.Longitude);
                    y[idx] = projection.LatitudeToY(
                        way.Nodes[idx].Coordinate.Latitude);
                }

                // simplify.
                if (x.Length > 2)
                {
                    double[][] simplified = SimplifyCurve.Simplify(new double[][] {x, y}, 0.0001);
                    x = simplified[0];
                    y = simplified[1];
                }
            }

            // add the z-index.
            foreach (var rule in rules)
            {
                float minZoom = (float)projection.ToZoomFactor(rule.MinZoom);
                float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom);

                int zIndex ;
                if (!rule.TryGetProperty<int>("zIndex", out zIndex))
                {
                    zIndex = 0;
                }

                // interpret the results.
                if (x != null &&
                    x.Length > 1)
                { // there is a valid interpretation of this way.
                    int color;
                    bool renderAsLine = true;
                    if (way.IsOfType(MapCSSTypes.Area))
                    { // the way is an area. check if it can be rendered as an area.
                        int fillColor;
                        if (rule.TryGetProperty("fillColor", out fillColor))
                        { // render as an area.
                            uint? pointsId = scene.AddPoints(x, y);
                            if (pointsId.HasValue)
                            {
                                scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetArea, zIndex), minZoom, maxZoom, fillColor, 1, true);
                                success = true;
                                if (rule.TryGetProperty("color", out color))
                                {
                                    scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, color, 1, false);
                                    success = true;
                                }
                            }
                            renderAsLine = false; // was validly rendered als a line.
                        }
                    }

                    if (renderAsLine)
                    { // was not rendered as an area.
                        // the way has to rendered as a line.
                        LineJoin lineJoin;
                        if (!rule.TryGetProperty("lineJoin", out lineJoin))
                        {
                            lineJoin = LineJoin.Miter;
                        }
                        int[] dashes;
                        if (!rule.TryGetProperty("dashes", out dashes))
                        {
                            dashes = null;
                        }
                        if (rule.TryGetProperty("color", out color))
//.........这里部分代码省略.........
开发者ID:kochizufan,项目名称:OsmSharp,代码行数:101,代码来源:MapCSSInterpreter.cs

示例3: TranslateNode

        /// <summary>
        /// Translates a node.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="node"></param>
        private void TranslateNode(Scene2D scene, IProjection projection, Node node)
        {
            // build the rules.
            IEnumerable<MapCSSRuleProperties> rules =
                this.BuildRules(new MapCSSObject(node));

            // interpret the results.
            foreach (var rule in rules)
            {
                int zIndex;
                if (!rule.TryGetProperty<int>("zIndex", out zIndex))
                {
                    zIndex = 0;
                }

                float minZoom = (float)projection.ToZoomFactor(rule.MinZoom);
                float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom);

                uint? pointId = null;
                int color;
                if (rule.TryGetProperty<int>("color", out color))
                {
                    float width;
                    if (rule.TryGetProperty<float>("width", out width))
                    {
                        pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude),
                                       projection.LatitudeToY(node.Coordinate.Latitude));
                        scene.AddStylePoint(pointId.Value, this.CalculateSceneLayer(OffsetPoint, zIndex), minZoom, maxZoom, color, width);
                    }
                    else
                    {
                        pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude),
                                       projection.LatitudeToY(node.Coordinate.Latitude));
                        scene.AddStylePoint(pointId.Value, this.CalculateSceneLayer(OffsetPoint, zIndex), minZoom, maxZoom, color, 1);
                    }
                }
                byte[] iconImage;
                if (rule.TryGetProperty("iconImage", out iconImage))
                {
                    if (!pointId.HasValue)
                    {
                        pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude),
                                       projection.LatitudeToY(node.Coordinate.Latitude));
                    }
                    // an icon is to be drawn!
                    ushort imageId = scene.AddImage(iconImage);
                    scene.AddIcon(pointId.Value, this.CalculateSceneLayer(OffsetPoint, zIndex), minZoom, maxZoom, imageId);
                }

                string text;
                if (rule.TryGetProperty("text", out text))
                {
                    int textColor;
                    if(!rule.TryGetProperty("textColor", out textColor))
                    {
                        textColor = SimpleColor.FromKnownColor(KnownColor.Black).Value;
                    }
                    int haloColor;
                    int? haloColorNullable = null;
                    if (rule.TryGetProperty("textHaloColor", out haloColor))
                    {
                        haloColorNullable = haloColor;
                    }
                    int haloRadius;
                    int? haloRadiusNullable = null;
                    if (rule.TryGetProperty("textHaloRadius", out haloRadius))
                    {
                        haloRadiusNullable = haloRadius;
                    }
                    int fontSize;
                    if (!rule.TryGetProperty("fontSize", out fontSize))
                    {
                        fontSize = 10;
                    }
                    string fontFamily;
                    if (!rule.TryGetProperty ("fontFamily", out fontFamily))
                    {
                        fontFamily = "Arial"; // just some default font.
                    }

                    // a text is to be drawn.
                    string value;
                    if (node.Tags.TryGetValue(text, out value))
                    {
                        if (!pointId.HasValue)
                        {
                            pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude),
                                           projection.LatitudeToY(node.Coordinate.Latitude));
                        }
                        scene.AddText(pointId.Value, this.CalculateSceneLayer(OffsetPointText, zIndex), minZoom, maxZoom, fontSize, value, textColor,
                                      haloColorNullable, haloRadiusNullable, fontFamily);
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:kochizufan,项目名称:OsmSharp,代码行数:101,代码来源:MapCSSInterpreter.cs

示例4: TranslateLineairRing

        /// <summary>
        /// Translates a lineair ring.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="lineairRing"></param>
        private void TranslateLineairRing(Scene2D scene, IProjection projection, LineairRing lineairRing)
        {
            // build the rules.
            List<MapCSSRuleProperties> rules =
                this.BuildRules(new MapCSSObject(lineairRing));

            // validate what's there.
            if (rules.Count == 0)
            {
                return;
            }

            // get x/y.
            double[] x = null, y = null;
            if (lineairRing.Coordinates != null &&
                lineairRing.Coordinates.Count > 0)
            { // pre-calculate x/y.
                x = new double[lineairRing.Coordinates.Count];
                y = new double[lineairRing.Coordinates.Count];
                for (int idx = 0; idx < lineairRing.Coordinates.Count; idx++)
                {
                    x[idx] = projection.LongitudeToX(
                        lineairRing.Coordinates[idx].Longitude);
                    y[idx] = projection.LatitudeToY(
                        lineairRing.Coordinates[idx].Latitude);
                }

                // simplify.
                if (x.Length > 2)
                {
                    double[][] simplified = SimplifyCurve.Simplify(new double[][] { x, y }, 0.0001);
                    x = simplified[0];
                    y = simplified[1];
                }
            }
            // add the z-index.
            foreach (var rule in rules)
            {
                float minZoom = (float)projection.ToZoomFactor(rule.MinZoom);
                float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom);

                int zIndex;
                if (!rule.TryGetProperty<int>("zIndex", out zIndex))
                {
                    zIndex = 0;
                }

                // interpret the results.
                if (x != null)
                { // there is a valid interpretation of this way.
                    int color;
                    int fillColor;
                    if (rule.TryGetProperty("fillColor", out fillColor))
                    { // render as an area.
                        float fillOpacity;
                        if(rule.TryGetProperty("fillOpacity", out fillOpacity))
                        {
                            SimpleColor simpleFillColor = new SimpleColor() { Value = fillColor };
                            fillColor = SimpleColor.FromArgb((int)(255 * fillOpacity),
                                simpleFillColor.R, simpleFillColor.G, simpleFillColor.B).Value;
                        }
                        uint? pointsId = scene.AddPoints(x, y);
                        if (pointsId.HasValue)
                        {
                            scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetArea, zIndex), minZoom, maxZoom, fillColor, 1, true);
                            if (rule.TryGetProperty("color", out color))
                            {
                                scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, color, 1, false);
                            }
                        }
                    }
                }
            }
        }
开发者ID:kochizufan,项目名称:OsmSharp,代码行数:80,代码来源:MapCSSInterpreter.cs

示例5: TranslateWay

        /// <summary>
        /// Translates a way.
        /// </summary>
        /// <param name="scene">The scene to add primitives to.</param>
        /// <param name="projection">The projection used to convert the objects.</param>
        /// <param name="way"></param>
        private void TranslateWay(Scene2D scene, IProjection projection, CompleteWay way)
        {
            // build the rules.
            List<MapCSSRuleProperties> rules =
                this.BuildRules(new MapCSSObject(way));

            // validate what's there.
            if (rules.Count == 0)
            {
                return;
            }

            // get x/y.
            double[] x = null, y = null;
            if (x == null)
            { // pre-calculate x/y.
                x = new double[way.Nodes.Count];
                y = new double[way.Nodes.Count];
                for (int idx = 0; idx < way.Nodes.Count; idx++)
                {
                    x[idx] = projection.LongitudeToX(
                        way.Nodes[idx].Coordinate.Longitude);
                    y[idx] = projection.LatitudeToY(
                        way.Nodes[idx].Coordinate.Latitude);
                }

                // simplify.
                if (x.Length > 2)
                {
                    double[][] simplified = SimplifyCurve.Simplify(new double[][] {x, y}, 0.0001);
                    x = simplified[0];
                    y = simplified[1];
                }
            }

            // add the z-index.
            foreach (var rule in rules)
            {
                float minZoom = (float)projection.ToZoomFactor(rule.MinZoom);
                float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom);

                int zIndex ;
                if (!rule.TryGetProperty<int>("zIndex", out zIndex))
                {
                    zIndex = 0;
                }

                // interpret the results.
                if (x != null)
                { // there is a valid interpretation of this way.
                    int color;
                    if (way.IsOfType(MapCSSTypes.Area))
                    { // the way is an area. check if it can be rendered as an area.
                        int fillColor;
                        if (rule.TryGetProperty("fillColor", out fillColor))
                        { // render as an area.
                            scene.AddPolygon(this.CalculateSceneLayer(OffsetArea, zIndex), minZoom, maxZoom, x, y, fillColor, 1, true);
                            if (rule.TryGetProperty("color", out color))
                            {
                                scene.AddPolygon(this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, x, y, color, 1, false);
                            }
                        }
                    }

                    // the way has to rendered as a line.
                    LineJoin lineJoin;
                    if (!rule.TryGetProperty("lineJoin", out lineJoin))
                    {
                        lineJoin = LineJoin.Miter;
                    }
                    int[] dashes;
                    if (!rule.TryGetProperty("dashes", out dashes))
                    {
                        dashes = null;
                    }
                    if (rule.TryGetProperty("color", out color))
                    {
                        float casingWidth;
                        int casingColor;
                        if (!rule.TryGetProperty("casingWidth", out casingWidth))
                        {
                            casingWidth = 0;
                        }
                        if(!rule.TryGetProperty("casingColor", out casingColor))
                        { // casing: use the casing layer.
                            casingColor = -1;
                        }
                        float width;
                        if (!rule.TryGetProperty("width", out width))
                        {
                            width = 1;
                        }
                        if (casingWidth > 0)
                        { // adds the casing
//.........这里部分代码省略.........
开发者ID:vcotlearov,项目名称:OsmSharp,代码行数:101,代码来源:MapCSSInterpreter.cs


注:本文中的IProjection.ToZoomFactor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。