Skip to content

Commit

Permalink
Load the boundary once the map is showing
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Jan 25, 2024
1 parent 649a954 commit c111a80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/assets/javascripts/tailwind/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,10 @@ async function initialiseAuthorityMap(el, params) {
var ne = new LatLng(params.ne.lat, params.ne.lng);
var bounds = new LatLngBounds(sw, ne);
map.fitBounds(bounds);
map.data.loadGeoJson(params.json);
map.addListener('tilesloaded', function() {
// Only load the boundary once the map has displayed. Do this because loading the boundary can
// take a while and the map is already showing roughly where the council is without the boundary
// and so it is immediately useful
map.data.loadGeoJson(params.json);
});
}
1 change: 0 additions & 1 deletion app/views/_tailwind/authorities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

<% if @authority.boundary && Flipper.enabled?(:show_authority_map, current_user) %>
<%# TODO: Probably want to precompute the bounding box when the boundary data is loaded instead %>
<%# TODO: Load the boundary data asynchronously so that it doesn't hold up a page load %>
<% bb = RGeo::Cartesian::BoundingBox.create_from_geometry(@authority.boundary) %>
<div class="w-full my-8 h-80 bg-google-maps-green"
x-init="initialiseAuthorityMap($el, <%= { json: boundary_authority_url(format: :json), sw: { lng: bb.min_x, lat: bb.min_y }, ne: { lng: bb.max_x, lat: bb.max_y } }.to_json %>)">
Expand Down

0 comments on commit c111a80

Please sign in to comment.