I am trying to shift control of react mapbox builtin button controls over my own button #2201
Unanswered
HamzaIrfan008
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
import React, { useState, useRef, useEffect } from "react";
import {
Accordion,
AccordionDetails,
AccordionSummary,
Button,
} from "@mui/material";
import { ExpandMore } from "@mui/icons-material";
import AddIcon from "assets/svg/AddIcon.svg";
import { NormalInput } from "component/common";
import { NormalButton } from "component/common/NormalButton";
import { getZonesListApi } from "action/Programs/zonesAct";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import ReactMapboxGl, { Layer, Feature } from "react-mapbox-gl";
import DrawControl from "react-mapbox-gl-draw";
import "@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css";
import "../style.scss";
import { Header } from "component/common/ProgramsHeader";
import "mapbox-gl/dist/mapbox-gl.css";
import { ColorPicker } from "react-color-palette";
import CustomModal from "component/common/Modal";
const ZonesFCMain = (props) => {
const Map = ReactMapboxGl({
accessToken:
"pk.eyJ1IjoiZGFpbWsiLCJhIjoiY2ttbmt2dzc2MXZ1bjJwcGZsZndoaGdkbiJ9.KzEXKpaGb0yYkV8Npdg65g",
});
const mapRef = useRef(null);
const drawControlRef = useRef(null);
const [openZoneModal, setOpenZoneModal] = useState(false);
const [color, setColor] = useState("#121212");
const [totalValue, setTotalValue] = useState([]);
const [modalValue, setModalValue] = useState({
zoneName: "",
description: "",
});
useEffect(() => {
props.getZonesListApi().then((res) => {
console.log("####", res);
});
}, []);
const handleInput = (e) => {
let { value, name } = e.target;
setModalValue({ ...modalValue, [name]: value });
};
const handleAddZone = () => {
setTotalValue([...totalValue, { ...modalValue, color: color }]);
setModalValue({ zoneName: "", description: "" });
setOpenZoneModal(false);
};
const handleCancel = () => {
setOpenZoneModal(!openZoneModal);
};
const handleDelete = (item) => {
let findItem = totalValue.filter((e) => e.zoneName !== item.zoneName);
setTotalValue(findItem);
};
const onDrawCreate = ({ features }) => {
console.log("features", features);
// Handle the created polygon features
};
const onDrawUpdate = ({ features }) => {
console.log("features 2", features);
// Handle the updated polygon features
};
const handleMapLoad = (map) => {
mapRef.current = map;
drawControlRef.current = mapRef.current.drawControl;
};
const handleAddPolygon = () => {
if (drawControlRef.current) {
const drawControl = drawControlRef.current;
drawControl.changeMode("draw_polygon");
drawControl.onCreate({
features: [],
});
}
};
return (
<CustomModal
isOpen={openZoneModal}
size="md"
title="ADD ZONE"
onClose={() => {
setOpenZoneModal(false);
setModalValue({ name: "", description: "" });
}}
>
);
};
const mapDispatchToProps = (dispatch) => {
return bindActionCreators(
{
getZonesListApi,
},
dispatch
);
};
const Zones = connect(null, mapDispatchToProps)(ZonesFCMain);
export default Zones;
How can I create custom controls ?
Beta Was this translation helpful? Give feedback.
All reactions