# Mixins

Mixins (opens new window) are a flexible way to distribute reusable functionalities for Vue components (opens new window). A mixin object can contain any component options. When a component uses a mixin, all options in the mixin will be "mixed" into the component's own options.

WARNING

Mixins are only part of the legacy Weacast client module (opens new window), which will not evolve anymore (see discussion here (opens new window)) and will only be maintained for the purpose of our demo application (opens new window). If you'd like to build client applications using Weacast you'd better have a look to our client API layer in core module (opens new window) and build your own map component using dedicated map engine modules like our Leaflet plugin (opens new window).

# Map mixins

A Weacast map is based on a Leaflet (opens new window) map object.

This set of mixins is to be used to construct a new Weacast Map component and underlying Leaflet objects:

A Weacast map relies on a configuration object detailing mixins to be used with their options like this:

module.exports = {
  ...
map: {
    // Mixins to be applied to map
    mixins: [ 'base', 'baseLayers', 'forecastLayers', 'geojsonLayers', 'fileLayers', 'fullscreen', 'measure', 'scalebar', 'legend' ],
    // Config for Base Layers mixin
    baseLayers: [
      {
        type: 'tileLayer',
        arguments: [
          'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png',
          {
            maxZoom: 20,
            label: 'Streets',
            attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
          }
        ]
      },
      ...
    ],
    // Config for Forecast Layers mixin
    forecastLayers: [
      {
        type: 'FlowLayer',
        options: {
          elements: ['u-wind', 'v-wind'],
          attribution: 'Forecast data from <a href="http://www.meteofrance.com">Météo-France</a>',
        }
      },
      ...
    ],
    // Default GeoJSON layer style for polygons/lines in File Layers mixin
    featureStyle: {
      opacity: 1,
      radius: 6,
      color: 'red',
      fillOpacity: 0.5,
      fillColor: 'green',
      popup: {
        excludedProperties: ['wikipedia']
      }
    },
    // Default GeoJSON layer style for points in File Layers mixin
    pointStyle: {
      type: 'circleMarker',
      options: {
        opacity: 1,
        color: 'red',
        fillOpacity: 0.5,
        fillColor: 'green'
      }
    }
  }
...