OpenLayers OpenLayers

Ticket #830 (closed bug: fixed)

Opened 1 year ago

Last modified 2 months ago

Switching between google layers after map resize

Reported by: openlayers Assigned to: jrmerz@gmail.com
Priority: minor Milestone: 2.7 Release
Component: Layer.Google Version: 2.4
Keywords: Cc:
State: Complete

Description

--Bug-- After creating a map with multiple Google layers (ie map, satellite, hybrid), if the map is then resized, switching between the layers will cause multiple errors. One, the map display fills part of the view plane. Two, the map is no longer centered to the same spot as before the layer switch.

--Possible Cause-- The OL view plane and the Google View plane seem to be off.

--Proposed solution-- In OpenLayers.Layer.Google class, in the setMapObjectCenter function, call the Google onMapResize which alerts the Google API that the view plane has changed and to updated the map accordingly.

Attachments

googleResizeBug.patch (465 bytes) - added by openlayers on 07/11/07 12:55:16.
830.Google.patch (0.9 kB) - added by edgemaster on 04/25/08 18:31:14.
Patch based upon #830#comment:4, briefly tested, seems to work as expected.

Change History

07/11/07 12:55:16 changed by openlayers

  • attachment googleResizeBug.patch added.

07/11/07 12:56:14 changed by openlayers

  • keywords set to review.

(follow-up: ↓ 3 ) 07/12/07 23:39:21 changed by euzuro

this patch seems to me like it will add a lot of overhead to the dragging in google maps layer. we shouldnt be calling that check every time the map is pan/zoomed.... we should be calling it precisely when the map is resized.

..I guess that is not happening correctly?

(in reply to: ↑ 2 ) 07/16/07 19:07:18 changed by jrmerz

Replying to euzuro:

this patch seems to me like it will add a lot of overhead to the dragging in google maps layer. we shouldnt be calling that check every time the map is pan/zoomed.... we should be calling it precisely when the map is resized. ..I guess that is not happening correctly?

Yes, this is adding overhead, but over all performance seems to be on par with the current version. W/o fixing the the view plane issue (which is beyond me ... at the moment) I don't know if there is any other way to do this. It would make (some) sense to place a set center command in onMapResize, but the API does not currently pass any parameters to this function. Also this function is called multiple times upon a resize of the map (not sure why that is happening either). The solution above would be for the short term, till the view plane issue can be resolved.

08/06/07 13:34:48 changed by jrmerz

Problem: The current setup calls the google maps API's checkResize() on all layers when a map resize happens and then assumes that all maps are up-to-date on with current view plane. The problem is that checkResize() only works on visible maps. The simple fix to this is to check for visibility when the map is resized, if visible run checkResize, otherwise set a flag so next time the map is displayed it runs checkResize. Looks something like this. Still need to test and then will make a patch.

onMapResize: function() {

if( this.visibility ){

this.mapObject.checkResize();

} else {

this.windowResized = true;

}

},

/* the google layer now inherits layer.js display function

  • and adds the resize functionality. Note you also have
  • to re-center the map */

display: function(display) {

OpenLayers.Layer.prototype.display.apply(this, arguments); if( this.div.style.display == "block" && this.windowResized ){

var center = this.map.getCenter(); var gcenter = this.getMapObjectLonLatFromLonLat( center.lon, center.lat ); this.mapObject.setCenter(gcenter, this.map.getZoom() ); this.mapObject.checkResize(); this.windowResized = false;

}

},

10/10/07 01:25:38 changed by crschmidt

Note that #1077 was a dupe of this.

10/10/07 01:25:44 changed by crschmidt

  • milestone set to 2.6 Release.

11/22/07 11:45:01 changed by crschmidt

#1171 is also a dupe

12/02/07 15:24:45 changed by crschmidt

  • keywords deleted.

The psuedo-patch in the comments here needs to be turned into a patch, and probably also needs to be applied more generally to the rest of the eventpane layers.

12/15/07 15:40:51 changed by crschmidt

  • state set to Needs More Work.

01/22/08 17:37:03 changed by crschmidt

  • milestone changed from 2.6 Release to 2.7 Release.

Mass ticket move to 2.7 post dev meeting. If you are actively working on this task, please update this ticket with information and change the milestone to 2.6. At the time of the next IRC meeting (most likely 1-31-08), this will mean the ticket can *not* be brought back into 2.6 unless there is further feedback.

04/25/08 18:31:14 changed by edgemaster

  • attachment 830.Google.patch added.

Patch based upon #830#comment:4, briefly tested, seems to work as expected.

04/25/08 18:40:49 changed by edgemaster

  • state changed from Needs More Work to Review.

04/28/08 11:46:03 changed by crschmidt

My earlier comments regarding applying this to other layers are no longer relevant: this bug exists because the Google API tries to be smart and registers for browser events that OL doesn't control, which the other layers don't do.

05/31/08 13:19:48 changed by crschmidt

  • status changed from new to closed.
  • state changed from Review to Complete.
  • resolution set to fixed.

(In [7300]) Fix for GMaps layers to display in correct position when they were originally loaded as the not default layer, or the map is resized while the gmaps layer is hidden. Patch put together by Edgemaster (thanks), (Closes #830)