diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js index c90cd3d6b82308bbba586120adb9f743d7a6609b..cdbbcd533d6de2e534db3da6d5a57a62a70eb7ad 100644 --- a/frontend-js/src/main/js/map/AbstractCustomMap.js +++ b/frontend-js/src/main/js/map/AbstractCustomMap.js @@ -21,6 +21,8 @@ var ReactionSurface = require('./surface/ReactionSurface'); var MarkerSurfaceCollection = require('./marker/MarkerSurfaceCollection'); var MapCanvas = require('./canvas/MapCanvas'); +var GoogleMapsApiCanvas = require('./canvas/GoogleMaps/GoogleMapsApiCanvas'); +var OpenLayerCanvas = require('./canvas/OpenLayers/OpenLayerCanvas'); /** * Default constructor. @@ -902,6 +904,11 @@ AbstractCustomMap.prototype.fitBounds = function (markers) { AbstractCustomMap.prototype.setProject = function (project) { this._project = project; }; + +/** + * + * @returns {Project} + */ AbstractCustomMap.prototype.getProject = function () { return this._project; }; @@ -926,5 +933,19 @@ AbstractCustomMap.prototype.triggerEvent = function (type, data) { } }; +AbstractCustomMap.prototype.createMapCanvas = function (div) { + var self = this; + + var mapCanvasType = self.getProject().getMapCanvasType(); + if (mapCanvasType === "GOOGLE_MAPS_API") { + self.setMapCanvas(new GoogleMapsApiCanvas(div, self.createMapOptions())); + } else if (mapCanvasType === "OPEN_LAYERS") { + self.setMapCanvas(new OpenLayerCanvas(div, self.createMapOptions())); + } else { + throw new Error("Unknown mapCanvasType: " + mapCanvasType); + } + self.registerMapClickEvents(); +}; + module.exports = AbstractCustomMap; diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js index 408becc5a1d36a9a7d4e9d78ce1ef57918570eaf..3c144e71c95c1491e3ad3e9ee33ca962cb5290e8 100644 --- a/frontend-js/src/main/js/map/CustomMap.js +++ b/frontend-js/src/main/js/map/CustomMap.js @@ -19,8 +19,6 @@ var ReferenceGenome = require('./data/ReferenceGenome'); var SecurityError = require('../SecurityError'); var Submap = require('./Submap'); -var GoogleMapsApiCanvas = require('./canvas/GoogleMaps/GoogleMapsApiCanvas'); -var OpenLayerCanvas = require('./canvas/OpenLayers/OpenLayerCanvas'); var Bounds = require('./canvas/Bounds'); var Point = require('./canvas/Point'); @@ -456,10 +454,7 @@ CustomMap.prototype.openSubmap = function (id) { CustomMap.prototype.customizeGoogleMapView = function (div) { var self = this; - self.setMapCanvas(new OpenLayerCanvas(div, self.createMapOptions())); - // self.setMapCanvas(new GoogleMapsApiCanvas(div, self.createMapOptions())); - - self.registerMapClickEvents(); + self.createMapCanvas(div); self.createLogo(); @@ -976,6 +971,10 @@ CustomMap.prototype.getInfoWindowForIdentifiedElement = function (identifiedElem return infoWindow; }; +/** + * + * @returns {null|number} + */ CustomMap.prototype.getActiveSubmapId = function () { return this._activeSubmapId; }; diff --git a/frontend-js/src/main/js/map/Submap.js b/frontend-js/src/main/js/map/Submap.js index 561af0afdd9b8ad925ee1108fa7bc2dcdf4702a9..8a7e7e5d864287322664995cfedb632f9accb9cf 100644 --- a/frontend-js/src/main/js/map/Submap.js +++ b/frontend-js/src/main/js/map/Submap.js @@ -77,14 +77,12 @@ Submap.prototype.open = function (htmlTag) { $(self.getElement()).dialog("open"); - self.setMapCanvas(new GoogleMapsApiCanvas(mapDiv, self.createMapOptions())); + self.createMapCanvas(mapDiv); self._createMapChangedCallbacks(); self.getMapCanvas().triggerListeners('resize'); - self.registerMapClickEvents(); - self.initialized = true; } else { $(self.getElement()).dialog("open"); diff --git a/frontend-js/src/main/js/map/data/Project.js b/frontend-js/src/main/js/map/data/Project.js index 43dbd5051a0f9f81186931f70ff8a84369b2eb2c..9c5748edd73e166b479553f7732d389711f8f32b 100644 --- a/frontend-js/src/main/js/map/data/Project.js +++ b/frontend-js/src/main/js/map/data/Project.js @@ -15,7 +15,7 @@ var logger = require('../../logger'); /** * - * @param {Project|string} data + * @param {Project|string} [data] * @constructor */ function Project(data) { diff --git a/frontend-js/src/test/js/helper.js b/frontend-js/src/test/js/helper.js index 04e9c7480dc2ed9709526bb3dffba15d0514afa3..f2a49e295f8138d291effd3f9125fe4997eb99e9 100644 --- a/frontend-js/src/test/js/helper.js +++ b/frontend-js/src/test/js/helper.js @@ -152,13 +152,26 @@ Helper.prototype.createComment = function (element) { }); }; -Helper.prototype.createProject = function () { +/** + * + * @param {Object} [params] + * @param {string} [params.mapCanvasType=OPEN_LAYERS] + * @returns {Project} + */ +Helper.prototype.createProject = function (params) { + if (params === undefined) { + params = {}; + } + if (params.mapCanvasType === undefined) { + params.mapCanvasType = "OPEN_LAYERS"; + } var result = new Project(); result.setProjectId("testId"); result.setId(this.idCounter++); result.addModel(this.createModel()); - var overlay = this.createOverlay(result); - result.addDataOverlay(overlay); + var overlay = this.createOverlay(result.getModels()[0]); + result.addDataOverlay(overlay, false); + result.setMapCanvasType(params.mapCanvasType); return result; }; @@ -330,7 +343,7 @@ Helper.prototype.createModel = function () { /** * - * @param {Model} [model] + * @param {MapModel} [model] * @returns {DataOverlay} */ Helper.prototype.createOverlay = function (model) { diff --git a/frontend-js/src/test/js/map/canvas/GoogleMaps/GoogleMapsApiCanvas-test.js b/frontend-js/src/test/js/map/canvas/GoogleMaps/GoogleMapsApiCanvas-test.js index c245f6e71ded5605080486533b12ca2a9e3aa258..c124fc6299958307da779338bfff02bfe6e04a3b 100644 --- a/frontend-js/src/test/js/map/canvas/GoogleMaps/GoogleMapsApiCanvas-test.js +++ b/frontend-js/src/test/js/map/canvas/GoogleMaps/GoogleMapsApiCanvas-test.js @@ -93,7 +93,8 @@ describe('GoogleMapsApiCanvas', function () { }); it("create polygon through drawingManager", function () { - var map = helper.createCustomMap(); + var project = helper.createProject({mapCanvasType: "GOOGLE_MAPS_API"}); + var map = helper.createCustomMap(project); var canvas = map.getMapCanvas(); map.setSelectionContextMenu(new SelectionContextMenu({ @@ -188,7 +189,8 @@ describe('GoogleMapsApiCanvas', function () { }); it("removeSelection", function () { - var map = helper.createCustomMap(); + var project = helper.createProject({mapCanvasType: "GOOGLE_MAPS_API"}); + var map = helper.createCustomMap(project); map.setActiveSubmapId(map.getId()); map.getMapCanvas().setSelectedArea(new google.maps.Rectangle({}));