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

current center point of map is stored in js session

parent 2e2ed619
...@@ -49,36 +49,6 @@ ServerConnector.lastActualization = 0; ...@@ -49,36 +49,6 @@ ServerConnector.lastActualization = 0;
ServerConnector._customMap = null; ServerConnector._customMap = null;
/**
* Set x coordinate for {@link CustomMap} on the server side.
*/
ServerConnector.setCenterCoordinateX = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':centerCoordinateX').value = "" + value;
};
/**
* Get x coordinate of the {@link CustomMap} at which it was last browsed.
*/
ServerConnector.getCenterCoordinateX = function() {
var result = parseFloat(document.getElementById(ServerConnector.formIdentifier + ':centerCoordinateX').value);
return result;
};
/**
* Set y coordinate for {@link CustomMap} on the server side.
*/
ServerConnector.setCenterCoordinateY = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':centerCoordinateY').value = "" + value;
};
/**
* Get y coordinate of the {@link CustomMap} at which it was last browsed.
*/
ServerConnector.getCenterCoordinateY = function() {
var result = parseFloat(document.getElementById(ServerConnector.formIdentifier + ':centerCoordinateY').value);
return result;
};
/** /**
* Set layout that is currently browsed for {@link CustomMap} on the server * Set layout that is currently browsed for {@link CustomMap} on the server
* side. * side.
......
...@@ -21,14 +21,11 @@ SessionData.prototype.getProjectId = function(project) { ...@@ -21,14 +21,11 @@ SessionData.prototype.getProjectId = function(project) {
SessionData.prototype.getShowComments = function() { SessionData.prototype.getShowComments = function() {
var key = this.getKey(SessionObjectType.SHOW_COMMENT); var key = this.getKey(SessionObjectType.SHOW_COMMENT);
console.log("GET:",key,Cookies.get(key));
return Cookies.get(key) === "true"; return Cookies.get(key) === "true";
}; };
SessionData.prototype.setShowComments = function(value) { SessionData.prototype.setShowComments = function(value) {
var key = this.getKey(SessionObjectType.SHOW_COMMENT); var key = this.getKey(SessionObjectType.SHOW_COMMENT);
console.log(key,value);
Cookies.set(key, value + ""); Cookies.set(key, value + "");
}; };
...@@ -46,6 +43,21 @@ SessionData.prototype.getZoomLevel = function(model) { ...@@ -46,6 +43,21 @@ SessionData.prototype.getZoomLevel = function(model) {
return value; return value;
}; };
SessionData.prototype.setCenter = function(model, value) {
var key = this.getKey(SessionObjectType.CENTER, [ model.getId() ]);
Cookies.set(key, value.x + "," + value.y);
};
SessionData.prototype.getCenter = function(model) {
var key = this.getKey(SessionObjectType.CENTER, [ model.getId() ]);
var value = Cookies.get(key);
if (value !== undefined) {
var tmp = value.split(",");
value = new google.maps.Point(tmp[0], tmp[1]);
}
return value;
};
SessionData.prototype.getKey = function(type, args) { SessionData.prototype.getKey = function(type, args) {
if (type === undefined) { if (type === undefined) {
throw new Error("Undefined type"); throw new Error("Undefined type");
......
"use strict"; "use strict";
var SessionObjectType = { var SessionObjectType = {
CENTER : "CENTER",
SHOW_COMMENT : "SHOW_COMMENT", SHOW_COMMENT : "SHOW_COMMENT",
ZOOM_LEVEL : "ZOOM_LEVEL", ZOOM_LEVEL : "ZOOM_LEVEL",
}; };
......
...@@ -692,10 +692,10 @@ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) { ...@@ -692,10 +692,10 @@ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) {
*/ */
CustomMap.prototype.createMapChangedCallbacks = function() { CustomMap.prototype.createMapChangedCallbacks = function() {
var customMapSelf = this; var customMapSelf = this;
var sessionData = ServerConnector.getSessionData(customMapSelf.getProject());
// listener for changing zoom level // listener for changing zoom level
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() { google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
ServerConnector.getSessionData(customMapSelf.getProject()).setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom()); sessionData.setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
ServerConnector.actualizeSessionData();
}); });
// if we have zoom level data stored in session then restore it // if we have zoom level data stored in session then restore it
...@@ -704,23 +704,19 @@ CustomMap.prototype.createMapChangedCallbacks = function() { ...@@ -704,23 +704,19 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
level = parseInt(level); level = parseInt(level);
this.getGoogleMap().setZoom(level); this.getGoogleMap().setZoom(level);
} else { } else {
ServerConnector.getSessionData(customMapSelf.getProject()).setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom()); sessionData.setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
} }
// listener for changing location of the map (moving left/reght/top/bottom // listener for changing location of the map (moving left/reght/top/bottom
google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function() { google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function() {
var coord = customMapSelf.getGoogleMap().getCenter(); var coord = customMapSelf.getGoogleMap().getCenter();
var point = customMapSelf.fromLatLngToPoint(coord); var point = customMapSelf.fromLatLngToPoint(coord);
ServerConnector.setCenterCoordinateX(point.x); sessionData.setCenter(customMapSelf.getModel(),point);
ServerConnector.setCenterCoordinateY(point.y);
ServerConnector.actualizeSessionData();
}); });
// if we have coordinate data stored in session then restore it // if we have coordinate data stored in session then restore it
var x = ServerConnector.getCenterCoordinateX(); var point = sessionData.getCenter(customMapSelf.getModel());
var y = ServerConnector.getCenterCoordinateY(); if (point!== undefined) {
if (!isNaN(x) && !isNaN(y)) {
var point = new google.maps.Point(x, y);
var coord = customMapSelf.fromPointToLatLng(point); var coord = customMapSelf.fromPointToLatLng(point);
customMapSelf.getGoogleMap().setCenter(coord); customMapSelf.getGoogleMap().setCenter(coord);
} }
......
...@@ -12,19 +12,20 @@ var OriginalServerConnector = require('./ServerConnector'); ...@@ -12,19 +12,20 @@ var OriginalServerConnector = require('./ServerConnector');
var logger = require('./logger'); var logger = require('./logger');
function processUrlGetParams(params) { function processUrlGetParams(params) {
var project = params.project; var project = params.project;
if (project===undefined) { if (project===undefined) {
project = params.getProject(); project = params.getProject();
} }
var sessionData = ServerConnector.getSessionData(project);
if (GuiConnector.getParams["submap"] === undefined if (GuiConnector.getParams["submap"] === undefined
|| project.getModel().getId() === parseInt(GuiConnector.getParams["submap"])) { || project.getModel().getId() === parseInt(GuiConnector.getParams["submap"])) {
if (GuiConnector.getParams["x"] !== undefined && GuiConnector.getParams["y"] !== undefined) { if (GuiConnector.getParams["x"] !== undefined && GuiConnector.getParams["y"] !== undefined) {
ServerConnector.setCenterCoordinateX(GuiConnector.getParams["x"]); var point = new google.maps.Point(GuiConnector.getParams["x"],GuiConnector.getParams["y"]);
ServerConnector.setCenterCoordinateY(GuiConnector.getParams["y"]); sessionData.setCenter(project.getModel(), point);
} }
if (GuiConnector.getParams["zoom"] !== undefined) { if (GuiConnector.getParams["zoom"] !== undefined) {
ServerConnector.getSessionData(project).setZoomLevel(project.getModel(),GuiConnector.getParams["zoom"]); sessionData.setZoomLevel(project.getModel(),GuiConnector.getParams["zoom"]);
} }
} }
} }
......
...@@ -83,22 +83,6 @@ ServerConnectorMock.callListeners = function(type, param) { ...@@ -83,22 +83,6 @@ ServerConnectorMock.callListeners = function(type, param) {
} }
}; };
ServerConnectorMock.setCenterCoordinateX = function(value) {
this.centerCoordinateX = value;
};
ServerConnectorMock.getCenterCoordinateX = function() {
return this.centerCoordinateX;
};
ServerConnectorMock.setCenterCoordinateY = function(value) {
this.centerCoordinateY = value;
};
ServerConnectorMock.getCenterCoordinateY = function() {
return this.centerCoordinateY;
};
ServerConnectorMock.setSelectedLayout = function(value) { ServerConnectorMock.setSelectedLayout = function(value) {
this.selectedLayout = value; this.selectedLayout = value;
}; };
......
...@@ -84,6 +84,7 @@ Helper.prototype.createDbOverlay = function(map) { ...@@ -84,6 +84,7 @@ Helper.prototype.createDbOverlay = function(map) {
Helper.prototype.createProject = function() { Helper.prototype.createProject = function() {
var result = new Project(); var result = new Project();
result.setProjectId("testId");
result.setId(this.idCounter++); result.setId(this.idCounter++);
result.setModel(this.createModel()); result.setModel(this.createModel());
return result; return result;
......
...@@ -542,6 +542,18 @@ describe('CustomMap', function() { ...@@ -542,6 +542,18 @@ describe('CustomMap', function() {
assert.ok(ServerConnector.getSessionData(map.getProject()).getShowComments()); assert.ok(ServerConnector.getSessionData(map.getProject()).getShowComments());
}); });
it("changed coords in map", function() {
var map = helper.createCustomMap();
var oldCenter = map.getGoogleMap().getCenter();
var newCenter = new google.maps.LatLng(3, 87);
map.getGoogleMap().setCenter(newCenter);
google.maps.event.trigger(map.getGoogleMap(), "center_changed");
var center = ServerConnector.getSessionData(map.getProject()).getCenter(map.getModel());
assert.ok(center !== oldCenter);
assert.ok(center instanceof google.maps.Point);
});
it("refreshComments", function() { it("refreshComments", function() {
var map = helper.createCustomMap(); var map = helper.createCustomMap();
map.getModel().setId(15781); map.getModel().setId(15781);
......
...@@ -34,6 +34,18 @@ describe('minerva global', function() { ...@@ -34,6 +34,18 @@ describe('minerva global', function() {
}); });
}); });
it("contructor with GET coord param", function() {
var options = helper.createCustomMapOptions();
GuiConnector.getParams["x"] = "5";
GuiConnector.getParams["y"] = "6";
return minerva.create(options).then(function(result) {
var center = ServerConnector.getSessionData(options.getProject()).getCenter(options.getProject().getModel());
assert.ok(center instanceof google.maps.Point);
assert.equal(center.x, 5);
assert.equal(center.y, 6);
});
});
it('create with layout', function() { it('create with layout', function() {
......
...@@ -38,9 +38,6 @@ ...@@ -38,9 +38,6 @@
<h:inputHidden id="selectedDrugPolygon" value="#{drugMB.polygon}"/> <h:inputHidden id="selectedDrugPolygon" value="#{drugMB.polygon}"/>
<p:remoteCommand name="_actualizeParams" actionListener="#{mapMB.actualizeParams}"/> <p:remoteCommand name="_actualizeParams" actionListener="#{mapMB.actualizeParams}"/>
<h:inputHidden id="centerCoordinateX" value="#{mapMB.topModelMapData.centerCoordinateX}"/>
<h:inputHidden id="centerCoordinateY" value="#{mapMB.topModelMapData.centerCoordinateY}"/>
<h:inputHidden id="zoomLevel" value="#{mapMB.topModelMapData.zoomLevel}"/>
<h:inputHidden id="selectedLayout" value="#{mapMB.topModelMapData.selectedLayout}"/> <h:inputHidden id="selectedLayout" value="#{mapMB.topModelMapData.selectedLayout}"/>
<h:panelGroup layout="block" id="submodelDialogGroup"> <h:panelGroup layout="block" id="submodelDialogGroup">
......
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