IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

IGN API Géoportail Discussion :

Ajout couche WFS-T


Sujet :

IGN API Géoportail

  1. #1
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut Ajout couche WFS-T
    Bonjour à tous,

    Je cherche à ajouter une couche WFS (diffusée par Geoserver) afin de faire de la saisie sur l'api geoportail.

    J'ai 2 synthaxes qui bloquent l'une et l'autre à des endroits différents :

    Synthaxe 1 : basée sue l'exemple 'Sandre' utilisant la fonction "addLayer("

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     var couche1= VISU.getMap().addLayer(
                "WFS",
                "couche1",
                "http://192.168.3.85:8080/geoserver/wfs",
                {
                    typename: 'poly4326',
    				featureNS :  "http://192.168.3.85:8080/postgis",
    				featureType: "poly4326",
    				featurePrefix:'postgis',
    				geometryName: "geom"
                },
                {
                    projection: 'EPSG:4326',
                    units:'degrees',
                    // maxExtent expressed in EPSG:4326 :
                    maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
                    minZoomLevel:0,
                    maxZoomLevel:15,
                    hover: true
                }
            );
    Mes données s'affichent bien au bon endroit mais je n'arrive pas a rendre cette couche éditable... Est-ce possible ? Je suppose qu'il faut ajouter "Strategy.save()" mais mes essais n'ont rien donnés ...

    Synthaxe 2 : basée sur la fonction "OpenLayers.Layers.Vector"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    var saveStrategy = new OpenLayers.Strategy.Save();
    		
    		couche2 = new OpenLayers.Layer.Vector("couche2", {
    			strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
    			projection: 'EPSG:4326',//new OpenLayers.Projection("EPSG:4326"),
    			protocol: new OpenLayers.Protocol.WFS({
    				version: "1.0.0",
    				srsName: "EPSG:4326",
    				url: "http://192.168.3.85:8080/geoserver/wfs",
    				featureNS :  "http://192.168.3.85:8080/postgis",
    				featureType: "poly4326",
    				featurePrefix:'postgis',
    				geometryName: "geom",
    				formatOptions:{
    					internalProjection: VISU.getMap().getProjection().clone(),
    					externalProjection: new OpenLayers.Projection('EPSG:4326')
    				}
    			})	
    		});
    			
    			
    		OpenLayers.Format.WFS.prototype.layerName = 'postgis:poly4326';
    		VISU.getMap().addLayer(couche2);
    Ma couche s'affiche, est bien éditable mais les coordonnées stockées dans la base de données sont aberrantes, par exemple : 0.00003338447460205927,0.00044795598208281995 pour un point situé en france...

    Variante de la synthaxe 2 : J'enlève la ligne "internalProjection"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    var saveStrategy = new OpenLayers.Strategy.Save();
    		
    		couche2 = new OpenLayers.Layer.Vector("couche2", {
    			strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
    			projection: 'EPSG:4326',//new OpenLayers.Projection("EPSG:4326"),
    			protocol: new OpenLayers.Protocol.WFS({
    				version: "1.0.0",
    				srsName: "EPSG:4326",
    				url: "http://192.168.3.85:8080/geoserver/wfs",
    				featureNS :  "http://192.168.3.85:8080/postgis",
    				featureType: "poly4326",
    				featurePrefix:'postgis',
    				geometryName: "geom",
    				formatOptions:{
    					//internalProjection: VISU.getMap().getProjection().clone(),
    					externalProjection: new OpenLayers.Projection('EPSG:4326')
    				}
    			})	
    		});
    			
    			
    		OpenLayers.Format.WFS.prototype.layerName = 'postgis:poly4326';
    		VISU.getMap().addLayer(couche2);
    Dans ce cas mes coordonnées s'enregistrent bien, par exemple 2.103806357303835,45.542820023849856 mais ne réapparaissent pas au bon endroit après ré actualisation...

    Bref pour résumer :

    - Y-a-t'il un moyen de rendre une couche éditable en utilisant la synthaxe n°1 (exemple sandre) ?

    ou

    - Est-il possible de corriger la synthaxe n°2 pour que mes coordonnées s'enregistre et s'affichent bien en EPSG:4326 ... ?

    Merci beaucoup à ceux qui se pencheront sur mon problème...

  2. #2
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Tout OpenLayers.Layer.WFS expose une méthode save() qui renvoit les objets vers le service WFS (celui-ci doit donc supporter le mode transactionnel).

    L'exemple suivant donne les pistes ad hoc.
    Il te faut ajouter les contrôles d'édition qui vont dialoguer avec la méthode save() en question comme l'exemple précédent le montre.

  3. #3
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    Citation Envoyé par dgrichard Voir le message
    Tout OpenLayers.Layer.WFS expose une méthode save() qui renvoit les objets vers le service WFS (celui-ci doit donc supporter le mode transactionnel).

    L'exemple suivant donne les pistes ad hoc.
    Il te faut ajouter les contrôles d'édition qui vont dialoguer avec la méthode save() en question comme l'exemple précédent le montre.
    Merci dgrichard pour cette réponse.

    Je me suis effectivement basé sur cet exemple pour ma synthaxe n°2, le mode transctionnel fonctionne bien mais j'ai des problèmes de projections...

    A priori je peux donc relier les outils d'edition a ma couche créée avec la synthaxe 1 également ? j'ai tenté d'y rajouter :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy]
    mais cela n'a pas l'air de fonctionner... Ou puis-je trouver la synthaxe pour activer "save()" sur ma synthaxe n°1 utilisant 'getMap().addLayer(' ...?

    Merci d'avance

  4. #4
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Citation Envoyé par Sigmax Voir le message
    Je me suis effectivement basé sur cet exemple pour ma synthaxe n°2, le mode transctionnel fonctionne bien mais j'ai des problèmes de projections...
    Effectivement, il y a une double conversion :

    carte->EPSG:4326->EPSG:4326 lors du save

    J'ai souvent ce type de boggue avec OpenLayers : la plupart des exemples sont avec les mêmes projections pour les baseLayers et les overlays ...

    Il faudrait débogguer ...
    Une analyse rapide OpenLayers.Strategy.Save et de OpenLayers.Protocol.WFS montre que :

    OpenLayers.Strategy.Save.save() fait SYSTEMATIQUEMENT la transformation de coordonnées avant de passer la main à OpenLayers.Protocol.WFS qui fait de même gràce au formatOptions (internal -> external).

    Comme l'option formatOptions permet justement d'afficher les données au bon endroit, j'opterai pour le test suivant : retirer projection:'EPSG:4326' dans la syntaxe n°2.

    Citation Envoyé par Sigmax Voir le message
    A priori je peux donc relier les outils d'edition a ma couche créée avec la synthaxe 1 également ?
    J'irai pas-à-pas :

    * création d'un EditingToolbar ;
    * branchement des outils (select, modify, etc ...);

    L'exemple cité le montre (sur le bouton save) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
        var save = new OpenLayers.Control.Button({
            title: "Save Changes",
            trigger: function() {
                if(edit.feature) {
                    edit.selectControl.unselectAll();
                }
                saveStrategy.save();
            },
            displayClass: "olControlSaveFeatures"
        });

  5. #5
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut OpenLayers.Strategy.Save
    Dans la syntaxe n°2, pourrais-tu tester avec ce patch ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
        /**
         * APIMethod: save
         * Tell the layer protocol to commit unsaved features.  If the layer
         *     projection differs from the map projection, features will be
         *     transformed into the layer projection before being committed.
         *     IGNF: this transformation only occurs when the underlying
         *     protocol's format does not know about the external projection.
         *
         * Parameters:
         * features - {Array} Features to be saved.  If null, then default is all
         *     features in the layer.  Features are assumed to be in the map
         *     projection.
         */
        OpenLayers.Strategy.Save.prototype.save= function(features) {
            if(!features) {
                features = this.layer.features;
            }
            //IGNF (begin)
            //var remote = this.layer.projection;
            var remote = this.layer.getNativeProjection();
            //var local = this.layer.map.getProjectionObject();
            var local = this.layer.map.getProjection();
            var needsReprojection= !(local.equals(remote));
            var format = this.layer.protocol.format;
            if (format && format.externalProjection) {
                needsReprojection= !(format.externalProjection.equals(remote));
            }
            //if(!local.equals(remote)) {
            //IGNF (end)
            if (needsReprojection) {
                var len = features.length;
                var clones = new Array(len);
                var orig, clone;
                for(var i=0; i<len; ++i) {
                    orig = features[i];
                    clone = orig.clone();
                    clone.fid = orig.fid;
                    clone.state = orig.state;
                    clone._original = orig;
                    clone.geometry.transform(local, remote);
                    clones[i] = clone;
                }
                features = clones;
            }
            this.layer.protocol.commit(features, {
                callback: this.onCommit,
                scope: this
            });
        };

  6. #6
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    Merci beaucoup je vais tester tout ca,

    Pour le patch, faut-il que je rajoute le code a un endroit précis ?

  7. #7
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Citation Envoyé par Sigmax Voir le message
    Merci beaucoup je vais tester tout ca,

    Pour le patch, faut-il que je rajoute le code a un endroit précis ?
    A l'intérieur de la méthode initiGeoportalMap() ou équivalent au début par exemple.

  8. #8
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    Ok j'ai rajouter le patch en debut de initGeoportalMap() et j'ai une erreur lorsque j'essai d'enregistrer un nouvel objet...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    layer is not defined
    sur la ligne " var format = layer.protocol.format; "

  9. #9
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Citation Envoyé par Sigmax Voir le message
    Ok j'ai rajouter le patch en debut de initGeoportalMap() et j'ai une erreur lorsque j'essai d'enregistrer un nouvel objet...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    layer is not defined
    sur la ligne " var format = layer.protocol.format; "
    Oops ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     var format = this.layer.protocol.format;

  10. #10
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    oups pour moi aussi je regardais les lignes autours et j'avais pas vu qu'il manquait "this."

    bilan du patch :

    avant le patch :
    - avec "internalProjection" les données partaient en "0.000 , 0.0000" mais se réaffichaient bien au même endroit après actualisation
    - sans "internalProjection" les données partaient bien en EPSG:4326 mais ne se réaffichaient pas après actualisation

    après le patch :
    - avec "internalProjection" les données partent bien en EPSG:4326 mais ne se réaffichent pas après actualisation...
    - sans "internalProjection" les données partent en "350000.000 , 5268000.000" et ne se réaffichent pas non plus après actualisation...

    On progresse donc les coord partent bien en EPSG:4326 grace au patch... par contre l'affichage ne se fait toujours pas comme il faut...

  11. #11
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Citation Envoyé par Sigmax Voir le message
    après le patch :
    - avec "internalProjection" les données partent bien en EPSG:4326 mais ne se réaffichent pas après actualisation...
    Ok, as-tu bien :
    * retirer projection:'EPSG:4326' dans l'initialisation :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    var saveStrategy = new OpenLayers.Strategy.Save();
            
    couche2 = new OpenLayers.Layer.Vector("couche2", {
                strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
                /*projection: 'EPSG:4326',//new OpenLayers.Projection("EPSG:4326"),*/
                protocol: new OpenLayers.Protocol.WFS({
                    version: "1.0.0",
                    srsName: "EPSG:4326",
                    url: "http://192.168.3.85:8080/geoserver/wfs",
                    featureNS :  "http://192.168.3.85:8080/postgis",
                    featureType: "poly4326",
                    featurePrefix:'postgis',
                    geometryName: "geom",
                    formatOptions:{
                        internalProjection: VISU.getMap().getProjection().clone(),
                        externalProjection: new OpenLayers.Projection('EPSG:4326')
                    }
                })    
            });
                
                
    OpenLayers.Format.WFS.prototype.layerName = 'postgis:poly4326';
    VISU.getMap().addLayer(couche2);
    Citation Envoyé par Sigmax Voir le message
    On progresse donc les coord partent bien en EPSG:4326 grace au patch... par contre l'affichage ne se fait toujours pas comme il faut...
    Il faudrait creuser maintenant onCommit() en débogguant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    OpenLayers.Strategy.Save.prototype.onCommit= function(response) {
      //copie le code de onCommit
    }
    et débogguer pas-à-pas ...

  12. #12
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    J'avais bien enlevé la projection oui ...

    J'avoue ne pas avoir les connaissances suffisantes pour "débogguer pas à pas"
    Je ne sais pas comment m'y prendre...

    je vais voir ce que je trouve sur "onCommit()"...

  13. #13
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    Au niveau de ma requête d'affichage je viens de voir que j'avais une erreur en retour si j'enlève la projection :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?xml version="1.0" ?>
    <ServiceExceptionReport
       version="1.2.0"
       xmlns="http://www.opengis.net/ogc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
       <ServiceException>
          java.lang.RuntimeException: Could not decode srs &apos;IGNF:GEOPORTALFXX&apos;
    Could not decode srs &apos;IGNF:GEOPORTALFXX&apos;
    Le type &quot;IGNF&quot; n&apos;est pas reconnu dans ce contexte.
    Le type &quot;IGNF&quot; n&apos;est pas reconnu dans ce contexte.
    </ServiceException></ServiceExceptionReport>
    ma requête :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <wfs:getfeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <wfs:query typeName="postgis:poly4326" xmlns:postgis="http://192.168.3.85:8080/postgis">
    <ogc:filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:bbox>
    <ogc:propertyname>geom</ogc:propertyname>
    <gml:box xmlns:gml="http://www.opengis.net/gml" srsName="IGNF:GEOPORTALFXX">
    <gml:coordinates decimal="." cs="," ts=" ">-1465927.039401816,3898347.5343446694 2437560.960598184,6274027.534344669</gml:coordinates>
    </gml:box>
    </ogc:bbox>
    </ogc:filter>
    </wfs:query>
    </wfs:getfeature>
    par contre si je réactive la projection j'obtiens une réponse correcte mais centrée sur les coord : 0.000 0.000... alors que pour la france en EPSG:4326 il faudrait plutot du 0.000 45.000

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <wfs:getfeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <wfs:query typeName="postgis:poly4326" xmlns:postgis="http://192.168.3.85:8080/postgis">
    <ogc:filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:bbox>
    <ogc:propertyname>geom</ogc:propertyname>
    <gml:box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
    <gml:coordinates decimal="." cs="," ts=" ">-0.0002496580224581627,0.00031458508729749517 0.0004151343366259816,0.0005062954193309235</gml:coordinates>
    </gml:box>
    </ogc:bbox>
    </ogc:filter>
    </wfs:query>
    </wfs:getfeature>

  14. #14
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Ok, il me semble que , il y a un patch sur l'opération GetFeature avec BBOX ....

    Voici, une version plus à jour du patch qui supporte donc la reprojection des BBOX, ajoute les requêtes avec filtres sous forme de polygone :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    /**
     * Class: OpenLayers.Control.GetFeature
     * OpenLayers 2.9 bug fixes and enhancements (IGNF).
     */
    
        /**
         * APIProperty: polygon
         * {Boolean} Allow feature selection by drawing a polygon.
         */
        OpenLayers.Control.GetFeature.prototype.polygon= false;
    
        /**
         * Property: filterType
         * {<String>} The type of filter to use when sending off a request.
         *     Possible values:
         *     OpenLayers.Filter.Spatial.<BBOX|INTERSECTS|WITHIN|CONTAINS>
         *     Defaults to: OpenLayers.Filter.Spatial.BBOX
         */
        OpenLayers.Control.GetFeature.prototype.filterType= OpenLayers.Filter.Spatial.BBOX;
    
        /**
         * Constant: EVENT_TYPES
         *
         * Supported event types:
         * beforefeatureselected - Triggered when <click> is true before a
         *      feature is selected. The event object has a feature property with
         *      the feature about to select
         * featureselected - Triggered when <click> is true and a feature is
         *      selected. The event object has a feature property with the
         *      selected feature
         * beforefeaturesselected - Triggered when <click> is true before a
         *      set of features is selected. The event object is an array of
         *      feature properties with the features about to be selected.
         *      Return false after receiving this event to discontinue processing
         *      of all featureselected events and the featuresselected event.
         * featuresselected - Triggered when <click> is true and a set of
         *      features is selected.  The event object is an array of feature
         *      properties of the selected features
         * featureunselected - Triggered when <click> is true and a feature is
         *      unselected. The event object has a feature property with the
         *      unselected feature
         * clickout - Triggered when when <click> is true and no feature was
         *      selected.
         * hoverfeature - Triggered when <hover> is true and the mouse has
         *      stopped over a feature
         * outfeature - Triggered when <hover> is true and the mouse moves
         *      moved away from a hover-selected feature
         */
        OpenLayers.Control.GetFeature.prototype.EVENT_TYPES= [
            "featureselected", "featuresselected", "featureunselected",
            "clickout", "beforefeatureselected", "beforefeaturesselected",
            "hoverfeature", "outfeature"];
    
        /**
         * Constructor: OpenLayers.Control.GetFeature
         * Create a new control for fetching remote features.
         *
         * Parameters:
         * options - {Object} A configuration object which at least has to contain
         *     a <protocol> property
         */
        OpenLayers.Control.GetFeature.prototype.initialize= function(options) {
            // concatenate events specific to vector with those from the base
            this.EVENT_TYPES =
                OpenLayers.Control.GetFeature.prototype.EVENT_TYPES.concat(
                OpenLayers.Control.prototype.EVENT_TYPES
            );
    
            options.handlerOptions = options.handlerOptions || {};
    
            OpenLayers.Control.prototype.initialize.apply(this, [options]);
    
            this.features = {};
    
            this.handlers = {};
    
            if(this.click) {
                this.handlers.click = new OpenLayers.Handler.Click(this,
                    {click: this.selectSingle}, this.handlerOptions.click || {})
            };
    
            if(this.box) {
                this.handlers.box = new OpenLayers.Handler.Box(
                    this, {done: this.selectBox},
                    OpenLayers.Util.extend(this.handlerOptions.box, {
                        boxDivClassName: "olHandlerBoxSelectFeature"
                    })
                );
            }
    
            if(this.polygon) {
                this.handlers.polygon = new OpenLayers.Handler.Polygon(
                    this, {done: this.selectPolygon},
                    OpenLayers.Util.extend(this.handlerOptions.polygon, {
                    })
                );
            }
    
            if(this.hover) {
                this.handlers.hover = new OpenLayers.Handler.Hover(
                    this, {'move': this.cancelHover, 'pause': this.selectHover},
                    OpenLayers.Util.extend(this.handlerOptions.hover, {
                        'delay': 250
                    })
                );
            }
        };
    
        /**
         * Method: destroy
         * The destroy method is used to perform any clean up before the control
         * is dereferenced.  Typically this is where event listeners are removed
         * to prevent memory leaks.
         */
        OpenLayers.Control.GetFeature.prototype.destroy= function () {
            if (this.srs) {//IGNF
                this.srs.destroy();
                this.srs= null;
            }
            OpenLayers.Control.prototype.destroy.apply(this,arguments);
        };
    
        /**
         * Method: selectSingle
         * Called on click
         *
         * Parameters:
         * evt - {<OpenLayers.Event>}
         */
        OpenLayers.Control.GetFeature.prototype.selectSingle= function(evt) {
            // Set the cursor to "wait" to tell the user we're working on their click.
            //IGNF see request :OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
    
            var bounds = this.pixelToBounds(evt.xy);
    
            this.setModifiers(evt);
            this.request(bounds, {single: true});
        };
    
        /**
         * Method: selectBox
         * Callback from the handlers.box set up when <box> selection is on
         *
         * Parameters:
         * position - {<OpenLayers.Bounds>}
         */
        OpenLayers.Control.GetFeature.prototype.selectBox= function(position) {
            var bounds;
            if (position instanceof OpenLayers.Bounds) {
                var minXY = this.map.getLonLatFromPixel(
                    new OpenLayers.Pixel(position.left, position.bottom)
                );
                var maxXY = this.map.getLonLatFromPixel(
                    new OpenLayers.Pixel(position.right, position.top)
                );
                bounds = new OpenLayers.Bounds(
                    minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
                );
    
            } else {
                if(this.click) {
                    // box without extent - let the click handler take care of it
                    return;
                }
                bounds = this.pixelToBounds(position);
            }
            //IGNF
            if (!this.srs && this.protocol.srsName && !this.map.getProjection().equals(this.protocol.srsName)) {
                this.srs= new OpenLayers.Projection(this.protocol.srsName);
            }
            if (this.srs) {
                bounds= bounds.transform(this.map.getProjection(),this.srs);
            }
            this.setModifiers(this.handlers.box.dragHandler.evt);
            this.request(bounds);
        };
    
        /**
         * Method: selectPolygon
         * Callback from handlers.polygon set up when <polygon> selection is on
         *
         * Parameters:
         * geom - {<OpenLayers.Geometry.Polygon>}
         */
        OpenLayers.Control.GetFeature.prototype.selectPolygon= function(geom) {
            if (geom instanceof OpenLayers.Geometry.Polygon) {
                this.setModifiers(this.handlers.polygon.evt);
                this.request(geom);
            }
        };
    
        /**
         * Method: cancelHover
         * Callback from the handlers.hover set up when <hover> selection is on
         */
        OpenLayers.Control.GetFeature.prototype.cancelHover= function() {
            if (this.hoverResponse) {
                // IGNF: Reset the cursor.
                OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
                this.protocol.abort(this.hoverResponse);
                this.hoverResponse = null;
            }
        };
    
        /**
         * Method: request
         * Sends a GetFeature request to the WFS
         *
         * Parameters:
         * bounds - {<OpenLayers.Bounds | OpenLayers.Geometry>} bounds or geometry for the request's filter
         * options - {Object} additional options for this method.
         *
         * Supported options include:
         * single - {Boolean} A single feature should be returned.
         *     Note that this will be ignored if the protocol does not
         *     return the geometries of the features.
         * hover - {Boolean} Do the request for the hover handler.
         */
        OpenLayers.Control.GetFeature.prototype.request= function(bounds, options) {
            // IGNF
            // Set the cursor to "wait" to tell the user we're working on their click.
            OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
    
            options = options || {};
            var filter = new OpenLayers.Filter.Spatial({
                type: this.filterType,
                value: bounds
            });
    
            var response = this.protocol.read({
                maxFeatures: options.single == true ? this.maxFeatures : undefined,
                filter: filter,
                callback: function(result) {
                    if(result.success()) {
                        if(result.features.length) {
                            if(options.single == true) {
                                //IGNF
                                var c= (bounds instanceof OpenLayers.Bounds?
                                    bounds
                                :   bounds.getBounds()).getCenterLonLat();
                                this.selectBestFeature(result.features, c, options);
                            } else {
                                this.select(result.features);
                            }
                        } else if(options.hover) {
                            this.hoverSelect();
                        } else {
                            this.events.triggerEvent("clickout");
                            if(this.clickout) {
                                this.unselectAll();
                            }
                        }
                    }
                    // Reset the cursor.
                    OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
                },
                scope: this
            });
            if(options.hover == true) {
                this.hoverResponse = response;
            }
        };
    
        /**
         * Method: select
         * Add feature to the hash of selected features and trigger the
         * featureselected and featuresselected events.
         *
         * Parameters:
         * features - {<OpenLayers.Feature.Vector>} or an array of features
         */
        OpenLayers.Control.GetFeature.prototype.select= function(features) {
            if(!this.modifiers.multiple && !this.modifiers.toggle) {
                this.unselectAll();
            }
            if(!(features instanceof Array)) {
                features = [features];
            }
    
            var cont = this.events.triggerEvent("beforefeaturesselected", {
                features: features
            });
            if(cont !== false) {
                var selectedFeatures = [];
                var feature;
                for(var i=0, len=features.length; i<len; ++i) {
                    feature = features[i];
                    if(this.features[feature.fid || feature.id]) {
                        if(this.modifiers.toggle) {
                            this.unselect(this.features[feature.fid || feature.id]);
                        }
                    } else {
                        cont = this.events.triggerEvent("beforefeatureselected", {
                            feature: feature
                        });
                        if(cont !== false) {
                            this.features[feature.fid || feature.id] = feature;
                            selectedFeatures.push(feature);
    
                            this.events.triggerEvent("featureselected",
                                {feature: feature});
                        }
                    }
                }
                this.events.triggerEvent("featuresselected", {
                    features: selectedFeatures
                });
            }
        };
    Il faut donc garder projection:'EPSG:4326' à l'init.

  15. #15
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    J'ai rajouté ce patch en début d'init au dessus de l'autre mais apparemment il n'y a pas de changement... ma bbox se fait toujours sur des coord de type 0.000 , 0.000 ...

    faut-il modifier quelques chose dans la syntaxe d'ajout de couche pour qu'elle utilise le patch ...?

  16. #16
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    Pour savoir si le code du patch était appelé à un moment ou a un autre j'y ai rajouté un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    ...
        OpenLayers.Control.GetFeature.prototype.request= function(bounds, options) {
    	alert('hello');
            // IGNF
            // Set the cursor to "wait" to tell the user we're working on their click.
            OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
    ...
    dans la méthode "Request"... eh ben je n'ai pas d'alerte quand la couche se charge ...

    Est-ce que cela veut dire que le patch n'est pas pris en compte ...?

  17. #17
    Membre chevronné
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    2 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 2 124
    Points : 1 764
    Points
    1 764
    Par défaut Eh ben oui
    Si ton message ne s'affiche pas, c'est que la surcharge ne s'applique pas!
    Peux-tu mettre ton code en ligne ? même s'il manque le serveur wfs

  18. #18
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Citation Envoyé par mga_geo Voir le message
    Si ton message ne s'affiche pas, c'est que la surcharge ne s'applique pas!
    Peux-tu mettre ton code en ligne ? même s'il manque le serveur wfs
    Cela me permettrait aussi de tester en local avec mon Geoserver

  19. #19
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    73
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 73
    Points : 33
    Points
    33
    Par défaut
    Merci à tous les deux de vous pencher sur mon cas

    toujours pas compris pourquoi le patch n'est pas pris en compte...

    Mon code :
    (attention les yeux c'est surement pas le code le plus propre du monde...)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
     var feature, couche2;
      
    	function initGeoportalMap() {
    		 // API chargée ?
        if (typeof(Geoportal) == "undefined") {
            setTimeout("Chargement()",100);//100 millisecondes
            return;
        }
    
    /**
     * Class: OpenLayers.Control.GetFeature
     * OpenLayers 2.9 bug fixes and enhancements (IGNF).
     */
    
        /**
         * APIProperty: polygon
         * {Boolean} Allow feature selection by drawing a polygon.
         */
        OpenLayers.Control.GetFeature.prototype.polygon= false;
    
        /**
         * Property: filterType
         * {<String>} The type of filter to use when sending off a request.
         *     Possible values:
         *     OpenLayers.Filter.Spatial.<BBOX|INTERSECTS|WITHIN|CONTAINS>
         *     Defaults to: OpenLayers.Filter.Spatial.BBOX
         */
        OpenLayers.Control.GetFeature.prototype.filterType= OpenLayers.Filter.Spatial.BBOX;
    
        /**
         * Constant: EVENT_TYPES
         *
         * Supported event types:
         * beforefeatureselected - Triggered when <click> is true before a
         *      feature is selected. The event object has a feature property with
         *      the feature about to select
         * featureselected - Triggered when <click> is true and a feature is
         *      selected. The event object has a feature property with the
         *      selected feature
         * beforefeaturesselected - Triggered when <click> is true before a
         *      set of features is selected. The event object is an array of
         *      feature properties with the features about to be selected.
         *      Return false after receiving this event to discontinue processing
         *      of all featureselected events and the featuresselected event.
         * featuresselected - Triggered when <click> is true and a set of
         *      features is selected.  The event object is an array of feature
         *      properties of the selected features
         * featureunselected - Triggered when <click> is true and a feature is
         *      unselected. The event object has a feature property with the
         *      unselected feature
         * clickout - Triggered when when <click> is true and no feature was
         *      selected.
         * hoverfeature - Triggered when <hover> is true and the mouse has
         *      stopped over a feature
         * outfeature - Triggered when <hover> is true and the mouse moves
         *      moved away from a hover-selected feature
         */
        OpenLayers.Control.GetFeature.prototype.EVENT_TYPES= [
            "featureselected", "featuresselected", "featureunselected",
            "clickout", "beforefeatureselected", "beforefeaturesselected",
            "hoverfeature", "outfeature"];
    
        /**
         * Constructor: OpenLayers.Control.GetFeature
         * Create a new control for fetching remote features.
         *
         * Parameters:
         * options - {Object} A configuration object which at least has to contain
         *     a <protocol> property
         */
        OpenLayers.Control.GetFeature.prototype.initialize= function(options) {
            // concatenate events specific to vector with those from the base
            this.EVENT_TYPES =
                OpenLayers.Control.GetFeature.prototype.EVENT_TYPES.concat(
                OpenLayers.Control.prototype.EVENT_TYPES
            );
    
            options.handlerOptions = options.handlerOptions || {};
    
            OpenLayers.Control.prototype.initialize.apply(this, [options]);
    
            this.features = {};
    
            this.handlers = {};
    
            if(this.click) {
                this.handlers.click = new OpenLayers.Handler.Click(this,
                    {click: this.selectSingle}, this.handlerOptions.click || {})
            };
    
            if(this.box) {
                this.handlers.box = new OpenLayers.Handler.Box(
                    this, {done: this.selectBox},
                    OpenLayers.Util.extend(this.handlerOptions.box, {
                        boxDivClassName: "olHandlerBoxSelectFeature"
                    })
                );
            }
    
            if(this.polygon) {
                this.handlers.polygon = new OpenLayers.Handler.Polygon(
                    this, {done: this.selectPolygon},
                    OpenLayers.Util.extend(this.handlerOptions.polygon, {
                    })
                );
            }
    
            if(this.hover) {
                this.handlers.hover = new OpenLayers.Handler.Hover(
                    this, {'move': this.cancelHover, 'pause': this.selectHover},
                    OpenLayers.Util.extend(this.handlerOptions.hover, {
                        'delay': 250
                    })
                );
            }
        };
    
        /**
         * Method: destroy
         * The destroy method is used to perform any clean up before the control
         * is dereferenced.  Typically this is where event listeners are removed
         * to prevent memory leaks.
         */
        OpenLayers.Control.GetFeature.prototype.destroy= function () {
            if (this.srs) {//IGNF
                this.srs.destroy();
                this.srs= null;
            }
            OpenLayers.Control.prototype.destroy.apply(this,arguments);
        };
    
        /**
         * Method: selectSingle
         * Called on click
         *
         * Parameters:
         * evt - {<OpenLayers.Event>}
         */
        OpenLayers.Control.GetFeature.prototype.selectSingle= function(evt) {
            // Set the cursor to "wait" to tell the user we're working on their click.
            //IGNF see request :OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
    
            var bounds = this.pixelToBounds(evt.xy);
    
            this.setModifiers(evt);
            this.request(bounds, {single: true});
        };
    
        /**
         * Method: selectBox
         * Callback from the handlers.box set up when <box> selection is on
         *
         * Parameters:
         * position - {<OpenLayers.Bounds>}
         */
        OpenLayers.Control.GetFeature.prototype.selectBox= function(position) {
            var bounds;
            if (position instanceof OpenLayers.Bounds) {
                var minXY = this.map.getLonLatFromPixel(
                    new OpenLayers.Pixel(position.left, position.bottom)
                );
                var maxXY = this.map.getLonLatFromPixel(
                    new OpenLayers.Pixel(position.right, position.top)
                );
                bounds = new OpenLayers.Bounds(
                    minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
                );
    
            } else {
                if(this.click) {
                    // box without extent - let the click handler take care of it
                    return;
                }
                bounds = this.pixelToBounds(position);
            }
            //IGNF
            if (!this.srs && this.protocol.srsName && !this.map.getProjection().equals(this.protocol.srsName)) {
                this.srs= new OpenLayers.Projection(this.protocol.srsName);
            }
            if (this.srs) {
                bounds= bounds.transform(this.map.getProjection(),this.srs);
            }
            this.setModifiers(this.handlers.box.dragHandler.evt);
            this.request(bounds);
        };
    
        /**
         * Method: selectPolygon
         * Callback from handlers.polygon set up when <polygon> selection is on
         *
         * Parameters:
         * geom - {<OpenLayers.Geometry.Polygon>}
         */
        OpenLayers.Control.GetFeature.prototype.selectPolygon= function(geom) {
            if (geom instanceof OpenLayers.Geometry.Polygon) {
                this.setModifiers(this.handlers.polygon.evt);
                this.request(geom);
            }
        };
    
        /**
         * Method: cancelHover
         * Callback from the handlers.hover set up when <hover> selection is on
         */
        OpenLayers.Control.GetFeature.prototype.cancelHover= function() {
            if (this.hoverResponse) {
                // IGNF: Reset the cursor.
                OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
                this.protocol.abort(this.hoverResponse);
                this.hoverResponse = null;
            }
        };
    
        /**
         * Method: request
         * Sends a GetFeature request to the WFS
         *
         * Parameters:
         * bounds - {<OpenLayers.Bounds | OpenLayers.Geometry>} bounds or geometry for the request's filter
         * options - {Object} additional options for this method.
         *
         * Supported options include:
         * single - {Boolean} A single feature should be returned.
         *     Note that this will be ignored if the protocol does not
         *     return the geometries of the features.
         * hover - {Boolean} Do the request for the hover handler.
         */
        OpenLayers.Control.GetFeature.prototype.request= function(bounds, options) {
            // IGNF
            // Set the cursor to "wait" to tell the user we're working on their click.
            OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
    
            options = options || {};
            var filter = new OpenLayers.Filter.Spatial({
                type: this.filterType,
                value: bounds
            });
    
            var response = this.protocol.read({
                maxFeatures: options.single == true ? this.maxFeatures : undefined,
                filter: filter,
                callback: function(result) {
                    if(result.success()) {
                        if(result.features.length) {
                            if(options.single == true) {
                                //IGNF
                                var c= (bounds instanceof OpenLayers.Bounds?
                                    bounds
                                :   bounds.getBounds()).getCenterLonLat();
                                this.selectBestFeature(result.features, c, options);
                            } else {
                                this.select(result.features);
                            }
                        } else if(options.hover) {
                            this.hoverSelect();
                        } else {
                            this.events.triggerEvent("clickout");
                            if(this.clickout) {
                                this.unselectAll();
                            }
                        }
                    }
                    // Reset the cursor.
                    OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
                },
                scope: this
            });
            if(options.hover == true) {
                this.hoverResponse = response;
            }
        };
    
        /**
         * Method: select
         * Add feature to the hash of selected features and trigger the
         * featureselected and featuresselected events.
         *
         * Parameters:
         * features - {<OpenLayers.Feature.Vector>} or an array of features
         */
        OpenLayers.Control.GetFeature.prototype.select= function(features) {
            if(!this.modifiers.multiple && !this.modifiers.toggle) {
                this.unselectAll();
            }
            if(!(features instanceof Array)) {
                features = [features];
            }
    
            var cont = this.events.triggerEvent("beforefeaturesselected", {
                features: features
            });
            if(cont !== false) {
                var selectedFeatures = [];
                var feature;
                for(var i=0, len=features.length; i<len; ++i) {
                    feature = features[i];
                    if(this.features[feature.fid || feature.id]) {
                        if(this.modifiers.toggle) {
                            this.unselect(this.features[feature.fid || feature.id]);
                        }
                    } else {
                        cont = this.events.triggerEvent("beforefeatureselected", {
                            feature: feature
                        });
                        if(cont !== false) {
                            this.features[feature.fid || feature.id] = feature;
                            selectedFeatures.push(feature);
    
                            this.events.triggerEvent("featureselected",
                                {feature: feature});
                        }
                    }
                }
                this.events.triggerEvent("featuresselected", {
                    features: selectedFeatures
                });
            }
        };
    
    
    
    	//patch dgrichard save
    		OpenLayers.Strategy.Save.prototype.save= function(features) {
    			if(!features) {
    			    features = this.layer.features;
    			}
    			//IGNF (begin)
    			//var remote = this.layer.projection;
    			var remote = this.layer.getNativeProjection();
    			//var local = this.layer.map.getProjectionObject();
    			var local = this.layer.map.getProjection();
    			var needsReprojection= !(local.equals(remote));
    			var format = this.layer.protocol.format;
    			if (format && format.externalProjection) {
    			    needsReprojection= !(format.externalProjection.equals(remote));
    			}
    			//if(!local.equals(remote)) {
    			//IGNF (end)
    			if (needsReprojection) {
    			    var len = features.length;
    			    var clones = new Array(len);
    			    var orig, clone;
    			    for(var i=0; i<len; ++i) {
    				orig = features[i];
    				clone = orig.clone();
    				clone.fid = orig.fid;
    				clone.state = orig.state;
    				clone._original = orig;
    				clone.geometry.transform(local, remote);
    				clones[i] = clone;
    			    }
    			    features = clones;
    			}
    			this.layer.protocol.commit(features, {
    			    callback: this.onCommit,
    			    scope: this
    			});
    		    };
    	
          // On implémente la carte
    	  geoportalLoadVISU("GeoportalVisuDiv", "normal","FXX","IGNF:GEOPORTALFXX","EPSG:4326");
    		VISU.getMap().setProxyUrl("/cgi-bin/proxy.cgi?url=");
          // On charge les couches de données définies dans le contrat
    		if (VISU.getMap().allowedGeoportalLayers) {
    			VISU.addGeoportalLayer('GEOGRAPHICALGRIDSYSTEMS.MAPS:WMSC',{opacity:1});
    			VISU.addGeoportalLayer('ORTHOIMAGERY.ORTHOPHOTOS:WMSC',{visibility:false});
    			VISU.addGeoportalLayer('CADASTRALPARCELS.PARCELS:WMSC', {'CADASTRALPARCELS.PARCELS':{minZoomLevel:17,maxZoomLevel:18,opacity:1}});
    		}
    		
    			
    	var saveStrategy = new OpenLayers.Strategy.Save();
    
    	/*
    	var couche1= VISU.getMap().addLayer(
                "WFS",
                "couche1",
                "http://192.168.3.85:8080/geoserver/wfs",
                {
                    typename: 'poly4326',
    		featureNS :  "http://192.168.3.85:8080/postgis",
    		featureType: "poly4326",
    		featurePrefix:'postgis',
    		geometryName: "geom"
                },
                {
    		strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
                    projection: 'EPSG:4326',
                    units:'degrees',
                    // maxExtent expressed in EPSG:4326 :
                    maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
                    minZoomLevel:0,
                    maxZoomLevel:15,
                    hover: false,
    	
                }
            );*/
    		
    		
    		
    		couche2 = new OpenLayers.Layer.Vector("couche2", {
    			strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
    			projection: 'EPSG:4326',//new OpenLayers.Projection("EPSG:4326"),
    			protocol: new OpenLayers.Protocol.WFS({
    				version: "1.0.0",
    				srsName: "EPSG:4326",
    				url: "http://192.168.3.85:8080/geoserver/wfs",
    				featureNS :  "http://192.168.3.85:8080/postgis",
    				featureType: "poly4326",
    				featurePrefix:'postgis',
    				geometryName: "geom",
    				formatOptions:{
    					internalProjection: VISU.getMap().getProjection().clone(),
    					externalProjection: new OpenLayers.Projection('EPSG:4326')
    				}
    			})	
    		}); 
    			
    			
    		OpenLayers.Format.WFS.prototype.layerName = 'postgis:poly4326';
    
    		VISU.getMap().addLayer(couche2);
    				
    		
    
    /*//////////////////////////////
    VISU.getMap().addLayer(
                "WMS",
    			"WMS",
                "http://192.168.3.85:8080/geoserver/wms",
                {
                    layers:'poly2154',
                    format:'image/png',
                    transparent:'true'
                },
                {
                    singleTile:true,
                    projection:'EPSG:2154',
                    //units:'degrees',
                    // maxExtent expressed in EPSG:4326 :
                    maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
                    minZoomLevel: 5,
                    maxZoomLevel:15,
                    opacity:1,
                    isBaseLayer: false,
                    visibility: false,
                    originators:[
                        {
                            logo:'sandre',
                            pictureUrl: 'cofogar.JPG',
                            url: 'http://www.cofogar.com/'
                        }
                    ]
                }
            );
    
    //////////////////////////////*/
    
    			
    	// Ajout des outils de mesure au menu "outils"
    	var tbx= VISU.getMap().getControlsByClass('Geoportal.Control.ToolBox')[0];
            // add "Measure toolbar" :
            var measurebar= new Geoportal.Control.MeasureToolbar(
                {
                    div: OpenLayers.Util.getElement(tbx.id+'_measure'),
                    displaySystem:
                        (VISU.getMap().getProjection().proj.projName=='longlat'?
                            'geographic'
                        :   'metric'),
                    targetElement: OpenLayers.Util.getElement(tbx.id+'_meares')
                }
            );
    		
        VISU.getMap().addControl(measurebar);
    	
    	var searchbar= new Geoportal.Control.SearchToolbar(
                {
                    div: OpenLayers.Util.getElement(tbx.id+'_search'),
                    geonamesOptions: {
                        setZoom: Geoportal.Control.LocationUtilityService.GeoNames.setZoomForBDNyme,
                        layerOptions: {
                            name: 'TOPONYMS.ALL:OPENLS',
                            formatOptions: {
                                version:'1.0'
                            }
                        }
                    },
                    geocodeOptions: {
                        layerOptions: {
                            name: 'ADDRESSES.CROSSINGS:OPENLS',
                            formatOptions: {
                                version:'1.0'
                            }
                        },
                        matchTypes: [
                            {re:/city/i,    src:Geoportal.Util.getImagesLocation()+'OLScity.gif'},
                            {re:/street$/i, src:Geoportal.Util.getImagesLocation()+'OLSstreet.gif'},
                            {re:/number/i,  src:Geoportal.Util.getImagesLocation()+'OLSstreetnumber.gif'},
                            {re:/enhanced/i,src:Geoportal.Util.getImagesLocation()+'OLSstreetenhanced.gif'},
                            {re:null,       src:Geoportal.Util.getImagesLocation()+'OLSstreet.gif'}
                        ]
                    }
                }
            );
            //VISU.getMap().addControl(searchbar);
    
    	var panel = new OpenLayers.Control.Panel(
            {'displayClass': 'customEditingToolbar'}
        );
    	
    	var select = new OpenLayers.Control.SelectFeature(couche2, {title: "Select Feature", displayClass: "olControlSelectFeature"});
        
        var draw = new OpenLayers.Control.DrawFeature(
            couche2, OpenLayers.Handler.Polygon,
            {
                title: "Draw Feature",
                displayClass: "olControlDrawFeaturePolygon",
                multi: false
            }
        );
        
        var edit = new OpenLayers.Control.ModifyFeature(couche2, {
            title: "Modify Feature",
            displayClass: "olControlModifyFeature"
        });
    
    	
    	var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
    		initialize: function(layer, options) {
            OpenLayers.Control.prototype.initialize.apply(this, [options]);
            this.layer = layer;
            this.handler = new OpenLayers.Handler.Feature(
                this, layer, {click: this.clickFeature}
    			);
        },
        
    	clickFeature: function(feature) {
            // if feature doesn't have a fid, destroy it
            if(feature.fid == undefined) {
                this.layer.destroyFeatures([feature]);
            } else {
                feature.state = OpenLayers.State.DELETE;
                this.layer.events.triggerEvent("afterfeaturemodified", 
                                               {feature: feature});
                feature.renderIntent = "select";
                this.layer.drawFeature(feature);
            }
        },
        setMap: function(map) {
            this.handler.setMap(map);
            OpenLayers.Control.prototype.setMap.apply(this, arguments);
        },
        CLASS_NAME: "OpenLayers.Control.DeleteFeature"
    	});
    	
        var del = new DeleteFeature(couche2, {title: "Delete Feature"});
    	
    	
       
        var save = new OpenLayers.Control.Button({
            title: "Save Changes",
            trigger: function() {
    		if ($("descriptionField").value != ''){
    			edit.feature = true;
                //if(edit.feature) {
                    edit.selectControl.unselectAll();
                //}
    			feature.attributes.texte = $("descriptionField").value;
                saveStrategy.save();
    			$("titleField").value = '';
    			$("descriptionField").value = '';
    			alert("Données sauvegardées");
    			}
    		else {
    			alert("Données manquantes");
    			}
    		//VISU.getMap().setCenterAtLonLat(6.34, 45.69, 5);
            },
            displayClass: "olControlSaveFeatures"
    		
        });
    	
    		// listen for feature selection and update stats
        couche2.events.on({"featureselected": function(evt) {
            feature = evt.feature;
            selected = feature;
    		//$("fid").innerHTML = feature.fid || "Newly added point";
            $("titleField").value = feature.attributes.id;
            $("descriptionField").value = feature.attributes.texte;
        }});
    	
    	couche2.events.on({"featureunselected": function(evt) {
            //$("fid").innerHTML = feature.fid || "Newly added point";
            //$("titleField").value = feature.attributes.id;
            //$("descriptionField").value = '';
        }});
    	
    	// listen for feature add and update stats
        couche2.events.on({"featureadded": function(evt) {
            feature = evt.feature;
            added = feature;
    		//OpenCenterPopUp();
    		//$("fid").innerHTML = feature.fid || "Newly added point";
            //$("titleField").value = feature.attributes.id;
            //$("descriptionField").value = feature.attributes.texte;
        }});
    
    
        panel.addControls([save, del, edit, draw, select]);
       
        VISU.getMap().addControl(panel);
    
    	VISU.getMap().setCenterAtLonLat(6.34, 45.69, 5);
    	
    
    			  searchControl = new Geoportal.Control.SearchToolbar({
    			  div: OpenLayers.Util.getElement(tbx.id + '_search'),
    			  geonamesOptions: {
    			  layerOptions: {
    				name: 'TOPONYMS.ALL:OPENLS',
    				// ou OPENLS:TOPONYMS.ALL????
    				formatOptions: {
    				version: '1.0'
    				}
    			      }
    			    }
      			});
     
    			  //VISU.getMap().addControl(searchControl);
    			  //searchControl.controls[0].activate();	
    
    	}
    	
    	function save_manuelle (){
    		if ($("descriptionField").value != ''){
    			//edit.feature = true;
                //if(edit.feature) {
                //    edit.selectControl.unselectAll();
                //}
    			feature.attributes.texte = $("descriptionField").value;
                saveStrategy.save();
    			$("titleField").value = '';
    			$("descriptionField").value = '';
    			alert("Données sauvegardées");
    			}
    		else {
    			alert("Données manquantes");
    			}
    	};
    
    	
    
    	
    	function doSelect (feature) 
    	{
    		alert('selected');
    	}
    	
    	function doUnselect (feature)
    	{
    		alert('unselected');
    	}

  20. #20
    Membre chevronné
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    2 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 2 124
    Points : 1 764
    Points
    1 764
    Par défaut http://atlasnw.free.fr/geoportail/exemples/sigmax.html
    J'ai mis en ligne le code avec quelques ajouts ...
    Peux-tu nous indiquer comment tu crées la couche dans postgis et GeoServer ?

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 3 123 DernièreDernière

Discussions similaires

  1. Ajout de couche wfs (BD Carthage)
    Par flobel69 dans le forum IGN API Géoportail
    Réponses: 1
    Dernier message: 16/09/2012, 15h22
  2. Ajout de couche WFS (BD Carthage)
    Par flobel69 dans le forum IGN API Géoportail
    Réponses: 2
    Dernier message: 31/08/2012, 16h23
  3. Ajout couche wfs
    Par Mic75 dans le forum IGN API Géoportail
    Réponses: 3
    Dernier message: 23/08/2012, 15h32
  4. Ajout couche wfs/wms
    Par celem dans le forum IGN API Géoportail
    Réponses: 5
    Dernier message: 01/06/2010, 08h14
  5. intégration couches WFS
    Par EmilieDB dans le forum IGN API Géoportail
    Réponses: 3
    Dernier message: 15/05/2009, 17h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo