Comments (9)
I struggled with the same thing and I solved that by setting class to the map element and styling it with CSS. Which I believe should be the best practice anyway.
<Map className="map" ...
.map {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
from react-googlemaps.
I struggled with the same thing and I solved that by setting class to the map element and styling it with CSS. Which I believe should be the best practice anyway.
<Map className="map" ... .map { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
After struggling for 24 hours, you made my day. Thank you sooooooooo much!!!!!!
from react-googlemaps.
For some reason setting width={"100%"}
didn't work the first time I tried, now it works
👍
from react-googlemaps.
I was wrong, setting width={"100%"}
is okay but can't seem to make the height dynamically adjust to the width of the map.
This makes it problematic embedding this in a responsive layout.
Any idea ?
from react-googlemaps.
did not work for me... Usually when adding a google map I just set the width to 100% of the container and the height adjusts itself perfectly.
from react-googlemaps.
you can try using vh
units:
height={"100vh"}
some old browsers don't support it though
from react-googlemaps.
turns out vh
is a nightmare in terms of browser compat, so i'm back to trying to use % based width / height
Don't know if i'm writing this into void or if someone's listening, but i'll write anyway:
Debugging a little further, I found out that if I give the map component's wrapping element height: 100%
and remove it from the map component itself then things are working as expected
i.e. instead of
<div data-reactid=".0.2">
<div style="width: 100%; height: 100%; position: relative; overflow: hidden; transform: translateZ(0px); background-color: rgb(229, 227, 223);" data-reactid=".0.2.0">
<div class="gm-style" style="position: absolute; left: 0px; top: 0px; overflow: hidden; width: 100%; height: 100%; z-index: 0;">
</div>
</div>
</div>
(notice the height / width in the second div)
<div data-reactid=".0.2" style="width: 100%; height: 100%;">
<div style="position: relative; overflow: hidden; transform: translateZ(0px); background-color: rgb(229, 227, 223);" data-reactid=".0.2.0">
<div class="gm-style" style="position: absolute; left: 0px; top: 0px; overflow: hidden; width: 100%; height: 100%; z-index: 0;">
</div>
</div>
</div>
(notice it now in the first div)
Problem is I don't have any access to the wrapping div, as it's generated internally by the component.
I looked at the code a little but couldn't pinpoint an easy solution for this problem.
Any idea ?
from react-googlemaps.
Hi there.
Your problem can be solved with CSS.
Let's say that you want to render map in parent component like this:
render() {
<div className="wrapper">
<OtherComponent />
<Map width="100%" />
</div>
}
Now you know that Map will render div
so you can do in css:
.wrapper > div {
height: 100%;
width: 100%;
}
Yes. We can style that javascripticaly-inaccessible div with CSS child selector.
But remember that this will affect all children elements of type div
. As you can see in the example I have OtherComponent, to build that component I now must use other element for example section
.
Also if our OtherComponent is div
and there is no way to change it, we can use nth:child
selector to select our Map's div wrapper and style it.
Try it :)
from react-googlemaps.
I have tried wrapping it in a div and applying css. Didn't work for me.
I wish I could put a jsfiddle example, but not sure how to pack browserify and react-googlemaps
from react-googlemaps.
Related Issues (20)
- Rerendering all markers
- Confusing instructions on how to run examples HOT 1
- Event listener on OverlayView and its children HOT 2
- Directions
- Unable to Build Examples on 0.4.0
- Cannot install package via NPM HOT 1
- `google.maps` global object not found, make sure Google maps in included before react-googlemaps is defined HOT 2
- server-side rendering HOT 3
- Warning when using google.maps.MVCArray in Polyline path
- t google maps
- Overlay should not draw before it is added to the map
- react-googlemaps for react 0.13.x HOT 8
- Warning: ReactMap is accessing getDOMNode or findDOMNode inside its render().
- future support for isomorhpic apps?
- Get marker instances?
- StreetView
- Cannot resolve module 'react/lib/invariant' HOT 7
- examples did not work: Module not found: Error: HOT 3
- Wall of errors when using in ES6 project HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-googlemaps.