Exemplo n.º 1
0
        public void RemoveOverlay(IMapOverlay item)
        {
            if (item is ICircleOverlay)
            {
                var    circle = (ICircleOverlay)item;
                Circle mapCircle;
                if (_circles.TryGetValue(circle, out mapCircle))
                {
                    _circles.Remove(circle);
                    mapCircle.Remove();
                }

                return;
            }

            if (item is IPolylineOverlay)
            {
                var      polyline = (IPolylineOverlay)item;
                Polyline mapPolyline;
                if (_polylines.TryGetValue(polyline, out mapPolyline))
                {
                    _polylines.Remove(polyline);
                    mapPolyline.Remove();
                }

                return;
            }
        }
Exemplo n.º 2
0
        public void AddOverlay(IMapOverlay item)
        {
            if (item is ICircleOverlay)
            {
                var circle  = (ICircleOverlay)item;
                var overlay = new UnifiedCircleOverlay(MKCircle.Circle(circle.Location.ToCoordinate(), circle.Radius))
                {
                    Data = circle
                };

                _overlays.Add(overlay);
                Control.AddOverlay(overlay);
                return;
            }

            if (item is IPolylineOverlay)
            {
                var polyline    = (IPolylineOverlay)item;
                var coordinates = polyline
                                  .Select(p => new CLLocationCoordinate2D(p.Latitude, p.Longitude))
                                  .ToArray();

                var overlay = new UnifiedPolylineOverlay(MKPolyline.FromCoordinates(coordinates))
                {
                    Data = polyline
                };

                _overlays.Add(overlay);
                Control.AddOverlay(overlay);
                return;
            }
        }
Exemplo n.º 3
0
        public void RemoveOverlay(IMapOverlay item)
        {
            var overlay = _overlays.FirstOrDefault(x => x.Data == item);

            if (overlay != null)
            {
                Control.RemoveOverlay((IMKOverlay)overlay);
                _overlays.Remove(overlay);
            }
        }
