void CreateZone(Zone z) { Overlay polygon; Marker marker; if (!z.Active || !z.Visible) { if (overlays.ContainsKey (z.ObjIndex)) { overlays.TryGetValue (z.ObjIndex, out polygon); if (polygon != null) polygon.Map = null; overlays.Remove (z.ObjIndex); markers.TryGetValue (z.ObjIndex, out marker); if (marker != null) marker.Map = null; markers.Remove (z.ObjIndex); } return; } if (!overlays.TryGetValue(z.ObjIndex, out polygon)) { polygon = new Polygon () { FillColor = Colors.ZoneFill, StrokeColor = Colors.ZoneStroke, StrokeWidth = 2, Tappable = true, Map = mapView }; overlays.Add (z.ObjIndex, polygon); } if (!markers.TryGetValue(z.ObjIndex, out marker)) { marker = new Marker () { Tappable = true, Icon = (z.Icon != null ? UIImage.LoadFromData (NSData.FromArray (z.Icon.Data)) : Images.IconMapZone), GroundAnchor = z.Icon != null ? new PointF(0.5f, 0.5f) : new PointF(0.075f, 0.95f), InfoWindowAnchor = z.Icon != null ? new PointF(0.5f, 0.5f) : new PointF(0.075f, 0.0f), Map = mapView }; markers.Add (z.ObjIndex, marker); } polygon.Title = z.Name; marker.Title = z.Name; var inventory = (WherigoCollection<Thing>)z.Inventory; if (inventory.Count > 0) { StringBuilder s = new StringBuilder (); foreach (Thing thing in inventory) { s.Append ((s.Length > 0 ? ", " : "") + (thing.Name == null ? "" : thing.Name)); } marker.Snippet = Catalog.Format(Catalog.GetString("Contains {0}"), s.ToString()); } MutablePath path = new MutablePath ();; WherigoCollection<ZonePoint> points = z.Points; double lat = 0; double lon = 0; foreach (ZonePoint zp in points) { lat += zp.Latitude; lon += zp.Longitude; path.AddLatLon (zp.Latitude, zp.Longitude); } ((Polygon)polygon).Path = path; polygon.ZIndex = 50; marker.Position = new CLLocationCoordinate2D ((float)lat / (float)points.Count, (float)lon / (float)points.Count); marker.ZIndex = 100; }
/// <summary> /// Replaces the already visible zone or creates a new one. /// </summary> /// <param name="z">The z coordinate.</param> /// <param name="replace">The z coordinate.</param> void CreateZone (Zone z, Polygon replace = null) { IList<LatLng> points = new List<LatLng>(z.Points.Count); if (replace != null) { // Replace the points from the old polygon foreach (var zp in z.Points) { points.Add(new LatLng(zp.Latitude, zp.Longitude)); replace.Points = points; } } else { // Create a new polygon for zone PolygonOptions po = new PolygonOptions (); foreach (var zp in z.Points) { po.Points.Add (new LatLng (zp.Latitude, zp.Longitude)); } po.InvokeStrokeColor (Color.Argb (160, 255, 0, 0)); po.InvokeStrokeWidth (2); po.InvokeFillColor (Color.Argb (80, 255, 0, 0)); po.InvokeZIndex(1); // Add polygon to list of active zones zones.Add (z.ObjIndex, _map.AddPolygon (po)); } }