diff --git a/src/closure/conf/externs/vmap.js b/src/closure/conf/externs/vmap.js index b799165a0202a74c3d1fe51fe8ad666558122205..d9eff8e1c7ab9a59d3f9949b81a96f48824d9204 100755 --- a/src/closure/conf/externs/vmap.js +++ b/src/closure/conf/externs/vmap.js @@ -32,7 +32,7 @@ function bootstrapTable(arg1) {} function sortable(arg1) {} /** - * + * * @param {string} key * @returns {undefined} */ @@ -72,4 +72,4 @@ ol.source.TileEvent.tile * @type {string} * @see http://www.w3.org/TR/pointerevents/#the-touch-action-css-property */ -CSSProperties.prototype.touchAction; \ No newline at end of file +CSSProperties.prototype.touchAction; diff --git a/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json b/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json index 3c173b8f08c119992b87cab41bc204d55f9e7ed5..45642a3929dd6073831ede459b1149145b68e4d4 100755 --- a/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json +++ b/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json @@ -64,13 +64,13 @@ "label": "", "required": false, "nb_cols": 12, - "id": "Element_0_1_1", + "id":"anc_saisie_anc_controle_schema_map", "style": { "height": "350px" }, "grid_height": "150px", "map_options": { - "proj": "EPSG:3857", + "proj": "EPSG:2154", "base_proj": "EPSG:4326", "output_format": "geojson", "type": "OSM", @@ -307,6 +307,7 @@ ] } ], + "initEvent": "initAncControleSchemaFormMap()", "event": "sendSimpleForm()" } } diff --git a/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json b/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json index 3fa7403c885eecb9b18e8be300315c8146467e3d..76476b275a6405f3ee3e1e5b78fd88a04150ef50 100755 --- a/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json +++ b/src/module_anc/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json @@ -307,7 +307,7 @@ "label":"Emplacement", "required":false, "nb_cols":12, - "id":"geom_7_1", + "id":"anc_saisie_anc_installation_suivi_map", "style":{ "height":"350px" }, @@ -411,4 +411,4 @@ "datasources":{ } -} \ No newline at end of file +} diff --git a/src/module_anc/module/javascript/anc_saisie_map.js b/src/module_anc/module/javascript/anc_saisie_map.js new file mode 100644 index 0000000000000000000000000000000000000000..0ecd9857a302ebdb888e128f58ad5bd89b35d391 --- /dev/null +++ b/src/module_anc/module/javascript/anc_saisie_map.js @@ -0,0 +1,396 @@ +/* global vitisApp, goog, angular, bootbox, oVFB */ + +'use strict'; +goog.provide('vmap.anc.anc_saisie_map'); +vitisApp.on('appMainDrtvLoaded', function () { + + var $q = angular.element(vitisApp.appMainDrtv).injector().get(['$q']); + var $log = angular.element(vitisApp.appMainDrtv).injector().get(['$log']); + var envSrvc = angular.element(vitisApp.appMainDrtv).injector().get(['envSrvc']); + var $rootScope = angular.element(vitisApp.appMainDrtv).injector().get(["$rootScope"]); + var propertiesSrvc = angular.element(vitisApp.appMainDrtv).injector().get(['propertiesSrvc']); + + /** + * Initialise la carte du menu installation > suivi + */ + angular.element(vitisApp.appMainDrtv).scope()['initAncInstallationSuiviFormMap'] = function () { + $log.info("initAncInstallationSuiviFormMap"); + + var this_ = this; + var scope = this; + + // Remplace si besoin l'identifiant et le type de carte à utiliser + var sMapId = this['getAncFormMapId']('installation'); + this['setFormMapTreeByMapId'](sMapId); + + // Résultat de la propertie anc.installation.zoom_on_parcelle + var bZoomOnParcelle = this['getAncZoomOnParcellePropertie'](propertiesSrvc, 'installation'); + + // Récupère l'identifiant de la parcelle correspondante + var sIdPar = this['getAncInstallSuiviIdPar'](scope); + + // Récupère la géométrie de l'installation + var sGeom = this['ancMapGetFormGeom'](scope, 'installation'); + + if (!goog.isDefAndNotNull(sGeom)) { + // Zoom la carte sur la parcelle + if (goog.isDefAndNotNull(sIdPar) && bZoomOnParcelle === true) { + this['ancMapZoomOnParcelle'](sIdPar, 'installation'); + } + } + } + + /** + * Initialise la carte du menu controle > schema + */ + angular.element(vitisApp.appMainDrtv).scope()['initAncControleSchemaFormMap'] = function () { + $log.info("initAncInstallationSuiviFormMap"); + + var this_ = this; + var scope = angular.element("form[name='" + envSrvc["oFormDefinition"][envSrvc["sFormDefinitionName"]]["name"]).scope(); + + // Remplace si besoin l'identifiant et le type de carte à utiliser + var sMapId = this['getAncFormMapId']('controle'); + this['setFormMapTreeByMapId'](sMapId); + + // Résultat de la propertie anc.installation.zoom_on_parcelle + var bZoomOnParcelle = this['getAncZoomOnParcellePropertie'](propertiesSrvc, 'controle'); + + // Récupère la géométrie de l'installation + var sGeom = this['ancMapGetFormGeom'](scope, 'controle'); + + // Récupère l'identifiant de la parcelle correspondante + var sIdPar = this['getAncControleSchemaIdPar'](scope).then(function(sIdPar){ + + // Zoom la carte sur la parcelle + if (!goog.isDefAndNotNull(sGeom)) { + if (goog.isDefAndNotNull(sIdPar) && bZoomOnParcelle === true) { + this_['ancMapZoomOnParcelle'](sIdPar, 'controle'); + } + } + }); + } + + /** + * Remplace la carte OSM si une carte est fournie sur properties.anc.installation..map_id + * @param {string} sMapId map id + */ + angular.element(vitisApp.appMainDrtv).scope()['setFormMapTreeByMapId'] = function (sMapId) { + $log.info("initAncInstallationSuiviFormMapTree"); + + var formScope = angular.element("form[name='" + envSrvc["oFormDefinition"][envSrvc["sFormDefinitionName"]]["name"]).scope(); + + var oForm; + if (goog.isDefAndNotNull(formScope)) { + if (goog.isDefAndNotNull(formScope['oFormDefinition'])) { + if (goog.isDefAndNotNull(formScope['oFormDefinition'][envSrvc["sFormDefinitionName"]])) { + oForm = formScope['oFormDefinition'][envSrvc["sFormDefinitionName"]]; + } + } + } + if (goog.isDefAndNotNull(oForm) && goog.isDefAndNotNull(sMapId)) { + if (goog.isArray(oForm['rows'])) { + for (var i = 0; i < oForm['rows'].length; i++) { + if (goog.isArray(oForm['rows'][i]['fields'])) { + for (var ii = 0; ii < oForm['rows'][i]['fields'].length; ii++) { + if (goog.isObject(oForm['rows'][i]['fields'][ii]['map_options'])) { + if(oForm['rows'][i]['fields'][ii]['type'] === 'map_osm'){ + oForm['rows'][i]['fields'][ii]['type'] = 'map_vmap'; + } + oForm['rows'][i]['fields'][ii]['map_options']['type'] = 'vmap'; + oForm['rows'][i]['fields'][ii]['map_options']['map_id'] = sMapId; + } + } + } + } + } + } + } + + /** + * Récupère l'identifiant de la cate fourni sur properties.anc.installation.map_id + * + * @return {string|undefined} map_id + */ + angular.element(vitisApp.appMainDrtv).scope()['getAncFormMapId'] = function (sObject) { + + var sMapId; + if (goog.isDefAndNotNull(propertiesSrvc)) { + if (goog.isDefAndNotNull(propertiesSrvc["anc"])) { + if (goog.isDefAndNotNull(propertiesSrvc["anc"][sObject])) { + if (goog.isDefAndNotNull(propertiesSrvc["anc"][sObject]["map_id"])) { + if (propertiesSrvc["anc"][sObject]["map_id"] !== false) { + sMapId = propertiesSrvc["anc"][sObject]["map_id"]; + } + } + } + } + } + return sMapId; + } + + /** + * Get propertie anc.installation.zoom_on_parcelle + * + * @param {object} oProperties Properties + * @return {boolean} anc.installation.zoom_on_parcelle value + */ + angular.element(vitisApp.appMainDrtv).scope()['getAncZoomOnParcellePropertie'] = function(oProperties, sObject){ + $log.info('getAncZoomOnParcellePropertie'); + + var bZoomOnParcelle = false; + if (goog.isDefAndNotNull(oProperties)) { + if (goog.isDefAndNotNull(oProperties["anc"])) { + if (goog.isDefAndNotNull(oProperties["anc"][sObject])) { + if (goog.isDefAndNotNull(oProperties["anc"][sObject]["zoom_on_parcelle"])) { + if (oProperties["anc"][sObject]["zoom_on_parcelle"] === true) { + bZoomOnParcelle = true; + } + } + } + } + } + return bZoomOnParcelle; + } + + /** + * Récupère l'id_par correspondant à l'installation + * + * @param {object} scope description + * @return {string|undefined} id_par de la parcelle correspondante + */ + angular.element(vitisApp.appMainDrtv).scope()['getAncInstallSuiviIdPar'] = function(scope){ + $log.info('getAncInstallSuiviIdPar'); + + var sParcelle; + if (goog.isDefAndNotNull(scope['oFormValues'])) { + if (goog.isDefAndNotNull(scope['sFormDefinitionName'])) { + if (goog.isDefAndNotNull(scope['oFormValues'][scope['sFormDefinitionName']])) { + if (goog.isDefAndNotNull(scope['oFormValues'][scope['sFormDefinitionName']]['id_parc'])) { + sParcelle = scope['oFormValues'][scope['sFormDefinitionName']]['id_parc']; + } + } + } + } + + return sParcelle; + } + + /** + * Récupère l'id_par correspondant à l'installation dans une promesse + * + * @param {object} scope description + * @return {promise} + */ + angular.element(vitisApp.appMainDrtv).scope()['getAncControleSchemaIdPar'] = function(scope){ + $log.info('getAncControleSchemaIdPar'); + + var deferred = $q.defer(); + + var sInstall = this['getAncControleSchemaIdInstall'](scope); + + // Requête Ajax pour récupérer la définition complète de l'install + if (!goog.isDefAndNotNull(sInstall) || sInstall == '') { + console.error('id_installation non valide'); + deferred.reject(); + } else { + // Récupère la liste des rapports disponibles + ajaxRequest({ + 'method': 'GET', + 'url': propertiesSrvc["web_server_name"] + "/" + propertiesSrvc["services_alias"] + '/anc/installations/' + sInstall, + 'headers': { + 'Accept': 'application/x-vm-json' + }, + 'success': function (response) { + if (!goog.isDefAndNotNull(response['data'])) { + console.error('response.data undefined: ', response); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'])) { + console.error('Aucune installation disponible pour ' + sInstall); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0])) { + console.error('Aucune installation disponible pour ' + sInstall); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0]['id_parc'])) { + console.error('Aucune parcelle disponible pour ' + sInstall); + deferred.reject(); + return 0; + } + var sParcelle = response['data']['data'][0]['id_parc']; + deferred.resolve(sParcelle); + } + }); + } + + return deferred.promise; + } + + /** + * Récupère l'id_install correspondant au contrôle + * + * @param {object} scope description + * @return {string|undefined} id_install de la parcelle correspondante + */ + angular.element(vitisApp.appMainDrtv).scope()['getAncControleSchemaIdInstall'] = function(scope){ + $log.info('getAncControleSchemaIdInstall'); + + var sInstall; + if (goog.isDefAndNotNull(scope['oFormValues'])) { + if (goog.isDefAndNotNull(scope['sFormDefinitionName'])) { + if (goog.isDefAndNotNull(scope['oFormValues'][scope['sFormDefinitionName']])) { + if (goog.isDefAndNotNull(scope['oFormValues'][scope['sFormDefinitionName']]['id_installation'])) { + sInstall = scope['oFormValues'][scope['sFormDefinitionName']]['id_installation']; + } + } + } + } + + return sInstall; + } + + /** + * Récupère la geom correspondant à l'installation + * + * @param {object} scope description + * @return {string|undefined} + */ + angular.element(vitisApp.appMainDrtv).scope()['ancMapGetFormGeom'] = function(scope, sObject){ + $log.info('ancMapGetFormGeom'); + + var sGeom, sField; + + if (sObject === 'installation') { + sField = 'geom'; + } + if (sObject === 'controle') { + sField = 'composants'; + } + + if (goog.isDefAndNotNull(sField)) { + if (goog.isDefAndNotNull(scope['oFormValues'])) { + if (goog.isDefAndNotNull(scope['sFormDefinitionName'])) { + if (goog.isDefAndNotNull(scope['oFormValues'][scope['sFormDefinitionName']])) { + if (goog.isDefAndNotNull(scope['oFormValues'][scope['sFormDefinitionName']][sField])) { + sGeom = scope['oFormValues'][scope['sFormDefinitionName']][sField]; + } + } + } + } + } + + return sGeom; + } + + /** + * Requeête Ajax pour récupérer la définition de la parcelle + * + * @param {string} sIdPar id_par de la parcelle + * @return {promise} + */ + angular.element(vitisApp.appMainDrtv).scope()['ancMapGetParcelleDef'] = function(sIdPar){ + $log.info('ancMapGetParcelleDef'); + + var deferred = $q.defer(); + + if (!goog.isDefAndNotNull(sIdPar) || sIdPar == '') { + console.error('id_par non valide'); + deferred.reject(); + } else { + + // Récupère la liste des rapports disponibles + ajaxRequest({ + 'method': 'GET', + 'url': propertiesSrvc["web_server_name"] + "/" + propertiesSrvc["services_alias"] + '/cadastreV2/parcelles/' + sIdPar, + 'headers': { + 'Accept': 'application/x-vm-json' + }, + 'success': function (response) { + if (!goog.isDefAndNotNull(response['data'])) { + console.error('response.data undefined: ', response); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'])) { + console.error('Aucune parcelle disponible pour ' + sIdPar); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0])) { + console.error('Aucune parcelle disponible pour ' + sIdPar); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0]['id_par'])) { + console.error('Aucune parcelle disponible pour ' + sIdPar); + deferred.reject(); + return 0; + } + var oParcelle = response['data']['data'][0]; + deferred.resolve(oParcelle); + } + }); + } + + return deferred.promise; + } + + /** + * Met à jour l'étendue de la carte sur des features + * + * @param {object} oMap carte + * @param {array} aFeatures features + */ + angular.element(vitisApp.appMainDrtv).scope()['ancMapUpdateOlMapExtent'] = function(oMap, aFeatures){ + $log.info('ancMapUpdateOlMapExtent'); + + if (goog.isDefAndNotNull(aFeatures[0])) { + var featureExtent = aFeatures[0].getGeometry().getExtent(); + oMap.MapObject.getView().fit(featureExtent); + if (aFeatures[0].getGeometry().getType() === 'Point') { + oMap.MapObject.getView().setZoom(15); + } + } + } + + /** + * Zoom la carte sur la parcelle correspondante + * + * @param {string} sIdPar id_par de la parcelle + * @return {promise} + */ + angular.element(vitisApp.appMainDrtv).scope()['ancMapZoomOnParcelle'] = function(sIdPar, sObject){ + $log.info('ancMapZoomOnParcelle'); + + var this_ = this; + var sMapElemId; + + if (sObject === 'installation') { + sMapElemId = 'anc_saisie_anc_installation_suivi_map'; + } else if (sObject === 'controle') { + sMapElemId = 'anc_saisie_anc_controle_schema_map'; + } + + if (goog.isDefAndNotNull(sIdPar) || sIdPar == '') { + this['ancMapGetParcelleDef'](sIdPar).then(function(oParcelle){ + setTimeout(function () { + var oMap = angular.element($('#' + sMapElemId)).scope()['oMap']; + var sGeom = oParcelle['geom']; + if (!goog.isDefAndNotNull(sGeom) || sGeom == '') { + console.error('parcelle ' + sIdPar + ' non valide'); + return null; + } + var aFeatures = oMap.getFeaturesByString(oParcelle['geom'], 'ewkt'); + this_['ancMapUpdateOlMapExtent'](oMap, aFeatures); + }, 1000); + }); + } else { + console.error('parcelle ' + sIdPar + ' non valide'); + } + } +}); diff --git a/src/module_anc/module/javascript/script_module.js b/src/module_anc/module/javascript/script_module.js index c1c63cfd07f5433e38daffb81b8c6859810f8036..81e3922428dd7ee1abab391cc19ab0b2818772da 100755 --- a/src/module_anc/module/javascript/script_module.js +++ b/src/module_anc/module/javascript/script_module.js @@ -2,7 +2,9 @@ 'use strict'; goog.provide('vmap.anc.script_module'); +goog.require('vmap.anc.anc_saisie_map'); vitisApp.on('appMainDrtvLoaded', function () { + /** * initAncControlForm function. * Traitements avant l'affichage du formulaire de la section "Dossier" de l'onglet "Contrôle". @@ -337,9 +339,13 @@ vitisApp.on('appMainDrtvLoaded', function () { var $log = angular.element(vitisApp.appMainDrtv).injector().get(["$log"]); var $rootScope = angular.element(vitisApp.appMainDrtv).injector().get(["$rootScope"]); var envSrvc = angular.element(vitisApp.appMainDrtv).injector().get(["envSrvc"]); - // + $log.info("initAncInstallationSuiviForm"); - // Attends la fin du chargement de tous les champs du formulaire. + + // Initialise la carte + this['initAncInstallationSuiviFormMap'](); + + // Attend la fin du chargement de tous les champs du formulaire. var clearListener = $rootScope.$on('formExtracted', function (event, sFormDefinitionName) { // Supprime le "listener". clearListener(); diff --git a/src/module_anc/web_service/conf/properties.inc b/src/module_anc/web_service/conf/properties.inc index a8477bb70bdf2e2a65c76622d9d7b7d922ac521e..49ff6cc5d92f56cd3041f402deee449567e41717 100755 --- a/src/module_anc/web_service/conf/properties.inc +++ b/src/module_anc/web_service/conf/properties.inc @@ -8,4 +8,8 @@ $properties["anc"]["code_postal"]["table"] = ''; $properties["anc"]["code_postal"]["column"] = ''; $properties["anc"]["controle"]["business_object_id"] = ''; + $properties["anc"]["controle"]["map_id"] = false; + $properties["anc"]["controle"]["zoom_on_parcelle"] = true; + $properties["anc"]["installation"]["map_id"] = false; + $properties["anc"]["installation"]["zoom_on_parcelle"] = true; ?> diff --git a/src/vitis/client/javascript/externs/formReader/component/map.js b/src/vitis/client/javascript/externs/formReader/component/map.js index 0482db946269fcaebace4fb649834a3e949861c0..84e8ba3cc709ec0c973afeee8a915f6be0de8a41 100755 --- a/src/vitis/client/javascript/externs/formReader/component/map.js +++ b/src/vitis/client/javascript/externs/formReader/component/map.js @@ -117,6 +117,10 @@ nsVitisComponent.Map = function (opt_option) { * @private */ this.$log_ = angular.element(vitisApp.appHtmlFormDrtv).injector().get(["$log"]); + /** + * @private + */ + this.$q_ = angular.element(vitisApp.appHtmlFormDrtv).injector().get(["$q"]); var this_ = this; @@ -355,7 +359,31 @@ nsVitisComponent.Map = function (opt_option) { } } - /****************************************************Map*******************************/ + var hiddenFeatures = angular.copy($("#" + this.hiddenFieldId).val()); + + // Initialise la carte + this.initMap(options).then(function(){ + // Initialise l'étendue de la carte + this_.initExtent(options); + // Initialise le CSS de la carte + this_.initCSS(options); + // Initialise les features de la carte + this_.initFeatureOverlay(options, hiddenFeatures); + }); + + return this; +}; + +/** + * Initialise la carte + * + * @param {object} options + */ +nsVitisComponent.Map.prototype.initMap = function (options) { + this.$log_.info('nsVitisComponent.Map.initMap'); + + var deferred = this.$q_.defer(); + var this_ = this; this.MapObject = new ol.Map({ target: this_.Target, @@ -372,16 +400,54 @@ nsVitisComponent.Map = function (opt_option) { this.setExtent(options["center"]["extent"]); } - if (options["type"] === "vmap" && options["tree"]) { - this['aTree'] = this.loadTree(options["tree"]); + if (options["type"] === "vmap") { + if (options["tree"]) { + this['aTree'] = this.loadTree(options["tree"]); + } else if (options["map_id"]) { + this.getAjaxVmapMap(options["map_id"]).then(function(oMap){ + + // Set map + this_['aTree'] = this_.loadTree(oMap); + + // Set proj_ + this_.proj_ = this_.MapObject.getView().getProjection().getCode(); + + deferred.resolve(this_['aTree']); + }, + // Cas où carte non trouvée + function(){ + this_.MapObject.addLayer(new ol.layer.Tile({ + source: new ol.source.OSM() + })); + this_['aTree'] = [{ + 'service': options["type"], + 'layers': this_.Layers + }]; + setTimeout(function () { + deferred.resolve(this_['aTree']); + }); + }); + } } else { this['aTree'] = [{ - 'service': options["type"], - 'layers': this.Layers - }]; + 'service': options["type"], + 'layers': this.Layers + }]; + setTimeout(function () { + deferred.resolve(this_['aTree']); + }); } - /****************************************Extent***************************************/ + return deferred.promise; +} + +/** + * Initialise l'étendue de la carte + * + * @param {object} options + */ +nsVitisComponent.Map.prototype.initExtent = function (options) { + this.$log_.info('nsVitisComponent.Map.initExtent'); // Vérifie que l'étendue soit valable var projExtent = ol.proj.get(options["proj"]).getExtent(); @@ -393,20 +459,34 @@ nsVitisComponent.Map = function (opt_option) { console.error('map extent oversized'); this.MapObject.getView().fit(projExtent); } +} +/** + * Initialise lle CSS de la carte + * + * @param {object} options + */ +nsVitisComponent.Map.prototype.initCSS = function (options) { + this.$log_.info('nsVitisComponent.Map.initCSS'); - //****************************************CSS******************************************/ $(".ol-mouse-position").css("bottom", "8px"); $(".ol-mouse-position").css("top", "auto"); $(".ol-mouse-position").css("background", this.appColor); $(".ol-mouse-position").css("color", "#ffffff"); $(".ol-mouse-position").css("border-radius", "4px"); - $(".ol-scale-line").css("background", this.appColor); - $(".ol-current-projection-studio").css("background", this.appColor); +} + +/** + * Initialise les features de la carte + * + * @param {object} options + */ +nsVitisComponent.Map.prototype.initFeatureOverlay = function (options, hiddenFeatures) { + this.$log_.info('nsVitisComponent.Map.initFeatureOverlay'); - /****************************************Feature Overlay********************************/ + var this_ = this; options["draw_color"] = goog.isDef(options["draw_color"]) ? options["draw_color"] : "rgba(54,184,255,0.6)"; options["contour_color"] = goog.isDef(options["contour_color"]) ? options["contour_color"] : "rgba(0,0,0,0.4)"; @@ -464,40 +544,72 @@ nsVitisComponent.Map = function (opt_option) { source: this_.FeatureOverlay.getSource() }) - var hiddenFeatures = $("#" + this.hiddenFieldId).val(); + // Met en place les Features + this.setFeatures(hiddenFeatures); + + // Écrit les features dans le champ hidden + this.Features.on("change", function () { + setTimeout(function () { + this_.saveFeatures(); + this_.MapObject.dispatchEvent('moveend'); + }); + }); +} + +/** + * Set the map features + * + * @param {string} hiddenFeatures GeoJSON features + */ +nsVitisComponent.Map.prototype.setFeatures = function (hiddenFeatures) { + this.$log_.info('nsVitisComponent.Map.setFeatures'); + + // Vide les précédentes features + this.FeatureOverlay.getSource().forEachFeature(function(oFeature){ + this.FeatureOverlay.getSource().removeFeature(oFeature); + }, this); // Lit les features écrites dans le champ hidden if (goog.isDef(hiddenFeatures)) { if (!goog.string.isEmpty(hiddenFeatures) && hiddenFeatures !== "[object Object]") { - var aFeatures = this_.getFeaturesByString(hiddenFeatures); + var aFeatures = this.getFeaturesByString(hiddenFeatures); // Ajoute les features for (var i = 0; i < aFeatures.length; i++) { this.FeatureOverlay.getSource().addFeature(aFeatures[i]); } - var featuresExtent = this.FeatureOverlay.getSource().getExtent(); - this.MapObject.getView().fit(featuresExtent); - // En cas de simple point - if (aFeatures.length === 1) { - if (aFeatures[0].getGeometry().getType() === 'Point') { - this.MapObject.getView().setZoom(12); - } - } + // Zoom sur les features + this.zoomOnFeatures(); + + // Sauvegarde les features + this.saveFeatures(); } } +} - // Écrit les features dans le champ hidden - this.Features.on("change", function () { - setTimeout(function () { - this_.saveFeatures(); - this_.MapObject.dispatchEvent('moveend'); - }); - }); +/** + * Zoom sur les features de this.FeatureOverlay + */ +nsVitisComponent.Map.prototype.zoomOnFeatures = function () { + this.$log_.info('nsVitisComponent.Map.zoomOnFeatures'); - return this; -}; + var aFeatures = this.FeatureOverlay.getSource().getFeatures(); + var featuresExtent = this.FeatureOverlay.getSource().getExtent(); + + if (aFeatures.length > 0) { + + this.MapObject.getView().fit(featuresExtent); + + // En cas de simple point + if (aFeatures.length === 1) { + if (aFeatures[0].getGeometry().getType() === 'Point') { + this.MapObject.getView().setZoom(15); + } + } + } +} /** * Save the current features @@ -526,14 +638,20 @@ nsVitisComponent.Map.prototype.saveFeatures = function () { /** * Parse the string (GeoJSON, WKT) and return the features * @param {string} sFeatures + * @param {string} sFormat * @returns {Array} + * @export */ -nsVitisComponent.Map.prototype.getFeaturesByString = function (sFeatures) { +nsVitisComponent.Map.prototype.getFeaturesByString = function (sFeatures, sFormat) { this.$log_.info('nsVitisComponent.Map.getFeaturesByString'); var aFeatures = []; - if (this.outputFormat_ === 'wkt' || this.outputFormat_ === 'ewkt') { + if (!goog.isDefAndNotNull(sFormat)) { + sFormat = this.outputFormat_; + } + + if (sFormat === 'wkt' || sFormat === 'ewkt') { if (ol.isEWKTGeom(sFeatures)) { aFeatures = ol.getFeaturesFromEWKT(sFeatures, this.proj_); } else { @@ -547,7 +665,7 @@ nsVitisComponent.Map.prototype.getFeaturesByString = function (sFeatures) { console.error('cannot read the geometry on format wkt'); } } - } else if (this.outputFormat_ === 'geojson') { + } else if (sFormat === 'geojson') { try { aFeatures = this.geoJSONFormat.readFeatures(sFeatures, { dataProjection: this.baseProj_, @@ -1318,10 +1436,19 @@ nsVitisComponent.Map.prototype.activeInteraction = function (sInteraction, bForc this_.MapObject.addInteraction(this.snapInteraction_); }; +/** + * Get the formReaderScope + * @return {object} scope + */ nsVitisComponent.Map.prototype.getFormReaderScope_ = function (){ return angular.element(this.Target).scope(); } +/** + * Show the divide segment form + * @param {string} sFeature1 + * @param {string} sFeature2 + */ nsVitisComponent.Map.prototype.showDividedSegmentForm_ = function (sFeature1, sFeature2){ var this_ = this; @@ -1674,6 +1801,62 @@ nsVitisComponent.Map.prototype.removeFeature = function (oFeature) { this.Features.changed(); }; +/** + * Requête Ajax pour répupérer la définition d'une carte + * @param {string} sMapId map_id + * @return {object} map json + */ +nsVitisComponent.Map.prototype.getAjaxVmapMap = function (sMapId) { + + var deferred = this.$q_.defer(); + + if (!angular.isDefined(sMapId) || sMapId == '') { + console.error('map_id non valide'); + deferred.reject(); + } else { + + // Récupère la liste des rapports disponibles + ajaxRequest({ + 'method': 'GET', + 'url': this.$propertiesSrvc_["web_server_name"] + "/" + this.$propertiesSrvc_["services_alias"] + '/vmap/mapjsons/' + sMapId, + 'headers': { + 'Accept': 'application/x-vm-json' + }, + 'success': function (response) { + if (!goog.isDefAndNotNull(response['data'])) { + console.error('response.data undefined: ', response); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'])) { + console.error('Aucune carte disponible pour ' + sMapId); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0])) { + console.error('Aucune carte disponible pour ' + sMapId); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0]['children'])) { + console.error('Aucune carte disponible pour ' + sMapId); + deferred.reject(); + return 0; + } + if (!goog.isDefAndNotNull(response['data']['data'][0]['children'][1])) { + console.error('Aucune carte disponible pour ' + sMapId); + deferred.reject(); + return 0; + } + var oMap = response['data']['data'][0]; + deferred.resolve(oMap); + } + }); + } + + return deferred.promise; +} + /** * Load a Map.json to set layers and view of the map * @param {Object} tree Json tree to set the map (he's generated by Vmap) diff --git a/src/vitis/client/javascript/externs/formReader/component/map_workbench/map_workbench.js b/src/vitis/client/javascript/externs/formReader/component/map_workbench/map_workbench.js index 32ed53d696a53063fe3dd4020ed207461e8f235a..76b09c686bef4b3411631f3042d7f1c92ef4929c 100755 --- a/src/vitis/client/javascript/externs/formReader/component/map_workbench/map_workbench.js +++ b/src/vitis/client/javascript/externs/formReader/component/map_workbench/map_workbench.js @@ -365,7 +365,7 @@ nsVitisComponent.MapWorkbenchDirective = function ($timeout) { break; } }); - }); + }, 500); // Intancie le subform setTimeout(function () { @@ -745,7 +745,7 @@ nsVitisComponent.MapWorkbenchController.prototype.addFeature = function () { }); }); - // Désactive la possibilité d'ajouter des features + // Désactive la possibilité d'ajouter des features this.unactiveDrawInteractions_(); // Ajoute la/les nouvelle interaction @@ -811,7 +811,7 @@ nsVitisComponent.MapWorkbenchController.prototype.setStyleFromType_ = function ( // La chaine commence et se finit par {{ et }} ? if (oStyle[key1][key2].substr(0, 2) === '{{' && oStyle[key1][key2].substr(-2, 2) === '}}') { - // Le contenu des balises est un des champs du formulaire ? + // Le contenu des balises est un des champs du formulaire ? var sTag = oStyle[key1][key2].substr(2, oStyle[key1][key2].length - 4); if (goog.isDefAndNotNull(oAttributes[sTag])) { oStyle[key1][key2] = oAttributes[sTag]; @@ -887,4 +887,4 @@ nsVitisComponent.MapWorkbenchController.prototype.unactiveDrawInteractions_ = fu // this.$scope_['oMap']['setInteractions'](this.$scope_['field']['map_options']['interactions']); // } // } -}; \ No newline at end of file +};