Giter Club home page Giter Club logo

Comments (6)

Matt-Vance avatar Matt-Vance commented on July 22, 2024 2

FYI I had a similar issue when upgrading to [email protected]. Downgraded back to @5.2.3 and the geocoder now works.

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on July 22, 2024

Hi @LAYTHJABBAR, I think you may be missing some code. I don't see where your Geocoder component is being rendered. I can't really help debug without seeing how you're rendering that component. It would help if you provide a Code Sandbox demonstrating the issue.

You can also check out this closed issue #56.

from react-map-gl-geocoder.

LAYTHJABBAR avatar LAYTHJABBAR commented on July 22, 2024

Hi @SamSamskies thank you for your response, the Gecoder is rendering on GeocoderTag

import './map.scss';
import React, { useRef } from 'react';
import mapboxgl from 'mapbox-gl';
import ReactMapGL, { Marker, Source, layer } from 'react-map-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
import 'react-map-gl-geocoder/dist/mapbox-gl-geocoder.css';
import Geocoder from 'react-map-gl-geocoder';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import DropoffPinWithLayer  from '../../pages/Routing/Components/Pins/dropoffWithLayer'

const Map = (props) => {
  let ZoomCustomer, MarkAllCustomers, GeocoderTag, SearchBarRefrence;
  const geocoderContainerRef = React.useRef();
  const mapRef = useRef();
 
   if(props.isSearchOutOfMap === true) {
    SearchBarRefrence = (<div ref={geocoderContainerRef} />);
   }

  if (props.geocoder == true) {
    GeocoderTag = (
      <Geocoder
        containerRef={geocoderContainerRef}
        mapRef={mapRef}
        onViewportChange={props.handleGeocoderViewportChange}
        mapboxApiAccessToken={mapboxgl.accessToken}
        position={props.position}
        onResult={props.handleOnResult}
        ReverseGeoCode={true}
        onClear={props.handleOnClear}
      />
    );
  }
  if (props.customerToZoom == true) {
    ZoomCustomer = (
      <Marker latitude={props.customerToMark.lat} longitude={props.customerToMark.lon} >
        {props.marker}
      </Marker>
    );
  }
  if (props.customerToZoom == true && props.itsDraggable === true) {
     
    ZoomCustomer = (
      <DropoffPinWithLayer
        location={ props.customerToMark }
        onDragEnd={props.handleOnDragEnd}
        radius={props.radius}
      />
    );
  }

  if (props.markCustomers == true) {
    let customers = props.customers;
    MarkAllCustomers = customers.map((customer) => {
      const { lon, lat, uuid } = customer;
      if (props.customerArr) {
        return (
          <Marker key={uuid} longitude={lon} latitude={lat}>
            <i
              type="button"
              className={clsx(props.styles.pin, { [props.styles.selected]: props.customerArr.includes(customer) })}
              onMouseDown={() => props.mouseDown(customer)}
            />
          </Marker>
        );
      } else if (props.selcustomers) {
        return (
          <Marker key={uuid} longitude={lon} latitude={lat}>
            <i
              type="button"
              className={clsx(props.styles.pin, { [props.styles.selected]: customer.name === props.selCustomer })}
              onMouseDown={() => props.mouseDown(customer.name)}
            />
          </Marker>
        );
      }
    });
  }

  return (
    <div>
  {SearchBarRefrence}
    <ReactMapGL
      {...props.viewport}
      ref={mapRef}
      width={props.width}
      onClick={(event) => {
        props.handleOnClickEnd(event)
      }}
      height={props.height}
      onViewportChange={props.handleViewportChange}
      mapboxApiAccessToken={mapboxgl.accessToken}
      mapStyle="mapbox://styles/mapbox/outdoors-v11"
      >
      {ZoomCustomer}
      {MarkAllCustomers}
      {GeocoderTag}
    </ReactMapGL>
    
    </div>
  );
};

Map.propTypes = {
  width: PropTypes.string,
  onViewportChange: PropTypes.func,
  mapboxApiAccessToken: PropTypes.string,
  onResult: PropTypes.func,
  onClear: PropTypes.func,
  position: PropTypes.string,
  itsDraggable: PropTypes.bool,
  handleOnDragEnd: PropTypes.func,
  radius: PropTypes.number,
  height: PropTypes.string,
  handleOnClickEnd: PropTypes.func,
};

Map.defaultProps = {
  width: '100px',
  handleOnClickEnd: (event) => {console.log(event)},
  handleOnDragEnd: () => {},
  onViewportChange: () => {},
  onResult: () => {},
  onClear: () => {},
  mapboxApiAccessToken: '',
  position: 'top-left',
  itsDraggable: false,
  radius: 0,
  height: "220px"
};

export default Map;

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on July 22, 2024

It looks like you're conditionally rendering the geocoder container. The problem could be that you're rendering the Geocoder and not rendering SearchBarRefrence which would probably cause the errors that you're having. Try removing the containerRef prop to verify.

Another issue that I see is that there is no prop called ReverseGeoCode. I think you want reverseGeocode.

Also, make sure all of the Geocoder props that are objects or functions are memoized. You're passing in a bunch of the props from a parent component, and I'm not sure if you're memoizing the values or not.

from react-map-gl-geocoder.

daniela-green avatar daniela-green commented on July 22, 2024

@Matt-Vance exactly what happened to me. Downgrading to react-map-gl @5.2.3 solved it.

from react-map-gl-geocoder.

LAYTHJABBAR avatar LAYTHJABBAR commented on July 22, 2024

Thanks @Matt-Vance the issue got solved by downgrading react-map-gl to @5.2.3

from react-map-gl-geocoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.