Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markers are at not correct location in Mobile #2318

Closed
bsrinath4839 opened this issue Nov 18, 2023 · 6 comments
Closed

Markers are at not correct location in Mobile #2318

bsrinath4839 opened this issue Nov 18, 2023 · 6 comments
Labels

Comments

@bsrinath4839
Copy link

Description

Hi,

This is my code

import "mapbox-gl/dist/mapbox-gl.css";
import MapBoxGL from "mapbox-gl";
import MapDotIcon from "../../assets/icons/MapDotIcon";
import React from "react";
import { filterByType } from "../../helpers/filterData";
import { mapConfig } from "../../constants/map.constants";
import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux";
import ReactMapGl, { Marker, NavigationControl } from "react-map-gl";

const Map = () => {
  const nodes = useSelector((state) => state.data.nodes);
  const mapState = useSelector((state) => state.map.viewport);
  const navigate = useNavigate();
  const mapRef = React.useRef();

  const data = filterByType(nodes.data, nodes.filterBy);

  const handleMarkerClick = (address) => {
    navigate(`/nodes/${address}`);
  };

  React.useEffect(() => {
    if (mapRef && mapRef?.current) {
      mapRef.current?.flyTo({
        center: [mapState.longitude, mapState.latitude],
        duration: 8000,
        essential: true,
        zoom: mapState.zoom,
      });
    }
  }, [mapState.longitude, mapState.latitude, mapState.zoom]);

  const initialViewState = {
    bearing: 0,
    latitude: mapState.latitude,
    longitude: mapState.longitude,
    pitch: 0,
    zoom: mapState.zoom,
  };

  const settings = {
    doubleClickZoom: true,
    dragPan: true,
    dragRotate: false,
    interactive: true,
    maxPitch: 0,
    maxZoom: 14,
    minPitch: 0,
    minZoom: 2.5,
    renderWorldCopies: false,
    touchPitch: false,
    touchZoomRotate: false,
  };

  return (
    <ReactMapGl
      mapLib={MapBoxGL}
      mapboxAccessToken={mapConfig.token}
      ref={mapRef}
      maxBounds={[
        [-180, -90],
        [180, 90],
      ]}
      style={{ height: "100vh", width: "100vw" }}
      mapStyle={mapConfig.styles.custom}
      logoPosition="bottom-right"
      initialViewState={initialViewState}
      {...settings}
    >
      {data &&
        data.length > 0 &&
        data.map(({ location, address }, index) => (
          <Marker
            key={`marker-${index}`}
            onClick={() => handleMarkerClick(address)}
            latitude={location.latitude}
            longitude={location.longitude}
            style={{ cursor: "pointer" }}
            anchor="center"
          >
            <MapDotIcon />
          </Marker>
        ))}
      <NavigationControl position={"bottom-right"} zoomDiff={1} />
    </ReactMapGl>
  );
};

export default Map;

In Mobile view, the Markers are not showing at the correct place.
They are showing a lot below the actual location.

Expected Behavior

When I open in Desktop the Markers are at the correct place, even in Mobile Dimensions.
But When I open it on my mobile those are in the wrong place.

I am expecting this to get resolved.

Steps to Reproduce

I have provided the code above, let me know if any mistakes in it.

Environment

  • Framework version: "react-map-gl": "^7.1.6",
  • Map library: "mapbox-gl": "^2.15.0",
  • Browser: Mobile, Chrome
  • OS: Android, iOS

Logs

No response

@Pessimistress
Copy link
Collaborator

Hello, we cannot reproduce your issue from partial code. If you believe there is a bug, please create a Code Sandbox. Otherwise go to Discussions to get generic help with debugging your own application.

@bsrinath4839
Copy link
Author

If you check in the provided video, the upper part of the map is going behind the address bar, and the markers are in the wrong location.

2023-11-19.08.20.59.mp4

@bsrinath4839 bsrinath4839 changed the title [Bug]: Markers are at not correct location in Mobile Markers are at not correct location in Mobile Nov 19, 2023
@bsrinath4839
Copy link
Author

Hello, we cannot reproduce your issue from partial code. If you believe there is a bug, please create a Code Sandbox. Otherwise go to Discussions to get generic help with debugging your own application.

I have provided a video for your reference.

@Pessimistress
Copy link
Collaborator

We cannot debug from a video. If you are unable to provide reproduction I'm going to close this issue.

@bsrinath4839
Copy link
Author

We cannot debug from a video. If you are unable to provide reproduction I'm going to close this issue.

Found the issue.

Removing this from public/index.html is causing misplacement of the Markers

Here is sandbox.
https://codesandbox.io/p/devbox/serene-benji-4vgptf?file=%2Fpublic%2Findex.html%3A6%2C7-6%2C93

The thing is I don't want this for my app.

Any Idea how to tackle this??

@Pessimistress
Copy link
Collaborator

You can refer to mapbox's example for the correct meta tag to set. If you still have a problem with it, you should report the issue to mapbox-gl instead.

@Pessimistress Pessimistress closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants