Zoom-Scrolling not Working in Pigeon-Maps ReactJS - reactjs

I have a problem with pigeon-maps in my reactjs-app. Using the mouse to navigate through the map works fine, but zooming with the scroll wheel does not work. However, a double-click zooms in the map, but then i have no way of zooming out again.
zoom and center are controlled variables.
<Map
limitBounds='edge'
center={center}
onBoundsChanged={res => {setCenter(res.center); setZoom(res.zoom)}}
zoom={zoom}
provider={provider}
onClick={changeLocation}
width={width}
height={height}
zoomOnMouseWheel={true}
animate={true}>
{renderMarkers()}
</Map>
Once rendered the component looks like this:
These are the dependencies i am using:
"dependencies": {
"#types/jest": "^25.1.4",
"#types/node": "^13.9.0",
"#types/react": "^16.9.23",
"#types/react-dom": "^16.9.5",
"axios": "^0.19.0",
"classnames": "^2.2.6",
"pigeon-maps": "^0.14.0",
"pigeon-overlay": "^0.2.3",
"react": "^16.11.0",
"react-cookie": "^4.0.3",
"react-dom": "^16.11.0",
"react-redux": "^7.1.3",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.1",
"react-spring": "^8.0.27",
"react-use-clipboard": "1.0.2",
"reactjs-popup": "^1.5.0",
"redux": "^4.0.5",
"sockjs-client": "^1.4.0",
"stompjs": "^2.3.3",
"typescript": "^3.8.3"
}
If any of you have an Idea what might be causing my problem, i would be thankful if you shared it with me.
Best regards,
Koenigstein
edit: the whole code :
import React, {useEffect, useState} from 'react'
import Map from "pigeon-maps";
import "./editor.css";
export default function EditorInterface(props) {
const [selectedLocation, setSelectedLocation] = useState([0,0]);
const defaultWidth = window.innerWidth * 0.6;
const defaultHeight = window.innerHeight * .50 - 24;
const [zoom, setZoom] = useState(13);
const [width, setWidth] = useState(defaultWidth);
const [height, setHeight] = useState(defaultHeight);
const [center, setCenter] = useState([49.750049, 6.637275]);
const provider = (x, y, z) => {
const s = String.fromCharCode(97 + (x + y + z) % 3);
return `https://${s}.tile.openstreetmap.org/${z}/${x}/${y}.png`
};
const changeLocation = (e) =>{
setSelectedLocation(e.latLng);
};
return (
<div className="wrapper">
<div>
<Map
limitBounds='edge'
center={center}
onBoundsChanged={res => {setCenter(res.center); setZoom(res.zoom)}}
zoom={zoom}
provider={provider}
onClick={changeLocation}
width={width}
height={height}
zoomOnMouseWheel={true}
animate={true}>
</Map>
</div>
</div>
);
};
The component is being used here:
import React from 'react';
import {
BrowserRouter as Router,
Route} from "react-router-dom";
import AdminInterface from "./components/admininterface/AdminInterface";
import Watermark from "./components/watermark/Watermark";
import UserInterface from "./components/userinterface/UserInterface";
import EditorInterface from "./components/editorinterface/EditorInterface"
const App = () => {
return (
<Router>
<Route exact path={"/"} render={() =>
<UserInterface/>
}/>
<Route path={"/admin"} render={() =>
<AdminInterface/>
}/>
<Route path={"/scenarioCreator"} render={() =>
<EditorInterface/>
}/>
<Watermark/>
</Router>
);
};
export default App;

I will close this for now, because as DILEEP THOMAS pointed out, there is nothing wrong with the code, there seems to be something wrong with my project configuration or something else.
I will try to figure it out myself first.

According to pigeon-maps docs, you need to press (cmd/win) key while zooming with the mouse wheel
metaWheelZoom - Zooming with the mouse wheel only works when you hold down the meta (cmd/win) key. Defaults to false.
Docs here : https://github.com/mariusandra/pigeon-maps

Related

Gatsby 5, TS and new Slice component

