/// <summary> /// Add info about phone dimensions and creates a resized list of info /// </summary> /// <param name="phoneDimensions"></param> public void AddPhoneDimensions(Point phoneDimensions) { PhoneDimensions = phoneDimensions; foreach (var item in Hotspots) { //Calculate relationsship between original and new image double xModifier = phoneDimensions.X / Dimensions.X; double yModifier = phoneDimensions.Y / Dimensions.Y; Hotspot h = new Hotspot(); h.OfferId = item.OfferId; h.Polygon = new List <Point>(); //resize polygon to the page /*var minX = item.Polygon.Min(p => p.X * xModifier); * var maxX = item.Polygon.Max(p => p.X * xModifier); * var minY = item.Polygon.Min(p => (PhoneDimensions.Y - (p.Y * yModifier))); * var maxY = item.Polygon.Max(p => (PhoneDimensions.Y - (p.Y * yModifier))); * *///Create a rectange foreach (var p in item.Polygon) { h.Polygon.Add(new Point(p.X * xModifier, (PhoneDimensions.Y - (p.Y * yModifier)))); } PhoneHotspots.Add(h); } }
/// <summary> /// Creates a cataloghotspot from a json value /// </summary> /// <param name="item"></param> /// <returns></returns> public static CatalogHotspot FromJson(JsonValue item) { CatalogHotspot ch = new CatalogHotspot(); var dimensions = item.GetJsonValue(() => ch.Dimensions); ch.Dimensions = new Point(dimensions["width"], dimensions["height"]); foreach (var hotSpot in item["hotspots"] as JsonArray) { ch.Hotspots.Add(Hotspot.FromJson(hotSpot)); } return(ch); }
/// <summary> /// Creates a hotspot from a json value /// </summary> /// <param name="item"></param> /// <returns></returns> public static Hotspot FromJson(JsonValue item) { //If the json item contains info about the polygon if (item.ContainsKey("poly")) { Hotspot h = new Hotspot(); h.Polygon = new List <Point>(); foreach (var p in item["poly"] as JsonArray) { h.Polygon.Add(new Point(p[0], p[1])); } h.OfferId = item["data"][0]; return(h); } return(null); }