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

[master][develop] Refresh is expecting coordinates? {in-progress} #230

Closed
jeppebemad opened this issue Jan 28, 2014 · 22 comments
Closed

[master][develop] Refresh is expecting coordinates? {in-progress} #230

jeppebemad opened this issue Jan 28, 2014 · 22 comments
Assignees
Labels
Milestone

Comments

@jeppebemad
Copy link

First of all, thanks for the work on this module!

I'm trying to get my map to refresh, but I've found that the $watch function for refresh() is expecting coordinates. See below:

        scope.$watch("refresh()", function(newValue, oldValue) {
          var coords;
          if (newValue && !oldValue) {
            coords = new google.maps.LatLng(newValue.latitude, newValue.longitude);

Is this a bug or am I missing something? Cheers.

@nlaplante
Copy link
Contributor

@nmccready you got a clue? i recall it should be a boolean value

@nmccready
Copy link
Contributor

This is the map directive? I'll have to look later or this weekend. I am slammed with work :/ .

@nmccready
Copy link
Contributor

It looks like refresh is expected to be a function. Have you tried passing coords into the bounded refresh callback? IE whatever function you have linked to refresh.

@nmccready
Copy link
Contributor

Actually whatever refresh is linked to should be returning coords.

@jeppebemad
Copy link
Author

Wouldn't that just make the refresh attribute a way of panning/centering when the refresh evaluates to new coordinates?

In my case I want to refresh the map when a specific page is visible, ie. refresh="isCurrentPage('map')"

Actually I'm thinking that the content of this watch was copied from the watch on center, and never replaced. It should just call
google.maps.event.trigger(_m, "resize");

@nlaplante
Copy link
Contributor

The refresh attribute on the google-map directive was (and I think should
still be) a way to tell the map to redraw itself. This is useful if the map
is initialized while hidden (like in another tab).

The refresh attribute is an expression. In the directive it is treated as a
function (see how it is declared in the scope). By calling this function,
it evaluates the expression given in the argument.

So:

<google-map ... refresh="activeTab == 'myTab'">...</google-map>

In this case, the refresh "function" in the directive is equivalent to:

function () { return scope.activeTab == 'myTab'; }

Sent from Gmail web

On Tue, Jan 28, 2014 at 6:08 PM, jeppebemad [email protected]:

Wouldn't that just make the refresh attribute a way of panning/centering
when the refresh evaluates to new coordinates?

In my case I want to refresh the map when a specific page is visible, ie.
refresh="isCurrentPage('map')"

Actually I'm thinking that the content of this watch was copied from the
watch on center, and never replaced. It should just call
google.maps.event.trigger(_m, "resize");

Reply to this email directly or view it on GitHubhttps://github.com//issues/230#issuecomment-33538393
.

@jeppebemad
Copy link
Author

Exactly. The watch function works when written like this:

scope.$watch("refresh()", function(newValue, oldValue) {
if (newValue && !oldValue) {
google.maps.event.trigger(_m, "resize");
}
});

@nlaplante
Copy link
Contributor

In the legacy branch, this was handled like this:

scope.$watch("refresh()", function (newValue, oldValue) {
            if (newValue && !oldValue) {
              _m.draw();
            }
          }); 

And _m.draw() was:

// Refresh the existing instance
          google.maps.event.trigger(_instance, "resize");

          var instanceCenter = _instance.getCenter();

          if (!floatEqual(instanceCenter.lat(), that.center.lat())
            || !floatEqual(instanceCenter.lng(), that.center.lng())) {
              _instance.setCenter(that.center);
          }

          if (_instance.getZoom() != that.zoom) {
            _instance.setZoom(that.zoom);
          }   

@nmccready you have an idea why this has changed?

@nmccready
Copy link
Contributor

I'll have to look into this deeper, but the m.draws() commented out due to performance issues, and unnecessary draws (I think).

@ansonphong
Copy link

When I instantiate the built-in 'refresh' attribute in the map directive, it is just giving a grey screen in the map with no controls. Played around with it for too long with no luck.

So I'd like to run the resize manually. For instance:

google.maps.event.trigger(_m, "resize");

When I run this, it errors with:

ReferenceError: _m is not defined

Where/what is the map instance defined?

@nmccready
Copy link
Contributor

You can grab the map instance via tiles loaded. See go to the google plus communities and search FAQ.

#219

https://plus.google.com/communities/101653511105172739950

@ansonphong
Copy link

In what context is this hook happening? I just want to refresh the map because it's staying locked as though it thinks it's only 1x1 pixels dimension, since it was hidden on page load.

So do I add this to my controller? Then how to access the name? Can you give a concrete example?

angular.extend($scope, {
        map:{
            events: {
                tilesloaded: function (map, eventName, originalEventArgs) {
                },
        }
    });

I simply want to call google.maps.event.trigger(_m, "resize"); to resize the map, though need a definition for _m.

PS - Forgive my ignorance, I'm still getting the hang of this maps extension. Working well so far.

@nmccready
Copy link
Contributor

I'll work on this if I have time this week, or definitely the weekend.

@nmccready nmccready self-assigned this Feb 5, 2014
@nmccready nmccready added this to the 1.1.0 milestone Feb 5, 2014
@ansonphong
Copy link

Any action on this? Let me know what you think. Just looking for solid method to refresh the map manually.

@nmccready
Copy link
Contributor

more info at #52

@nmccready
Copy link
Contributor

I am looking at this now and will have an answer for you shortly.

@nmccready
Copy link
Contributor

So one issue is this problem goes back b4 I even started working on this. The refresh seems incorrect back here https://github.com/nlaplante/angular-google-maps/blob/aded23bd7922bca7055c73606dd3f78d00ee0fcc/src/directives/map.js

@nmccready
Copy link
Contributor

And here f67acfc where m.draw is also commented out.

@nmccready
Copy link
Contributor

Ok so back to r1-dev start so the copy paste problem probably happened then. https://github.com/nlaplante/angular-google-maps/blob/bdd6b4382e78258079171935fd592991e4e4979a/src/directives/map.js

@nmccready nmccready added bug and removed question labels Feb 17, 2014
@nmccready
Copy link
Contributor

@jeppebemad @phongmedia I agree that using google.maps.event.trigger(_instance, "resize"); is the way to go. I think it should still be optional to return coords for the refresh to change position if desired. Otherwise just use the existing coords.

nmccready added a commit that referenced this issue Feb 17, 2014
- version appended to non minified version same as develop
Map.Control:
- refresh and getGMap are now more functional oriented
- the directive looks for a controller to have control= defined. The
  object is extended with refresh and getGMap which are direct callback
hooks to the directive itself.

Refresh:
Accepts optional coordinated so that you can panTo or Center on a new
postion after refresh / "resize" is triggered

issue #230

See example.html for map.control.refresh and map.control.getGMap
@nmccready
Copy link
Contributor

Please check the above commit as this should satisfy everyones needs. Also this should make things a lot easier in the future without needing watching.

nmccready added a commit that referenced this issue Feb 17, 2014
- version appended to non minified version same as develop
Map.Control:
- refresh and getGMap are now more functional oriented
- the directive looks for a controller to have control= defined. The
  object is extended with refresh and getGMap which are direct callback
hooks to the directive itself.

Refresh:
Accepts optional coordinateis to  panTo or Center on a new
postion after refresh / "resize" is triggered

issue #230

See example.html for map.control.refresh and map.control.getGMap
nmccready added a commit that referenced this issue Feb 17, 2014
- version appended to non minified version same as develop
Map.Control:
- refresh and getGMap are now more functional oriented
- the directive looks for a controller to have control= defined. The
  object is extended with refresh and getGMap which are direct callback
hooks to the directive itself.

Refresh:
Accepts optional coordinates to  panTo or Center on a new
postion after refresh / "resize" is triggered

issue #230

See example.html for map.control.refresh and map.control.getGMap
@nmccready
Copy link
Contributor

In master I will bump to 1.0.13 after a few more fixes

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

No branches or pull requests

4 participants