Not sure if we are missing something obvious here.The documentation for slices says that you're supposed to be able to use children as usual for a slice component.
But whenever I add a child of any type. Like fragment, custom component or just plain HTML i get this:
The error goes away if I remove child props.
The rendered slice component looks like this:
const Layout = ({
children,
data,
}: SliceComponentProps<LayoutProps>) => {
const { meetingPlace, menuCards, menuItem } =
data.contentfulMeetingPlacePageHome;
return (
<>
{meetingPlace && (
<TabBar
menuGroups={menuItem}
menuCards={menuCards}
logo={meetingPlace?.logo}
socialMediaLinks={meetingPlace?.socialMediaLinks}
meetingPlace={meetingPlace}
/>
)}
<div className="relative lg:px-28 xl:container xl:px-28">
{meetingPlace && (
<Header meetingPlace={meetingPlace} logo={meetingPlace?.logo} />
)}
{children}
</div>
</>
);
};
export default Layout;
export const query = graphql`
...
`;
And
Inside gatsby-node I run the following code to create the slice:
actions.createSlice({
id: 'layout',
component: path.resolve('./src/components/layout/layout.tsx'),
});
I get same error even I make a simple dummy slice component with no data as long as it a child of any kind.
Have the following gatsby packages in the project:
"gatsby": "5.3.3",
"gatsby-plugin-google-tagmanager": "^5.3.1",
"gatsby-plugin-image": "^3.3.2",
"gatsby-plugin-manifest": "^5.3.1",
"gatsby-plugin-react-helmet": "^6.3.0",
"gatsby-plugin-react-svg": "^3.3.0",
"gatsby-plugin-robots-txt": "^1.8.0",
"gatsby-plugin-sass": "^6.3.1",
"gatsby-plugin-sharp": "^5.3.2",
"gatsby-plugin-sitemap": "^6.3.1",
"gatsby-source-contentful": "^8.3.1",
"gatsby-source-filesystem": "^5.3.1",
"gatsby-transformer-inline-svg": "^1.2.0",
"gatsby-transformer-sharp": "^5.3.1",
"gatsby-plugin-postcss": "^6.3.0",

webpack 5: magic comments not working for images

I am trying to preload/prefetch an image so that I don't have to be connected to the internet at the exact moment to display the image. It's for a "you are offline" page in my app.
My app is written in React and I am using webpack for my bundler.
I was reading online that the webpack magic comments feature might be able to do that.
https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c
It's not working for me.
The image that I am trying to preload/prefetch does not show and there is no <link rel tag added to the DOM.
Checkout the demo repository here:
https://github.com/aubreyquinn/preload-webpack-demo/tree/main
package.json:
"devDependencies": {
"#babel/core": "^7.19.6",
"#babel/preset-env": "^7.19.4",
"#babel/preset-react": "^7.18.6",
"babel-loader": "^8.2.5",
"css-loader": "^6.7.1",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^3.3.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
You have to use the useState hook to trigger the re-render, The webpack prefetching is working fine but react is not re-rendering since it is unaware of such loading.
import React, { useEffect, useState } from "react";
import Flowers from "../assets/flowers.jpg";
// Home component
const Home = () => {
const [lilies, setLilies] = useState(null);
useEffect(() => {
import(/* webpackPrefetch: true */ "../assets/lilies.jpg").then((res) => {
console.log(res);
setLilies(res.default);
});
}, []);
return (
<>
<div>React Application</div>
<img src={Flowers} height={200} />
<img src={lilies} height={200} />
</>
);
};
export default Home;
Try the above code out, it's working just fine.

Bootstrap React Component Fails to Load

I've created a react component called ImagePost and when I call it in my App.js it doesn't return on page load.
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
const ImagePost = () => {
return (
<div className='container'>
<Container fluid='md'>
<Col xs={6}><img src={'./Images/lonepeak.jpg'} alt="Post Image"></img></Col>
<Row>
<Col>Title</Col>
<Col>Description</Col>
</Row>
</Container>
</div>
)
}
export default ImagePost
Pls, check you imported the function at the top of app.js and that paths are correctly done.
If it is inside the route check the routing path. It works finely in my local(attached img at the bottom).
in app.js:
import ImagePost from "./ImagePost/ImagePost";
...
<Route path="/imagePost" element={<ImagePost></ImagePost>} />
package.json:
"react": "^18.2.0",
"react-activity": "^2.1.3",
"react-bootstrap": "^2.5.0",
"react-dom": "^18.2.0",
"react-router-bootstrap": "^0.26.2",
"react-router-dom": "^6.3.0",

Display marker in react-mapbox-gl with Feature and Layers

I'm using the example code that's on the "alex3165/react-mapbox-gl" GitHub repo. Not the example folder but the Getting Started example. The map shows but the marker just doesn't show. Not sure what I am dong wrong. Been cracking my head around such a basic thing but just cant solve it. I have looked at previous questions on the net around this topic but none is a solution for me. Here is my code and my dependencies. Help will be really appreciated. Thanks in advance guys.
PACKAGE JSON
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"mapbox-gl": "^1.13.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-mapbox-gl": "^5.0.0",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
},
CODE:
import React, { useState } from "react";
import "./App.css";
import ReactMapboxGl, { Layer, Feature, Marker } from "react-mapbox-gl";
const Map = ReactMapboxGl({
accessToken: "<my access token goes here>",
});
function App() {
const [Zoom, setZoom] = useState(10);
const [coordinates, setcoordinates] = useState([28.0473197, -26.2041059]);
return (
<div className="App">
<Map
center={coordinates}
zoom={[Zoom]}
// eslint-disable-next-line react/style-prop-object
style="mapbox://styles/mapbox/streets-v9"
containerStyle={{
height: "100vh",
width: "100vw",
}}
>
<Layer type="symbol" id="marker" layout={{ "icon-image": "marker-15" }}>
<Feature coordinates={[28.0473197, -26.2041059]} />
</Layer>
</Map>
</div>
);
}
export default App;

