Sha256: a2eb3a7335c5e2acd0fd882d282e5fc10d5d117d650e83fa0b226901d755b98e

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

import "src/decidim/map/icon"

import MapMarkersController from "src/decidim/map/controller/markers"
import MapStaticController from "src/decidim/map/controller/static"
import MapDragMarkerController from "src/decidim/map/controller/drag_marker"

/**
 * A factory method that creates a new map controller instance. This method
 * can be overridden in order to return different types of maps for
 * differently configured map elements.
 *
 * For instance, one map could pass an extra `type` configuration with the
 * value "custom" for the map element, this factory method would identify
 * it and then return a different controller for that map than the default.
 * This would allow this types of maps to function differently.
 *
 * An example how to use in the ERB view:
 *   <%= dynamic_map_for type: "custom" do %>
 *     <%= javascript_pack_tag "map_customization" %>
 *   <% end %>
 *
 * And then the actual customization at `map_customization.js.es6`:
 *   var originalCreateMapController = window.Decidim.createMapController;
 *   window.Decidim.createMapController = (mapId, config) => {
 *     if (config.type === "custom") {
 *       // Obviously you need to implement CustomMapController for this to
 *       // work. You can find an example at:
 *       // decidim-dev/app/packs/src/decidim/dev/test/custom_map_factory.js
 *       return new window.Decidim.CustomMapController(mapId, config);
 *     }
 *
 *     return originalCreateMapController(mapId, config);
 *   }
 *
 * @param {string} mapId The ID of the map element.
 * @param {Object} config The map configuration object.
 * @returns {MapController} The controller for the map.
 */
const createMapController = function(mapId, config) {
  if (config.type === "static") {
    return new MapStaticController(mapId, config);
  } else if (config.type === "drag-marker") {
    return new MapDragMarkerController(mapId, config);
  }

  return new MapMarkersController(mapId, config);
}

window.Decidim.createMapController = createMapController;

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/packs/src/decidim/map/factory.js
decidim-core-0.27.8 app/packs/src/decidim/map/factory.js
decidim-core-0.27.7 app/packs/src/decidim/map/factory.js
decidim-core-0.27.6 app/packs/src/decidim/map/factory.js
decidim-core-0.26.10 app/packs/src/decidim/map/factory.js
decidim-core-0.26.9 app/packs/src/decidim/map/factory.js
decidim-core-0.27.5 app/packs/src/decidim/map/factory.js
decidim-core-0.26.8 app/packs/src/decidim/map/factory.js
decidim-core-0.27.4 app/packs/src/decidim/map/factory.js