UNPKG

oneframe-react

Version:

Oneframe React ## Components, Hooks, Helper Functions & State Management

39 lines (38 loc) 1.44 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const withMap_1 = require("./withMap"); const PolygonComponent = (props) => { const { map, data, setPolygonLatLng, setPolygon, options, onClick, resetPolygon } = props; const [polygon, setPolygonObject] = react_1.useState(); react_1.useEffect(() => { if (map) { setPolygonObject(new google.maps.Polygon()); } }, [map]); const handleClick = (e) => { onClick && onClick(options); resetPolygon && resetPolygon(); }; react_1.useEffect(() => { if (polygon && map) { data.forEach((obj) => { setPolygonLatLng && setPolygonLatLng(obj); }); setPolygon && setPolygon(polygon); polygon.setPaths(data); polygon.setMap(map); polygon.addListener('click', handleClick); } // eslint-disable-next-line }, [polygon, data, map]); return react_1.default.createElement(react_1.default.Fragment, null); }; exports.default = withMap_1.withMap(PolygonComponent);