diff --git a/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json b/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json index 3c173b8f08c119992b87cab41bc204d55f9e7ed5..45642a3929dd6073831ede459b1149145b68e4d4 100755 --- a/module/forms/anc_saisie/anc_saisie_anc_controle_controle_schema.json +++ b/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/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json b/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json index 3fa7403c885eecb9b18e8be300315c8146467e3d..76476b275a6405f3ee3e1e5b78fd88a04150ef50 100755 --- a/module/forms/anc_saisie/anc_saisie_anc_installation_installation_suivi.json +++ b/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/module/javascript/anc_saisie_map.js b/module/javascript/anc_saisie_map.js new file mode 100644 index 0000000000000000000000000000000000000000..0ecd9857a302ebdb888e128f58ad5bd89b35d391 --- /dev/null +++ b/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/module/javascript/script_module.js b/module/javascript/script_module.js index c1c63cfd07f5433e38daffb81b8c6859810f8036..81e3922428dd7ee1abab391cc19ab0b2818772da 100755 --- a/module/javascript/script_module.js +++ b/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/web_service/conf/properties.inc b/web_service/conf/properties.inc index a8477bb70bdf2e2a65c76622d9d7b7d922ac521e..49ff6cc5d92f56cd3041f402deee449567e41717 100755 --- a/web_service/conf/properties.inc +++ b/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; ?>