Skip to content

Commit 51f7828

Browse files
committed
WIP
1 parent 3e167bc commit 51f7828

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

app/assets/config/manifest.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
//= link static-error-pages.js
1414

1515
//= link_tree ../builds
16-
//= link_tree ../../javascript .js
17-
//= link_tree ../../../vendor/javascript .js
16+
17+
//= link @defra/interactive-map/dist/esm/index.js
18+
//= link @defra/interactive-map/providers/maplibre/dist/esm/index.js
19+
//= link @defra/interactive-map/plugins/interact/dist/esm/index.js

app/assets/javascripts/components/map.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
window.GOVUK = window.GOVUK || {}
33
window.GOVUK.Modules = window.GOVUK.Modules || {};
44

5+
import InteractiveMap from '@defra/interactive-map'
6+
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
7+
58
(function (Modules) {
69
class Map {
710
constructor ($module) {
@@ -15,7 +18,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
1518
})
1619

1720
const config = {
18-
mapProvider: defra.maplibreProvider({ workerUrl: cspWorker }),
21+
mapProvider: maplibreProvider({ workerUrl: cspWorker }),
1922
behaviour: 'inline',
2023
mapStyle: {
2124
url: window.GOVUK.mapComponentStyles,
@@ -54,7 +57,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
5457
this.map_element.setAttribute('id', id)
5558
this.map_element.classList.add('app-c-map--enabled')
5659

57-
this.map = new defra.InteractiveMap(this.map_id, this.config)
60+
this.map = new InteractiveMap(this.map_id, this.config)
5861

5962
/* istanbul ignore next */
6063
this.map.on('map:ready', () => {

app/views/components/_map.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
@include_script ||= OpenStruct.new(script_included: false)
3838
%>
3939
<% if heading_text && ((map_config[:center] && map_config[:zoom]) || (markers || !geojson.nil?)) %>
40+
<%= javascript_importmap_tags %>
4041
<%= render "govuk_publishing_components/components/heading", heading_obj %>
4142
<% if description %>
4243
<%= render "govuk_publishing_components/components/govspeak", {} do %>
@@ -64,9 +65,7 @@
6465
<% end %>
6566

6667
<% unless @include_script[:script_included] %>
67-
<%= javascript_include_tag "components/map/defra-map.js", integrity: false %>
6868
<%= javascript_include_tag "components/map.js", integrity: false, type: "module" %>
69-
<%= javascript_include_tag "components/map/map-style-liberty.js", integrity: false %>
7069
<% @include_script[:script_included] = true %>
7170
<% end %>
7271

config/importmap.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Pin npm packages by running ./bin/importmap
22

3-
pin "application"
3+
pin "@defra/interactive-map", to: "@defra/interactive-map/dist/esm/index.js"
4+
pin "@defra/interactive-map/providers/maplibre", to: "@defra/interactive-map/providers/maplibre/dist/esm/index.js"
5+
pin "@defra/interactive-map/plugins/interact", to: "@defra/interactive-map/plugins/interact/dist/esm/index.js"
6+
pin "components/map", to: "components/map.js"

0 commit comments

Comments
 (0)