forked from WorldWindLabs/Quake-Hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.js
72 lines (61 loc) · 2.71 KB
/
Rectangle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
define([''], function(ww) {
"use strict";
var Rectangle = function (p1, p2, highlightActive, wraping) {
var minLong = Math.min(p2.Long, p1.Long);
var maxLong = Math.max(p2.Long, p1.Long);
var minLati = Math.min(p2.Lati, p1.Lati);
var maxLati = Math.max(p2.Lati, p1.Lati);
var boundaries = [];
boundaries[0] = [];
var step = 5, i;
var pointsLati = Math.floor((maxLati - minLati)/step);
var pointsLong = Math.floor((maxLong - minLong)/step);
boundaries[0].push(new WorldWind.Position(minLati, minLong, 0));
if (wraping) {
for (i = 1; i <= pointsLati; i++) {
boundaries[0].push(new WorldWind.Position(minLati+step*i, minLong, 0));
}
}
boundaries[0].push(new WorldWind.Position(maxLati, minLong, 0));
if (wraping) {
for (i = 1; i <= pointsLong; i++) {
boundaries[0].push(new WorldWind.Position(maxLati, minLong + step * i, 0));
}
}
boundaries[0].push(new WorldWind.Position(maxLati, maxLong, 0));
if (wraping) {
for (i = 1; i <= pointsLati; i++) {
boundaries[0].push(new WorldWind.Position(maxLati - step * i, maxLong, 0));
}
}
boundaries[0].push(new WorldWind.Position(minLati, maxLong, 0));
if (wraping) {
for (i = 1; i <= pointsLong; i++) {
boundaries[0].push(new WorldWind.Position(minLati, maxLong - step * i, 0));
}
}
// Create the polygon and assign its attributes.
var polygon = new WorldWind.Polygon(boundaries, null);
polygon.altitudeMode = WorldWind.ABSOLUTE;
polygon.extrude = true;
polygon.textureCoordinates = [
[new WorldWind.Vec2(0, 0), new WorldWind.Vec2(1, 0), new WorldWind.Vec2(1, 1), new WorldWind.Vec2(0, 1)]
];
var polygonAttributes = new WorldWind.ShapeAttributes(null);
// Specify a texture for the polygon and its four extruded sides.
polygonAttributes.drawInterior = false;
polygonAttributes.drawOutline = true;
polygonAttributes.outlineColor = WorldWind.Color.BLUE;
polygonAttributes.interiorColor = WorldWind.Color.WHITE;
polygonAttributes.drawVerticals = polygon.extrude;
polygonAttributes.applyLighting = true;
polygon.attributes = polygonAttributes;
if (highlightActive) {
var highlightAttributes = new WorldWind.ShapeAttributes(polygonAttributes);
highlightAttributes.outlineColor = WorldWind.Color.RED;
polygon.highlightAttributes = highlightAttributes;
}
return polygon;
};
return Rectangle;
});