diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d26f7557dadae45261078c95105c38769ee10c2..b926ed15fbe38763c5ce213b7d1a2daa271811d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed (for changes in existing functionality) +* Added `show` option to caosdb_map.MapConfig for showing the map initially and + storing the state accross page reloads. Defaults to `false`. This also bumps + the version of the map to 0.4.1 as it changes the behavior but the change is + backwards-compatible for the map config. Clients need to update their + version string in their config file, tho. + ### Deprecated (for soon-to-be removed features) ### Removed (for now removed features) diff --git a/src/core/js/ext_map.js b/src/core/js/ext_map.js index c20cdefc2e9de73a21db81e3a7d5ebacebe73416..c810163d2444c11fdf0c8ab16cb6b10d72c76eda 100644 --- a/src/core/js/ext_map.js +++ b/src/core/js/ext_map.js @@ -25,7 +25,7 @@ /** * @module caosdb_map - * @version 0.4 + * @version 0.4.1 * * For displaying a geographical map which shows entities at their associated * geolocation. @@ -34,7 +34,7 @@ * `conf/ext/json/ext_map.json` and comply with the {@link MapConfig} type * which is described below. * - * The current version is 0.4. It is not considered to be stable because + * The current version is 0.4.1. It is not considered to be stable because * implementation of the graticule still is not satisfactory. * * Apart from that the specification of the configuration and the @@ -43,7 +43,7 @@ var caosdb_map = new function () { var logger = log.getLogger("caosdb_map"); - this.version = "0.4"; + this.version = "0.4.1"; this.dependencies = ["log", { "L": ["latlngGraticule", "Proj"] }, "navbar", "caosdb_utils"]; @@ -63,6 +63,9 @@ var caosdb_map = new function () { * integrated query generator. * * @typedef {object} MapConfig + * @property {boolean} [show=false] - show the map immediately when it is + * ready. This configuration option is being stored locally for keeping + * the map shown/hidden accross page reloads. * @property {string} version - the version of the map * @property {string} default_view - the view which is shown when the user * opens the map and has no stored view from prior visits to the map. @@ -336,6 +339,7 @@ var caosdb_map = new function () { */ this._default_config = { "version": this.version, + "show": false, "datamodel": { "lat": "latitude", "lng": "longitude", @@ -843,8 +847,10 @@ var caosdb_map = new function () { * * The map panel is the HTMLElement which contains the map. Is is * hidden or shown when the user clicks on the toggle map button. + * + * @param {boolean} show - show this panel immediately. */ - this.init_map_panel = function () { + this.init_map_panel = function (show) { logger.trace("enter init_map_panel"); // remove old @@ -852,7 +858,9 @@ var caosdb_map = new function () { let panel = this.create_map_panel(); - $(panel).hide(); + if(!show) { + $(panel).hide(); + } $('nav').first().after(panel); logger.trace("leave init_map_panel"); @@ -865,6 +873,7 @@ var caosdb_map = new function () { */ this.toggle_map = function () { logger.trace("enter toggle_map"); + sessionStorage["caosdb_map.show"] = !$(".caosdb-f-map-panel").is(":visible"); $(".caosdb-f-map-panel").toggle(900, () => this ._toggle_cb()); } @@ -872,6 +881,7 @@ var caosdb_map = new function () { this.show_map = function () { logger.trace("enter show_map"); + sessionStorage["caosdb_map.show"] = "true"; $(".caosdb-f-map-panel").show(900, () => this ._toggle_cb()); } @@ -983,14 +993,18 @@ var caosdb_map = new function () { return; } this.config = config; + var show_map = config.show; + if(sessionStorage["caosdb_map.show"]) { + show_map = JSON.parse(sessionStorage["caosdb_map.show"]); + } this.init_select_handler(); this.init_view_change_handler(); - panel = this.init_map_panel(); + panel = this.init_map_panel(show_map); // TODO split in smaller pieces and move callback to separate function this.change_map_view = (view) => { if (this._map) { - this._map._container.remove(); + this._map._container.remove(); this._map.remove(); } diff --git a/test/core/js/modules/ext_map.js.js b/test/core/js/modules/ext_map.js.js index 9b6b01022d8106153d50eaa906a0ce33803a8dc3..4425b2e79076d92819cc31e2f5852ed1305bff54 100644 --- a/test/core/js/modules/ext_map.js.js +++ b/test/core/js/modules/ext_map.js.js @@ -51,7 +51,7 @@ QUnit.module("ext_map.js", { }); QUnit.test("availability", function (assert) { - assert.equal(caosdb_map.version, "0.4", "test version"); + assert.equal(caosdb_map.version, "0.4.1", "test version"); assert.ok(caosdb_map.init, "init available"); }); @@ -125,6 +125,20 @@ QUnit.test("create_map_panel", function (assert) { assert.ok($(panel).hasClass("container"), "has class container"); }); +QUnit.test("init_map_panel", function (assert) { + assert.ok(caosdb_map.init_map_panel, "available"); + const dummy_nav = $("<nav/>"); + $(document.body).append(dummy_nav); + let panel = caosdb_map.init_map_panel(true); + + assert.ok($(panel).is(":visible"), "Panel is visible"); + + panel = caosdb_map.create_map_panel(true); + assert.notOk($(panel).is(":visible"), "Panel is not visible"); + + dummy_nav.remove(); +}); + QUnit.test("create_map_view", function (assert) { var view_config = $.extend(true, {}, caosdb_map._unconfigured_views[0], { "select": true,