Exemplo n.º 4
0
        public void AddOverlay(IMapOverlay item)
        {
            if (_googleMap == null)
            {
                return;
            }

            if (item is ICircleOverlay)
            {
                var circle = (ICircleOverlay)item;

                var options = new CircleOptions();
                options.InvokeCenter(circle.Location.ToLatLng());
                options.InvokeRadius(circle.Radius);
                options.InvokeStrokeWidth(circle.LineWidth);
                options.InvokeStrokeColor(circle.StrokeColor.ToAndroid().ToArgb());
                options.InvokeFillColor(circle.FillColor.ToAndroid().ToArgb());

                var mapCircle = _googleMap.AddCircle(options);
                _circles.Add(circle, mapCircle);
                return;
            }

            if (item is IPolylineOverlay)
            {
                var polyline = (IPolylineOverlay)item;

                var options = new PolylineOptions();
                options.Add(polyline.Select(p => p.ToLatLng()).ToArray());
                options.InvokeColor(polyline.StrokeColor.ToAndroid());
                options.InvokeWidth(polyline.LineWidth);

                var mapPolyline = _googleMap.AddPolyline(options);
                _polylines.Add(polyline, mapPolyline);
                return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update the surface by redrawing necessary parts.
        /// </summary>
        public void UpdateScreen()
        {
            if (dirtyRect.isEmpty || offscreenBuffer == null)
            {
                return;                                                 // no need for draw.
            }
            DateTime start = DateTime.Now;

            IMapOverlay      overlay    = null;
            IModalController controller = MainWindow.mainWindow.CurrentController;

            if (controller != null)
            {
                overlay = controller.Overlay;
            }

            if (overlay != null)
            {
                overlay.DrawBefore(this, drawContext);
            }

            // draw the rect
            Rectangle dr = dirtyRect.rect;

            if (dr.Top < 0)
            {
                dr.Y = 0;               // clipping. higher voxel on the northen edge could make top<0
            }
            Draw(dr, overlay);
            dirtyRect.clear();

            // allow MapOverlay to do the wrap-up
            if (overlay != null)
            {
                overlay.DrawAfter(this, drawContext);
            }

            if (Core.Options.drawStationNames)
            {
                // REVISIT: I don't want these code inside this method.
                //  it needs to be extensible.

                /*Graphics graphics = drawContext.graphics;
                 *
                 * foreach( freetrain.world.rail.Station st in world.stations )
                 * {
                 *  Point pt = fromXYZToClient( st.baseLocation );
                 *  pt.Y -= 16;	// display the string above the station
                 *
                 *  SizeF sz = graphics.MeasureString( st.name, drawFont );
                 *  pt.X -= (int)sz.Width/2;
                 *
                 *  graphics.DrawString( st.name, drawFont, drawBrush1, pt.X+1, pt.Y+1 );
                 *  graphics.DrawString( st.name, drawFont, drawBrush2, pt.X  , pt.Y   );
                 * }*/
            }

            drawContext.Tag = null;             // reset the attached tag

            Debug.WriteLine("update took " + (DateTime.Now - start).TotalMilliseconds + "ms");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Redraw the specified region.
        /// Should be used only from the draw() method.
        /// </summary>
        /// <param name="rectAB">Rectangle in the (A,B) coordinates.</param>
        /// <param name="overlay"></param>
        public void Draw(Rectangle rectAB, IMapOverlay overlay)
        {
            // the same rectangle in the client coordinates
            Rectangle rectClient = fromABToClient(rectAB);

            int  waterLevel  = world.WaterLevel;
            bool noHeightCut = (HeightCutHeight == world.Size.z - 1);

            Color waterSurfaceColor = waterSurfaceDayColor;

            if (world.ViewOptions.UseNightView)
            {
                waterSurfaceColor = ColorMap.getNightColor(waterSurfaceColor);
            }

            rectAB.Inflate(20, 20);
            if (rectAB.X < 0)
            {
                rectAB.X = 0;
            }
            if (rectAB.Y < 0)
            {
                rectAB.Y = 0;
            }
            if ((rectAB.Width + rectAB.X) > offscreenBuffer.Size.Width)
            {
                rectAB.Width = (rectAB.Width - rectAB.X);
            }
            if ((rectAB.Height + rectAB.Y) > offscreenBuffer.Size.Height)
            {
                rectAB.Height = (rectAB.Height - rectAB.Y);
            }

            //if (rectClient. > offscreenBuffer.clipRect)
            //dirtyRect.add(rectClient);
            offscreenBuffer.ClipRect = rectAB;     // set clipping

            Rectangle rectHV = fromABToHV(rectAB); // determine the region to draw

            int Hmax = Math.Min(rectHV.Right, world.Size.x - 1);

            int Zinit = noHeightCut ? (int)waterLevel : 0;      // no need to draw underwater unless in the height cut mode
            int Z     = HeightCutHeight;
            int Vmax  = Math.Min(rectHV.Bottom + Z * 2, world.Size.y - 1);

            emptyChip = ResourceUtil.GetGroundChip(world);
            waterChip = ResourceUtil.UnderWaterChip;

            for (int v = Math.Max(0, rectHV.Top); v <= Vmax; v++)
            {
                for (int h = rectHV.Left; h <= Hmax; h++)
                {
                    int groundLevel = world.getGroundLevelFromHV(h, v);


                    int zi = Zinit;
                    if (Zinit <= groundLevel && !shouldDrawGround(h, v, Zinit))
                    {
                        zi = Math.Max(zi - 1, 0);                                                               // if the surface is being cut, start from one smaller
                    }
                    for (int z = zi; z <= Z; z++)
                    {
                        Voxel voxel = world.voxelHVD(h, v, z);
                        //						if(voxel!=null)
                        //							Debug.Assert( voxel.location==world.toXYZ(h,v,z) );

                        // point in the client coordinate to draw
                        Point pt = fromHVZToClient(h, v, z);
                        // draw the surface anyway.

                        if (voxel == null || voxel.Transparent)
                        {
                            if (z == groundLevel)
                            {
                                if (shouldDrawGround(h, v, z))
                                {
                                    if (waterLevel <= z)
                                    {
                                        //DateTime start = DateTime.Now;
                                        emptyChip.Draw(drawContext.Surface, pt);
                                        //Debug.WriteLine(z + "[3]: " + (DateTime.Now - start).TotalMilliseconds + "ms, ");
                                    }
                                    else
                                    {
                                        waterChip.Draw(drawContext.Surface, pt);
                                    }
                                }
                            }
                            else
                            if (z == waterLevel && noHeightCut)
                            {
                                emptyChip.DrawShape(drawContext.Surface, pt, waterSurfaceColor);
                            }
                            else
                            if (z == Z && Z < groundLevel)
                            {
                                // if the surface voxel is not drawn, draw the "under group" chip
                                if (shouldDrawGround(h, v, z))
                                {
                                    ResourceUtil.UnderGroundChip.Draw(drawContext.Surface, pt);
                                }
                            }
                        }
                        //					}
                        //				}
                        //			}
                        //
                        //			for( int v=Math.Max(0,rectHV.Top); v<=Vmax; v++ )
                        //			{
                        //				for( int h=rectHV.Left; h<=Hmax; h++ )
                        //				{
                        //					int groundLevel = world.getGroundLevelFromHV(h,v);
                        //
                        //					int zi = Zinit;
                        //					if( Zinit<=groundLevel && !shouldDrawGround(h,v,Zinit) )
                        //						zi = Math.Max(zi-1,0);	// if the surface is being cut, start from one smaller
                        //					for( int z=zi; z<=Z; z++  )
                        //					{
                        //						Voxel voxel = world.voxelHVD(h,v,z);
                        //						//						if(voxel!=null)	Debug.Assert( voxel.location==world.toXYZ(h,v,z) );
                        //
                        //						if( z<groundLevel && z<heightCutHeight ) continue;
                        //						Point pt = fromHVZToClient(h,v,z);

                        if (voxel != null)
                        {
                            //DateTime start = DateTime.Now;
                            voxel.DrawVoxel(drawContext, pt, noHeightCut ? -1 : (Z - z + 1));
                            //Debug.WriteLine("voxel took: " + (DateTime.Now - start).TotalMilliseconds + "ms");
                        }
                        if (overlay != null)
                        {
                            overlay.DrawVoxel(this, drawContext, world.toXYZ(h, v, z), pt);
                        }
                    }
                    // Debug.WriteLine("outer loop took: " + (DateTime.Now - start).TotalMilliseconds + "ms");
                }
            }

            if (Core.Options.drawBoundingBox)
            {
                rectAB.Inflate(-1, -1);
                offscreenBuffer.DrawBox(rectAB);
            }
        }