diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js index f1706fcab5cce893ded4f08deabfa52c5ec498d8..7156e413da97d1d7b3ffbe8996dd1d682a283734 100644 --- a/frontend-js/src/main/js/map/CustomMap.js +++ b/frontend-js/src/main/js/map/CustomMap.js @@ -1037,6 +1037,16 @@ CustomMap.prototype.getOverlayByName = function(name) { return this.overlayCollections[name]; }; +CustomMap.prototype.getDbOverlays = function() { + var result = []; + for (var overlayName in this.overlayCollections) { + if (this.overlayCollections.hasOwnProperty(overlayName)) { + result.push(this.overlayCollections[overlayName]); + } + } + return result; +}; + /** * Returns {@link AbstractInfoWindow} for element identified by the parameter. * diff --git a/frontend-js/src/main/js/minerva.js b/frontend-js/src/main/js/minerva.js index a0c667f285f98aaf5d183768eec9617a6d99fc62..7b8a1000ab833ba084066d944417c9ce3ba5f74b 100644 --- a/frontend-js/src/main/js/minerva.js +++ b/frontend-js/src/main/js/minerva.js @@ -18,6 +18,8 @@ var SelectionContextMenu = require('./gui/SelectionContextMenu'); var OriginalGuiConnector = require('./GuiConnector'); var OriginalServerConnector = require('./ServerConnector'); +var Promise = require("bluebird"); + var logger = require('./logger'); function processUrlGetParams(params) { @@ -128,7 +130,42 @@ function createDivStructure(element) { name : "selectionContextMenu", }); element.appendChild(selectionContextMenu); +} +function createResult(customMap) { + return { + getSelectedDataOverlays : function() { + return customMap.getSelectedLayouts(); + }, + getHiglightedElements : function(dbOverlayName) { + var dbOverlay = customMap.getOverlayByName(dbOverlayName); + if (dbOverlay === null) { + var validOverlays = ""; + var overlays = customMap.getDbOverlays(); + for ( var overlay in overlays) { + if (overlays.hasOwnProperty(overlay)) { + validOverlays += overlay.getName() + ", "; + } + } + throw new Error("Invalid DbOverlay: " + dbOverlayName + ". Valid DbOverlays: " + validOverlays); + } else { + return dbOverlay.getIdentifiedElements().then( + function(identifiedElements) { + var result = []; + return Promise.each( + identifiedElements, + function(item) { + return customMap.getSubmapById(item.getModelId()).getModel().getByIdentifiedElement(item, true) + .then(function(fullElement) { + result.push(fullElement); + }); + }).then(function() { + return result; + }); + }); + } + } + }; } function create(params) { @@ -171,44 +208,44 @@ function create(params) { createDivStructure(element); params.setElement(functions.getElementByName(element, "mapDiv")); - var result = new CustomMap(params); + var customMap = new CustomMap(params); new DbOverlayCollection({ - map : result + map : customMap }); var leftPanel = new LeftPanel({ element : functions.getElementByName(element, "leftPanelDiv"), - customMap : result + customMap : customMap }); var topMenu = new TopMenu({ element : functions.getElementByName(element, "menuDiv"), - customMap : result + customMap : customMap }); var legend = new Legend({ element : functions.getElementByName(element, "legendDiv"), - customMap : result + customMap : customMap }); var mapContextMenu = new MapContextMenu({ element : functions.getElementByName(element, "contextMenu"), - customMap : result + customMap : customMap }); - result.setContextMenu(mapContextMenu); + customMap.setContextMenu(mapContextMenu); var selectionContextMenu = new SelectionContextMenu({ element : functions.getElementByName(element, "selectionContextMenu"), - customMap : result + customMap : customMap }); - result.setSelectionContextMenu(selectionContextMenu); + customMap.setSelectionContextMenu(selectionContextMenu); topMenu.setLegend(legend); topMenu.setLeftPanel(leftPanel); - return result.init().then(function() { - return insertGoogleAnalyticsCode(result); + return customMap.init().then(function() { + return insertGoogleAnalyticsCode(customMap); }).then(function() { return leftPanel.init(); }).then(function() { @@ -225,7 +262,7 @@ function create(params) { for (var j = 0; j < layouts.length; j++) { var layout = layouts[j]; if (layout.getName() === GuiConnector.getParams["layout"]) { - return result.openDataOverlay(layout); + return customMap.openDataOverlay(layout); } } } @@ -233,11 +270,14 @@ function create(params) { var submapId = GuiConnector.getParams["submap"]; if (submapId !== undefined) { - result.openSubmap(submapId); + return customMap.openSubmap(submapId); } + }).then(function() { + var result = createResult(customMap); if (params.isDebug()) { - global.leftPanel = leftPanel; + result.leftPanel = leftPanel; + result.customMap = customMap; } return result; }); diff --git a/frontend-js/src/test/js/minerva-test.js b/frontend-js/src/test/js/minerva-test.js index bac9ad5f874aa3e356be3194a093b149f723d581..bb5635c0a97f5cbc5bd9d0398c1fbab36a5085c1 100644 --- a/frontend-js/src/test/js/minerva-test.js +++ b/frontend-js/src/test/js/minerva-test.js @@ -105,7 +105,7 @@ describe('minerva global', function() { return minerva.create(options).then(function(result) { assert.ok(result); // input file is not available so it's the background - assert.equal(result.getSelectedLayouts().length, 0); + assert.equal(result.getSelectedDataOverlays().length, 0); assert.equal(ServerConnector.getSessionData(project).getSelectedBackgroundOverlay(), layoutId); assert.equal(logger.getWarnings().length, 0); }); @@ -147,7 +147,7 @@ describe('minerva global', function() { return minerva.create(options).then(function(result) { assert.ok(result); // input file is available so it's not the background file but overlay - assert.equal(result.getSelectedLayouts().length, 1); + assert.equal(result.getSelectedDataOverlays().length, 1); assert.equal(logger.getWarnings().length, 0); }); }); @@ -161,7 +161,7 @@ describe('minerva global', function() { var options = helper.createOptions(project); return minerva.create(options).then(function(result) { - return result.getOverlayByName("search").getIdentifiedElements(); + return result.getHiglightedElements("search"); }).then(function(elements) { assert.ok(elements.length > 0); });