Sha256: b1bc5914df5ae3df7211cb2b1de2e6cec7aeb99719f79c0d77b1903f8aa998d5

Contents?: true

Size: 1.31 KB

Versions: 36

Compression:

Stored size: 1.31 KB

Contents

// map_controller.js
import ApplicationController from "satis/controllers/application_controller"
import L from "leaflet"

export default class MapComponentController extends ApplicationController {
  static targets = ["container"]
  static values = { urls: String, latitude: Number, longitude: Number, zoomLevel: Number, geoJsonUrl: String }

  connect() {
    super.connect()

    // Example https://leafletjs.com/examples/choropleth/
    // Data https://public.opendatasoft.com/explore/?sort=modified&q=netherlands

    this.map = L.map(this.containerTarget).setView([this.latitudeValue, this.longitudeValue], this.zoomLevelValue)
    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(this.map)

    // this.map.setView() etc... as normal.

    if(this.geoJsonUrlValue) {
      // Load layers and setup event handlers, for example:
      fetch(this.geoJsonUrlValue)
        .then((response) => response.json())
        .then((data) => {
          L.geoJSON(data, {
            onEachFeature: (feature, layer) => {
              layer.on("click", () => this.onClick(layer))
            },
          }).addTo(this.map)
        })
    }
  }

  disconnect() {
    this.map.remove()
  }

  onClick(layer) {}
}

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
satis-2.1.43 app/components/satis/map/component_controller.js
satis-2.1.42 app/components/satis/map/component_controller.js
satis-2.1.41 app/components/satis/map/component_controller.js
satis-2.1.40 app/components/satis/map/component_controller.js
satis-2.1.39 app/components/satis/map/component_controller.js
satis-2.1.38 app/components/satis/map/component_controller.js
satis-2.1.37 app/components/satis/map/component_controller.js
satis-2.1.36 app/components/satis/map/component_controller.js
satis-2.1.35 app/components/satis/map/component_controller.js
satis-2.1.33 app/components/satis/map/component_controller.js
satis-2.1.31 app/components/satis/map/component_controller.js
satis-2.1.30 app/components/satis/map/component_controller.js
satis-2.1.29 app/components/satis/map/component_controller.js
satis-2.1.28 app/components/satis/map/component_controller.js
satis-2.1.27 app/components/satis/map/component_controller.js
satis-2.1.26 app/components/satis/map/component_controller.js
satis-2.1.24 app/components/satis/map/component_controller.js
satis-2.1.23 app/components/satis/map/component_controller.js
satis-2.1.22 app/components/satis/map/component_controller.js
satis-2.1.21 app/components/satis/map/component_controller.js