Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix maps not loading in Matrix/Neo blocks after first new block #24

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/assetbundles/entrycoordinatesfield/dist/js/EntryCoordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ class CoordinatesField {
this.options.zoomLevel = options.defaultZoomLevel;
}

this.searchInput = document.querySelector('.location-search-' + this.options.suffix);
this.coordsInput = document.querySelector('.location-coords-' + this.options.suffix);
this.addressInput = document.querySelector('.location-address-' + this.options.suffix);
this.zoomInput = document.querySelector('.location-zoom-' + this.options.suffix);
const container = document.getElementById(this.options.namespace + '-field');
this.searchInput = container.querySelector('.location-search-' + this.options.suffix);
this.coordsInput = container.querySelector('.location-coords-' + this.options.suffix);
this.addressInput = container.querySelector('.location-address-' + this.options.suffix);
this.zoomInput = container.querySelector('.location-zoom-' + this.options.suffix);

this.mapElement = document.querySelector('.fields-map-' + this.options.suffix);
this.mapElement = container.querySelector('.fields-map-' + this.options.suffix);
}

// Deletes all markers in the array by removing references to them.
Expand Down Expand Up @@ -273,7 +274,14 @@ class EntryCoordinatesContainer {
this.loadMapsScript(this.apiKey ?? options.apiKey)
}

this.markers.push(new CoordinatesField(name, options));
const marker = new CoordinatesField(name, options);

// Ensure markers created after the Google Maps API script is loaded are still initialised
if (typeof google !== 'undefined') {
marker.initThisMap();
}

this.markers.push(marker);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@

{% js %}
EntryCoordinates.setApiKey('{{ googleApiKey }}');
EntryCoordinates.addField('{{ name }}', { suffix: '{{ suffix }}', originalLocation: '{{ value.coordinates }}', zoomLevel: '{{ value.zoomLevel }}', defaultCenterCoordinates: '{{ defaultCenterCoordinates }}', defaultZoomLevel: '{{ defaultZoomLevel ?? 1 }}', apiKey: '{{ googleApiKey }}'});
EntryCoordinates.addField('{{ name }}', { namespace: '{{ namespacedId }}', suffix: '{{ suffix }}', originalLocation: '{{ value.coordinates }}', zoomLevel: '{{ value.zoomLevel }}', defaultCenterCoordinates: '{{ defaultCenterCoordinates }}', defaultZoomLevel: '{{ defaultZoomLevel ?? 1 }}', apiKey: '{{ googleApiKey }}'});
{% endjs %}