import React from 'react' import { BottomNavigation, BottomNavigationAction, Box, Paper, Skeleton, SwipeableDrawer, styled } from '@mui/material' import { useEffect, useRef, useState } from 'react' import { Col, Label, Nav, NavItem, NavLink, Row, TabContent, TabPane } from 'reactstrap' import { AutorenewOutlined, CloseOutlined } from '@mui/icons-material' import { red } from '@mui/material/colors' import { useDispatch } from 'react-redux' import collect from 'collect.js' import { useMap } from 'react-leaflet' import L from 'leaflet' import { Button as ButtonP } from 'primereact/button' // import Wkt from 'wicket' const parse = require('wellknown') const anchor = 'bottom' const StyledBox = styled('div')(({ theme }) => ({ backgroundColor: theme.palette.mode === 'light' ? '#fff' : grey[800] })) const Item = styled(Paper)(({ theme }) => ({ backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff', ...theme.typography.body2, padding: theme.spacing(1), textAlign: 'center', color: theme.palette.text.secondary })) import { MultiSelect } from 'react-multi-select-component' import Select from 'react-select' import jquery from 'jquery' import { isObjEmpty } from '../kytp/util' import { setCqlFilterWilayah, setSelectedOpsi } from '../kytp/store/PetaStore' import { Toast } from 'primereact/toast' import NipPerekam from './components/NipPerekam' import NipPengampu from './components/NipPengampu' import { matoaLayers } from './layers/overlayLayers' const PopUpWilayah = (props) => { const { isOpenPopUpWilayah, setIsOpenPopUpWilayah, wmsRef, refFeatureBawah, zonaRef, dataSend, setDataSend, dataOpsi, setDataOpsi } = props const toast = useRef() const map = useMap() const dispatch = useDispatch() const [tabActive, setTabActive] = useState('zona') const [isTerapkan, setIsTerapkan] = useState(false) const [prop, setProp] = useState([]) const [kota, setKota] = useState([]) const [kec, setKec] = useState([]) const [kel, setKel] = useState([]) const [propSelected, setPropSelected] = useState([]) const [kotaSelected, setKotaSelected] = useState([]) const [kecSelected, setKecSelected] = useState([]) const [kelSelected, setKelSelected] = useState([]) const [kanwil, setKanwil] = useState([]) const [kpp, setKpp] = useState([]) const [seksi, setSeksi] = useState([]) const [ar, setAr] = useState([]) const [zp, setZp] = useState([]) const [kanwilSelected, setKanwilSelected] = useState([]) const [kppSelected, setKppSelected] = useState([]) const [seksiSelected, setSeksiSelected] = useState([]) const [arSelected, setArSelected] = useState([]) const [zpSelected, setZpSelected] = useState([]) const toggle = (tab) => { setTabActive(tab) } useEffect(() => { jquery.ajax({ url: '/engineN/kewilayahan/ref/propinsi', method: 'GET', dataType: 'json', success: (data) => { setProp(data) } }) jquery.ajax({ url: '/engineN/kewilayahan/ref/zpkanwil', method: 'GET', dataType: 'json', success: (data) => { setKanwil(data) } }) }, []) useEffect(() => { setKota([]) setKec([]) setKel([]) setKotaSelected([]) setKecSelected([]) setKelSelected([]) if (propSelected && !isObjEmpty(propSelected)) { const prop = propSelected.value jquery.ajax({ url: '/engineN/kewilayahan/ref/kota', method: 'GET', dataType: 'json', data: { prop }, success: (data) => { setKota(data) } }) } }, [propSelected]) useEffect(() => { setKec([]) setKel([]) setKecSelected([]) setKelSelected([]) if (kotaSelected && !isObjEmpty(kotaSelected)) { const kota = kotaSelected.value jquery.ajax({ url: '/engineN/kewilayahan/ref/kecamatan', method: 'GET', dataType: 'json', data: { kota }, success: (data) => { setKec(data) } }) } }, [kotaSelected]) useEffect(() => { setKel([]) setKelSelected([]) if (kecSelected && !isObjEmpty(kecSelected)) { // const kec = collect(kecSelected).pluck('value').all() const kec = [kecSelected.value] jquery.ajax({ url: '/engineN/kewilayahan/ref/kelurahan', method: 'POST', dataType: 'json', data: { kec }, success: (data) => { setKel(data) } }) } }, [kecSelected]) useEffect(() => { setKpp([]) setSeksi([]) setAr([]) setZp([]) setKppSelected(null) setSeksiSelected([]) setArSelected([]) setZpSelected([]) if (kanwilSelected && !isObjEmpty(kanwilSelected)) { const kanwil = kanwilSelected.value jquery.ajax({ url: '/engineN/kewilayahan/ref/zpkpp', method: 'POST', dataType: 'json', data: { kanwil }, success: (data) => { setKpp(data) } }) } }, [kanwilSelected]) useEffect(() => { setSeksi([]) setAr([]) setZp([]) setSeksiSelected([]) setArSelected([]) setZpSelected([]) if (kppSelected && !isObjEmpty(kppSelected)) { const kpp = kppSelected.value jquery.ajax({ url: '/engineN/kewilayahan/ref/zpseksi', method: 'POST', dataType: 'json', data: { kpp }, success: (data) => { setSeksi(data) } }) } }, [kppSelected]) useEffect(() => { setAr([]) setZp([]) setArSelected([]) setZpSelected([]) if (seksiSelected && !isObjEmpty(seksiSelected)) { const kpp = kppSelected.value // const seksi = collect(seksiSelected).pluck('value').all() const seksi = [seksiSelected.value] jquery.ajax({ url: '/engineN/kewilayahan/ref/zpar', method: 'POST', dataType: 'json', data: { kpp, seksi }, success: (data) => { setAr(data) } }) } }, [seksiSelected]) useEffect(() => { setZp([]) setZpSelected([]) if (arSelected && !isObjEmpty(arSelected)) { const kpp = kppSelected.value // const seksi = collect(seksiSelected).pluck('value').all() const seksi = [seksiSelected.value] // const ar = collect(arSelected).pluck('value').all() const ar = [arSelected.value] jquery.ajax({ url: '/engineN/kewilayahan/ref/zpzp', method: 'POST', dataType: 'json', data: { kpp, seksi, ar }, success: (data) => { setZp(data) } }) } }, [arSelected]) const toggleDrawer = (anchor, open) => (event) => { if (event && event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) { return } setIsOpenPopUpWilayah(open) } const toggleTab = (newVal) => { setTabActive(newVal) } const onClickReset = () => { dispatch(setCqlFilterWilayah('(1=1)')) refFeatureBawah.current.clearLayers() matoaLayers.poiMatoaNpwpLayer.setParams({ styles: 'poi_matoa_npwp', cql_filter: '(1=1)' }) matoaLayers.poiMatoaNpwpNullLayer.setParams({ styles: 'poi_matoa_npwp_null', cql_filter: '(1=1)' }) // matoaLayers.poiGoogleLayer.setParams({ // styles: 'poi_google', // cql_filter: '(1=1)' // }) setIsOpenPopUpWilayah(false) } const buttonProsesOnClick = () => { refFeatureBawah.current.clearLayers() const opsiWilZona = tabActive // const adm4_pcode = collect(kelSelected).pluck('value').all() const adm4_pcode = [kelSelected.value] // const adm4_pcode2 = collect(kelSelected).pluck('value2').all() const adm4_pcode2 = [kelSelected.value2] const id_poly_zona = collect(zpSelected).pluck('value').all() const id_poly_zona2 = collect(zpSelected).pluck('value2').all() switch (opsiWilZona) { case 'wilayah': console.log('wilayah selected') if (adm4_pcode.length) { dispatch(setSelectedOpsi(dataOpsi.wilayah)) setDataSend({ opsiWilZona: dataOpsi.wilayah.key, adm4_pcode, id_poly_zona: [] }) //ID_POLY_ZONA const par_kelurahan = adm4_pcode2.join("','") const cq_filter_poi = "ADM4_PCODE in ('" + par_kelurahan + "')" dispatch(setCqlFilterWilayah(cq_filter_poi)) matoaLayers.poiMatoaNpwpLayer.setParams({ style: 'poi_matoa_npwp', cql_filter: cq_filter_poi }) matoaLayers.poiMatoaNpwpNullLayer.setParams({ style: 'poi_matoa_npwp_null', cql_filter: cq_filter_poi }) // matoaLayers.poiGoogleLayer.setParams({ // style: 'poi_google', // cql_filter: cq_filter_poi // }) // console.log('wait....') jquery.ajax({ url: '/engineN/kewilayahan/peta/kelurahanpoly', dataType: 'text', type: 'POST', data: { adm4_pcode }, success: (response) => { if (response) { const lyr_kota = L.geoJSON(parse(response), { style: function (feature) { return { color: 'blue', fillOpacity: 0, weight: 2, dashArray: '30 10', interactive: false } } }).addTo(refFeatureBawah.current) map.fitBounds(lyr_kota.getBounds()).setZoom(map.getZoom() - 1) setIsOpenPopUpWilayah(false) } } }) } else { toast.current.show({ severity: 'info', summary: 'Info', detail: 'Kelurahan harus dipilih' }) } break case 'zona': console.log('zona selected') if (id_poly_zona.length) { dispatch(setSelectedOpsi(dataOpsi.zona)) setDataSend({ opsiWilZona: dataOpsi.zona.key, adm4_pcode: [], id_poly_zona }) //ID_POLY_ZONA const par_zona = id_poly_zona2.join("','") const cq_filter_poi = "ID_POLY_ZONA in ('" + par_zona + "')" dispatch(setCqlFilterWilayah(cq_filter_poi)) matoaLayers.poiMatoaNpwpLayer.setParams({ styles: 'poi_matoa_npwp', cql_filter: cq_filter_poi }) matoaLayers.poiMatoaNpwpNullLayer.setParams({ styles: 'poi_matoa_npwp_null', cql_filter: cq_filter_poi }) // matoaLayers.poiGoogleLayer.setParams({ // styles: 'poi_google', // cql_filter: cq_filter_poi // }) jquery.ajax({ url: '/engineN/kewilayahan/peta/zonapoly', type: 'post', dataType: 'text', data: { id_poly_zona }, success: (response) => { if (response) { const lyr_kota = L.geoJSON(parse(response), { style: function (feature) { return { color: 'blue', fillOpacity: 0, weight: 2, dashArray: '30 10', interactive: false } } }).addTo(refFeatureBawah.current) map.fitBounds(lyr_kota.getBounds()).setZoom(map.getZoom() - 1) setIsOpenPopUpWilayah(false) } } }) } else { toast.current.show({ severity: 'info', summary: 'Info', detail: 'Zona harus dipilih' }) } break default: break } } return ( <>
{isTerapkan ? ( ) : ( <> { setKppSelected(e) }} classNamePrefix="select" // defaultValue={kanwilSelected} value={kppSelected} isClearable={false} options={kpp} /> { setArSelected(e) }} classNamePrefix="select" // defaultValue={kanwilSelected} value={arSelected} isClearable={false} options={ar} /> {/* { setArSelected(e) }} labelledBy="Pilih AR" overrideStrings={{ allItemsAreSelected: 'Semua dipilih', selectSomeItems: 'Pilih AR' }} /> */} { setZpSelected(e) }} labelledBy="Pilih Zona" overrideStrings={{ allItemsAreSelected: 'Semua dipilih', selectSomeItems: 'Pilih Zona' }} /> buttonProsesOnClick()} label="Proses" severity="" rounded className="w-10rem text-white text-base" /> { setKotaSelected(e) }} classNamePrefix="select" defaultValue={kotaSelected} value={kotaSelected} isClearable={false} options={kota} /> { setKelSelected(e) }} classNamePrefix="select" defaultValue={kelSelected} value={kelSelected} isClearable={false} options={kel} /> {/* { setKelSelected(e) }} labelledBy="Pilih Kelurahan" overrideStrings={{ allItemsAreSelected: 'Semua dipilih', selectSomeItems: 'Pilih Kelurahan' }} /> */} buttonProsesOnClick()} label="Proses" severity="" rounded className="w-10rem text-white text-base" /> )} {/*
{isTerapkan ? : }
*/} {/* btnBawahProsesOnClick()} className="text-primary text-xl" sx={{ width: '50%', maxWidth: '50% !important' }} label="Terapkan" value="proses" icon={} /> */} onClickReset()} className=" text-xl" sx={{ width: '50%', maxWidth: '50% !important' }} label="Reset Filter" value="clear" icon={} /> setIsOpenPopUpWilayah(false)} color={red[700]} sx={{ width: '50%', maxWidth: '50% !important' }} label="Tutup" value="close" icon={} />
) } export default PopUpWilayah