Précédent   Forum des professionnels en informatique > Applications > SIG : Système d'information Géographique > IGN API Géoportail
IGN API Géoportail Forum d'entraide sur l'API Géoportail développé par IGN
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 10/01/2012, 12h58   #1
Invité de passage
 
Inscription : juin 2009
Messages : 13
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 13
Points : 1
Points : 1
Par défaut bug openLayers containsPoint

Bonjour,

Je suis embêté par le bug containsPoint d'openlayers expliqué ici:
http://trac.osgeo.org/openlayers/ticket/2492

Ce bug n'est pas considéré comme prioritaire, et dois être corrigé pour la version 2.12 d'OL. Il impactera donc à priori la version 1.3 de l'api Geoportail.

Il semble que la solution proposée dans le ticket fonctionne (j'ai effectué qqs tests).

Serait-il envisageable de surcharger cette fonction dans la future version 1.3 de l'api ? Ce n'est peut-être pas si simple car LinearRing.containsPoint est utilisée par d'autres fonction d'OL, notamment par intersects et par distanceTo (qui utilise intersects), et ce pour plusieurs types de géométrie.

Bonne continuation.
LePouillot est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/01/2012, 23h10   #2
Expert Confirmé

 
Homme Didier Richard
Ingénieur cartographe
Inscription : avril 2009
Messages : 2 734
Détails du profil
Informations personnelles :
Nom : Homme Didier Richard
Localisation : France, Val de Marne (Île de France)

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

Informations forums :
Inscription : avril 2009
Messages : 2 734
Points : 3 502
Points : 3 502
Citation:
Envoyé par LePouillot Voir le message
Je suis embêté par le bug containsPoint d'openlayers expliqué ici:
http://trac.osgeo.org/openlayers/ticket/2492

Ce bug n'est pas considéré comme prioritaire, et dois être corrigé pour la version 2.12 d'OL. Il impactera donc à priori la version 1.3 de l'api Geoportail.
C'est taggué 2.12 parce que toujours pas pris avant
Rien n'assure que cela sera dans la 2.12 (pas plus dans notre 1.3 )

Comme il n'y a pas vraiment de patch, tu pourrais inclure le correctif ainsi dans tes pages :

* API 1.2 :

Code :
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
OpenLayers.Geometry.LinearRing.prototype.containsPoint=  function(point) {
        var approx = OpenLayers.Number.limitSigDigs;
        var digs = 14;
        var px = approx(point.x, digs);
        var py = approx(point.y, digs);
        function getX(y, x1, y1, x2, y2) {
            return (y-y2)*((x2-x1)/(y2-y1)) + x2;
        }
        var numSeg = this.components.length - 1;
        var start, end, x1, y1, x2, y2, cx, cy;
        var crosses = 0;
        for(var i=0; i<numSeg; ++i) {
            start = this.components[i];
            x1 = approx(start.x, digs);
            y1 = approx(start.y, digs);
            end = this.components[i + 1];
            x2 = approx(end.x, digs);
            y2 = approx(end.y, digs);

            /**
             * The following conditions enforce five edge-crossing rules:
             *    1. points coincident with edges are considered contained;
             *    2. an upward edge includes its starting endpoint, and
             *    excludes its final endpoint;
             *    3. a downward edge excludes its starting endpoint, and
             *    includes its final endpoint;
             *    4. horizontal edges are excluded; and
             *    5. the edge-ray intersection point must be strictly right
             *    of the point P.
             */
            if(y1 == y2) {
                // horizontal edge
                if(py == y1) {
                    // point on horizontal line
                    if(x1 <= x2 && (px >= x1 && px <= x2) || // right or vert
                       x1 >= x2 && (px <= x1 && px >= x2)) { // left or vert
                        // point on edge
                        crosses = -1;
                        break;
                    }
                }
                // ignore other horizontal edges
                continue;
            }
            cx = approx(getX(py, x1, y1, x2, y2), digs);
            if(cx == px) {
                // point on line
                if(y1 < y2 && (py >= y1 && py <= y2) || // upward
                   y1 > y2 && (py <= y1 && py >= y2)) { // downward
                    // point on edge
                    crosses = -1;
                    break;
                }
            }
            if(cx <= px) {
                // no crossing to the right
                continue;
            }
            if(x1 != x2 && (cx < Math.min(x1, x2) || cx > Math.max(x1, x2))) {
                // no crossing
                continue;
            }
            if(y1 < y2 && (py >= y1 && py < y2) || // upward
               y1 > y2 && (py < y1 && py >= y2)) { // downward
                ++crosses;
            }
        }
        var contained = (crosses == -1) ?
            // on edge
            1 :
            // even (out) or odd (in)
            !!(crosses & 1);

        return contained;
    };
et en 1.3 :

Code :
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
OpenLayers.Geometry.LinearRing= OpenLayers.overload(OpenLayers.Geometry.LinearRing, {
    containsPoint: function(point) {
        var approx = OpenLayers.Number.limitSigDigs;
        var digs = 14;
        var px = approx(point.x, digs);
        var py = approx(point.y, digs);
        function getX(y, x1, y1, x2, y2) {
            return (y-y2)*((x2-x1)/(y2-y1)) + x2;
        }
        var numSeg = this.components.length - 1;
        var start, end, x1, y1, x2, y2, cx, cy;
        var crosses = 0;
        for(var i=0; i<numSeg; ++i) {
            start = this.components[i];
            x1 = approx(start.x, digs);
            y1 = approx(start.y, digs);
            end = this.components[i + 1];
            x2 = approx(end.x, digs);
            y2 = approx(end.y, digs);

            /**
             * The following conditions enforce five edge-crossing rules:
             *    1. points coincident with edges are considered contained;
             *    2. an upward edge includes its starting endpoint, and
             *    excludes its final endpoint;
             *    3. a downward edge excludes its starting endpoint, and
             *    includes its final endpoint;
             *    4. horizontal edges are excluded; and
             *    5. the edge-ray intersection point must be strictly right
             *    of the point P.
             */
            if(y1 == y2) {
                // horizontal edge
                if(py == y1) {
                    // point on horizontal line
                    if(x1 <= x2 && (px >= x1 && px <= x2) || // right or vert
                       x1 >= x2 && (px <= x1 && px >= x2)) { // left or vert
                        // point on edge
                        crosses = -1;
                        break;
                    }
                }
                // ignore other horizontal edges
                continue;
            }
            cx = approx(getX(py, x1, y1, x2, y2), digs);
            if(cx == px) {
                // point on line
                if(y1 < y2 && (py >= y1 && py <= y2) || // upward
                   y1 > y2 && (py <= y1 && py >= y2)) { // downward
                    // point on edge
                    crosses = -1;
                    break;
                }
            }
            if(cx <= px) {
                // no crossing to the right
                continue;
            }
            if(x1 != x2 && (cx < Math.min(x1, x2) || cx > Math.max(x1, x2))) {
                // no crossing
                continue;
            }
            if(y1 < y2 && (py >= y1 && py < y2) || // upward
               y1 > y2 && (py < y1 && py >= y2)) { // downward
                ++crosses;
            }
        }
        var contained = (crosses == -1) ?
            // on edge
            1 :
            // even (out) or odd (in)
            !!(crosses & 1);

        return contained;
    }
});
dgrichard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/01/2012, 08h46   #3
Invité de passage
 
Homme
Inscription : janvier 2012
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : janvier 2012
Messages : 3
Points : 1
Points : 1
Bonjour, le ticket en question est désormais fermé.
pgiraud est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/01/2012, 13h15   #4
Invité de passage
 
Inscription : juin 2009
Messages : 13
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 13
Points : 1
Points : 1
Bonjour,

Merci à Didier Richard pour sa solution, qui m'a permis de mieux comprendre comment surcharger une fonction, et à P. Giraud pour finalement la résolution définitive du problème.

Cependant, compte-tenu de mes lacunes en anglais, je n'ai pas réussis à comprendre quelle version d'OL est corrigée ? Est-ce la 2.11 ou la future 2.12 ?

Bonne continuation.
LePouillot est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2012, 23h18   #5
Expert Confirmé

 
Homme Didier Richard
Ingénieur cartographe
Inscription : avril 2009
Messages : 2 734
Détails du profil
Informations personnelles :
Nom : Homme Didier Richard
Localisation : France, Val de Marne (Île de France)

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

Informations forums :
Inscription : avril 2009
Messages : 2 734
Points : 3 502
Points : 3 502
Sera dans OpenLayers 2.12 et j'ai intégré le patch dans l'API 1.3 du Géoportail
dgrichard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/01/2012, 10h49   #6
Invité de passage
 
Inscription : juin 2009
Messages : 13
Détails du profil
Informations forums :
Inscription : juin 2009
Messages : 13
Points : 1
Points : 1
Citation:
Envoyé par dgrichard Voir le message
Sera dans OpenLayers 2.12 et j'ai intégré le patch dans l'API 1.3 du Géoportail
Super nickel. Merci encore !
LePouillot est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 09h31.


 
 
 
 
Partenaires

Hébergement Web