Two Datepickers from formik-material-ui-pickers collide

I have a Formik form where I have two Datepickers from formik-material-ui-pickers
import {Field, Form} from "formik";
import React from "react";
import Button from "#material-ui/core/Button";
import { TextField } from "formik-material-ui";
import { DatePicker } from "formik-material-ui-pickers";
import InputAdornment from "#material-ui/core/InputAdornment";
import "./drillForm.css"
export function DrillForm(props) {
return (
<Form className="drillForm" onSubmit={props.handleSubmit}>
<div className="fieldSet">
<DatePicker label="FabricacĂ­on" name="built" />*
<DatePicker label="GarantĂ­a" name="warranty" />
</div>
</Form> );
}
If I remove any of them the remaining Datepicker work like a charm but if I try to use them together they race into this repeating error
index.js:1 Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
in PickerWithState (created by FormikMaterialUIDatePicker)
in FormikMaterialUIDatePicker (at drillForm.jsx:23)
in div (at drillForm.jsx:21)
in div (at drillForm.jsx:12)
in form (created by Form)
...
This is the component where I get the data and render the Form
import React, { useEffect } from "react";
import { useHistory} from "react-router";
import { useDispatch, useSelector } from "react-redux";
import { Formik } from "formik";
import {actions as drillActions} from "../../../ducks/drills";
import CircularProgress from "#material-ui/core/CircularProgress";
import {DrillForm} from "../../elements/forms/drillForm";
import Paper from "#material-ui/core/Paper";
import "./drillEdit.css"
import moment from "moment";
export default function ({idx}) {
const history = useHistory();
const dispatch = useDispatch();
const {username, token} = useSelector(({user})=> user);
const [drill, updating, errors] =
useSelector(({drills})=> [drills.drills[idx], drills.update, drills.errors]);
useEffect(
() => {
dispatch(drillActions.get(username, token, idx));
}, []
);
console.log("form Drill", {...drill});
return (
<Paper className="editForm">
<div>
<h1>{drill?drill.name:"Collecting Data"}</h1>
<h2>{drill?"Edit your drill " : "It may take few seconds"}</h2>
</div>
<div>
{drill?
<Formik
initialValues={drill}
initialErrors={errors}
onSubmit={(values, actions) => {
dispatch(drillActions.update(username, token, values));
actions.setSubmitting(false);
}}
>
{formikProps => <DrillForm {...formikProps} history={history}
updating={updating}/>}
</Formik>
: <CircularProgress/>
}
</div>
</Paper>);
These are my dependencies:
"#material-ui/core": "^4.8.3",
"#material-ui/icons": "^4.5.1",
"#material-ui/styles": "^4.8.2",
"#material-ui/pickers": "^3.2.10",
"#reduxjs/toolkit": "^1.2.3",
"formik": "^2.1.2",
"formik-material-ui": "^2.0.0-alpha.2",
"formik-material-ui-pickers": "^0.0.4",
"material-ui-popup-state": "^1.5.1",
"moment": "^2.24.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-redux": "^7.1.3",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-observable": "^1.2.0",
"remote-redux-devtools": "^0.5.16",
"#date-io/moment": "1.3.13",

Resources