protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
        {
            //Set the position of the scale bar on canvas.
            const float xpos = 15;
            var ypos = canvas.Height - 15;

            //Gets the left and right location of the scale bar in world coordinate according to the maximum width and X and Y position.
            var screenLocation = GetDrawingLocation(canvas, _width, ypos);
            var scaleBarMapPointR = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, screenLocation.X, screenLocation.Y, canvas.Width, canvas.Height);
            var scaleBarMapRightPointR = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, screenLocation.X + _width, screenLocation.Y, canvas.Width, canvas.Height);
            if ((Math.Abs(scaleBarMapPointR.X) > 180.0) || (Math.Abs(scaleBarMapRightPointR.X) > 180.0)) return;
            if ((Math.Abs(scaleBarMapPointR.Y) > 90.0) || (Math.Abs(scaleBarMapRightPointR.Y) > 90.0)) return;
            try
            {
                //Gets the length of the scale bar according to the unit and the maximum width of the scale bar.
                var fullBarLength = scaleBarMapPointR.GetDistanceTo(scaleBarMapRightPointR, canvas.MapUnit, DistanceUnit.Meter);
                //Adjusts the length of the scale bar in order to have a round number.
                _unitRoundValue = GetRoundValue(fullBarLength/_meterToUnit);
                var barLength = ((_unitRoundValue*_meterToUnit)*_width)/fullBarLength;

                //Draw the line of the scale bar according to the adjusted length.
                var pen = new GeoPen(GeoColor.StandardColors.White, 1F);
                canvas.DrawLine(new[]
                                {
                                    new ScreenPointF(xpos, ypos - 10), new ScreenPointF(xpos, ypos), new ScreenPointF((float) barLength + xpos, ypos), new ScreenPointF((float) barLength + xpos, ypos - 10)
                                }, pen, DrawingLevel.LevelOne, 0, 0);

                //Displays the text for the value and unit text.
                canvas.DrawText(Convert.ToString(_unitRoundValue) + " " + _unitText, GeoFont, GeoSolidBrush, new[]
                                                                                                             {
                                                                                                                 new ScreenPointF((float) (barLength/2) + xpos, ypos - 10)
                                                                                                             }, DrawingLevel.LevelOne);
            }
            catch (Exception) {}
        }
Example #2
0
        private void Map1_Loaded(object sender, RoutedEventArgs e)
        {
            Map1.MapUnit = GeoUnit.Meter;
            Map1.UseOpenStreetMapAsBaseMap();

            dataLayer = new ShapefileLayer("SampleData/countries-900913.shp");
            dataLayer.Open();

            GeoPen outlinePen = new GeoPen(GeoColor.FromHtml("#00BCD4"), 2)
            {
                DashPattern = new float[] { 4, 4 }
            };

            MemoryLayer highlightLayer = new MemoryLayer {
                Name = "HighlightLayer"
            };

            highlightLayer.Styles.Add(new FillStyle(GeoColor.FromHtml("#55FAB04D")));
            highlightLayer.Styles.Add(new LineStyle(outlinePen));
            highlightLayer.Styles.Add(new SymbolStyle(SymbolType.Circle, GeoColor.FromHtml("#99FF5722"), GeoColors.White));
            Map1.AddDynamicLayers("HighlightOverlay", highlightLayer);

            Map1.ZoomTo(new GeoBound(2171997.6512, 8356849.2669, 3515687.9933, 11097616.86));
        }
Example #3
0
        protected override void DrawLineCore(IEnumerable <ScreenPointF> screenPoints, GeoPen linePen, DrawingLevel drawingLevel, float xOffset, float yOffset)
        {
            int id = linePen.GetHashCode();

            if (!styleUrlDictionary.ContainsKey(id))
            {
                string kmlStyle = GetLineStyleKml(id, linePen);
                kmlBuilder.Append(kmlStyle);
                styleUrlDictionary.Add(id, string.Format("<styleUrl>#{0}</styleUrl>", id));
            }

            StringBuilder contentStringBuilder = GetStringBuilder(drawingLevel);

            contentStringBuilder.AppendLine();
            contentStringBuilder.AppendLine(@"<Placemark>");
            contentStringBuilder.AppendLine(styleUrlDictionary[id]);
            contentStringBuilder.AppendLine(@"<LineString>");

            contentStringBuilder.AppendLine(extrudeString);
            contentStringBuilder.AppendLine(tessellateString);
            contentStringBuilder.AppendLine(altitudeModeString);

            AppendCoordinates(screenPoints, xOffset, yOffset, contentStringBuilder);
            contentStringBuilder.AppendLine(@"</LineString>");
            contentStringBuilder.AppendLine(@"</Placemark>");
        }
