Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
tentone committed Oct 13, 2024
1 parent 8840927 commit 61bd81e
Show file tree
Hide file tree
Showing 41 changed files with 7,381 additions and 3,573 deletions.
131 changes: 111 additions & 20 deletions build/geo-three.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */


function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand Down Expand Up @@ -168,16 +170,7 @@ class MapNode extends three.Mesh {
}
try {
const image = yield this.mapView.provider.fetchTile(this.level, this.x, this.y);
if (this.disposed) {
return;
}
const texture = new three.Texture(image);
texture.generateMipmaps = false;
texture.format = three.RGBAFormat;
texture.magFilter = three.LinearFilter;
texture.minFilter = three.LinearFilter;
texture.needsUpdate = true;
this.material.map = texture;
yield this.applyTexture(image);
}
catch (e) {
if (this.disposed) {
Expand All @@ -189,6 +182,23 @@ class MapNode extends three.Mesh {
this.material.needsUpdate = true;
});
}
applyTexture(image) {
return __awaiter(this, void 0, void 0, function* () {
if (this.disposed) {
return;
}
const texture = new three.Texture(image);
if (parseInt(three.REVISION) >= 152) {
texture.colorSpace = 'srgb';
}
texture.generateMipmaps = false;
texture.format = three.RGBAFormat;
texture.magFilter = three.LinearFilter;
texture.minFilter = three.LinearFilter;
texture.needsUpdate = true;
this.material.map = texture;
});
}
nodeReady() {
if (this.disposed) {
console.warn('Geo-Three: nodeReady() called for disposed node.', this);
Expand Down Expand Up @@ -391,12 +401,32 @@ class UnitsUtils {
static mapboxAltitude(color) {
return (color.r * 255.0 * 65536.0 + color.g * 255.0 * 256.0 + color.b * 255.0) * 0.1 - 10000.0;
}
static getTileSize(zoom) {
const maxExtent = UnitsUtils.WEB_MERCATOR_MAX_EXTENT;
const numTiles = Math.pow(2, zoom);
return 2 * maxExtent / numTiles;
}
static tileBounds(zoom, x, y) {
const tileSize = UnitsUtils.getTileSize(zoom);
const minX = -UnitsUtils.WEB_MERCATOR_MAX_EXTENT + x * tileSize;
const minY = UnitsUtils.WEB_MERCATOR_MAX_EXTENT - (y + 1) * tileSize;
return [minX, tileSize, minY, tileSize];
}
static webMercatorToLatitude(zoom, y) {
const yMerc = UnitsUtils.WEB_MERCATOR_MAX_EXTENT - y * UnitsUtils.getTileSize(zoom);
return Math.atan(Math.sinh(yMerc / UnitsUtils.EARTH_RADIUS));
}
static webMercatorToLongitude(zoom, x) {
const xMerc = -UnitsUtils.WEB_MERCATOR_MAX_EXTENT + x * UnitsUtils.getTileSize(zoom);
return xMerc / UnitsUtils.EARTH_RADIUS;
}
}
UnitsUtils.EARTH_RADIUS = 6371008;
UnitsUtils.EARTH_RADIUS_A = 6378137.0;
UnitsUtils.EARTH_RADIUS_B = 6356752.314245;
UnitsUtils.EARTH_PERIMETER = 2 * Math.PI * UnitsUtils.EARTH_RADIUS;
UnitsUtils.EARTH_ORIGIN = UnitsUtils.EARTH_PERIMETER / 2.0;
UnitsUtils.WEB_MERCATOR_MAX_EXTENT = 20037508.34;

class MapPlaneNode extends MapNode {
constructor(parentNode = null, mapView = null, location = QuadTreePosition.root, level = 0, x = 0, y = 0) {
Expand Down Expand Up @@ -674,7 +704,48 @@ class MapSphereNodeGeometry extends three.BufferGeometry {

class MapSphereNode extends MapNode {
constructor(parentNode = null, mapView = null, location = QuadTreePosition.root, level = 0, x = 0, y = 0) {
super(parentNode, mapView, location, level, x, y, MapSphereNode.createGeometry(level, x, y), new three.MeshBasicMaterial({ wireframe: false }));
let bounds = UnitsUtils.tileBounds(level, x, y);
const vertexShader = `
varying vec3 vPosition;
void main() {
vPosition = position;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = `
#define PI 3.1415926538
varying vec3 vPosition;
uniform sampler2D uTexture;
uniform vec4 webMercatorBounds;
void main() {
// this could also be a constant, but for some reason using a constant causes more visible tile gaps at high zoom
float radius = length(vPosition);
float latitude = asin(vPosition.y / radius);
float longitude = atan(-vPosition.z, vPosition.x);
float web_mercator_x = radius * longitude;
float web_mercator_y = radius * log(tan(PI / 4.0 + latitude / 2.0));
float y = (web_mercator_y - webMercatorBounds.z) / webMercatorBounds.w;
float x = (web_mercator_x - webMercatorBounds.x) / webMercatorBounds.y;
vec4 color = texture2D(uTexture, vec2(x, y));
gl_FragColor = color;
${parseInt(three.REVISION) < 152 ? '' : `
#include <tonemapping_fragment>
#include ${parseInt(three.REVISION) >= 154 ? '<colorspace_fragment>' : '<encodings_fragment>'}
`}
}
`;
let vBounds = new three.Vector4(...bounds);
const material = new three.ShaderMaterial({
uniforms: { uTexture: { value: new three.Texture() }, webMercatorBounds: { value: vBounds } },
vertexShader: vertexShader,
fragmentShader: fragmentShader
});
super(parentNode, mapView, location, level, x, y, MapSphereNode.createGeometry(level, x, y), material);
this.applyScaleNode();
this.matrixAutoUpdate = false;
this.isMesh = true;
Expand All @@ -694,12 +765,28 @@ class MapSphereNode extends MapNode {
const range = Math.pow(2, zoom);
const max = 40;
const segments = Math.floor(MapSphereNode.segments * (max / (zoom + 1)) / max);
const phiLength = 1 / range * 2 * Math.PI;
const phiStart = x * phiLength;
const thetaLength = 1 / range * Math.PI;
const thetaStart = y * thetaLength;
const lon1 = x > 0 ? UnitsUtils.webMercatorToLongitude(zoom, x) + Math.PI : 0;
const lon2 = x < range - 1 ? UnitsUtils.webMercatorToLongitude(zoom, x + 1) + Math.PI : 2 * Math.PI;
const phiStart = lon1;
const phiLength = lon2 - lon1;
const lat1 = y > 0 ? UnitsUtils.webMercatorToLatitude(zoom, y) : Math.PI / 2;
const lat2 = y < range - 1 ? UnitsUtils.webMercatorToLatitude(zoom, y + 1) : -Math.PI / 2;
const thetaLength = lat1 - lat2;
const thetaStart = Math.PI - (lat1 + Math.PI / 2);
return new MapSphereNodeGeometry(1, segments, segments, phiStart, phiLength, thetaStart, thetaLength);
}
applyTexture(image) {
return __awaiter(this, void 0, void 0, function* () {
const textureLoader = new three.TextureLoader();
const texture = textureLoader.load(image.src, function () {
if (parseInt(three.REVISION) >= 152) {
texture.colorSpace = 'srgb';
}
});
this.material.uniforms.uTexture.value = texture;
this.material.uniforms.uTexture.needsUpdate = true;
});
}
applyScaleNode() {
this.geometry.computeBoundingBox();
const box = this.geometry.boundingBox.clone();
Expand Down Expand Up @@ -854,7 +941,11 @@ class LODRaycast {
for (let t = 0; t < this.subdivisionRays; t++) {
this.mouse.set(Math.random() * 2 - 1, Math.random() * 2 - 1);
this.raycaster.setFromCamera(this.mouse, camera);
this.raycaster.intersectObjects(view.children, true, intersects);
let myIntersects = [];
this.raycaster.intersectObjects(view.children, true, myIntersects);
if (myIntersects.length > 0) {
intersects.push(myIntersects[0]);
}
}
for (let i = 0; i < intersects.length; i++) {
const node = intersects[i].object;
Expand Down Expand Up @@ -1305,7 +1396,7 @@ MapMartiniHeightNode.tileSize = 256;

class MapView extends three.Mesh {
constructor(root = MapView.PLANAR, provider = new OpenStreetMapsProvider(), heightProvider = null) {
super(undefined, new three.MeshBasicMaterial({ transparent: true, opacity: 0.0 }));
super(undefined, new three.MeshBasicMaterial({ transparent: true, opacity: 0.0, depthWrite: false, colorWrite: false }));
this.lod = null;
this.provider = null;
this.heightProvider = null;
Expand Down Expand Up @@ -1592,7 +1683,7 @@ class GoogleMapsProvider extends MapProvider {
this.createSession();
}
createSession() {
const address = 'https://www.googleapis.com/tile/v1/createSession?key=' + this.apiToken;
const address = 'https://tile.googleapis.com/v1/createSession?key=' + this.apiToken;
const data = JSON.stringify({
mapType: this.mapType,
language: 'en-EN',
Expand All @@ -1601,7 +1692,7 @@ class GoogleMapsProvider extends MapProvider {
overlay: this.overlay,
scale: 'scaleFactor1x'
});
XHRUtils.request(address, 'GET', { 'Content-Type': 'text/json' }, data, (response, xhr) => {
XHRUtils.request(address, 'POST', { 'Content-Type': 'text/json' }, data, (response, xhr) => {
this.sessionToken = response.session;
}, function (xhr) {
throw new Error('Unable to create a google maps session.');
Expand All @@ -1617,7 +1708,7 @@ class GoogleMapsProvider extends MapProvider {
reject();
};
image.crossOrigin = 'Anonymous';
image.src = 'https://www.googleapis.com/tile/v1/tiles/' + zoom + '/' + x + '/' + y + '?session=' + this.sessionToken + '&orientation=' + this.orientation + '&key=' + this.apiToken;
image.src = 'https://tile.googleapis.com/v1/2dtiles/' + zoom + '/' + x + '/' + y + '?session=' + this.sessionToken + '&orientation=' + this.orientation + '&key=' + this.apiToken;
});
}
}
Expand Down
Loading

0 comments on commit 61bd81e

Please sign in to comment.