Skip to content

Commit

Permalink
Merge pull request #321 from data-mermaid/site_count_fix
Browse files Browse the repository at this point in the history
Remove bbox site filtering and extra data call
  • Loading branch information
saanobhaai authored Jun 22, 2024
2 parents effa47d + 0b17006 commit bc44afb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 76 deletions.
58 changes: 2 additions & 56 deletions src/components/LeafletMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class LeafletMap extends Component {
)
}

componentDidUpdate(prevProps, prevState) {
componentDidUpdate(prevProps) {
const {
markersData: prevMarkersData,
sidePanelOpen: prevSidePanelOpen,
Expand All @@ -182,21 +182,12 @@ class LeafletMap extends Component {
zoomToSite,
} = this.props

const {
mapZoomLevel: prevMapZoomLevel,
mapBoundingBoxCorner: prevMapBoundingBoxCorner,
} = prevState

const { mapZoomLevel, mapBoundingBoxCorner, popUpList, miniMap } = this.state
const { popUpList, miniMap } = this.state
const prevSiteDetailId = prevSiteDetail && prevSiteDetail[0].site_id
const siteDetailId = siteDetail && siteDetail[0].site_id

if (markersData !== prevMarkersData) this.updateMarkers(markersData)

if (mapZoomLevel !== prevMapZoomLevel) this.updateBoundingBoxFromZoom()

if (mapBoundingBoxCorner !== prevMapBoundingBoxCorner) this.updateBoundingBoxFromPan()

// Redraw leaflet map when dashboard is open or close
if (sidePanelOpen !== prevSidePanelOpen) this.map.invalidateSize()

Expand Down Expand Up @@ -420,50 +411,6 @@ class LeafletMap extends Component {
})
}

updateBoundingBoxFromZoom() {
const { getMapBounds, contentLoadHandler } = this.props
const { mapZoomLevel } = this.state

this.map.once('zoomstart', () => contentLoadHandler(true))

this.map.once('zoomend', e => {
const curBounds = e.target.getBounds()
const curZoom = e.target.getZoom()
const curBBox = this.createBoundingBox(curBounds)

if (mapZoomLevel === curZoom) {
this.setState({ mapZoomLevel: curZoom + 1 })
contentLoadHandler(false)
} else {
this.setState({ mapZoomLevel: curZoom })
getMapBounds(curBBox)
}
})
}

updateBoundingBoxFromPan() {
const { mapBoundingBoxCorner } = this.state
const { getMapBounds, contentLoadHandler } = this.props

this.map.once('dragstart', () => contentLoadHandler(true))

this.map.once('dragend', e => {
const curBounds = e.target.getBounds()
const southBound = curBounds.getSouth()
const curBBox = this.createBoundingBox(curBounds)

setTimeout(() => {
if (mapBoundingBoxCorner === southBound) {
this.setState({ mapBoundingBoxCorner: southBound + 0.1 })
contentLoadHandler(false)
} else {
this.setState({ mapBoundingBoxCorner: southBound })
getMapBounds(curBBox)
}
}, 750)
})
}

createPopup(markersData, coordinates) {
const popUpContentStyles =
markersData.length >= 10 || this.#countClusterPopupChar(markersData) >= 450
Expand Down Expand Up @@ -651,7 +598,6 @@ LeafletMap.propTypes = {
removeHighlightCluster: PropTypes.func.isRequired,
setClusterActive: PropTypes.func.isRequired,
setIconActive: PropTypes.func.isRequired,
contentLoadHandler: PropTypes.func.isRequired,
highlightMarker: PropTypes.shape({
_latlng: PropTypes.shape({
lat: PropTypes.number,
Expand Down
22 changes: 2 additions & 20 deletions src/components/MermaidDash.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class MermaidDash extends Component {
}

this.fetchAllSites(paramsObj)
this.fetchAllSitesWithEmptyQueryParams()

if (countryName) {
filterParams.country = countryName.split(',')
Expand Down Expand Up @@ -155,8 +154,7 @@ class MermaidDash extends Component {
}

if (bbox !== prevBbox && !isFiltering) {
const updatedSites = this.filterSites(sites, bbox)
const sampleEventsFromSites = updatedSites.reduce((sampleEvents, site) => {
const sampleEventsFromSites = sites.reduce((sampleEvents, site) => {
for (const sampleEvent of site[1]) {
sampleEvents.push(sampleEvent)
}
Expand All @@ -171,7 +169,7 @@ class MermaidDash extends Component {
const countryCount = this.getCount(sampleEventsFromSites, 'country_id')
const projectCount = this.getCount(sampleEventsFromSites, 'project_id')
const yearCount = this.getCount(sampleEventsFromSites, 'sample_date')
const uniqueSiteCount = updatedSites.length
const uniqueSiteCount = sites.length
const transectCount = this.getTransectCount(sampleUnitProtocols)
const averageCoralCoverageCount = this.getAverageCoralCoverage(sampleUnitProtocols)

Expand Down Expand Up @@ -541,22 +539,6 @@ class MermaidDash extends Component {

contentLoadHandler = option => this.setState({ isLoading: option })

filterSites = (sites, bbox) => {
const bboxList = this.getBboxXY(bbox)

return sites.reduce((newSites, site) => {
const { longitude, latitude } = site[1][0]

for (const { x, y } of bboxList) {
if (longitude >= x[0] && longitude <= x[1] && latitude >= y[0] && latitude <= y[1]) {
newSites.push(site)
}
}

return newSites
}, [])
}

filterHandler = ({ country, project, organization, sample_date_after, sample_date_before }) => {
this.setState({
filterParams: {
Expand Down

0 comments on commit bc44afb

Please sign in to comment.