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

map is accessed via getters/setters

parent 8889ef1a
......@@ -26,7 +26,7 @@
"dependencies": {
"log4js": "0.6.38",
"pileup": "^0.6.8",
"request": "^2.79.0",
"xmlhttprequest": "^1.8.0"
"js-cookie" : "^2.1.3",
"request": "^2.79.0"
}
}
......@@ -183,7 +183,7 @@ AbstractCustomMap.prototype.getMouseLatLng = function() {
// this is magic :)
// find offset of the div where google map is located related to top left
// corner of the browser
var el = self.map.getDiv();
var el = self.getGoogleMap().getDiv();
for (var lx = 0, ly = 0; el !== null && el !== undefined; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent) {
}
......
......@@ -38,7 +38,7 @@ function CustomMap(options) {
this.setProject(options.getProject());
// set config parameters
this.map = options.getMap();
this.setGoogleMap(options.getMap());
if (options.isCustomTouchInterface()) {
this._touchInterface = new TouchMap(this);
......@@ -52,7 +52,7 @@ function CustomMap(options) {
this.fitBounds(bounds);
this.fitBounds = tmp;
};
this.map.fitBounds2 = fitBounds;
this.getGoogleMap().fitBounds2 = fitBounds;
this.buttons = [];
......@@ -111,7 +111,7 @@ CustomMap.prototype.createLogo = function() {
win.focus();
});
logoControlDiv2.index = 0; // used for ordering
this.map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(logoControlDiv2);
this.getGoogleMap().controls[google.maps.ControlPosition.LEFT_BOTTOM].push(logoControlDiv2);
var logoControlDiv = document.createElement('DIV');
logoControlDiv.style.padding = '5px';
......@@ -126,7 +126,7 @@ CustomMap.prototype.createLogo = function() {
});
logoControlDiv.index = 1; // used for ordering
this.map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(logoControlDiv);
this.getGoogleMap().controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(logoControlDiv);
};
CustomMap.prototype.createBelt = function() {
......@@ -148,18 +148,18 @@ CustomMap.prototype.createBelt = function() {
var button = hideButton;
var div = self.getHideDiv();
var left = GuiConnector.getObjectByPrimefaceId(self.map.getDiv().id).offset().left;
var left = GuiConnector.getObjectByPrimefaceId(self.getGoogleMap().getDiv().id).offset().left;
return function() {
if (button.innerHTML.indexOf('fa-chevron-left') > 0) {
button.innerHTML = "<i class='fa fa-chevron-right'></i>";
div.style.display = 'none';
self.map.getDiv().style.left = "0px";
self.getGoogleMap().getDiv().style.left = "0px";
} else {
div.style.display = 'block';
button.innerHTML = "<i class='fa fa-chevron-left'></i>";
self.map.getDiv().style.left = left + "px";
self.getGoogleMap().getDiv().style.left = left + "px";
}
google.maps.event.trigger(self.map, 'resize');
google.maps.event.trigger(self.getGoogleMap(), 'resize');
return false;
};
})();
......@@ -176,7 +176,7 @@ CustomMap.prototype.createBelt = function() {
controlText.innerHTML = this.getProject().getName();
this.divBelt.appendChild(controlText);
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(this.divBelt);
this.getGoogleMap().controls[google.maps.ControlPosition.TOP_LEFT].push(this.divBelt);
};
CustomMap.prototype.setLegendVisible = function(vis) {
......@@ -263,7 +263,7 @@ CustomMap.prototype.updateOverlayCollection = function(overlayCollection, fitBou
CustomMap.prototype.openLayout = function(identifier) {
logger.debug("Opening layout: " + identifier);
this.map.setMapTypeId(identifier);
this.getGoogleMap().setMapTypeId(identifier);
var index = null;
for (var j = 0; j < this.getLayouts().length; j++) {
......@@ -553,7 +553,7 @@ CustomMap.prototype.refreshOverlayMarkers = function(overlay) {
if (!stillMissing && updated && overlay.fitBounds) {
for ( var mapId in boundsArray) {
if (boundsArray.hasOwnProperty(mapId)) {
var map = this.getSubmodelById(mapId).map;
var map = this.getSubmodelById(mapId).getGoogleMap();
bounds = boundsArray[mapId];
if (map !== undefined && !bounds.isEmpty()) {
if (typeof map.fitBounds2 !== "undefined") {
......@@ -580,7 +580,7 @@ CustomMap.prototype.openSubmodel = function(id, htmlTag, jsVar) {
} else {
submap.init(htmlTag, jsVar);
// we have to perform it on top map, because on submaps id is different
this.openLayout(this.map.getMapTypeId());
this.openLayout(this.getGoogleMap().getMapTypeId());
this.refreshOverlays();
......@@ -607,7 +607,7 @@ CustomMap.prototype.openSubmodel = function(id, htmlTag, jsVar) {
CustomMap.prototype.customizeGoogleMapView = function(fitMapBounds) {
var mapOptions = this.creatMapOptions();
this.map.setOptions(mapOptions);
this.getGoogleMap().setOptions(mapOptions);
this.createMapMenu();
......@@ -615,9 +615,9 @@ CustomMap.prototype.customizeGoogleMapView = function(fitMapBounds) {
this.createLogo();
// this.createMapVersion();
google.maps.event.trigger(this.map, 'resize');
google.maps.event.trigger(this.map, 'maptypeid_changed');
google.maps.event.trigger(this.map, 'projection_changed');
google.maps.event.trigger(this.getGoogleMap(), 'resize');
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) {
......@@ -625,17 +625,17 @@ CustomMap.prototype.customizeGoogleMapView = function(fitMapBounds) {
bounds.extend(this.getTopLeftLatLng());
bounds.extend(this.getBottomRightLatLng());
if (typeof this.map.fitBounds2 !== undefined) {
this.map.fitBounds2(bounds);
if (typeof this.getGoogleMap().fitBounds2 !== undefined) {
this.getGoogleMap().fitBounds2(bounds);
} else {
this.map.fitBounds(bounds);
this.getGoogleMap().fitBounds(bounds);
}
}
};
CustomMap.prototype.setCenter = function(mapIdentifier, coordinates) {
if (this.getModel().getId() === mapIdentifier) {
this.map.setCenter(coordinates);
this.getGoogleMap().setCenter(coordinates);
} else {
GuiConnector.openDialog(mapIdentifier);
for (var i = 0; i < this.submaps.length; i++) {
......@@ -643,7 +643,7 @@ CustomMap.prototype.setCenter = function(mapIdentifier, coordinates) {
if (coordinates instanceof google.maps.Point) {
coordinates = this.submaps[i].fromPointToLatLng(coordinates);
}
this.submaps[i].map.setCenter(coordinates);
this.submaps[i].getGoogleMap().setCenter(coordinates);
}
}
}
......@@ -651,12 +651,12 @@ CustomMap.prototype.setCenter = function(mapIdentifier, coordinates) {
CustomMap.prototype.setZoom = function(mapIdentifier, zoom) {
if (this.getModel().getId() === mapIdentifier) {
this.map.setZoom(zoom);
this.getGoogleMap().setZoom(zoom);
} else {
GuiConnector.openDialog(mapIdentifier);
for (var i = 0; i < this.submaps.length; i++) {
if (this.submaps[i].getId() === mapIdentifier) {
this.submaps[i].map.setZoom(zoom);
this.submaps[i].getGoogleMap().setZoom(zoom);
}
}
}
......@@ -669,8 +669,8 @@ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) {
CustomMap.prototype.createMapChangedCallbacks = function() {
var customMapSelf = this;
// listener for changing zoom level
google.maps.event.addListener(this.map, 'zoom_changed', function() {
ServerConnector.setZoomLevel(customMapSelf.map.getZoom());
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
ServerConnector.setZoomLevel(customMapSelf.getGoogleMap().getZoom());
ServerConnector.actualizeSessionData();
});
......@@ -678,14 +678,14 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
var level = ServerConnector.getZoomLevel();
if (parseInt(level) > 0) {
level = parseInt(level);
this.map.setZoom(level);
this.getGoogleMap().setZoom(level);
} else {
ServerConnector.setZoomLevel(customMapSelf.map.getZoom());
ServerConnector.setZoomLevel(customMapSelf.getGoogleMap().getZoom());
}
// listener for changing location of the map (moving left/reght/top/bottom
google.maps.event.addListener(this.map, 'center_changed', function() {
var coord = customMapSelf.map.getCenter();
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);
......@@ -698,12 +698,12 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
if (!isNaN(x) && !isNaN(y)) {
var point = new google.maps.Point(x, y);
var coord = customMapSelf.fromPointToLatLng(point);
customMapSelf.map.setCenter(coord);
customMapSelf.getGoogleMap().setCenter(coord);
}
// listener for changing type of layout
google.maps.event.addListener(this.map, 'maptypeid_changed', function() {
ServerConnector.setSelectedLayout(customMapSelf.map.getMapTypeId());
google.maps.event.addListener(this.getGoogleMap(), 'maptypeid_changed', function() {
ServerConnector.setSelectedLayout(customMapSelf.getGoogleMap().getMapTypeId());
ServerConnector.actualizeParams();
});
......@@ -1417,7 +1417,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
if (elements.length > 0 && fitBounds) {
for ( var mapId in boundsArray) {
if (boundsArray.hasOwnProperty(mapId)) {
var map = self.getSubmodelById(mapId).map;
var map = self.getSubmodelById(mapId).getGoogleMap();
bounds = boundsArray[mapId];
if (map !== undefined && !bounds.isEmpty()) {
if (typeof map.fitBounds2 !== "undefined") {
......
......@@ -89,7 +89,7 @@ Submap.prototype.init = function(htmlTag, jsVar) {
if (timestamp > self.lastResize) {
self.lastResize = timestamp + 200;
setTimeout(function() {
google.maps.event.trigger(self.map, 'resize');
google.maps.event.trigger(self.getGoogleMap(), 'resize');
self.lastResize = Math.min(new Date().getTime(), self.lastResize);
}, 100);
}
......@@ -97,7 +97,7 @@ Submap.prototype.init = function(htmlTag, jsVar) {
htmlTag.style.width = Math.floor(window.innerWidth * 2 / 3) + "px";
htmlTag.style.height = Math.floor(window.innerHeight * 2 / 3) + "px";
google.maps.event.trigger(self.map, 'resize');
google.maps.event.trigger(self.getGoogleMap(), 'resize');
jsVar.submapControler = this;
......@@ -105,21 +105,21 @@ Submap.prototype.init = function(htmlTag, jsVar) {
// after resizing center map
var centerPoint = new google.maps.LatLng(this.configuration.CENTER_LAT, this.configuration.CENTER_LNG);
self.map.setCenter(centerPoint);
self.getGoogleMap().setCenter(centerPoint);
// and now send the zoom level to the client side
google.maps.event.addListener(this.map, 'zoom_changed', function() {
ServerConnector.setModelZoomLevel(self.getId(), self.map.getZoom());
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
ServerConnector.setModelZoomLevel(self.getId(), self.getGoogleMap().getZoom());
});
ServerConnector.setModelZoomLevel(self.getId(), self.map.getZoom());
ServerConnector.setModelZoomLevel(self.getId(), self.getGoogleMap().getZoom());
}
};
Submap.prototype.openLayout = function(identifier) {
if (this.initialized) {
this.map.setMapTypeId(identifier);
this.getGoogleMap().setMapTypeId(identifier);
}
};
......
......@@ -8,11 +8,11 @@ var GuiConnector = require('../GuiConnector');
*/
function TouchMap(paramCustomMap) {
this._customMap = paramCustomMap;
this.map = paramCustomMap.getGoogleMap();
this.setMap (paramCustomMap.getGoogleMap());
logger.info("Turning on custom touch interfaces");
var self = this;
var el = this.map.getDiv();
var el = this.getMap().getDiv();
el.addEventListener('touchstart', function(evt) {
self.handleStart(evt);
......@@ -34,13 +34,13 @@ function TouchMap(paramCustomMap) {
this.rightMenuOn = false;
this.latLng = new google.maps.LatLng(0.0, 0.0);
google.maps.event.addListener(this.map, 'mouseover', function(mouseEvent) {
google.maps.event.addListener(this.getMap(), 'mouseover', function(mouseEvent) {
self.latLng = mouseEvent.latLng;
});
google.maps.event.addListener(this.map, 'mousemove', function(mouseEvent) {
google.maps.event.addListener(this.getMap(), 'mousemove', function(mouseEvent) {
self.latLng = mouseEvent.latLng;
});
google.maps.event.addListener(this.map, 'zoom_changed', function() {
google.maps.event.addListener(this.getMap(), 'zoom_changed', function() {
self.getCustomMap().refreshMarkers();
});
......@@ -103,7 +103,7 @@ TouchMap.prototype.handleStart = function(evt) {
self.firstStartY = touches[i].clientY;
self.firstEndX = touches[i].clientX;
self.firstEndY = touches[i].clientY;
self.startCoord = self.map.getCenter();
self.startCoord = self.getMap().getCenter();
self.lastMoveDx = 0;
self.lastMoveDy = 0;
self.rightMenuOn = GuiConnector.isRightMenuVisible();
......@@ -116,14 +116,14 @@ TouchMap.prototype.handleStart = function(evt) {
self.secondStartY = touches[i].clientY;
self.secondEndX = touches[i].clientX;
self.secondEndY = touches[i].clientY;
self.startZoom = self.map.getZoom();
self.startZoom = self.getMap().getZoom();
self.lastZoom = self.startZoom;
for (var j = 0; j < self.ongoingTouches.length; j++) {
if (self.ongoingTouches[j].identifier === self.firstFingerId) {
self.firstStartX = self.ongoingTouches[j].clientX;
self.firstStartY = self.ongoingTouches[j].clientY;
self.startCoord = self.map.getCenter();
self.startCoord = self.getMap().getCenter();
self.lastMoveDx = 0;
self.lastMoveDy = 0;
}
......@@ -161,7 +161,7 @@ TouchMap.prototype.lineDistance = function(x1, y1, x2, y2) {
TouchMap.prototype.moveMap = function(dx, dy) {
var self = this;
self.map.panBy(dx - self.lastMoveDx, dy - self.lastMoveDy);
self.getMap().panBy(dx - self.lastMoveDx, dy - self.lastMoveDy);
self.lastMoveDx = dx;
self.lastMoveDy = dy;
};
......@@ -169,9 +169,9 @@ TouchMap.prototype.moveMap = function(dx, dy) {
TouchMap.prototype.zoomMap = function(pointX, pointY, zoomLevel) {
var self = this;
if (self.lastZoom !== zoomLevel) {
logger.debug(this.map.getDiv());
logger.debug(this.map.getDiv().id);
var id = PrimeFaces.escapeClientId(this.map.getDiv().id);
logger.debug(this.getMap().getDiv());
logger.debug(this.getMap().getDiv().id);
var id = PrimeFaces.escapeClientId(this.getMap().getDiv().id);
logger.debug(id);
self.lastZoom = zoomLevel;
logger.debug("zoom6: " + zoomLevel);
......@@ -187,9 +187,9 @@ TouchMap.prototype.zoomMap = function(pointX, pointY, zoomLevel) {
logger.debug(width + " - " + height);
var dx = width / 2 - pointX;
var dy = height / 2 - pointY;
self.map.panBy(-dx, -dy);
self.map.setZoom(zoomLevel);
self.map.panBy(dx, dy);
self.getMap().panBy(-dx, -dy);
self.getMap().setZoom(zoomLevel);
self.getMap().panBy(dx, dy);
logger.debug(dx + " - " + dy + " - " + zoomLevel);
}
};
......@@ -232,7 +232,7 @@ TouchMap.prototype.makeLeftClick = function(x, y) {
stop : null,
latLng : self.getCustomMap().getMouseLatLng()
};
google.maps.event.trigger(self.map, 'click', mev);
google.maps.event.trigger(self.getMap(), 'click', mev);
}
};
......@@ -251,7 +251,7 @@ TouchMap.prototype.makeRightClick = function(x, y) {
stop : null,
latLng : self.getCustomMap().getMouseLatLng()
};
google.maps.event.trigger(self.map, 'rightclick', mev);
google.maps.event.trigger(self.getMap(), 'rightclick', mev);
}
};
......@@ -289,7 +289,7 @@ TouchMap.prototype.handleEnd = function(evt) {
if (self.ongoingTouches[j].identifier === self.firstFingerId) {
self.firstStartX = self.ongoingTouches[j].clientX;
self.firstStartY = self.ongoingTouches[j].clientY;
self.startCoord = self.map.getCenter();
self.startCoord = self.getMap().getCenter();
}
}
}
......@@ -372,4 +372,13 @@ TouchMap.prototype.ongoingTouchIndexById = function(idToFind) {
return -1; // not found
};
TouchMap.prototype.setMap = function(map) {
this.map = map;
};
TouchMap.prototype.getMap = function() {
return this.map;
};
module.exports = TouchMap;
......@@ -106,7 +106,7 @@ AliasOverlay.create = function(layoutAlias, aliasData, map, startX, endX) {
var rectangle = new google.maps.Rectangle({
fillOpacity : 0.8,
strokeWeight : 1,
map : map.map,
map : map.getGoogleMap(),
fillColor : functions.overlayToColor(layoutAlias),
bounds : bounds
});
......
......@@ -20,7 +20,7 @@ function OverlayCollection(map, name, allowSearchById, allowGeneralSearch) {
this.elements = [];
this.name = name;
this.map = map;
this.setMap(map);
this._ids = [];
......@@ -83,7 +83,7 @@ OverlayCollection.prototype.updateOverlays = function(newElements, fitBounds) {
this.elements.push(new IdentifiedElement(newElements[i]));
}
this.fitBounds = fitBounds;
this.map.updateOverlayCollection(self, fitBounds);
this.getMap().updateOverlayCollection(self, fitBounds);
};
/**
......@@ -92,7 +92,7 @@ OverlayCollection.prototype.updateOverlays = function(newElements, fitBounds) {
OverlayCollection.prototype.clear = function() {
var self = this;
this.elements = [];
this.map.updateOverlayCollection(self);
this.getMap().updateOverlayCollection(self);
};
/**
......@@ -104,7 +104,7 @@ OverlayCollection.prototype.refresh = function() {
OverlayCollection.prototype.setResultsIds = function(ids) {
this._ids = ids;
this.map.refreshInfoWindows();
this.getMap().refreshInfoWindows();
};
OverlayCollection.prototype.getResultsIds = function() {
......@@ -172,7 +172,7 @@ OverlayCollection.prototype.updateOverviewElementDetailData = function(javaObjec
} else {
data[searchResultIdentifier] = newData;
}
this.map.updateInfoWindowForIdentifiedElement(element);
this.getMap().updateInfoWindowForIdentifiedElement(element);
};
OverlayCollection.prototype.getDetailDataByIdentifiedElement = function(element, general) {
......@@ -208,4 +208,12 @@ OverlayCollection.prototype._getDetailArrayByIdentifiedElement = function(elemen
return this._detailDataByIdentifiedElement[elementKey];
};
OverlayCollection.prototype.setMap = function(map) {
this.map = map;
};
OverlayCollection.prototype.getMap = function() {
return this.map;
};
module.exports = OverlayCollection;
......@@ -123,7 +123,7 @@ AbstractInfoWindow.prototype.open = function() {
return;
}
this.update();
this.googleInfowindow.open(this.getCustomMap().map, this.getGoogleMarker());
this.googleInfowindow.open(this.getCustomMap().getGoogleMap(), this.getGoogleMarker());
this.callListeners("onShow");
};
......
......@@ -22,7 +22,7 @@ function PointInfoWindow(pointMarker, map) {
content : this.content,
position : latLng
});
this.googleInfowindow.open(this.customMap.map, this.getGoogleMarker());
this.googleInfowindow.open(this.getCustomMap().getGoogleMap(), this.getGoogleMarker());
} else {
logger.warn("Opening window without alias specified");
}
......
......@@ -28,7 +28,7 @@ function ReactionInfoWindow(reactionData, map) {
content : this.content,
position : latLng
});
this.googleInfowindow.open(this.customMap.map, this.getGoogleMarker());
this.googleInfowindow.open(this.getCustomMap().getGoogleMap(), this.getGoogleMarker());
this.update(this._reactionData);
}
......
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