Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.

[r1-dev] How to trigger resize events on the underlying map instance? #114

Closed
fwitzke opened this issue Sep 9, 2013 · 9 comments
Closed

Comments

@fwitzke
Copy link
Contributor

fwitzke commented Sep 9, 2013

Let's say I have a map is inside a div that takes 70% of the width and I want to dynamically change it to 100%. In this case I would need to notify the map it was resized:
google.maps.event.trigger(map, 'resize');

Any ideas on how to accomplish that?

api reference:

Developers should trigger this event on the map when the div changes size: google.maps.event.trigger(map, 'resize').

@nmccready
Copy link
Contributor

I believe sizing is definitely an issue / bug. My main guess right now is that the height is basically hard coded due to some twitter bootstrap issues. @nlaplante can you confirm this?

@ghost ghost assigned nlaplante Sep 10, 2013
@fwitzke
Copy link
Contributor Author

fwitzke commented Sep 10, 2013

@nmccready: I don't think there is any size hard coded, you can set whatever width/height you want and it works fine. The issue happens when you resize the map container div after the map is loaded, which would require us to notify the map it has changed but.

There is a kind-of-related question on stackoverflow

@nmccready
Copy link
Contributor

When I say "hard coded" I mean that the map height will only change via pixel settings. IE height=700px. I would be better if percentage worked since it is way more flexible.

@fwitzke
Copy link
Contributor Author

fwitzke commented Sep 10, 2013

The relative height works only if you set it to all DOM tree until the map itself, I think this is not related to the angular directive. This is the structure you might have with bootstrap, you need to set height on all the elements since html, body and so on.

<html>
  <body>
    <div class="container">
      <div class="row">
        <div class="span*">
          <div class="google.map"> <!-- your map div -->
            <div class="angular-google-map"> <!-- this is generated by the maps directive -->
              <div class="angular-google-map-container"> <!-- this is generated by the maps directive -->

If you miss setting height on one of these the map will have height undefined and won't display.

@TigerNutRulez
Copy link

Adding the following CSS will do the trick:

.angular-google-map {
position: relative;
padding-bottom: 66.67%; /* aspectratio 3:2 */
height: 0;
overflow: hidden;
}
.angular-google-map-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

@23tux
Copy link

23tux commented Apr 3, 2015

@fbuskens Can you explain why this works?

@TigerNutRulez
Copy link

hi 23tux

You can find an explanation here: https://niklausgerber.com/blog/responsive-google-or-bing-maps/

@nmccready
Copy link
Contributor

Nice

@FlavorScape
Copy link

Using that strategy I can successfully resize the angular gmap container and the iframe responds accordingly. however, there is a visual defect in the actual map, it fails to load tiles beyond a certain bounds from the initialization size. My use case is I have a map widget inside a gridster draggable/resizable element.

So, I have an interesting solution. Initialize the map's container size .angular-google-map-container to a known value well above your max size. Like several thousand pixels. Then set your .google-maps:{width:100%;height:100%; etc so that it is liquid (the bounds of the actual map). Then set your overflow on the container to hidden.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants