mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
BingTileController
This commit is contained in:
parent
fa86c46f43
commit
87feda3fba
1
.gitignore
vendored
1
.gitignore
vendored
@ -94,3 +94,4 @@ typings/
|
||||
/ShadowEditor.Web/test/unit/build
|
||||
/ShadowEditor.Web/temp
|
||||
/ShadowEditor.Web/src/gis2/build
|
||||
/ShadowEditor.Web/Upload/Tiles
|
||||
|
||||
@ -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
|
||||
/// </summary>
|
||||
public class BingTileController : ApiBase
|
||||
{
|
||||
private static readonly string rootPath;
|
||||
|
||||
static BingTileController()
|
||||
{
|
||||
rootPath = HttpContext.Current.Server.MapPath("~/Upload/Tiles/Bing");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取必应瓦片
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="z"></param>
|
||||
[HttpPost]
|
||||
public void Get(int x, int y, int z)
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载底图
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="z"></param>
|
||||
/// <param name="savePath"></param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TileXY转QuadKey
|
||||
/// </summary>
|
||||
/// <param name="tileX"></param>
|
||||
/// <param name="tileY"></param>
|
||||
/// <param name="levelOfDetail"></param>
|
||||
/// <returns></returns>
|
||||
/// <see cref="https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system"/>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -596,6 +596,7 @@
|
||||
<Folder Include="Upload\File\" />
|
||||
<Folder Include="Upload\Model\" />
|
||||
<Folder Include="Upload\Texture\" />
|
||||
<Folder Include="Upload\Tiles\" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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];
|
||||
};
|
||||
}();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user