Giter Club home page Giter Club logo

Comments (6)

bguillozet avatar bguillozet commented on September 26, 2024

FYI: googlemaps/react-wrapper#642

from google-map-react.

HelloNeptune avatar HelloNeptune commented on September 26, 2024

I found a workaround until this issue get resolved;

with react 18 you can use createRoot method from 'react-dom/client' module so, in the onGoogleApiLoaded callback it is possible to render your custom marker into the map dynamically;

import { createRoot } from 'react-dom/client';
...

const HQMarkerTemplate: React.FC = () => (
  <>
   <div>Test Marker</div>
  </>
);

export const MapHandler = () => {
  const handleApiLoaded = (map: GoogleMapReact, maps: any) => {
    const HQMarker = function (lat, lng) {
        this.lat = lat;
        this.lng = lng;
        this.pos = new maps.LatLng(lat, lng);
    };

    HQMarker.prototype = new maps.OverlayView();
    HQMarker.prototype.onAdd = function () {

      // here is the solution -->
      const container = document.createElement('span');
      const root = createRoot(container);
      root.render(<HQMarkerTemplate />);

      const panes = this.getPanes();
      panes.overlayImage.appendChild(container);
    };

    HQMarker.prototype.draw = function () {
      var overlayProjection = this.getProjection();
      var position = overlayProjection.fromLatLngToDivPixel(this.pos);
      var panes = this.getPanes();
      panes.overlayImage.style.left = position.x + "px";
      panes.overlayImage.style.top = position.y - 20 + "px";
    };

    new HQMarker(endPoint.lat, endPoint.lng).setMap(map);
  };

    ...
    ...
    ...


  return (
    <GoogleMapReact
        yesIWantToUseGoogleMapApiInternals
        onGoogleApiLoaded={({ map, maps }) => handleApiLoaded(map, maps)}
        options={...}
    />
  )
}

from google-map-react.

tragicmj avatar tragicmj commented on September 26, 2024

@HelloNeptune from where is endPoint coming?

from google-map-react.

HelloNeptune avatar HelloNeptune commented on September 26, 2024

@HelloNeptune from where is endPoint coming?

Its just an object which contains lat and lng fields

from google-map-react.

tragicmj avatar tragicmj commented on September 26, 2024

@HelloNeptune from where is endPoint coming?

Its just an object which contains lat and lng fields

I do understand that but it not defined anywhere else, it is throwing error at my end, endPoint is undefined

from google-map-react.

HelloNeptune avatar HelloNeptune commented on September 26, 2024

@HelloNeptune from where is endPoint coming?

Its just an object which contains lat and lng fields

I do understand that but it not defined anywhere else, it is throwing error at my end, endPoint is undefined

You can use your own values 👍

from google-map-react.

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.