Skip to content

Commit 98765da

Browse files
authored
Merge branch 'main' into Additional-tests
2 parents 70fc546 + c07bc96 commit 98765da

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ OSM Building Viewer
66

77
### Visualize an OSM Building in 3D
88

9-
Visualize an OSM Building from the live OSM data.
109
To visualize a building tagged with a way, use the URL:
11-
https://beakerboy.github.io/OSMBuilding/index.html?id=[id]
10+
https://beakerboy.github.io/OSMBuilding?id=[id]
1211

1312
If the building is a multipolygon, or a relation, use:
14-
https://beakerboy.github.io/OSMBuilding/index.html?type=relation&id=[id]
13+
https://beakerboy.github.io/OSMBuilding?type=relation&id=[id]
1514

1615
...replacing [id] with the actual id of the way or relation.
1716

18-
Additional details will be displayed if "&info" is appended to the URL.
17+
Additional details will be displayed if `&info` is appended to the URL.
1918

20-
Console debug messages can be printed to the screen if "&errorBox" is appended to the url. Helpful since mobile browsers often lack any inspection capability.
19+
Console debug messages can be printed to the screen if `&errorBox` is appended to the url. Helpful since mobile browsers often lack any inspection capability.
2120

21+
Use the left mouse button to rotate the camera. To move, use the right one.
2222

2323
Supports:
2424
* Ways with a building tag
2525
* Ways with building parts inside.
2626
* Building relations with way and/or multipolygon parts
27-
* Mulipolygon buildings
27+
* Multipolygon buildings
2828
* Multipolygon building with multiple open ways which combine to a closed way.
2929

3030
Roof Types:
@@ -43,3 +43,7 @@ Examples:
4343
* Building Relation [Burj Khalifa](https://beakerboy.github.io/OSMBuilding/index.html?type=relation&id=7584462)
4444
* Multipolygon with no parts - [Freer Art Gallery](https://beakerboy.github.io/OSMBuilding/index.html?type=relation&id=1029355)
4545
* Relation with multipolygon parts - [Leaning Tower of Pisa](https://beakerboy.github.io/OSMBuilding/index.html?type=relation&id=12982338)
46+
47+
Specify the `osmApiUrl` parameter to use other OSM APIs. Examples:
48+
* [OpenHistoricalMap](https://beakerboy.github.io/OSMBuilding/?id=2826540&osmApiUrl=https://api.openhistoricalmap.org/api/0.6&type=relation)
49+
* [OpenGeofiction](https://beakerboy.github.io/OSMBuilding/?id=461819&osmApiUrl=https://opengeofiction.net/api/0.6&type=relation)

src/extras/BuildingShapeUtils.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ class BuildingShapeUtils extends ShapeUtils {
402402
p1 = points[i];
403403
p2 = points[i + 1];
404404
let angle = Math.atan2((p2.y - p1.y), (p2.x - p1.x));
405-
if (angle >= Math.PI / 2) {
406-
angle -= Math.PI;
407-
} else if (angle < -Math.PI / 2) {
408-
angle += Math.PI;
405+
if (angle >= Math.PI) {
406+
angle -= 2 * Math.PI;
407+
} else if (angle < -Math.PI) {
408+
angle += 2* Math.PI;
409409
}
410410
angles.push(angle);
411411
}
@@ -455,14 +455,12 @@ class BuildingShapeUtils extends ShapeUtils {
455455
}
456456

457457
/**
458-
* Calculate the angle of the longest side of a shape with 90° vertices.
459-
* is begining / end duplicated?
458+
* Return the angle of the longest side of a shape with 90° vertices.
460459
*
461460
* @param {THREE.Shape} shape - the shape
462461
* @return {number}
463462
*/
464463
static longestSideAngle(shape) {
465-
const vecs = shape.extractPoints().shape;
466464
const lengths = BuildingShapeUtils.edgeLength(shape);
467465
const directions = BuildingShapeUtils.edgeDirection(shape);
468466
var index;

test/utils.test.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ rightTriangle.moveTo(1, 1);
5252
rightTriangle.lineTo(1, -1);
5353
rightTriangle.lineTo(-1, 1);
5454

55+
const rightTriangle2 = new Shape();
56+
rightTriangle2.moveTo(1, 1);
57+
rightTriangle2.lineTo(-1, 1);
58+
rightTriangle2.lineTo(1, -1);
59+
5560
test('Extents no Rotation', () => {
5661
expect(BuildingShapeUtils.extents(rightTriangle)).toStrictEqual([-1, -1, 1, 1]);
5762
});
@@ -67,13 +72,15 @@ test('Edge Lengths', () => {
6772
});
6873

6974
test('Edge Direction', () => {
70-
expect(BuildingShapeUtils.edgeDirection(rightTriangle)).toBeDeepCloseTo([-Math.PI / 2, -Math.PI / 4, 0]);
75+
expect(BuildingShapeUtils.edgeDirection(rightTriangle)).toBeDeepCloseTo([-Math.PI / 2, 3 * Math.PI / 4, 0]);
76+
});
77+
78+
test('Edge Direction2', () => {
79+
expect(BuildingShapeUtils.edgeDirection(rightTriangle2)).toBeDeepCloseTo([-Math.PI, -Math.PI / 4, Math.PI / 2]);
7180
});
7281

7382
test('Longest side angle', () => {
74-
// A three.Shape object does not repeat the fist and last nodes.
75-
expect(rightTriangle.extractPoints().shape.length).toBe(3);
76-
expect(BuildingShapeUtils.longestSideAngle(rightTriangle)).toBe(-Math.PI / 4);
83+
expect(BuildingShapeUtils.longestSideAngle(rightTriangle)).toBe(3 * Math.PI / 4);
7784
});
7885

7986
describe.each([
@@ -101,10 +108,6 @@ test('Vertex Angles', () => {
101108
expect(BuildingShapeUtils.vertexAngle(rightTriangle)).toStrictEqual([Math.PI / 2, Math.PI / 4, Math.PI / 4]);
102109
});
103110

104-
const rightTriangle2 = new Shape();
105-
rightTriangle2.moveTo(1, 1);
106-
rightTriangle2.lineTo(-1, 1);
107-
rightTriangle2.lineTo(1, -1);
108111
test('Vertex Angles counterclockwise', () => {
109112
expect(BuildingShapeUtils.vertexAngle(rightTriangle2)).toStrictEqual([-Math.PI / 2, -Math.PI / 4, -Math.PI / 4]);
110113
});

0 commit comments

Comments
 (0)