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;
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
* side.
......
......@@ -21,14 +21,11 @@ SessionData.prototype.getProjectId = function(project) {
SessionData.prototype.getShowComments = function() {
var key = this.getKey(SessionObjectType.SHOW_COMMENT);
console.log("GET:",key,Cookies.get(key));
return Cookies.get(key) === "true";
};
SessionData.prototype.setShowComments = function(value) {
var key = this.getKey(SessionObjectType.SHOW_COMMENT);
console.log(key,value);
Cookies.set(key, value + "");
};
......@@ -46,6 +43,21 @@ SessionData.prototype.getZoomLevel = function(model) {
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) {
if (type === undefined) {
throw new Error("Undefined type");
......
"use strict";
var SessionObjectType = {
CENTER : "CENTER",
SHOW_COMMENT : "SHOW_COMMENT",
ZOOM_LEVEL : "ZOOM_LEVEL",
};
......
......@@ -692,10 +692,10 @@ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) {
*/
CustomMap.prototype.createMapChangedCallbacks = function() {
var customMapSelf = this;
var sessionData = ServerConnector.getSessionData(customMapSelf.getProject());
// listener for changing zoom level
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
ServerConnector.getSessionData(customMapSelf.getProject()).setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
ServerConnector.actualizeSessionData();
sessionData.setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
});
// if we have zoom level data stored in session then restore it
......@@ -704,23 +704,19 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
level = parseInt(level);
this.getGoogleMap().setZoom(level);
} 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
google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function() {
var coord = customMapSelf.getGoogleMap().getCenter();
var point = customMapSelf.fromLatLngToPoint(coord);
ServerConnector.setCenterCoordinateX(point.x);
ServerConnector.setCenterCoordinateY(point.y);
ServerConnector.actualizeSessionData();
sessionData.setCenter(customMapSelf.getModel(),point);
});
// if we have coordinate data stored in session then restore it
var x = ServerConnector.getCenterCoordinateX();
var y = ServerConnector.getCenterCoordinateY();
if (!isNaN(x) && !isNaN(y)) {
var point = new google.maps.Point(x, y);
var point = sessionData.getCenter(customMapSelf.getModel());
if (point!== undefined) {
var coord = customMapSelf.fromPointToLatLng(point);
customMapSelf.getGoogleMap().setCenter(coord);
}
......
......@@ -12,19 +12,20 @@ var OriginalServerConnector = require('./ServerConnector');
var logger = require('./logger');
function processUrlGetParams(params) {
var project = params.project;
if (project===undefined) {
project = params.getProject();
}
var sessionData = ServerConnector.getSessionData(project);
if (GuiConnector.getParams["submap"] === undefined
|| project.getModel().getId() === parseInt(GuiConnector.getParams["submap"])) {
if (GuiConnector.getParams["x"] !== undefined && GuiConnector.getParams["y"] !== undefined) {
ServerConnector.setCenterCoordinateX(GuiConnector.getParams["x"]);
ServerConnector.setCenterCoordinateY(GuiConnector.getParams["y"]);
var point = new google.maps.Point(GuiConnector.getParams["x"],GuiConnector.getParams["y"]);
sessionData.setCenter(project.getModel(), point);
}
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) {
}
};
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) {
this.selectedLayout = value;
};
......
......@@ -84,6 +84,7 @@ Helper.prototype.createDbOverlay = function(map) {
Helper.prototype.createProject = function() {
var result = new Project();
result.setProjectId("testId");
result.setId(this.idCounter++);
result.setModel(this.createModel());
return result;
......
......@@ -542,6 +542,18 @@ describe('CustomMap', function() {
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() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
......
......@@ -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() {
......
......@@ -38,9 +38,6 @@
<h:inputHidden id="selectedDrugPolygon" value="#{drugMB.polygon}"/>
<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: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