public object DOMParse(XmlElement element, params object[] parameters) { var mapScene = new MapScene(element.Attributes["id"].Value); var chapter = parameters[0] as Chapter; mapScene.CameraType = ExParsers.ParseEnum <CameraType>(ExString.Default(element.GetAttribute("cameraType"), CameraType.Aerial2D.ToString())); mapScene.RenderStyle = ExParsers.ParseEnum <RenderStyle>(ExString.Default(element.GetAttribute("renderStyle"), RenderStyle.Tile.ToString())); mapScene.TileMetaIdentifier = ExString.Default(element.GetAttribute("tileMetaIdentifier"), "OSMTile"); mapScene.UsesGameplayArea = ExString.EqualsDefault(element.GetAttribute("usesGameplayArea"), "yes", false); mapScene.GameplayArea = ExParsers.ParseDefault(element.GetAttribute("gameplayArea"), new RectD(Vector2d.zero, Vector2d.zero)); mapScene.LatLon = ExParsers.ParseDefault(element.GetAttribute("center"), Vector2d.zero); mapScene.Zoom = ExParsers.ParseDefault(element.GetAttribute("zoom"), 19); bool initialScene = ExString.EqualsDefault(element.GetAttribute("start"), "yes", false); if (initialScene) { chapter.setTargetId(mapScene.getId()); } int layer = 0; foreach (var e in element.SelectNodes("map-element")) { var mapElementNode = e as XmlElement; MapElement mapElement = null; XmlElement extElemNode; var targetId = mapElementNode.GetAttribute("targetId"); if ((extElemNode = (XmlElement)mapElementNode.SelectSingleNode("ext-elem-ref")) != null) { var extElem = new ExtElemReference(targetId); mapElement = extElem; extElem.TransformManagerDescriptor = GetDescriptor(ExString.Default(extElemNode.GetAttribute("transformManager"), typeof(GeopositionedDescriptor).FullName)); foreach (var param in extElem.TransformManagerDescriptor.ParameterDescription) { var paramNode = extElemNode.SelectSingleNode("param[@name=\"" + param.Key + "\"]"); if (paramNode != null) { extElem.TransformManagerParameters.Add(param.Key, parseParam(param.Value.Type, paramNode.InnerText)); } } } else { mapElement = new GeoReference(targetId); } mapElement.Conditions = DOMParserUtility.DOMParse <Conditions>(mapElementNode.SelectSingleNode("condition") as XmlElement, parameters); mapElement.Layer = ExParsers.ParseDefault(mapElementNode.GetAttribute("layer"), layer); mapElement.Scale = ExParsers.ParseDefault(mapElementNode.GetAttribute("scale"), 1f); mapElement.Orientation = (Orientation)ExParsers.ParseDefault(mapElementNode.GetAttribute("orientation"), 2); layer = Mathf.Max(mapElement.Layer, layer) + 1; mapScene.Elements.Add(mapElement); } return(mapScene); }
private GeoElement FindGeoElement(GeoReference reference) { if (!cache.ContainsKey(reference)) { var elem = Game.Instance.GameState.FindElement <GeoElement>(reference.getTargetId()); cache.Add(reference, elem); } return(cache.ContainsKey(reference) ? cache[reference] : null); }
public object DOMParse(XmlElement element, params object[] parameters) { var mapScene = new MapScene(element.Attributes["id"].Value); var chapter = parameters[0] as Chapter; mapScene.CameraType = element.Attributes["cameraType"].Value.ToEnum <CameraType>(); var tmpArgVal = element.GetAttribute("start"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("yes")) { chapter.setTargetId(mapScene.getId()); } } tmpArgVal = element.GetAttribute("center"); if (!string.IsNullOrEmpty(tmpArgVal)) { mapScene.LatLon = (Vector2d)parseParam(typeof(Vector2d), tmpArgVal); } foreach (var e in element.SelectNodes("map-element")) { var mapElementNode = e as XmlElement; MapElement mapElement = null; XmlElement extElemNode; if ((extElemNode = (XmlElement)mapElementNode.SelectSingleNode("ext-elem-ref")) != null) { var extElem = new ExtElemReference(mapElementNode.Attributes["targetId"].Value); mapElement = extElem; extElem.TransformManagerDescriptor = GetDescriptor(extElemNode.Attributes["transformManager"].Value); foreach (var param in extElem.TransformManagerDescriptor.ParameterDescription) { var paramNode = extElemNode.SelectSingleNode("param[@name=\"" + param.Key + "\"]"); if (paramNode != null) { extElem.TransformManagerParameters.Add(param.Key, parseParam(param.Value.Type, paramNode.InnerText)); } } } else { mapElement = new GeoReference(mapElementNode.Attributes["targetId"].Value); } mapElement.Conditions = (Conditions)DOMParserUtility.DOMParse(mapElementNode.SelectSingleNode("condition") as XmlElement, parameters); mapElement.Layer = int.Parse(mapElementNode.Attributes["layer"].Value); mapScene.Elements.Add(mapElement); } return(mapScene); }
private bool Intersects(Tile tile, GeoReference elem) { var element = FindGeoElement(elem); // do the clipping var tb = GM.TileBounds(tile.TileTms, tile.Zoom); var tilePoints = AdaptToClipper(new List <Vector2d> { tb.Min, tb.Min + new Vector2d(tb.Width, 0), tb.Min + new Vector2d(tb.Width, tb.Height), tb.Min + new Vector2d(0, tb.Height) }.ConvertAll(p => GM.MetersToLatLon(p))); var geoPoints = AdaptToClipper(element.Geometry.Points); var solution = new List <List <IntPoint> >(); clipper.Clear(); clipper.AddPath(tilePoints, PolyType.ptSubject, true); clipper.AddPath(geoPoints, PolyType.ptSubject, true); return(clipper.Execute(ClipType.ctIntersection, solution) && solution.Count > 0); }
public GeoElementRefDataControl(GeoReference geoReference) : base(geoReference) { this.geoReference = geoReference; }