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 google map zoom out bug #2189

Merged
merged 2 commits into from
Feb 4, 2023
Merged
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion static/js/components/google_map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import _ from "lodash";
import React from "react";

const DEFAULT_MAP_ZOOM = 4;
const MAP_BOUNDS_PADDING = 0;

/**
* Response format of /api/place/mapinfo/.
Expand Down Expand Up @@ -98,7 +99,13 @@ function drawKmlCoordinates(
const bounds = new google.maps.LatLngBounds();
bounds.extend(sw);
bounds.extend(ne);
map.fitBounds(bounds);

// add listener to set bounds after map finishes loading.
// fitting bounds needs to be called after map finishes loading
// otherwise, the map will zoom all the way out to earth.
map.addListener("idle", () => {
map.fitBounds(bounds, MAP_BOUNDS_PADDING);
});

// Add polygons
if (mapInfo.coordinateSequenceSet) {
Expand Down