VIAMICHELIN JAVASCRIPT API


Weather

Weather is responsible for displaying data from the closest weather station. Launched via VMLaunch().

Weather parameter object

Constant prefix: ViaMichelin.Api.Constants.Weather

PropertyTypeDescriptionDefault
center GeoPoint or {address: {GeocodingConfig}} Geographical coordinates of the search centre. Only weather forecast of the nearest station is returned.
A geocoding is performed if an address is input.
N/A
nbDays int Number of days to forecast. 5
map {container: DOMElement, focus: boolean} DOM element containing the map to display the weather in.focus specifies if the map should be redrawn to fit all contained graphics objects (including newly added weather icon). null

 

Response object in onSuccess

WeatherResponse object type. If a datum is not available, it is valued at [prefix].NO_DATA. See the list of possibles forecasts.

{
	name 		: /* string */,
	location : {
		coords : {
			lon : /* double */,		//longitude
			lat : /* double */,		//latitude
		},
	},
	dist 		: /* integer */,		//distance from search center to closest station
	observation: {
		dayReport 		: /* string as DD/MM/YY */,
		hourReport 		: /* string as HH:MM */
		image : {
			iconId 		: /* integer */,		//Index of weather
			mapIconPath 		: /* string */,		//Path to ViaMichelin weather icon
		},
		imageLabel 		: /* string */,		//Weather description
		temperatureMesured 		: /* float */,		//in deg Celcius
		temperatureApparent 		: /* float */,		//in deg Celcius
		windSpeedInfo 		: /* float */,		//In Km/h
		windDirectionInfo 		: /* string */,
		humidityInfo 		: /* float */,
		visibilityInfo 		: /* string */,
		sunRise 		: /* string as ISO-8601 date*/,
		sunSet 		: /* string as ISO-8601 date*/,
		moonRise 		: /* string as ISO-8601 date*/,
		moonSet 		: /* string as ISO-8601 date*/
	},
	forecastList : [{ /* Forecast structure */
		dayForecast 		: /* integer */,
		dayReport 		: /* string as DD/MM/YY */,
		hourReport 		: /* string as HH:MM */
		image : {
			iconId 		: /* integer */,		//Index of weather forecast
			mapIconPath 		: /* string */,		//Path to ViaMichelin weather icon
		},
		imageLabel 		: /* string */,		//Weather forecast description
		windSpeedInfo 		: /* float */,
		windDirectionInfo 		: /* string */,
		temperatureMinInfo 		: /* float */,		//in deg Celcius
		temperatureMaxInfo 		: /* float */,		//in deg Celcius
		fog 		: /* integer */,		//probability as a percentage
		rainFall 		: /* integer */,		//Precipitation in milimeters
		snowRoad 		: /* integer */,		//Probability of snow on roads as a risk index from 0 (no risk) to 4 (more than 10cm, probably also on cleaned roads).	

		getForecast()   : /* Method to retrieve the single forecast as an HTML structure */,
	}],
	todayForecastList : [{ /* Same forecast structure */}],

	getStationForecasts()  : /* Method to retrieve the whole weather forecast as an HTML structure */,
	getStationObservation() : /* Method to retrieve the weather observation as an HTML structure */,
	getStationCalendar()  : /* Method to retrieve  the station calendar (ephemeris) as an HTML structure  */,
	
	getLayer()  : /* Method to retrieve the graphics object linked to the current object */,
	release () : /* Method to destroy current object and free memory */,
	
}

 

Billing

A charged request for a weather access and geocoding of the search centre (if center is an address).

 

Main dedicated examples

Get weather

Launch this example (ser1.htm)

var myMap = null;

function fLoadMap(){
 VMLaunch("ViaMichelin.Api.Map",{
   container: $_id("dMapContainer"),
   center: {coords:{lon: 2.34277, lat: 48.85767}},
   zoom: 6
  },{
   onInitError: function(){
    alert('Whoops Map cannot be loaded!');
   },
   onInit: function(serviceMap){
    myMap = serviceMap;
   },
   onError: function(error){
    alert("onError - error: "+ error);
   },
   onClick: function(event){
    var clickCoords = event;
    //Launch weather search centered on click coords.
    VMLaunch("ViaMichelin.Api.Weather", {
     center : event,
     //Gets 3-day forecast
     nbDays : 3
    },{
     onInitError: function(ref, error){
      alert("onInitError ref: "+ ref +", error: "+ error);
     },
     onError: function(error){
      alert("onError - error: "+ error);
     },
     onSuccess: function(weatherStation){
      if(weatherStation != null){
       //Display weather data
       $_id("dWeatherStationData").innerHTML = "<p>getStationObservation():</p>" + weatherStation.getStationObservation() + "<p>getStationCalendar():</p>" + weatherStation.getStationCalendar() + "<p>getStationForecasts():</p>" + weatherStation.getStationForecasts();
       myMap.removeAllLayers();
       //Plots weather icon, search center icon and link between them
       myMap.addLayer(new ViaMichelin.Api.Map.PolyLine({
        coords: [weatherStation.coords, clickCoords]
       }));         
       myMap.addLayer(new ViaMichelin.Api.Map.Marker({
        coords: clickCoords,
        zIndex:3,
        title: "Search center - Weather station: " + Math.round(weatherStation.dist/1000) + "km"
       }));
       myMap.addLayer(weatherStation.getLayer());
       myMap.drawMapFromLayers();
      }else{
       $_id("dWeatherStationData").innerHTML = "Unfortunately, there is no weather station close from this point!";
      }
     }
    }); //VMLaunch      
   }
  });//VMLaunch
 };//fLoadMap

Launch this example (ser1.htm)


Back to top