diff --git a/www/plugins/map/i18n/locale-en-GB.json b/www/plugins/map/i18n/locale-en-GB.json index 4b1d6525ad862b1caaf0fa680b62b01b635ee5a1..cbac13090cf1b32e5a2d346e50770e0d7cbabd09 100644 --- a/www/plugins/map/i18n/locale-en-GB.json +++ b/www/plugins/map/i18n/locale-en-GB.json @@ -1,7 +1,8 @@ { "MAP": { "COMMON": { - "SEARCH_DOTS": "Search..." + "SEARCH_DOTS": "Search...", + "BTN_LOCALIZE_ME": "Localize me" }, "NETWORK": { "LOOKUP": { @@ -45,6 +46,13 @@ "BTN_GOOGLE_API": "Getting a key", "BTN_GOOGLE_API_WARNING": "requires a Google account", "GOOGLE_API_KEY_PLACEHOLDER": "eg: AIzaqyAgszvWm0tM81x1sMK_ipDHBI7EowLqR7I" + }, + "HELP": { + "TIP": { + "WOT": "This map displays <b>profiles with a position</b>, whether they are member accounts or not.<br/><br/>Only profiles with the option "appear on the map" has been activated.", + "WOT_BTN_LAYERS": "<b>Filter the displayed data</b>: members, pending registrations, simple portfolios, etc.", + "WOT_BTN_SEARCH": "You can <b>search</b> by name, public key, or member pseudonym." + } } } } diff --git a/www/plugins/map/i18n/locale-en.json b/www/plugins/map/i18n/locale-en.json index 4b1d6525ad862b1caaf0fa680b62b01b635ee5a1..cbac13090cf1b32e5a2d346e50770e0d7cbabd09 100644 --- a/www/plugins/map/i18n/locale-en.json +++ b/www/plugins/map/i18n/locale-en.json @@ -1,7 +1,8 @@ { "MAP": { "COMMON": { - "SEARCH_DOTS": "Search..." + "SEARCH_DOTS": "Search...", + "BTN_LOCALIZE_ME": "Localize me" }, "NETWORK": { "LOOKUP": { @@ -45,6 +46,13 @@ "BTN_GOOGLE_API": "Getting a key", "BTN_GOOGLE_API_WARNING": "requires a Google account", "GOOGLE_API_KEY_PLACEHOLDER": "eg: AIzaqyAgszvWm0tM81x1sMK_ipDHBI7EowLqR7I" + }, + "HELP": { + "TIP": { + "WOT": "This map displays <b>profiles with a position</b>, whether they are member accounts or not.<br/><br/>Only profiles with the option "appear on the map" has been activated.", + "WOT_BTN_LAYERS": "<b>Filter the displayed data</b>: members, pending registrations, simple portfolios, etc.", + "WOT_BTN_SEARCH": "You can <b>search</b> by name, public key, or member pseudonym." + } } } } diff --git a/www/plugins/map/i18n/locale-fr-FR.json b/www/plugins/map/i18n/locale-fr-FR.json index aee644d6604a52290a781f9f7a7047815146e87c..6a25cd993c7564061b90cc41b613d70774bf94fe 100644 --- a/www/plugins/map/i18n/locale-fr-FR.json +++ b/www/plugins/map/i18n/locale-fr-FR.json @@ -50,7 +50,7 @@ "HELP": { "TIP": { "WOT": "Cette carte affiche <b>les profils ayant une position</b>, qu'ils correspondent à des comptes membre ou non.<br/><br/>Seuls sont visibles les profils dont l'option "apparaitre sur le carte" a été activée.", - "WOT_BTN_LAYERS": "<b>Filtrez ici les données</b> affichées : membres, inscriptions en attente, simples portefeuilles, etc.", + "WOT_BTN_LAYERS": "<b>Filtrez ici les données affichées</b>: membres, inscriptions en attente, simples portefeuilles, etc.", "WOT_BTN_SEARCH": "Vous pouvez <b>effectuer une recherche</b> par nom, clef publique ou pseudonyme de membre." } } diff --git a/www/plugins/map/js/controllers/wot-controllers.js b/www/plugins/map/js/controllers/wot-controllers.js index ae56d76428936cb933f700efd5468192f6de2795..0a2702be038b1768bbb13aada95a0ac9afa80327 100644 --- a/www/plugins/map/js/controllers/wot-controllers.js +++ b/www/plugins/map/js/controllers/wot-controllers.js @@ -26,7 +26,8 @@ angular.module('cesium.map.wot.controllers', ['cesium.services', 'cesium.map.ser controller: 'MapWotViewCtrl' } }, - cache: false, + // Seems to works without cache ?? + //cache: false, data: { silentLocationChange: true } @@ -103,9 +104,26 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti loading: true }, $scope.mapId); + // [NEW] When opening the view $scope.enter = function(e, state) { + + if ($scope.loading) { + if (state.stateParams && state.stateParams.c) { + var cPart = state.stateParams.c.split(':'); + $scope.map.center.lat = parseFloat(cPart[0]); + $scope.map.center.lng = parseFloat(cPart[1]); + $scope.map.center.zoom = parseInt(cPart[2]); + } + + $scope.$watch("map.center", function() { + if (!$scope.loading) { + return $timeout(function() { + $scope.updateLocationHref(); + }, 300); + } + }, true); // Load the map (and init if need) $scope.loadMap() @@ -117,7 +135,7 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti }); } else { - // Make sur to have previous center coordinate defined in the location URL + // Make sure to have previous center coordinate defined in the location URL $scope.updateLocationHref(); if (csWallet.isLogin()) { $scope.showHelpTip(); @@ -128,9 +146,9 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti // View leave: store map options (center) to cache $scope.leave = function() { - if ($scope.map.cache) { + /*if ($scope.map.cache) { MapUtils.cache.save($scope.map); - } + }*/ }; $scope.$on('$ionicView.leave', $scope.leave); @@ -209,9 +227,9 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti popupMarker && popupMarker.openPopup(); }, 400); }, - firstTipSubmit: true, - tooltipLimit: 50, - hideMarkerOnCollapse: true + //firstTipSubmit: true, + tooltipLimit: 50/*, + hideMarkerOnCollapse: true*/ }).addTo(map); // Add marker cluster layer @@ -245,6 +263,10 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti }); markerClusterLayer.addTo(map); + // Bind map with options (e.g. to received overlays visibility updates) + // Cache no more need, as view is not cached + //MapUtils.cache.bind($scope, $scope.mapId, $scope.map); + $scope.map.loading = false; return map; }); @@ -253,9 +275,9 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti // Load markers data $scope.load = function(map) { if (!map) { - return leafletData.getMap($scope.mapId).then(function(map) { - return $scope.load(map); // loop with the map object - }); + return leafletData.getMap($scope.mapId) + // loop with the map object + .then($scope.load); } $scope.loading = true; @@ -268,7 +290,7 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti } }; - // Load wot data + // Load wot data, from service return mapWot.load(options) .then(function(res) { @@ -321,7 +343,9 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti searchMarker)); }); } + $scope.map.markers = markers; + $scope.loading = false; // hide loading indicator @@ -335,13 +359,14 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti var params = $location.search() || {}; if (!params.c || !MapUtils.center.isDefault($scope.map.center)) { centerHash = centerHash || '{0}:{1}:{2}'.format($scope.map.center.lat.toFixed(4), $scope.map.center.lng.toFixed(4), $scope.map.center.zoom); - $location.search({ c: centerHash}).replace(); + $location.search({c: centerHash}).replace(); } // endRemoveIf(device) }; // removeIf(device) // Update the browser location, to be able to refresh the page + // FIXME: not need, should be removed $scope.$on("centerUrlHash", function(event, centerHash) { if (!$scope.loading) { @@ -355,8 +380,8 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti /* -- help tip -- */ + // Show help tour $scope.startHelpTour = function() { - //$scope.hideActionsPopover(); return $scope.showHelpTip(0, true); }; diff --git a/www/plugins/map/js/services/utils-services.js b/www/plugins/map/js/services/utils-services.js index 1f53a698dbe065fd6a2b4ad02cb67b8b314ef562..e38d88b746ca5584c0e6a94d17d142da18e2f928 100644 --- a/www/plugins/map/js/services/utils-services.js +++ b/www/plugins/map/js/services/utils-services.js @@ -43,7 +43,7 @@ angular.module('cesium.map.utils.services', ['cesium.services', 'ui-leaflet']) continuousWorld: true } }, - cycle: { + google: { name: "Google map", type: "xyz", url: (isHttps ? 'https' : 'http' ) + '://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}&key='+googleApiKey, @@ -62,7 +62,7 @@ angular.module('cesium.map.utils.services', ['cesium.services', 'ui-leaflet']) // Restore existing map options if (options.cache && data.cache[options.cache]) { - console.debug("Restoring cache :", data.cache[options.cache]); + console.debug("[map] Restoring map from cache :", data.cache[options.cache]); options = angular.merge(options, data.cache[options.cache]); } @@ -93,6 +93,50 @@ angular.module('cesium.map.utils.services', ['cesium.services', 'ui-leaflet']) }, 300); } + function bindMapOptions(scope, mapId, options) { + options = options || {}; + if (!mapId || !options.layers || !scope) throw 'Illegal arguments'; + if (!options.cache) return; // no cache, so bind not need + + // Bind overlays visibility + if (options.layers.overlays) { + var overlayNames = _.keys(options.layers.overlays); + + // Init the cache if need + if (!data.cache[options.cache]) { + data.cache[options.cache] = { + center: options.center, + bounds: options.bounds, + layers: angular.copy(options.layers) + }; + } + + // Listen for changes + leafletData.getMap(mapId) + .then(function() { + _($window.document.querySelectorAll('#{0} .leaflet-control-layers-overlays input[type=checkbox]'.format(mapId))) + .forEach(function (element, index) { + var overlayName = overlayNames[index]; + var state = options.layers.overlays[overlayName].visible; + element.addEventListener('change', function (e) { + state = !state; // update state + // update cache + data.cache[options.cache].layers.overlays[overlayName].visible = state; + }); + }); + }); + } + + // Refresh center and bound, when leaving the view + scope.$on('$ionicView.leave', function() { + // update center and bounds + data.cache[options.cache].center = options.center; + data.cache[options.cache].bounds = options.bounds; + }); + + } + + function getCenter(options) { if (!options) return; var center; @@ -129,18 +173,6 @@ angular.module('cesium.map.utils.services', ['cesium.services', 'ui-leaflet']) return false; } - function saveMapOptions(options) { - if (options.cache) { - data.cache[options.cache] = { - center: options.center, - bounds: options.bounds, - layers: { - baselayers: options.layers.baselayers - } - }; - } - } - // Set the id of a control (set the attribute 'id' of the HTML container) function setControlId(control, id) { if (!control || !id) throw 'Illegal arguments'; @@ -202,13 +234,12 @@ angular.module('cesium.map.utils.services', ['cesium.services', 'ui-leaflet']) states:[{ // specify different icons and responses for your button stateName: 'locate-me', onClick: function(btn, map){ - return esGeo.point.current() + esGeo.point.current() .then(function(res) { - map.invalidateSize(); - map._resetView({ + map.setView({ lat: res.lat, lng: res.lon - }, constants.LOCALIZE_ZOOM, true); + }, constants.LOCALIZE_ZOOM); }) .catch(function(err) { console.error(err); @@ -223,19 +254,19 @@ angular.module('cesium.map.utils.services', ['cesium.services', 'ui-leaflet']) return { map: initMap, + updateCenter: updateMapCenter, center: { get: getCenter, isSame: isSameCenter, isDefault: isDefaultCenter }, - updateCenter: updateMapCenter, control: { search: initSearchControl, localizeMe: initLocalizeMeControl, setId: setControlId }, cache: { - save: saveMapOptions + bind: bindMapOptions }, constants: constants }; diff --git a/www/plugins/map/templates/wot/view_map.html b/www/plugins/map/templates/wot/view_map.html index 102f82f10b522ae3efd418fe3bdb1ef8500bea34..e6febd5583267d00b6f7b77c62bda1a8c5cad02b 100644 --- a/www/plugins/map/templates/wot/view_map.html +++ b/www/plugins/map/templates/wot/view_map.html @@ -10,9 +10,8 @@ <ion-content data-tap-disabled="true"> <a id="helptip-map-wot" style="left: 150px; top: 50px; position: relative;"></a> - <leaflet id="{{mapId}}" + <leaflet id="{{::mapId}}" height="100%" - url-hash-center="yes" layers="map.layers" markers="map.markers" lf-center="map.center"