Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
stw
stwkit
Commits
7bb2b6d3
Commit
7bb2b6d3
authored
Sep 01, 2017
by
Tomas Pettersson
🏸
Browse files
added lots of helper functions
parent
76fd2f78
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/stwkit.js
View file @
7bb2b6d3
...
...
@@ -148,6 +148,64 @@ var STWkit = {
parent
=
true
;
}
return
result
;
},
convertDDtoDDM
:
function
(
dd
,
lat
)
{
var
round
=
function
(
value
,
n
)
{
return
Math
.
round
(
value
*
Math
.
pow
(
10
,
n
))
/
Math
.
pow
(
10
,
n
);
};
var
pad
=
function
(
n
,
width
)
{
var
z
=
'
0
'
;
n
=
n
+
''
;
return
n
.
length
>=
width
?
n
:
new
Array
(
width
-
n
.
length
+
1
).
join
(
z
)
+
n
;
};
var
hemisphere
;
if
((
dd
>=
0
)
&&
lat
)
hemisphere
=
"
N
"
;
if
((
dd
<
0
)
&&
lat
)
hemisphere
=
"
S
"
;
if
((
dd
>=
0
)
&&
!
lat
)
hemisphere
=
"
E
"
;
if
((
dd
<
0
)
&&
!
lat
)
hemisphere
=
"
W
"
;
var
degree
=
parseInt
((
Math
.
abs
(
dd
)
+
""
).
split
(
"
.
"
)[
0
]);
var
minutes
=
round
(
60.0
*
(
Math
.
abs
(
dd
)
-
degree
),
3
);
var
parts
=
minutes
.
toFixed
(
3
).
split
(
'
.
'
);
return
hemisphere
+
"
"
+
pad
(
degree
,
2
)
+
"
"
+
pad
(
parts
[
0
],
2
)
+
"
.
"
+
pad
(
parts
[
1
],
3
);
},
featurecollection
:
function
()
{
var
json
=
{};
json
[
"
type
"
]
=
"
FeatureCollection
"
;
json
[
"
features
"
]
=
[];
return
json
;
},
createFeature
:
function
(
type
)
{
var
feature
=
{};
feature
[
"
type
"
]
=
"
Feature
"
;
feature
[
"
properties
"
]
=
{};
feature
[
"
geometry
"
]
=
{};
feature
[
"
geometry
"
][
"
type
"
]
=
type
;
feature
[
"
geometry
"
][
"
coordinates
"
]
=
[];
return
feature
;
},
uriencodejson
:
function
(
json
)
{
var
query
=
""
;
for
(
var
key
in
json
)
{
query
+=
encodeURIComponent
(
key
)
+
"
=
"
+
encodeURIComponent
(
json
[
key
])
+
"
&
"
;
}
return
query
;
},
intersect
:
function
(
a
,
b
)
{
return
(
a
.
left
<=
b
.
right
&&
b
.
left
<=
a
.
right
&&
a
.
top
<=
b
.
bottom
&&
b
.
top
<=
a
.
bottom
);
},
getRectangle
:
function
(
p
)
{
return
{
left
:
p
.
x
,
right
:
p
.
x
+
210
,
top
:
p
.
y
,
bottom
:
p
.
y
+
20
};
}
};
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment