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

centering of map from session data fixed

parent f0354fac
......@@ -101,7 +101,15 @@ AbstractCustomMap.prototype.setupLayouts = function() {
*
*/
AbstractCustomMap.prototype.creatMapOptions = function() {
var self = this;
var centerPoint = this.getModel().getCenterLatLng();
// if we have coordinate data stored in session then restore it
var point = ServerConnector.getSessionData(self.getProject()).getCenter(self.getModel());
if (point!== undefined) {
centerPoint = self.fromPointToLatLng(point);
}
var result = {
center : centerPoint,
......
......@@ -47,7 +47,7 @@ function CustomMap(options) {
this.selectedLayouts = [];
this.customizeGoogleMapView(options.getFitMapBounds(),options.getMapDiv());
this.customizeGoogleMapView(options.getMapDiv());
this.createBelt();
......@@ -578,7 +578,7 @@ CustomMap.prototype.openSubmodel = function(id, htmlTag, jsVar) {
};
CustomMap.prototype.customizeGoogleMapView = function(fitMapBounds, div) {
CustomMap.prototype.customizeGoogleMapView = function(div) {
var mapOptions = this.creatMapOptions(this.getLayouts().length);
this.setGoogleMap(new google.maps.Map(div, mapOptions));
this.setupLayouts();
......@@ -591,13 +591,14 @@ CustomMap.prototype.customizeGoogleMapView = function(fitMapBounds, div) {
google.maps.event.trigger(this.getGoogleMap(), 'maptypeid_changed');
google.maps.event.trigger(this.getGoogleMap(), 'projection_changed');
// center map and zoom in to fit into browser window
if (fitMapBounds) {
// center map and zoom in to fit into browser window if there is no
// information about coordinates in the session
if (ServerConnector.getSessionData(this.getProject()).getCenter(this.getModel())===undefined) {
var bounds = new google.maps.LatLngBounds();
bounds.extend(this.getTopLeftLatLng());
bounds.extend(this.getBottomRightLatLng());
this.getGoogleMap().fitBounds(bounds);
this.getGoogleMap().fitBounds(bounds);
}
};
......@@ -658,13 +659,6 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
sessionData.setCenter(customMapSelf.getModel(),point);
});
// if we have coordinate data stored in session then restore it
var point = sessionData.getCenter(customMapSelf.getModel());
if (point!== undefined) {
var coord = customMapSelf.fromPointToLatLng(point);
customMapSelf.getGoogleMap().setCenter(coord);
}
// listener for changing type of layout
google.maps.event.addListener(this.getGoogleMap(), 'maptypeid_changed', function() {
sessionData.setSelectedBackgroundOverlay(customMapSelf.getGoogleMap().getMapTypeId());
......@@ -1799,4 +1793,5 @@ CustomMap.prototype.getSearchAutocomplete = function(query){
return this._searchAutocomplete[query];
};
module.exports = CustomMap;
......@@ -63,7 +63,6 @@ function CustomMapOptions(params) {
}
this.setDebug(params.debug);
this.setFitMapBounds(params.debug);
}
CustomMapOptions.prototype.getMapDiv = function() {
......@@ -102,26 +101,14 @@ CustomMapOptions.prototype.setDebug = function(debug) {
}
};
CustomMapOptions.prototype.setFitMapBounds = function(fitMapBounds) {
this._fitMapBounds = fitMapBounds;
};
CustomMapOptions.prototype.setCustomTouchInterface = function(customTouchInterface) {
this._customTouchInterface = customTouchInterface;
};
CustomMapOptions.prototype.getFitMapBounds = function() {
return this._fitMapBounds;
};
CustomMapOptions.prototype.setMapDiv = function(mapDiv) {
this._mapDiv = mapDiv;
};
CustomMapOptions.prototype.getFitMapBounds = function() {
return this._fitMapBounds;
};
CustomMapOptions.prototype.isDebug = function() {
return this.debug === true;
};
......
......@@ -107,7 +107,7 @@ Submap.prototype.init = function(htmlTag, jsVar) {
var centerPoint = this.getModel().getCenterLatLng();
self.getGoogleMap().setCenter(centerPoint);
var sessionData = ServerConnector.getSessionData(this.getCustomMap().getProject());
var sessionData = ServerConnector.getSessionData(this.getProject());
// and now send the zoom level to the client side
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
sessionData.setZoomLevel(self.getModel(), self.getGoogleMap().getZoom());
......@@ -156,4 +156,10 @@ Submap.prototype.setCustomMap = function(customMap) {
this._customMap = customMap;
};
Submap.prototype.getProject = function(customMap) {
return this.getCustomMap().getProject();
};
module.exports = Submap;
......@@ -111,6 +111,7 @@ function create(params) {
logger.warn("No overlay collection defined");
}
return new Promise(function(resolve, reject) {
var sessionData =ServerConnector.getSessionData();
result.refreshOverlays().then(function() {
......
......@@ -145,6 +145,9 @@ var google = {
if (options !== undefined) {
data = options;
}
if (data.center === undefined) {
data.center = new google.maps.LatLng(83.42558775689403, -135);
}
data.div = div;
if (data.bounds === undefined) {
data.bounds = new google.maps.LatLngBounds(new google.maps.LatLng(10, 10), new google.maps.LatLng(12, 12));
......@@ -190,6 +193,9 @@ var google = {
setBounds : function(bounds) {
data.bounds = bounds;
},
fitBounds : function(bounds) {
this.setBounds(bounds);
},
};
},
MVCArray : function(data) {
......
......@@ -92,8 +92,8 @@ Helper.prototype.createDrugDbOverlay = function(map) {
var result = new DrugDbOverlay({
map : map,
name : "drug",
allowGeneralSearch:true,
allowSearchById:true,
allowGeneralSearch : true,
allowSearchById : true,
});
map.registerSource(result);
return result;
......@@ -284,6 +284,18 @@ Helper.prototype.createModel = function() {
result.setHeight(800);
result.setMaxZoom(8);
result.setMinZoom(2);
result.setCenterLatLng({
lat : 10,
lng : 20
});
result.setTopLeftLatLng({
lat : 8,
lng : 8
});
result.setBottomRightLatLng({
lat : 30,
lng : 30
});
var layout = this.createLayout();
result.addLayout(layout);
......@@ -313,7 +325,7 @@ Helper.prototype.createGoogleMap = function() {
Helper.prototype.createCustomMapOptions = function() {
var project = this.createProject();
var result = new CustomMapOptions({
markerOptimization : true,
project : project,
......
......@@ -57,7 +57,7 @@ describe('AbstractCustomMap', function() {
});
it("creatMapOptions", function() {
var mockObject = helper.createAbstractCustomMap();
var mockObject = helper.createCustomMap();
assert.ok(mockObject.creatMapOptions());
});
......
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