Example #4
0
 protected override void DrawEllipseCore(ScreenPointF screenPoint, float width, float height, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
 {
     //throw new NotImplementedException();
     return;
 }
Example #5
0
        protected override void DrawLineCore(IEnumerable <ScreenPointF> screenPoints, GeoPen linePen, DrawingLevel drawingLevel, float xOffset, float yOffset)
        {
            Collection <ScreenPointF> convertedPoints = new Collection <ScreenPointF>();

            foreach (ScreenPointF item in screenPoints)
            {
                convertedPoints.Add(GetScreenPoint(item));
            }

            GeoPen scaledPen = GetScaledPen(linePen);

            canvas.DrawLine(convertedPoints, scaledPen, drawingLevel, xOffset, yOffset);
        }
Example #6
0
        protected override void DrawEllipseCore(ScreenPointF screenPoint, float width, float height, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
        {
            screenPoint = GetScreenPoint(screenPoint);

            GeoPen scaledPen = GetScaledPen(outlinePen);;

            canvas.DrawEllipse(new ScreenPointF(screenPoint.X, screenPoint.Y), width, height, scaledPen, fillBrush, drawingLevel, xOffset, yOffset, penBrushDrawingOrder);
        }
Example #7
0
        protected override void DrawAreaCore(IEnumerable <ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
        {
            foreach (ScreenPointF[] screenPointFs in screenPoints)
            {
                for (int i = 0; i < screenPointFs.Length; i++)
                {
                    screenPointFs[i] = GetScreenPoint(screenPointFs[i]);
                }
            }

            GeoPen scaledPen = GetScaledPen(outlinePen);

            canvas.DrawArea(screenPoints, scaledPen, fillBrush, drawingLevel, xOffset, yOffset, penBrushDrawingOrder);
        }
Example #8
0
        protected override void DrawTextCore(string text, GeoFont font, GeoBrush fillBrush, GeoPen haloPen, IEnumerable <ScreenPointF> textPathInScreen, DrawingLevel drawingLevel, float xOffset, float yOffset, float rotateAngle)
        {
            List <ScreenPointF> screenPoints = new List <ScreenPointF>();

            foreach (ScreenPointF screenPointF in textPathInScreen)
            {
                screenPoints.Add(GetScreenPoint(screenPointF));
            }

            GeoFont scaledFont = GetScaledFont(font);

            canvas.DrawText(text, scaledFont, fillBrush, haloPen, screenPoints, drawingLevel, xOffset, yOffset, rotateAngle);
        }
Example #9
0
 protected override void DrawEllipseCore(ScreenPointF screenPoint, float width, float height, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
 {
     return;
 }
 private void Initialize()
 {
     DrawingLevel             = DrawingLevel.LabelLevel;
     HaloPen                  = new GeoPen(GeoColor.SimpleColors.White, 1f);
     labelFunctionColumnNames = new Dictionary <string, string>();
 }
Example #11
0
 protected override void DrawTextCore(string text, GeoFont font, GeoBrush fillBrush, GeoPen haloPen, IEnumerable <ScreenPointF> textPathInScreen, DrawingLevel drawingLevel, float xOffset, float yOffset, float rotateAngle)
 {
     //StringBuilder rnSB = new StringBuilder();
     //rnSB.AppendLine("<Placemark>");
     //rnSB.AppendFormat("<description>{0}</description>", text);
     //rnSB.AppendFormat("<name>{0}</name>", text);
     //rnSB.AppendLine("<visibility>1</visibility>");
     //rnSB.AppendLine("<Point>");
     //AppendCoordinates(textPathInScreen,xOffset,yOffset,rnSB);
     ////rnSB.AppendFormat("<coordinates>{0},{1},20000</coordinates>",
     ////    ((ScreenPointF[])(textPathInScreen))[0].X,
     ////    ((ScreenPointF[])(textPathInScreen))[0].Y);
     //rnSB.AppendLine("</Point>");
     //rnSB.AppendLine("<Style><IconStyle><Icon><href></href></Icon></IconStyle></Style>");
     //rnSB.AppendLine("</Placemark>");
     //StringBuilder contentStringBuilder = GetStringBuilder(drawingLevel);
     //contentStringBuilder.Append(rnSB.ToString());
 }
Example #12
0
        protected override void DrawAreaCore(IEnumerable <ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
        {
            //if (fillBrush == null)
            //{
            //    fillBrush = new GeoSolidBrush(GeoColor.SimpleColors.Transparent);
            //}
            int id = 0;

            if (fillBrush != null)
            {
                id = fillBrush.GetHashCode();
            }
            else
            {
                id        = outlinePen.GetHashCode();
                fillBrush = new GeoSolidBrush(GeoColor.SimpleColors.Transparent);
            }

            if (!_styleUrlDictionary.ContainsKey(id))
            {
                string kmlStyle = GetPolygonStyleKml(id, outlinePen, ((GeoSolidBrush)fillBrush).Color);
                _kmlBuilder.Append(kmlStyle);
                _styleUrlDictionary.Add(id, string.Format("<styleUrl>#{0}</styleUrl>", id));
            }

            StringBuilder contentStringBuilder = GetStringBuilder(drawingLevel);

            contentStringBuilder.AppendLine();
            contentStringBuilder.AppendLine(@"<Placemark>");
            contentStringBuilder.AppendLine(_styleUrlDictionary[id]);
            contentStringBuilder.AppendLine(@"<Polygon>");

            contentStringBuilder.AppendLine(_extrudeString);
            contentStringBuilder.AppendLine(_tessellateString);
            contentStringBuilder.AppendLine(_altitudeModeString);

            bool firstCoordinates = true;

            foreach (ScreenPointF[] screenPoint in screenPoints)
            {
                if (firstCoordinates)
                {
                    contentStringBuilder.AppendLine(@"<outerBoundaryIs>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</outerBoundaryIs>");
                    firstCoordinates = false;
                }
                else
                {
                    contentStringBuilder.AppendLine(@"<innerBoundaryIs>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</innerBoundaryIs>");
                }
            }
            contentStringBuilder.AppendLine(@"</Polygon>");
            contentStringBuilder.AppendLine(@"</Placemark>");
        }
Example #13
0
 public MyLineStyle(GeoPen outerPen, GeoPen innerPen, GeoPen centerPen)
     : base(outerPen, innerPen, centerPen)
 {
 }
Example #14
0
        protected override void DrawTextCore(string text, GeoFont font, GeoBrush fillBrush, GeoPen haloPen, IEnumerable <ScreenPointF> textPathInScreen, DrawingLevel drawingLevel, float xOffset, float yOffset, float rotateAngle, DrawingTextAlignment drawingTextAlignment)
        {
            int id = 0;

            if (fillBrush != null)
            {
                id = fillBrush.GetHashCode();
            }

            if (!styleUrlDictionary.ContainsKey(id))
            {
                string kmlStyle = GetTextStyleKml(id, ((GeoSolidBrush)fillBrush).Color, font.Size);
                kmlBuilder.Append(kmlStyle);
                styleUrlDictionary.Add(id, string.Format("<styleUrl>#{0}</styleUrl>", id));
            }

            StringBuilder contentStringBuilder = GetStringBuilder(drawingLevel);

            contentStringBuilder.AppendLine();
            contentStringBuilder.AppendLine(@"<Placemark>");
            contentStringBuilder.AppendLine(styleUrlDictionary[id]);
            text = text.Replace("<", "&lt;");
            text = text.Replace(">", "&gt;");
            text = text.Replace("`", "&apos;");
            text = text.Replace("\"", "&quot;");
            text = text.Replace("&", "&amp;");
            contentStringBuilder.AppendLine(@"<name>" + text + @"</name>");

            if (textPathInScreen.Count() > 1)
            {
                contentStringBuilder.AppendLine(@"<LineString>");

                contentStringBuilder.AppendLine(extrudeString);
                contentStringBuilder.AppendLine(tessellateString);
                contentStringBuilder.AppendLine(altitudeModeString);
                AppendCoordinates(textPathInScreen, xOffset, yOffset, contentStringBuilder);
                contentStringBuilder.AppendLine(@"</LineString>");
            }
            else
            {
                contentStringBuilder.AppendLine(@"<Point>");

                contentStringBuilder.AppendLine(extrudeString);
                contentStringBuilder.AppendLine(tessellateString);
                contentStringBuilder.AppendLine(altitudeModeString);
                AppendCoordinates(textPathInScreen, xOffset, yOffset, contentStringBuilder);
                contentStringBuilder.AppendLine(@"</Point>");
            }

            contentStringBuilder.AppendLine(@"</Placemark>");
        }
        protected override void DrawAreaCore(IEnumerable <ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
        {
            var outline = screenPoints.FirstOrDefault();

            if (outline != null)
            {
                switch (outlineDrawMode)
                {
                case OutlineDrawMode.Open:
                    DrawLineCore(outline.Take(outline.Length - 1), outlinePen, drawingLevel, xOffset, yOffset);
                    break;

                case OutlineDrawMode.Dynamic:
                    DrawLineCore(outline.Skip(outline.Length - 3).Take(3), outlinePen, drawingLevel, xOffset, yOffset);
                    break;

                case OutlineDrawMode.Sealed:
                    DrawLineCore(outline, outlinePen, drawingLevel, xOffset, yOffset);
                    break;

                case OutlineDrawMode.LineWithFill:
                default:
                    base.DrawAreaCore(screenPoints, outlinePen, fillBrush, drawingLevel, xOffset, yOffset, penBrushDrawingOrder);
                    break;
                }
            }
        }
Example #16
0
        protected override void DrawAreaCore(IEnumerable <ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
        {
            if (fillBrush == null)
            {
                fillBrush = new GeoSolidBrush(GeoColor.SimpleColors.Transparent);
            }

            int id = 0;

            if (outlinePen != null)
            {
                id = outlinePen.GetHashCode();
            }
            else if (fillBrush != null)
            {
                id = id ^ fillBrush.GetHashCode();
            }

            if (!styleUrlDictionary.ContainsKey(id))
            {
                GeoSolidBrush          brush         = fillBrush as GeoSolidBrush;
                GeoLinearGradientBrush gradientBrush = fillBrush as GeoLinearGradientBrush;
                GeoHatchBrush          hatchBrush    = fillBrush as GeoHatchBrush;
                string kmlStyle = string.Empty;
                if (gradientBrush != null)
                {
                    kmlStyle = GetPolygonStyleKml(id, outlinePen, gradientBrush.StartColor);
                }
                else if (hatchBrush != null)
                {
                    kmlStyle = GetPolygonStyleKml(id, outlinePen, hatchBrush.BackgroundColor);
                }
                else
                {
                    kmlStyle = GetPolygonStyleKml(id, outlinePen, brush.Color);
                }
                kmlBuilder.Append(kmlStyle);
                styleUrlDictionary.Add(id, string.Format("<styleUrl>#{0}</styleUrl>", id));
            }

            StringBuilder contentStringBuilder = GetStringBuilder(drawingLevel);

            contentStringBuilder.AppendLine();
            contentStringBuilder.AppendLine(@"<Placemark>");
            contentStringBuilder.AppendLine(styleUrlDictionary[id]);
            contentStringBuilder.AppendLine(@"<Polygon>");

            contentStringBuilder.AppendLine(extrudeString);
            contentStringBuilder.AppendLine(tessellateString);
            contentStringBuilder.AppendLine(altitudeModeString);

            bool firstCoordinates = true;

            foreach (ScreenPointF[] screenPoint in screenPoints)
            {
                if (firstCoordinates)
                {
                    contentStringBuilder.AppendLine(@"<outerBoundaryIs>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</outerBoundaryIs>");
                    firstCoordinates = false;
                }
                else
                {
                    contentStringBuilder.AppendLine(@"<innerBoundaryIs>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</innerBoundaryIs>");
                }
            }
            contentStringBuilder.AppendLine(@"</Polygon>");
            contentStringBuilder.AppendLine(@"</Placemark>");

            foreach (ScreenPointF[] screenPoint in screenPoints)
            {
                switch (Mode)
                {
                case AltitudeMode.Absolute:
                case AltitudeMode.RelativeToGround:
                    contentStringBuilder.AppendLine(@"<Placemark>");
                    AppendLinearRing(screenPoint, xOffset, yOffset, ZHeight, contentStringBuilder);
                    contentStringBuilder.AppendLine(@"</Placemark>");
                    break;

                default:
                    break;
                }
            }
        }
        protected override void DrawLineCore(IEnumerable <ScreenPointF> screenPoints, GeoPen linePen, DrawingLevel drawingLevel, float xOffset, float yOffset)
        {
            switch (outlineDrawMode)
            {
            case OutlineDrawMode.Open:
                var tmpScreenPoints = screenPoints.ToArray();
                base.DrawLineCore(tmpScreenPoints.Take(tmpScreenPoints.Length - 1), linePen, drawingLevel, xOffset, yOffset);
                break;

            default:
                base.DrawLineCore(screenPoints, linePen, drawingLevel, xOffset, yOffset);
                break;
            }
        }