{"size": 2087, "ext": "js", "max_stars_repo_path": "src/components/input/Geometry.js", "max_stars_repo_name": "City-of-Helsinki/kaavapino-ui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/input/Geometry.js", "max_issues_repo_name": "City-of-Helsinki/kaavapino-ui", "max_issues_repo_issues_event_min_datetime": "2018-09-19T11:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T18:51:31.000Z", "max_forks_repo_path": "src/components/input/Geometry.js", "max_forks_repo_name": "City-of-Helsinki/kaavapino-ui", "max_forks_repo_forks_event_min_datetime": "2018-11-05T14:20:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T12:27:47.000Z"}
{"max_stars_count": null, "max_issues_count": 76, "max_forks_count": 5, "avg_line_length": 30.6911764706, "max_line_length": 247, "alphanum_fraction": 0.6229036895}
import React from 'react'
import { Map, TileLayer } from 'react-leaflet'
import Polygon from '../common/Polygon'
import { EPSG3879, formatGeoJSONToPositions, helsinkiCenter } from '../../utils/mapUtils'

function Geometry(props) {
  const crs = EPSG3879()

  const disabled = false

  const getCoordinates = () => {
    const value = props.input.value
    if (!value) {
      if (props.value) {
        return props.value.coordinates
      }
      return {}
    }
    const coordinates = value[0] && value[0].geometry && value[0].geometry.coordinates
    return coordinates || {}
  }

  const getCenterCoordinates = () => {
    const coordinates = getCoordinates()

    if (!coordinates || !coordinates[0] || !coordinates[0][0]) {
      return helsinkiCenter
    }
    return coordinates[0][0]
  }

  return (
    <div className="geometry-input-container">
      <Map
        className={`geometry-input${disabled ? ' disabled' : ''}`}
        center={getCenterCoordinates()}
        doubleClickZoom={true}
        scrollWheelZoom={true}
        maxZoom={18}
        zoomControl={!disabled}
        dragging={!disabled}
        crs={crs}
        style={!disabled ? { cursor: 'pointer' } : {}}
        zoom={9}
        minZoom={9}
        clusterPopupVisibility={11}
        unitZoom={12}
        mobileZoom={9}
        detailZoom={14}
        mapBounds={[
          [60.402200415095926, 25.271114398151653],
          [60.402200415095926, 24.49246149510767],
          [60.00855312110063, 24.49246149510767],
          [60.00855312110063, 25.271114398151653]
        ]}
      >
        <TileLayer
          attribution="Leaflet | © Helsingin, Espoon, Vantaan ja Kauniaisen kaupungit, karttasarja"
          url="https://kartta.hel.fi/ws/geoserver/avoindata/gwc/service/wmts?layer=avoindata:Karttasarja_harmaa&tilematrixset=ETRS-GK25&Service=WMTS&Request=GetTile&Version=1.0.0&TileMatrix=ETRS-GK25:{z}&TileCol={x}&TileRow={y}&Format=image%2Fpng"
        />
        <Polygon positions={formatGeoJSONToPositions([getCoordinates()])} />
      </Map>
    </div>
  )
}

export default Geometry
