Author Topic: javascript wind dir  (Read 545 times)

0 Members and 1 Guest are viewing this topic.

Offline dazza

  • Member
  • *
  • Posts: 2
javascript wind dir
« on: February 21, 2018, 06:16:17 AM »
hi all i want to have a wind dir in icon/gif can it be donevi javascript and out put to html ive tred this but it just say NE NW BUT I WANT THE ICON NOT THE TEXT
     // Calculate the Beaufort desc
var currentwdir = rawdata[15];
if (currentwdir==N){var dir = "N.gif";}
if (currentwdir>E){var dir = "E.gif";}
if (currentwdir<NE){var dir = "NE.gif";}
if (currentwdir>ENE){var dir = "ENE.gif";}
if (currentwdir<ESE){var dir = "ESE.gif";}
if (currentwdir>NNE){var dir = "NNE.gif";}
if (currentwdir<NWW){var dir = "NNW.gif";}
if (currentwdir>0){var dir = "NNE.gif";}
if (currentwdir<0){var dir = "WSW.gif";}
if (currentwdir>0){var dir = "S.gif";}
if (currentwdir<0){var dir = "SE.gif";}
if (currentwdir>0){var dir = "SSE.gif";}
if (currentwdir<0){var dir = "SSW.gif";}
if (currentwdir>0){var dir = "SW.gif";}
if (currentwdir==W){var dir = "W.gif";}
$("#currentwdir").html('<img src="http://www.davisworthing.co.uk/one/'+dir+'"align =absmiddle>');

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6738
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: javascript wind dir
« Reply #1 on: February 21, 2018, 04:24:42 PM »
You seem to be using Cumulus.  If you're decoding the realtime.txt file, then rawdata[11] is the wind direction.
Code: [Select]
21/02/18 21:17:37 4.9 81 2.0 3.0 5.0 65 0.0 0.0 1024.59 ENE 1 mph C hPa mm 90.3 -0.02 22.4 82.8 0.4 19.4 57 4.1 -0.1 7.6 14:08 1.6 07:30 8.0 00:47 17.0 16:10 1026.85 11:07 1023.81 00:00 3.0.0 3043 8.0 4.9 3.3 0.0 0.00 0 42 0.0 1 0 0 NE 1223 ft 2.3 0.0 0 0
So something like
Code: [Select]
var currentwdir = rawdata[11];
$("#currentwdir").html('<img src="/one/'+currentwdir+'.gif" alt="Wind from '.currentwdir+'" align="absmiddle"/>');
would likely do the job.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline dazza

  • Member
  • *
  • Posts: 2
Re: javascript wind dir
« Reply #2 on: February 21, 2018, 05:35:25 PM »
o thank u so much mate  :lol: ive been trying this for so long now i will give it a go and let u know just one thin wood it be in the html out put as

(<span id="currentwdir"></span>)