import 'tippy.js/dist/tippy.css' import Tippy from '@tippyjs/react' import axios from 'axios' import Image from 'next/image' import React, { useEffect, useState } from 'react' import { Fade } from 'react-awesome-reveal' const ImagePin = () => { const [data, setData] = useState(null) const [delayHandler, setDelayHandler] = useState(null) const [actv, setActv] = useState(null) const [page, setPage] = useState(null) useEffect(() => { const fetchData = async () => { let maps = await axios.get('/api/map') console.log(maps) maps = maps.data.map(function (r) { let d = {} let ct = r.page.content d['kode'] = r.kode d['cordX'] = r.cordX d['cordY'] = r.cordY d['title'] = r.page.title d['slug'] = r.page.slug d['content'] = (function (x) { let dt = [] ;(function deep(v, l) { for (let i = 0; i < l; i++) { Object.keys(v[i]).forEach(function (f) { if (f == 'children') { deep(v[i][f], v[i][f].length) } else if (f == 'text') { dt.push(v[i][f]) } }) } })(x, x.length) return dt })(ct) return d }) console.log(maps) setData(maps) } if (data === null) { fetchData() } }, [data]) function open(e) { var t = e.target if (t.className.indexOf('pin-b') == -1) { t = e.target.parentNode } console.log(t) } function EventPoinEnter(event) { var cod = event.target.dataset.kodePc var poin = document.querySelector( "div[data-point='" + cod + "']" ) var df = document.querySelector("div[data-open='" + cod + "']") df.style.display = 'block' var y = poin.getBoundingClientRect() var px = Math.round((y.left / window.innerWidth) * 100) if (px < 0) { px = px * -1 } console.log(px) if (px < 40) { df.style.right = 'auto' df.style.left = '0px' } else if (px >= 40 && px <= 70) { df.style.right = '-180px' df.style.left = 'auto' } else if (px > 70) { df.style.right = '0px' df.style.left = 'auto' } if (actv != null && actv != event.target.dataset.kodePc) { var f = document.querySelector( "div[data-open='" + actv + "']" ) f.style.display = 'none' setActv(cod) } else { setActv(cod) } clearTimeout(delayHandler) } function EventPointerLeave(event) { var cod = event.target.dataset.kodePc setDelayHandler( setTimeout(() => { document.querySelector( "div[data-open='" + cod + "']" ).style.display = 'none' }, 500) ) } return (
GWK Cultural Park Map {/* */} {(function () { if (Array.isArray(data)) { return data.map((s, i) => (
{s.kode}

{s.title}

{(function (sr) { if (sr.content.length > 0) { return sr.content.map((r, i) => (

{r}

)) } return <> })(s)}
)) } else { return <> } })()}
) } export default ImagePin