diff --git a/.gitignore b/.gitignore index 6bd3840d..542f92cf 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,4 @@ typings/ /ShadowEditor.Web/test/unit/build /ShadowEditor.Web/temp /ShadowEditor.Web/src/gis2/build +/ShadowEditor.Web/Upload/Tiles diff --git a/ShadowEditor.Server/Controllers/Tile/BingTileController.cs b/ShadowEditor.Server/Controllers/Tile/BingTileController.cs index 28d7b63b..c81c5402 100644 --- a/ShadowEditor.Server/Controllers/Tile/BingTileController.cs +++ b/ShadowEditor.Server/Controllers/Tile/BingTileController.cs @@ -4,14 +4,12 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; using System.Web; using System.Web.Http; using System.Web.Http.Results; -using MongoDB.Bson; -using MongoDB.Driver; -using Newtonsoft.Json.Linq; using ShadowEditor.Server.Base; -using ShadowEditor.Server.Helpers; namespace ShadowEditor.Server.Controllers.Tile { @@ -20,16 +18,113 @@ namespace ShadowEditor.Server.Controllers.Tile /// public class BingTileController : ApiBase { + private static readonly string rootPath; + + static BingTileController() + { + rootPath = HttpContext.Current.Server.MapPath("~/Upload/Tiles/Bing"); + } + /// /// 获取必应瓦片 /// /// /// /// - [HttpPost] - public void Get(int x, int y, int z) + /// + [HttpGet] + public HttpResponseMessage Get(int x, int y, int z) { + var path = $"{rootPath}\\{z}\\{y}\\{x}.jpg"; + if (!File.Exists(path)) + { + DownloadTile(x, y, z, path); + } + + var bytes = File.ReadAllBytes(path); + + var msg = new HttpResponseMessage + { + StatusCode = HttpStatusCode.OK, + Content = new ByteArrayContent(bytes) + }; + + msg.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); + + return msg; + } + + /// + /// 下载底图 + /// + /// + /// + /// + /// + private void DownloadTile(int x, int y, int z, string savePath) + { + var dir = Path.GetDirectoryName(savePath); + + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + var quadKey = TileXYToQuadKey(x, y, z); + var url = $"http://t0.ssl.ak.tiles.virtualearth.net/tiles/a{quadKey}.jpeg?g=5793"; + + var request = (HttpWebRequest)HttpWebRequest.Create(url); + request.Referer = "https://cn.bing.com/maps"; + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"; + var response = (HttpWebResponse)request.GetResponse(); + var stream = response.GetResponseStream(); + + var file = new FileStream(savePath, FileMode.Create, FileAccess.Write); + + var buffer = new byte[1000]; + var bytesRead = 0; + + while ((bytesRead = stream.Read(buffer, 0, 1000)) > 0) + { + file.Write(buffer, 0, bytesRead); + } + + file.Close(); + + stream.Close(); + } + + /// + /// TileXY转QuadKey + /// + /// + /// + /// + /// + /// + private string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail) + { + var quadKey = new StringBuilder(); + char digit; + int mask; + + for (var i = levelOfDetail; i > 0; i--) + { + digit = '0'; + mask = 1 << (i - 1); + if ((tileX & mask) != 0) + { + digit++; + } + if ((tileY & mask) != 0) + { + digit++; + digit++; + } + quadKey.Append(digit); + } + return quadKey.ToString(); } } } diff --git a/ShadowEditor.Web/ShadowEditor.Web.csproj b/ShadowEditor.Web/ShadowEditor.Web.csproj index e904db5b..cab23452 100644 --- a/ShadowEditor.Web/ShadowEditor.Web.csproj +++ b/ShadowEditor.Web/ShadowEditor.Web.csproj @@ -596,6 +596,7 @@ + 10.0 diff --git a/ShadowEditor.Web/src/Options.js b/ShadowEditor.Web/src/Options.js index 3a2438ac..2e1e010f 100644 --- a/ShadowEditor.Web/src/Options.js +++ b/ShadowEditor.Web/src/Options.js @@ -24,6 +24,9 @@ function Options(options = {}) { this.grayscale = 0; this.invert = 0; this.sepia = 0; + + // GIS配置 + this.proxy = options.proxy || false; } export default Options; \ No newline at end of file diff --git a/ShadowEditor.Web/src/gis/render/TiledLayerRenderer.js b/ShadowEditor.Web/src/gis/render/TiledLayerRenderer.js index e5a2ea62..19fc3bbd 100644 --- a/ShadowEditor.Web/src/gis/render/TiledLayerRenderer.js +++ b/ShadowEditor.Web/src/gis/render/TiledLayerRenderer.js @@ -18,9 +18,8 @@ function TiledLayerRenderer(globe) { var geometry = new TiledGeometry(); this.mesh = new THREE.Mesh(geometry, []); - this.mesh.rotation.x = -Math.PI / 2; - this.mesh.frustumCulled = false; - this.mesh.updateMatrix(); + this.mesh.matrix.copy(this.globe.matrix); + this.mesh.matrixAutoUpdate = false; this.gl = this.renderer.context; this.program = null; diff --git a/ShadowEditor.Web/src/gis/tile/Tile.js b/ShadowEditor.Web/src/gis/tile/Tile.js index 8b44172f..a6752128 100644 --- a/ShadowEditor.Web/src/gis/tile/Tile.js +++ b/ShadowEditor.Web/src/gis/tile/Tile.js @@ -1,6 +1,9 @@ import WGS84 from '../core/WGS84'; import MathUtils from '../utils/MathUtils'; +var mat4 = new THREE.Matrix4(); +mat4.makeRotationX(-Math.PI / 2); + /** * 瓦片 * @author tengge / https://github.com/tengge1 @@ -62,6 +65,12 @@ Tile.prototype._getVertices = function () { var p3 = MathUtils._lonlatToXYZ(lonlat.set(aabb.max.x, aabb.max.y, 0)); // 右上 var p4 = MathUtils._lonlatToXYZ(lonlat.set(aabb.min.x, aabb.max.y, 0)); // 左上 + // p0.applyMatrix4(mat4); + // p1.applyMatrix4(mat4); + // p2.applyMatrix4(mat4); + // p3.applyMatrix4(mat4); + // p4.applyMatrix4(mat4); + return [p0, p1, p2, p3, p4]; }; }();