Commit a0d86c1f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '453-map-resize-doesn-t-trigger-coordinates-change-listener' into 'master'

Resolve "map resize doesn't trigger coordinates change listener"

Closes #453

See merge request !343
parents cc71a2bd 8c8e6f4c
......@@ -95,17 +95,42 @@ CustomMap.prototype.init = function () {
ids.push(mapType);
}
return Promise.each(ids, function (overlayId) {
try {
return self.openDataOverlay(overlayId);
} catch (e) {
if (e instanceof SecurityError) {
logger.debug(e.message);
sessionData.setSelectedBackgroundOverlay(self.getProject().getDataOverlays()[0].getId());
} else {
return Promise.reject(e);
}
return Promise.all([self.getMapCanvas().triggerListeners('resize'),
// noinspection SpellCheckingInspection
self.getMapCanvas().triggerListeners('maptypeid_changed'),
self.getMapCanvas().triggerListeners('projection_changed')
]).then(function() {
// center map and zoom in to fit into browser window if there is no
// information about coordinates in the session
var x = self.getModel().getDefaultCenterX();
var y = self.getModel().getDefaultCenterY();
var zoom = self.getModel().getDefaultZoomLevel();
if (self.getServerConnector().getSessionData(self.getProject()).getCenter(self.getModel()) === undefined &&
(x === undefined || y === undefined || zoom === undefined ||
x === null || y === null || zoom === null
)) {
var bounds = new Bounds();
bounds.extend(self.getTopLeft());
bounds.extend(self.getBottomRight());
self.getMapCanvas().fitBounds(bounds);
}
return Promise.each(ids, function (overlayId) {
try {
return self.openDataOverlay(overlayId);
} catch (e) {
if (e instanceof SecurityError) {
logger.debug(e.message);
sessionData.setSelectedBackgroundOverlay(self.getProject().getDataOverlays()[0].getId());
} else {
return Promise.reject(e);
}
}
});
}).then(function () {
return self.getServerConnector().getLogoImg();
}).then(function (url) {
......@@ -473,28 +498,6 @@ CustomMap.prototype.customizeGoogleMapView = function (div) {
self.createMapCanvas(div);
self.createLogo();
self.getMapCanvas().triggerListeners('resize');
// noinspection SpellCheckingInspection
self.getMapCanvas().triggerListeners('maptypeid_changed');
self.getMapCanvas().triggerListeners('projection_changed');
// center map and zoom in to fit into browser window if there is no
// information about coordinates in the session
var x = self.getModel().getDefaultCenterX();
var y = self.getModel().getDefaultCenterY();
var zoom = self.getModel().getDefaultZoomLevel();
if (self.getServerConnector().getSessionData(self.getProject()).getCenter(self.getModel()) === undefined &&
(x === undefined || y === undefined || zoom === undefined ||
x === null || y === null || zoom === null
)) {
var bounds = new Bounds();
bounds.extend(self.getTopLeft());
bounds.extend(self.getBottomRight());
self.getMapCanvas().fitBounds(bounds);
}
};
/**
......
......@@ -13,6 +13,8 @@ var GoogleMapsApiMarker = require('./GoogleMapsApiMarker');
var GoogleMapsApiPolyline = require('./GoogleMapsApiPolyline');
var GoogleMapsApiRectangle = require('./GoogleMapsApiRectangle');
var Promise = require('bluebird');
/**
*
* @param {HTMLElement} element
......@@ -301,7 +303,13 @@ GoogleMapsApiCanvas.prototype.addRightBottomControl = function (element) {
* @param {Object} [data]
*/
GoogleMapsApiCanvas.prototype.triggerListeners = function (type, data) {
var self = this;
google.maps.event.trigger(this.getGoogleMap(), type, data);
if (type === "resize") {
return Promise.delay(100).then(function () {
return self.callListeners("center_changed");
});
}
};
/**
......
......@@ -493,7 +493,8 @@ OpenLayerCanvas.prototype.triggerListeners = function (type, data) {
var self = this;
if (type === "resize") {
return Promise.delay(200).then(function () {
return self.getOpenLayersMap().updateSize();
self.getOpenLayersMap().updateSize();
return self.callListeners("center_changed");
});
} else if (type === "maptypeid_changed") {
return self.callListeners("maptypeid_changed");
......
......@@ -108,8 +108,8 @@ describe('minerva global', function () {
}).then(function (result) {
var center = ServerConnectorMock.getSessionData(options.getProject()).getCenter(options.getProject().getModels()[0]);
assert.ok(center instanceof Point);
assert.equal(center.x, 5);
assert.equal(center.y, 6);
assert.closeTo(center.x, 5, helper.EPSILON);
assert.closeTo(center.y, 6, helper.EPSILON);
return result.destroy();
});
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment