public AvrMapInfo(double pLon, double pLat) { //MtInfo mtInfo = new MtInfo(); //var connectionCredentials = new bv.common.Configuration.ConnectionCredentials(); //mtInfo.ConnectionString = connectionCredentials.ConnectionString; //mtInfo.LoadTranslations(); //m_InfoRegion = new string[4]; //m_InfoRayon = new string[4]; //m_InfoResult = mtInfo.GetWebPointInfo(pLon, pLat, m_InfoRegion, m_InfoRayon, ref m_InfoSettlement); var connectionCredentials = new bv.common.Configuration.ConnectionCredentials(); var lng = Localizer.CurrentCultureLanguageID; m_InfoRegion = new string[4]; m_InfoRayon = new string[4]; // Old version: uses map control and requires devex. Causes an error. //MtInfo mtInfo = new MtInfo(); //mtInfo.ConnectionString = connectionCredentials.ConnectionString; //mtInfo.LoadTranslations(); //m_InfoResult = mtInfo.GetWebPointInfo(pLon, pLat, m_InfoRegion, m_InfoRayon, ref m_InfoSettlement); m_InfoResult = CoordinatesUtils.GetWebPointInfo1(connectionCredentials.ConnectionString, lng, pLon, pLat, m_InfoRegion, m_InfoRayon, ref m_InfoSettlement); }
private void ProcessMouseClick(object sender, MouseEventArgs e) { var locationInMap = CoordinatesUtils.GetLocationInMapByLocationInControl(new Vector(e.X, e.Y), cellSize); var gemToDelete = new List <Gem>(); foreach (var gem in Game.CurrentLevel.Map.Gems) { if ((gem.Position - locationInMap).Length < 0.9) { Game.CurrentLevel.GemCount += 25; gemToDelete.Add(gem); } } foreach (var gem in gemToDelete) { Game.CurrentLevel.Map.Delete(gem); } if (gemToDelete.Count > 0) { return; } if (isDeleteSelected) { foreach (var hero in Game.CurrentLevel.Map.GetHeroesFromLine((int)locationInMap.Y)) { if (Math.Abs(hero.Position.X - locationInMap.X) < double.Epsilon) { Game.CurrentLevel.Map.Delete(hero); } } isDeleteSelected = false; return; } if (currentObjectToPurchase != null) { if (Game.CurrentLevel.GemCount >= currentObjectToPurchase.Price && !Game.CurrentLevel.Map.Heroes .Any(hero => (locationInMap - hero.Position).Length < 0.1)) { var ctor = currentObjectToPurchase.Type.GetConstructors()[0]; var heroToAdd = (IHero)ctor.Invoke( new object[] { currentObjectToPurchase.Parameters, locationInMap }); Game.CurrentLevel.Map.Add(heroToAdd); Game.CurrentLevel.GemCount -= currentObjectToPurchase.Price; } } }
private void DrawMap(object sender, PaintEventArgs e) { if (Game.IsWin) { CheckPanelAlreadySet(gameWinPanel); return; } if (Game.IsOver) { CheckPanelAlreadySet(gameOverPanel); return; } if (Game.CurrentLevel.IsWin) { ShopForm.UpdateCoinsLabel(); CheckPanelAlreadySet(levelWinPanel); return; } foreach (var gameObject in Game.CurrentLevel.Map.GetGameObjects()) { var visualObject = ResourceManager.GetVisualObject(gameObject.GetType()); var currentAnimation = visualObject.PassiveImage; if (gameObject.State != State.Idle) { currentAnimation = gameObject.State == State.Moves ? visualObject.MoveImage : visualObject.AttackImage; if (!visualObject.Animations.ContainsKey(gameObject)) { visualObject.Animations[gameObject] = new Animation( false, currentAnimation); } AnimationUtils.AnimateImage(visualObject.Animations[gameObject], currentAnimation, OnFrameChanged); ImageAnimator.UpdateFrames(); } var rectangleInMapControl = CoordinatesUtils.GetRectangleToPaintByLocationInMap(gameObject.Position, cellSize); if (gameObject is IStrike) { rectangleInMapControl.Height /= 3; rectangleInMapControl.Y += rectangleInMapControl.Height / 2; } e.Graphics.DrawImage(currentAnimation, rectangleInMapControl); } }
public void CreateEnvironment(Coords worldPoint, int worldRadius, Vector3 editorPoint, float height, int editorRadius) { SetupGOInstance(editorPoint); var square = CoordinatesUtils.SquareFromCenter((worldPoint.Latitude, worldPoint.Longitude), worldRadius); var squareSim = CoordinatesUtils.SquareFromCenterSim(new Vector3(0, 0, 0), editorRadius); var tile = new Tile(square[2], square[0], squareSim[2], squareSim[0]); // Retrieve data from API only if necessary var data = SessionState.GetString("prev_environment", ""); if (SettingsHaveChanged(worldPoint, worldRadius, height) == true) { SessionState.SetFloat("prev_latitude", worldPoint.Latitude); SessionState.SetFloat("prev_longitude", worldPoint.Longitude); SessionState.SetInt("prev_radius", worldRadius); SessionState.SetFloat("prev_editor_heigh", height); data = Overpass.GetBuildingsInArea(tile); } var dataObj = JsonConvert.DeserializeObject <DataProperties>(data); SessionState.SetString("prev_environment", data); foreach (Elements elem in dataObj.elements) { Vector3[] points = new Vector3[elem.geometry.Length]; for (int i = 0; i < elem.geometry.Length; i++) { Coords geoPoint = new Coords(elem.geometry[i].lat, elem.geometry[i].lon); Vector3 simPoint = SimCoordinatesUtils.GPSToSim(geoPoint, tile); points[i] = simPoint; } GenerateBuilding(points, height); } }
private string GetMapJson(DataTable data) { var connectionCredentials = new bv.common.Configuration.ConnectionCredentials(); string connection = connectionCredentials.ConnectionString; var column = new DataColumn { DataType = typeof(SqlGeometry), ColumnName = "geom" }; data.Columns.Add(column); var sqlConnection = new SqlConnection(connection); sqlConnection.Open(); string lTableName = CoordinatesUtils.GetWKBTableName(data, connection); const int srid = 4326; string ratio = "0"; // Settlement if (lTableName == "gisWKBRegion") { ratio = "50"; } if ((lTableName == "gisWKBRayon") || (lTableName == "gisWKBDistrict")) { ratio = "100"; } string strIds = string.Empty; if (data.Rows.Count > 0) { strIds = String.Join(",", data.AsEnumerable().Select(x => x.Field <long>("id").ToString()).ToArray()); strIds = string.Format("idfsGeoObject in ({0}) and ", strIds); if ((data.PrimaryKey == null) || (data.PrimaryKey.Length == 0)) { var key = new DataColumn[1]; key[0] = data.Columns["id"]; data.PrimaryKey = key; } try // Try get it from precached table geomShape_4326 { string strBatchSql = "SELECT g.idfsGeoObject as id, g.geomShape_4326 as geom FROM " + lTableName + "Ready g WHERE " + strIds + " Ratio = " + ratio; var cmdBatch = new SqlCommand(strBatchSql, sqlConnection); using (SqlDataReader dr = cmdBatch.ExecuteReader()) { var resBatch = new DataTable(); resBatch.Load(dr); if ((resBatch != null) && resBatch.Rows.Count > 0) { if ((resBatch.PrimaryKey == null) || (resBatch.PrimaryKey.Length == 0)) { var resBatchKey = new DataColumn[1]; resBatchKey[0] = resBatch.Columns["id"]; resBatch.PrimaryKey = resBatchKey; } data.Merge(resBatch, false, MissingSchemaAction.Ignore); } } } catch (Exception /*ex*/) { /*var strErr = ex.Message;*/ } foreach (var rEmptyGeom in data.Select("geom is null")) { SharpMap.Geometries.Geometry feature = null; long id = 0; if (rEmptyGeom["id"].ToString() != "") { id = Int64.Parse(rEmptyGeom["id"].ToString()); } // Try get it as usual feature = Extents.GetGeomById(sqlConnection, lTableName, id); if (feature != null) { feature = GeometryTransform.TransformGeometry(feature, GIS_V4.Common.CoordinateSystems.SphericalMercatorCS, GIS_V4.Common.CoordinateSystems.WGS84); var wktGeometry = new System.Data.SqlTypes.SqlChars(feature.AsText()); rEmptyGeom["geom"] = SqlGeometry.STGeomFromText(wktGeometry, srid); } if (feature != null) { SharpMap.Geometries.Point point = feature.GetBoundingBox().GetCentroid(); rEmptyGeom["x"] = point.X; rEmptyGeom["y"] = point.Y; } else { double x, y; if (CoordinatesUtils.GetAdminUnitCoordinates(connection, id, out x, out y)) { rEmptyGeom["x"] = x; rEmptyGeom["y"] = y; } } } } sqlConnection.Close(); var ds = new DataSet(); ds.Tables.Add(data.Copy()); string json = GeoJSON.DataSetToJSON(ds); json = json.Replace("\\r\\n", " "); return(json); }
/// <summary> /// Get relative coordinates /// </summary> /// <param name="settlementID">settlement id</param> /// <param name="azimuth">Azimuth from North direction in decimal degree</param> /// <param name="distance">Distance in kilometers</param> /// <param name="x">x or Longitude in Geo coordinates</param> /// <param name="y">y or Latitude in Geo coordinates</param> /// <returns></returns> public static bool GetRelativeCoordinates(long settlementID, double azimuth, double distance, out double x, out double y) { string connectionString = ConnectionManager.DefaultInstance.ConnectionString; return(CoordinatesUtils.GetRelativeCoordinates(connectionString, settlementID, azimuth, distance * 1000, out x, out y)); }
/// <summary> /// Get coordinates of administrative unit /// </summary> /// <param name="id">Administrative unit ID</param> /// <param name="x">out X</param> /// <param name="y">out Y</param> /// <returns>True if exists</returns> public static bool GetAdminUnitCoordinates(long id, out double x, out double y) { string connectionString = ConnectionManager.DefaultInstance.ConnectionString; return(CoordinatesUtils.GetAdminUnitCoordinates(connectionString, id, out x, out y)); }
/// <summary> /// Get coordinates of the settlement /// </summary> /// <param name="settlementID">settlement id</param> /// <param name="x">x or Longitude in Geo coordinates</param> /// <param name="y">y or Latitude in Geo coordinates</param> /// <param name="z">Elevation</param> /// <returns></returns> public static bool GetSettlementCoordinates(long settlementID, out double x, out double y, out int z) { string connectionString = ConnectionManager.DefaultInstance.ConnectionString; return(CoordinatesUtils.GetSettlementCoordinates(connectionString, settlementID, out x, out y, out z)); }