Skip to content

Commit

Permalink
Map: change URL to open Earth Map (#3163)
Browse files Browse the repository at this point in the history
* map / open in Earth Map: add aoi and name (WIP)

* map / open in Earth Map: add aoi and name

---------

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent 482a846 commit a0e0d64
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import React, { useCallback, useMemo, useRef, useState } from 'react'
import { Popup } from 'react-leaflet'
import PropTypes from 'prop-types'
import circleToPolygon from 'circle-to-polygon'
import L from 'leaflet'

import { PointFactory } from '@openforis/arena-core'
import { Objects, PointFactory } from '@openforis/arena-core'

import * as Survey from '@core/survey/survey'
import * as NodeDef from '@core/survey/nodeDef'

import { useSurvey, useSurveyPreferredLang, useSurveyInfo } from '@webapp/store/survey'
import * as SamplingPolygon from '@core/survey/SamplingPolygon'
import L from 'leaflet'

import { Button, ButtonIconEdit } from '@webapp/components'
import Markdown from '@webapp/components/markdown'
import { ButtonPrevious } from '@webapp/components/buttons/ButtonPrevious'
import { ButtonNext } from '@webapp/components/buttons/ButtonNext'

import { useAltitude } from '../common/useAltitude'
import { useSurvey, useSurveyPreferredLang, useSurveyInfo } from '@webapp/store/survey'
import { useI18n } from '@webapp/store/system'

import { useAltitude } from '../common/useAltitude'

// Builds the path to an attribute like ANCESTOR_ENTITY_LABEL_0 [ANCESTOR_ENTITY_0_KEYS] -> ANCESTOR_ENTITY_LABEL_1 [ANCESTOR_ENTITY_1_KEYS] ...
// E.g. Cluster [123] -> Plot [4].
const buildPath = ({ survey, attributeDef, ancestorsKeys, lang }) => {
Expand Down Expand Up @@ -80,6 +80,10 @@ export const CoordinateAttributePopUp = (props) => {
popupRef.current?.close()
}, [flyToPreviousPoint, pointFeature])

const path = useMemo(
() => buildPath({ survey, attributeDef, ancestorsKeys, lang }),
[ancestorsKeys, attributeDef, lang, survey]
)
const onEarthMapButtonClick = useCallback(() => {
let geojson
if (Survey.isSampleBasedImageInterpretationEnabled(surveyInfo)) {
Expand All @@ -96,14 +100,10 @@ export const CoordinateAttributePopUp = (props) => {
const bounds = SamplingPolygon.generateBounds({ latitude, longitude })
geojson = L.rectangle(bounds).toGeoJSON()
}
const earthMapUrl = 'https://earthmap.org/?polygon=' + JSON.stringify(geojson)
Objects.setInPath({ obj: geojson, path: ['properties', 'name'], value: path })
const earthMapUrl = 'https://earthmap.org/?aoi=global&polygon=' + JSON.stringify(geojson)
window.open(earthMapUrl, 'EarthMap')
}, [latitude, longitude, surveyInfo])

const path = useMemo(
() => buildPath({ survey, attributeDef, ancestorsKeys, lang }),
[ancestorsKeys, attributeDef, lang, survey]
)
}, [latitude, longitude, path, surveyInfo])

const content = `**${path}**
* **X**: ${point.x}
Expand Down

0 comments on commit a0e0d64

Please sign in to comment.