-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathEQPlacemark.js
153 lines (126 loc) · 6.08 KB
/
EQPlacemark.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Created by gagaus on 7/29/16.
*/
define(['./worldwind.min'],
function(WorldWind) {
"use strict";
function EQPlacemark(coordinates, coloring, magnitude, time, query) {
var longitude = coordinates[0],
latitude = coordinates[1],
depth = coordinates[2];
var placemark, highlightAttributes,
placemarkAttributes = new WorldWind.PlacemarkAttributes(null);
var green = ('rgb(0, 255, 0)'),
yellow = ('rgb(255, 255, 0)'),
orange = ('rgb(255, 165, 0)'),
red = ('rgb(255, 0, 0)'),
white = ('rgb(255, 255, 255)');
function getColor() {
var color = {};
if (coloring == 'magnitude') {
if (0 < magnitude && magnitude <= 3) {
color.code = green;
color.name = "green";
} else if (3 < magnitude && magnitude <= 5) {
color.code = yellow;
color.name = "yellow";
} else if (5 < magnitude && magnitude<= 7) {
color.code = orange;
color.name = "orange";
} else if (7 < magnitude && magnitude <= 10) {
color.code = red;
color.name = "red";
} else {
color.code = white;
color.name = "white";
}
}
else if (coloring == 'time') {
var toDate = new Date(query.ToDate);
var fromDate = new Date(query.FromDate);
var deltaT = toDate - time;
var percentInterval = 100*deltaT/(toDate - fromDate);
if (0 < percentInterval && percentInterval <= 10) {
color.code = red;
color.name = "red";
} else if (10 < percentInterval && percentInterval <= 30) {
color.code = orange;
color.name = "orange";
} else if (30 < percentInterval && percentInterval <= 60) {
color.code = yellow;
color.name = "yellow";
} else {
color.code = green;
color.name = "green";
}
// var day = 86400000;
// var week = 7*day;
// var month = 31*day;
// var year = 365*day;
//
// if (deltaT <= day) {
// color.code = green;
// color.name = "green";
// } else if (deltaT <= week) {
// color.code = yellow;
// color.name = "yellow";
// } else if (deltaT <= month) {
// color.code = orange;
// color.name = "orange";
// } else if (deltaT <= year) {
// color.code = red;
// color.name = "red";
// } else {
// color.code = white;
// color.name = "white";
// }
}
return color;
}
function renderCircle() {
var canvas = document.createElement("canvas"),
ctx2d = canvas.getContext("2d");
var size = Math.abs(magnitude * 5),
c = size / 2 - 0.5,
outerRadius = size / 2.2;
canvas.width = size;
canvas.height = size;
ctx2d.fillStyle = getColor().code;
ctx2d.globalAlpha = 0.85;
ctx2d.arc(c, c, outerRadius, 0, 2 * Math.PI, false);
ctx2d.fill();
return canvas;
}
function getImage() {
var color = getColor().name;
return './images/dots/' + color + ".svg";
}
// Create the placemark.
placemark = new WorldWind.Placemark(new WorldWind.Position(latitude, longitude, -depth * 1000));
placemark.altitudeMode = WorldWind.RELATIVE_TO_GROUND;
placemark.data = this;
//placemark.indexInRenderables = self._baseLayer.renderables.length-1;
//this._indexInRenderables = self._baseLayer.renderables.length-1;
// Create the placemark attributes for the placemark.
placemarkAttributes = new WorldWind.PlacemarkAttributes(placemarkAttributes);
// Wrap the canvas created above in an ImageSource object to specify it as the placemark image source.
// var dotImage = getImage();
// placemarkAttributes.imageScale = magnitude / (5*1e1);
var dotImage = new WorldWind.ImageSource(renderCircle());
placemarkAttributes.imageScale = magnitude / 1e1;
placemarkAttributes.imageSource = dotImage;
// placemarkAttributes.imageColor = new WorldWind.Color(1, 1, 1, 0.55);
placemark.attributes = placemarkAttributes;
// Create the highlight attributes for this placemark. Note that the normal attributes are specified as
// the default highlight attributes so that all properties are identical except the image scale. You could
// instead vary the color, image, or other property to control the highlight representation.
highlightAttributes = new WorldWind.PlacemarkAttributes(placemarkAttributes);
// highlightAttributes.imageScale = magnitude / (2*1e1);
highlightAttributes.imageScale = 1.2;
highlightAttributes.imageSource = dotImage;
placemark.highlightAttributes = highlightAttributes;
this.placemark = placemark;
this.placemark.center = new WorldWind.Position(latitude, longitude);
}
return EQPlacemark;
});