GithubHelp home page GithubHelp logo

Comments (16)

istarkov avatar istarkov commented on May 18, 2024

What if you explicitly set width and remove display css prop
<div style={{height: "400px", width: "400px" }}>
?

Does window resize helps?

from google-map-react.

mbrookes avatar mbrookes commented on May 18, 2024

Hi @istarkov, window resize followed by moving the map does reposition the icon.

I narrowed it down to being related to a css zoom animation applied to one of the outer components by <ReactCSSTransitionGroup>. The CSS is "borrowed" from animate.css. This uses transform: scale3d(.3, .3, .3) which I believe is the cause.

Is there perhaps a way to defer the marker placement until after the animation completes?

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024

This is because on the moment of GoogleMap component created, size of it's container is unknown or small (because of animation).
It's almost impossible in browser without periodic checks to get component size. So one solution is to create GoogleMap control after animation completes.

Other hack solution is to call via ref next method on GoogleMap:

googleMapRef_._setViewSize(); and modify center prop on small small delta.

example:

// CALL THIS TO REFRESH SIZE
refresh() {
   this.googleMapRef_._setViewSize();
  // mb will work without changing center 
  this.setState({
     center: {
       lat: this.state.center.lat + 0.000000001,
       lng: this.state.center.lng + 0.000000001,
      }, 
   });
}

render() {
  return (
    <GoogleMap ref={r => this.googleMapRef_ = r} 
      center={this.state.center} 
      defaultZoom={10}><Marker lat lng/>...
  );
}

from google-map-react.

mbrookes avatar mbrookes commented on May 18, 2024

Thank you for your help!

from google-map-react.

martingg88 avatar martingg88 commented on May 18, 2024

@istarkov. tried your given hack solution and don't think it will work if change the height of div container after resize.

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024

@martingg88 Why u think so?

@mbrookes Does this hack works for you?

from google-map-react.

martingg88 avatar martingg88 commented on May 18, 2024

i tried it and it doesn't work..

it will work if i do not change height after resize.

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024

Provide source

from google-map-react.

martingg88 avatar martingg88 commented on May 18, 2024

run the following function and then your hack solution in onresize event.

_performLayoutFrame: function(){
this.height = window.clientHeight;
this.width = window.clientWidth;
this.refs.map_container.style.width= (this.width) + 'px';
this.refs.map_container.style.height = (this.height) + 'px';
},

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024

In onresize event? Why?

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024

Also

this.height = window.clientHeight;
this.width = window.clientWidth;
this.refs.map_container.style.width= (this.width) + 'px';
this.refs.map_container.style.height = (this.height) + 'px';

Do u think this is react?

from google-map-react.

martingg88 avatar martingg88 commented on May 18, 2024

i need to resize the container to fit into the visible screen when user resize the browser or rotate mobile device.

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024
  1. Never mutate Dom directly
  2. Call refresh NOT inside resize event handler (GoogleMap smart enough to do it)
  3. Call refresh after u changed size of above container. (ComponentDidUpdate is a good place for that)

from google-map-react.

martingg88 avatar martingg88 commented on May 18, 2024

it won't work after try to follow your suggestion.
it will only work without change height dimension for container.

from google-map-react.

istarkov avatar istarkov commented on May 18, 2024

I can't say anything without full component source

from google-map-react.

leehart avatar leehart commented on May 18, 2024

The following is working for me, but seems very smelly. Any improvements?

  onResize : function() 
  {
    this._googleMapRef._setViewSize();

    if (this.state.maps && this.state.map)
    {
      let center =  this.state.map.getCenter();
      this.state.maps.event.trigger(this.state.map, 'resize');
      this.state.map.setCenter(center);
    }
  }
...
      <DetectResize onResize={this.onResize}>
        <GoogleMap
          center={center}
          zoom={zoom}
          yesIWantToUseGoogleMapApiInternals={true}
          onGoogleApiLoaded={({map, maps}) => this.setState({map: map, maps: maps})}
          options={getMapOptions}
          ref={r => this._googleMapRef = r}
        >
...

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.