Skip to content

Commit 795c84a

Browse files
committed
Projection touch ups
1 parent 8c1ce09 commit 795c84a

File tree

10 files changed

+2320
-72
lines changed

10 files changed

+2320
-72
lines changed

dist/lithosphere.js

Lines changed: 2203 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/core/CRS.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export default class CRS {
55
_scales: number[];
66
R: number;
77
constructor(code: string, proj: string, options: any, radius: number);
8-
project(latlng: any): any;
9-
unproject(point: any, zoom: any): any;
8+
project(latlng: any, zoom: any, ll2p: any): any;
9+
unproject(point: any, zoom: any, p2ll: any): any;
10+
latLngToPoint(latlng: any, zoom: any): any;
1011
pointToLatLng(point: any, zoom: any): any;
1112
scale(zoom: number): number;
1213
}

examples/example.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
lat: -4.626971631163808,
4141
zoom: 16,
4242
},
43+
majorRadius: 3396190,
4344
loadingScreen: true, // default true
4445
customParsers: {
4546
All500: (tilePath, layerObj) => {

examples/exampleProj.html

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>LithoSphere Demo</title>
7+
8+
<script src="../dist/lithosphere.js"></script>
9+
<style>
10+
html,
11+
body {
12+
width: 100%;
13+
height: 100%;
14+
margin: 0;
15+
background: black;
16+
}
17+
#container {
18+
width: 100%;
19+
height: 100%;
20+
overflow: hidden;
21+
}
22+
#myCustomCoordDiv {
23+
position: absolute;
24+
top: 10px;
25+
left: 50%;
26+
transform: translateX(-50%);
27+
background: white;
28+
color: black;
29+
padding: 2px 4px;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
<div id="container"></div>
35+
<!--<div id="myCustomCoordDiv"></div>-->
36+
<script>
37+
const Litho = new LithoSphere.default('container', {
38+
initialView: {
39+
lng: 0, // default 0
40+
lat: -89.9,
41+
zoom: 0,
42+
},
43+
majorRadius: 1737400,
44+
tileMapResource: {
45+
// minx, miny, maxx, maxy
46+
bounds: [-1095700 - 1095600, 1095600, 1095700],
47+
origin: [-1095700, -1095600],
48+
crsCode: 'IAU2000:30166,0,-89.9',
49+
proj:
50+
'+proj=stere +lat_0=-89.9 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs', // proj4 string describing the global tileset projection: string (opt) | default wgs84
51+
resunitsperpixel: 128000,
52+
reszoomlevel: 0,
53+
},
54+
//radiusOfTiles: 3,
55+
useLOD: false,
56+
//wireframeMode: true,
57+
starsphere: {
58+
url:
59+
'https://miplmmgis.jpl.nasa.gov/public/images/eso0932a.jpg',
60+
color: '#444444',
61+
},
62+
atmosphere: {
63+
color: '#222227',
64+
},
65+
})
66+
67+
console.log(Litho)
68+
69+
Litho.addLayer('tile', {
70+
name: 'Mars',
71+
order: 1, //Orders are ordered only within the layer type
72+
on: true,
73+
path:
74+
'http://localhost:8889/Missions/Projections/Layers/Basemap/MarsDEM/LRO_WAC_Mosaic_SPole60_100m_v2/{z}/{x}/{y}.png',
75+
demPath: null,
76+
format: 'tms', // 'wmts' || 'wms' // wms requires a tileMapResource to be set to help compute tile bboxes
77+
formatOptions: {},
78+
demFormat: 'tms', //
79+
demFormatOptions: {},
80+
opacity: 1,
81+
minZoom: 0,
82+
maxZoom: 10,
83+
})
84+
85+
Litho.addControl('myLayers', Litho.controls.layers)
86+
Litho.addControl('myCompass', Litho.controls.compass)
87+
Litho.addControl('myCoords', Litho.controls.coordinates)
88+
</script>
89+
</body>
90+
</html>

examples/exampleWMS.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@
4141
zoom: 0,
4242
},
4343
majorRadius: 1737400,
44-
customParsers: {
45-
All500: (tilePath, layerObj) => {
46-
return new Promise((resolve, reject) => {
47-
const tileDimension = 32
48-
resolve(
49-
new Array(tileDimension * tileDimension).fill(
50-
500
51-
)
52-
)
53-
})
54-
},
55-
},
56-
//opt
5744
tileMapResource: {
5845
//bounds: [-868700, -868700, 868700, 868700],
5946
//origin: [-868700, -868700],

examples/exampleWMSPolar.html

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,10 @@
3838
initialView: {
3939
lng: 0, // default 0
4040
lat: -89.9,
41-
zoom: 0,
41+
zoom: 2,
4242
},
4343
majorRadius: 1737400,
44-
customParsers: {
45-
All500: (tilePath, layerObj) => {
46-
return new Promise((resolve, reject) => {
47-
const tileDimension = 32
48-
resolve(
49-
new Array(tileDimension * tileDimension).fill(
50-
500
51-
)
52-
)
53-
})
54-
},
55-
},
56-
//opt
5744
tileMapResource: {
58-
//bounds: [-868700, -868700, 868700, 868700],
59-
//origin: [-868700, -868700],
6045
bounds: [-1737400, -1737400, 1737400, 1737400],
6146
origin: [-1737400, 1737400],
6247
crsCode: 'IAU2000:30166,-89.9,0',

examples/exampleWMSwithDEM.html

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,15 @@
4141
zoom: 14,
4242
},
4343
majorRadius: 1737400,
44-
customParsers: {
45-
All500: (tilePath, layerObj) => {
46-
return new Promise((resolve, reject) => {
47-
const tileDimension = 32
48-
resolve(
49-
new Array(tileDimension * tileDimension).fill(
50-
500
51-
)
52-
)
53-
})
54-
},
55-
},
5644
//tileResolution: 3, // Good for debugging
57-
//opt
5845
tileMapResource: {
59-
//bounds: [-868700, -868700, 868700, 868700],
60-
//origin: [-868700, -868700],
6146
bounds: [-1737400, -1737400, 1737400, 1737400],
6247
origin: [-1737400, 1737400],
6348
crsCode: 'IAU2000:30166,31.1492746341015,-85.391176037601',
6449
proj:
6550
'+proj=stere +lat_0=-85.391176037601 +lon_0=31.1492746341015 +k=1 +x_0=0 +y_0=0 +a=1737400 +b=1737400 +units=m +no_defs', // proj4 string describing the global tileset projection: string (opt) | default wgs84
6651
resunitsperpixel: 8192,
67-
reszoomlevel: 3,
52+
reszoomlevel: 0,
6853
},
6954
//radiusOfTiles: 3,
7055
//useLOD: false,

src/core/crs.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ export default class CRS {
4141
}
4242
}
4343

