Skip to content

Commit

Permalink
manual resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
danwild committed Jun 14, 2017
2 parents 428c304 + 73860cc commit 38fe1a4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 26 deletions.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -18,7 +18,10 @@ var velocityLayer = L.velocityLayer({
velocityType: 'Global Wind',
position: 'bottomleft',
emptyString: 'No velocity data',
angleConvention: 'bearingCW'
angleConvention: 'bearingCW',
displayPosition: 'bottomleft',
displayEmptyString: 'No velocity data',
speedUnit: 'kt'
},
data: data, // see demo/*.json, or wind-js-server for example data service

Expand All @@ -33,6 +36,9 @@ The angle convention option refers to the convention used to express the wind di
It can be any combination of `bearing` (angle toward which the flow goes) or `meteo` (angle from which the flow comes),
and `CW` (angle value increases clock-wise) or `CCW` (angle value increases counter clock-wise). If not given defaults to `bearingCCW`.

The speed unit option refers to the unit used to express the wind speed in the control.
It can be `m/s` for meter per second, `k/h` for kilometer per hour or `kt` for knots. If not given defaults to `m/s`.

## Reference
`leaflet-velocity` is possible because of things like:
- [L.CanvasOverlay.js](https://gist.github.com/Sumbera/11114288)
Expand Down
25 changes: 22 additions & 3 deletions dist/leaflet-velocity.js
Expand Up @@ -159,7 +159,9 @@ L.Control.Velocity = L.Control.extend({
emptyString: 'Unavailable',
// Could be any combination of 'bearing' (angle toward which the flow goes) or 'meteo' (angle from which the flow comes)
// and 'CW' (angle value increases clock-wise) or 'CCW' (angle value increases counter clock-wise)
angleConvention: 'bearingCCW'
angleConvention: 'bearingCCW',
// Could be 'm/s' for meter per second, 'k/h' for kilometer per hour or 'kt' for knots
speedUnit: 'm/s'
},

onAdd: function onAdd(map) {
Expand All @@ -174,18 +176,27 @@ L.Control.Velocity = L.Control.extend({
map.off('mousemove', this._onMouseMove, this);
},

vectorToSpeed: function vectorToSpeed(uMs, vMs) {
vectorToSpeed: function vectorToSpeed(uMs, vMs, unit) {
var velocityAbs = Math.sqrt(Math.pow(uMs, 2) + Math.pow(vMs, 2));
return velocityAbs;
// Default is m/s
if (unit === 'k/h') {
return this.meterSec2kilometerHour(velocityAbs);
} else if (unit === 'kt') {
return this.meterSec2Knots(velocityAbs);
} else {
return velocityAbs;
}
},

vectorToDegrees: function vectorToDegrees(uMs, vMs, angleConvention) {

// Default angle convention is CW
if (angleConvention.endsWith('CCW')) {
// vMs comes out upside-down..
vMs = vMs > 0 ? vMs = -vMs : Math.abs(vMs);
}
var velocityAbs = Math.sqrt(Math.pow(uMs, 2) + Math.pow(vMs, 2));

var velocityDir = Math.atan2(uMs / velocityAbs, vMs / velocityAbs);
var velocityDirToDegrees = velocityDir * 180 / Math.PI + 180;

Expand All @@ -197,6 +208,14 @@ L.Control.Velocity = L.Control.extend({
return velocityDirToDegrees;
},

meterSec2Knots: function meterSec2Knots(meters) {
return meters / 0.514;
},

meterSec2kilometerHour: function meterSec2kilometerHour(meters) {
return meters * 3.6;
},

_onMouseMove: function _onMouseMove(e) {

var self = this;
Expand Down

0 comments on commit 38fe1a4

Please sign in to comment.