php矢量瓦片,矢量瓦片相关计算函数
import turf from 'turf'
export default {
TILE_SIZE: 256,
/*
* 獲取指定級別的瓦片數目
*/
_getMapSize(level) {
return Math.pow(2, level);
},
/**
* Convert a longitude coordinate (in degrees) to the tile X number at a
* certain zoom level.經度轉瓦片列號
* @param longitude
* the longitude coordinate that should be converted.
* @param zoom
* the zoom level at which the coordinate should be converted.
* @return the tile X number of the longitude value.
*/
longitudeToTileX(longitude, zoom) {
let px = this.longitudeToPixelX(longitude, zoom);
return this.pixelXToTileX(px, zoom);
},
/**
* Convert a latitude coordinate (in degrees) to a tile Y number at a
* certain zoom level.緯度轉瓦片行號
* @param latitude
* the latitude coordinate that should be converted.
* @param zoom
* the zoom level at which the coordinate should be converted.
* @return the tile Y number of the latitude value.
*/
latitudeToTileY(latitude, zoom) {
let py = this.latitudeToPixelY(latitude, zoom);
return this.pixelYToTileY(py, zoom);
},
/**
* Convert a latitude coordinate (in degrees) to a pixel Y coordinate at a
* certain zoom level.經緯度坐標(緯度)轉屏幕像素坐標(Y)
*
* @param latitude
* the latitude coordinate that should be converted.
* @param zoom
* the zoom level at which the coordinate should be converted.
* @return the pixel Y coordinate of the latitude value.
*/
latitudeToPixelY(latitude, zoom) {
let sinLatitude = Math.sin(latitude * Math.PI / 180);
return (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * (this.TILE_SIZE << zoom);
},
/**
* Convert a longitude coordinate (in degrees) to a pixel X coordinate at a
* certain zoom level.經緯度坐標(經度)轉屏幕像素坐標(X)
*
* @param longitude
* the longitude coordinate that should be converted.
* @param zoom
* the zoom level at which the coordinate should be converted.
* @return the pixel X coordinate of the longitude value.
*/
longitudeToPixelX(longitude, zoom) {
return (longitude + 180) / 360 * (this.TILE_SIZE << zoom);
},
/*
* 指定級別下,將宏觀上的經度轉換為對應列上的瓦片的像素矩陣列號(微觀)
例如:鼠標點擊地圖,鼠標位置在點擊的瓦片內的行列號(即使像素行列號)。根據該瓦片(png)和計算出的行列號,即可取得鼠標點擊位置的像素值。
*/
_lngToPixelX(longitude, level) {
let x = (longitude + 180) / 360;
let pixelX = Math.floor(x * this._getMapSize(level) * 256 % 256);
return pixelX;
},
/*
* 指定級別緯度對應的像素行號
*/
_latToPixelY(latitude, level) {
let sinLatitude = Math.sin(latitude * Math.PI / 180);
let y = 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
let pixelY = Math.floor(y * this._getMapSize(level) * 256 % 256);
return pixelY;
},
/**
* Convert a pixel X coordinate to the tile X number.
* 像素坐標X轉瓦片行列號X
* @param pixelX
* the pixel X coordinate that should be converted.
* @param zoom
* the zoom level at which the coordinate should be converted.
* @return the tile X number.
*/
pixelXToTileX(pixelX, zoom) {
return Math.floor(Math.min(Math.max(pixelX / this.TILE_SIZE, 0), Math.pow(2, zoom) - 1));
},
/**
* Converts a pixel Y coordinate to the tile Y number.
* 像素坐標Y轉瓦片行列號Y
* @param pixelY
* the pixel Y coordinate that should be converted.
* @param zoom
* the zoom level at which the coordinate should be converted.
* @return the tile Y number.
*/
pixelYToTileY(pixelY, zoom) {
return Math.floor(Math.min(Math.max(pixelY / this.TILE_SIZE, 0), Math.pow(2, zoom) - 1));
},
}
總結
以上是生活随笔為你收集整理的php矢量瓦片,矢量瓦片相关计算函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自动切换电脑或手机版(php aspx)
- 下一篇: 魅族老板朋友圈晒魅族20真机 背面“纽扣