44-
project(latlng) {
44+
project(latlng, zoom, ll2p) {
4545
return this.projection.project(latlng)
4646
}
4747

48-
unproject(point, zoom) {
48+
unproject(point, zoom, p2ll) {
4949
return this.projection.unproject(point)
5050
}
5151

52+
latLngToPoint(latlng, zoom) {
53+
const projectedPoint = this.projection.project(latlng)
54+
const scale = this.scale(zoom)
55+
56+
return this.transformation._transform(projectedPoint, scale)
57+
}
58+
5259
pointToLatLng(point, zoom) {
5360
const scale = this.scale(zoom)
5461
const untransformedPoint = this.transformation.untransform(point, scale)

src/core/projection.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ export default class Projection {
5656
this.tileMapResource.resunitsperpixel != null &&
5757
this.tileMapResource.reszoomlevel != null
5858
) {
59+
let reszoomlevel = this.tileMapResource.reszoomlevel
60+
reszoomlevel += Math.round(
61+
(4 * Math.PI * Math.pow(3396190, 2)) /
62+
(4 * Math.PI * Math.pow(this.radii.major, 2))
63+
)
5964
const baseRes =
6065
this.tileMapResource.resunitsperpixel *
61-
Math.pow(2, this.tileMapResource.reszoomlevel)
66+
Math.pow(2, reszoomlevel)
6267
const res = []
6368
for (let i = 0; i < 32; i++) {
6469
res.push(baseRes / Math.pow(2, i))
@@ -178,18 +183,7 @@ export default class Projection {
178183
(180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
179184
return { lat: lat, lng: lng }
180185
} else {
181-
//In these projections the origin is bottom left instead of top left
182-
//So flip the decimal value
183-
/*
184-
const dec = y % 1
185-
if (dec != 0) y = Math.floor(y) + (1 - dec)
186-
else if (flatXYZ) {
187-
if (y == flatXYZ.y) y = flatXYZ.y + 1
188-
else y = flatXYZ.y
189-
}
190-
*/
191-
192-
y = -y // For WMS
186+
y = -y
193187

194188
const easting =
195189
this.trueTileResolution * x * this.res[z] +
@@ -238,10 +232,8 @@ export default class Projection {
238232
(northing - this.tileMapResource.origin[1]) /
239233
(this.trueTileResolution * this.res[z])
240234

241-
//In these projections the origin is bottom left instead of top left
242-
//So flip the decimal value back
243-
//y = Math.floor(y) + (1 - (y % 1))
244-
y = -y // For WMS
235+
y = -y
236+
245237
return { x: x, y: y, z: z }
246238
}
247239
}

src/core/tiledWorld.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,6 @@ export default class TiledWorld {
923923

924924
removeTile(i: number, shouldFadeOut?: boolean): void {
925925
if (this.tilesDrawn[i]) {
926-
// [false] shouldFadeOut works but for some reason the center tiles blacken
927-
// briefly after everything loads. So off for now
928926
if (shouldFadeOut) {
929927
this.tilesDrawn[i].fadeOutAndRemove = true
930928
// Note that we aren't removing it for tilesDrawn just yet
@@ -1023,7 +1021,7 @@ export default class TiledWorld {
10231021
].value = Math.min(
10241022
this.tilesDrawn[m].t.material.uniforms[
10251023
'tA' + n
1026-
].value + 0.07,
1024+
].value + 0.1,
10271025
desiredOpacity
10281026
)
10291027
} else {
@@ -1032,7 +1030,7 @@ export default class TiledWorld {
10321030
].value = Math.max(
10331031
this.tilesDrawn[m].t.material.uniforms[
10341032
'tA' + n
1035-
].value - 0.07,
1033+
].value - 0.1,
10361034
desiredOpacity
10371035
)
10381036
}
@@ -1062,7 +1060,7 @@ export default class TiledWorld {
10621060
) {
10631061
const nextOpacity = Math.max(
10641062
this.tilesDrawn[i].t.material.uniforms['tA' + n]
1065-
.value - 0.07,
1063+
.value - 0.1,
10661064
0
10671065
)
10681066
if (nextOpacity <= 0) this.removeTile(i)

0 commit comments

Comments
 (0)