Commit 7bb2b6d3 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸
Browse files

added lots of helper functions

parent 76fd2f78
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment