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

Interfaces Graphiques en Java Discussion :

Geotools ne m'affiche pas la carte


Sujet :

Interfaces Graphiques en Java

  1. #1
    Nouveau membre du Club
    Inscrit en
    Octobre 2010
    Messages
    109
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 109
    Points : 36
    Points
    36
    Par défaut Geotools ne m'affiche pas la carte
    bonjour

    j'ai un probleme qui m'intrigue .voila j'ai executer ce bout de programme qui sert normalement à afficher une carte à l'aide de geotools (à partir d'un fichier shp ) or ce n'estpas le cas il m'affichetout ( la fentre, les boutton....) sauf la carte qui n'apparait pas . je ne sais plus ou se situe le probleme


    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package geo;
     
     
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.URL;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import org.geotools.data.FeatureSource;
    import org.geotools.data.Query;
    import org.geotools.data.shapefile.ShapefileDataStore;
    import org.geotools.map.DefaultMapContext;
    import org.geotools.map.DefaultMapLayer;
    import org.geotools.map.MapContext;
    import org.geotools.map.MapLayer;
    import org.geotools.renderer.lite.StreamingRenderer;
    import org.geotools.styling.LineSymbolizer;
    import org.geotools.styling.PolygonSymbolizer;
    import org.geotools.styling.Style;
    import org.geotools.styling.StyleBuilder;
    import org.geotools.swing.JMapPane;
     
     
     
     
     
     
    public class Chap1Contact {
     
        private JMapPane mappane = new JMapPane();
     
        public Chap1Contact() {
            JFrame frm = new JFrame();
            frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frm.setSize(800, 600);
            frm.setTitle("Ma Première carte avec GeoTools");
     
     
            JPanel pfond = new JPanel(new BorderLayout());
            frm.setContentPane(pfond);
     
            frm.setJMenuBar(buildMenu());
            frm.getContentPane().add(BorderLayout.CENTER, buildMap());
            frm.getContentPane().add(BorderLayout.NORTH, buildTool());
     
            frm.setVisible(true);
        }
     
        private JMenuBar buildMenu() {
            JMenuBar menu = new JMenuBar();
            JMenu mfichier = new JMenu("Fichier");
            JMenuItem iquitter = new JMenuItem("Quitter");
     
            iquitter.addActionListener(new ActionListener() {
     
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });
            mfichier.add(iquitter);
            menu.add(mfichier);
     
            return menu;
        }
     
        private JPanel buildMap() {
     
            mappane.setBackground(new Color(157, 201, 255));
     
            try {
     
                MapContext mapcontext = new DefaultMapContext();
                mapcontext.setTitle("Projet");
     
                 mappane.setMapContext(mapcontext);
     
                MapLayer maplayer;
     
                URL shapeURL = Chap1Contact.class.getResource("world_borders.shx");
     
                ShapefileDataStore store = new ShapefileDataStore(shapeURL);
                String name = store.getTypeNames()[0];
                FeatureSource source = store.getFeatureSource(name);
                StyleBuilder sb = new StyleBuilder();
     
                PolygonSymbolizer ps = sb.createPolygonSymbolizer(new Color(253, 241, 187), new Color(163, 151, 97), 1);
                Style solstyle = sb.createStyle();
                solstyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(ps));
                maplayer = new DefaultMapLayer(source, solstyle);
                maplayer.setTitle("world_borders.shx");
                maplayer.setVisible(true);
                maplayer.setQuery(Query.ALL);
                mapcontext.addLayer(maplayer);
     
     
                shapeURL = Chap1Contact.class.getResource("D:\\reseau_route.shp");
     
                store = new ShapefileDataStore(shapeURL);
                name = store.getTypeNames()[0];
                source = store.getFeatureSource(name);
     
                sb = new StyleBuilder();
     
                LineSymbolizer ls2 = sb.createLineSymbolizer(Color.RED, 1);
                Style roadsStyle = sb.createStyle();
                roadsStyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(ls2));
     
                maplayer = new DefaultMapLayer(source, roadsStyle);
                maplayer.setTitle("reseau_route.shp");
                maplayer.setVisible(true);
                maplayer.setQuery(Query.ALL);
                mapcontext.addLayer(maplayer);
     
                StreamingRenderer render = new StreamingRenderer();
     
                mappane.setRenderer(render);
                mappane.setDisplayArea(mapcontext.getLayerBounds());
     
     
            } catch (Exception e) {
                e.printStackTrace();
            }
     
            return mappane;
        }
     
         private JPanel buildTool() {
            JPanel outil = new JPanel(new FlowLayout(FlowLayout.LEFT));
     
            JButton plus = new JButton("+");
            plus.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //mappane.setState(JMapPane.ZoomIn);
                }
            });
            outil.add(plus);
     
            JButton moins = new JButton("-");
            moins.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //mappane.setState(JMapPane.ZoomOut);
                }
            });
            outil.add(moins);
     
            JButton pan = new JButton("Pan");
            pan.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //mappane.setState(JMapPane.Pan);
                }
            });
            outil.add(pan);
     
            return outil;
        }
     
     
         public static void main(String[] args){
             new Chap1Contact();
         }
     
    }




    EXEPTION rencontré

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    run:
    java.lang.NullPointerException
    	at org.geotools.map.MapContent.listenToMapLayers(MapContent.java:274)
    	at org.geotools.map.MapContent.addMapLayerListListener(MapContent.java:224)
    	at org.geotools.map.MapContext.addMapLayerListListener(MapContext.java:513)
    	at org.geotools.swing.JMapPane.doSetMapContext(JMapPane.java:479)
    	at org.geotools.swing.JMapPane.setMapContext(JMapPane.java:461)
    	at geo.Chap1Contact.buildMap(Chap1Contact.java:88)
    	at geo.Chap1Contact.<init>(Chap1Contact.java:55)
    	at geo.Chap1Contact.main(Chap1Contact.java:172)

  2. #2
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    Bonjour sali2801

    Bizard, cela fonctionne bien chez moi. J'ai juste du faire une adaptation du code car je suis en version 8.0 m4.

    ce que je dois changer est comme par hasard la ligne 88 qui plante chez toi.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    mappane.setMapContext(mapcontext);
    devient
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    mappane.setMapContent(mapcontext);
    Tu as quelle version de geotools.
    Page sur Developpez : http://pbriand.developpez.com

  3. #3
    Nouveau membre du Club
    Inscrit en
    Octobre 2010
    Messages
    109
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 109
    Points : 36
    Points
    36
    Par défaut help
    Bonjour,
    D'abord je tiens à vous remercier d'avoir pris le soin de me répondre

    j'ai la version geotools-2.7.1 mon netbeans et de version "NetBeans IDE 7.0.1" je vais vous montrer qu'est ce que m'affiche le code sous dessus et je vous suplie de me montrer qu'est ce que vous affiche et s'il vous plie quelle version de geotools utilisez vous ?

    et que dois je faire?????
    Images attachées Images attachées  

  4. #4
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    Voici ce que j'obtiens

    je suis sous eclipse et GeoTools 8.0 M4
    Images attachées Images attachées  
    Page sur Developpez : http://pbriand.developpez.com

  5. #5
    Nouveau membre du Club
    Inscrit en
    Octobre 2010
    Messages
    109
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 109
    Points : 36
    Points
    36
    Par défaut
    wawoo vraiment wawoo si exactement ce que je voudrais faire

    pourqoui il m'affiche pas ce qu'il vous affiche
    di moi est ce que vous avez telecharger le JAI si oui quelle version (passez moi le lien, je vous suplie)


    Autre chose , est ce que vous avez copie coller executer mon code seulemnt ou vous avez fait autre chose ,et pour l'ajout de la bibliothéque geotools sous eclipse comment faire ???

    veuillez m'execuser mais là comme je suis perdu je cherche les petits detailles , qui à peuvent m'echapper et inhiber l'affichage de la carte.

  6. #6
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    pourquoi il m'affiche pas ce qu'il vous affiche
    Je pense que cela est du a ta version de Geotools 2.7.1 alors que la mienne est 8.0 M4

    Je l'ai téléchargé ici

    Peut être aussi que ton fichier shd est incorrect.
    tu peux en trouver ici pour faire un test (j'ai pris le 22- cotes d'armors. J'y ai fait un pre-traitement pour éviter une déformation.

    Dans ton code, je n'ai modifié qu'une seule ligne, celle que je t'ai cité dans mon premier post ligne 88

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    mappane.setMapContent(mapcontext);
    et aussi juste modifié le nom du fichier shx, pour lire le mien. Je ne peux pas t'envoyer ma carte le fichier est trop gros pour ce forum.

    et pour l'ajout de la bibliothéque geotools sous eclipse comment faire ???
    Tu fais un projet java sous eclipse, puis dans les propriétés du projet, tu modifie le build path, et tu y ajoute tous les jar de geotools.

    voici mon code modifié:
    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
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package geo;
     
     
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.URL;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import org.geotools.data.FeatureSource;
    import org.geotools.data.Query;
    import org.geotools.data.shapefile.ShapefileDataStore;
    import org.geotools.map.DefaultMapContext;
    import org.geotools.map.DefaultMapLayer;
    import org.geotools.map.MapContext;
    import org.geotools.map.MapLayer;
    import org.geotools.renderer.lite.StreamingRenderer;
    import org.geotools.styling.LineSymbolizer;
    import org.geotools.styling.PolygonSymbolizer;
    import org.geotools.styling.Style;
    import org.geotools.styling.StyleBuilder;
    import org.geotools.swing.JMapPane;
     
     
     
     
     
     
    public class Chap1Contact {
     
        private JMapPane mappane = new JMapPane();
     
        public Chap1Contact() {
            JFrame frm = new JFrame();
            frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frm.setSize(800, 600);
            frm.setTitle("Ma Première carte avec GeoTools");
     
     
            JPanel pfond = new JPanel(new BorderLayout());
            frm.setContentPane(pfond);
     
            frm.setJMenuBar(buildMenu());
            frm.getContentPane().add(BorderLayout.CENTER, buildMap());
            frm.getContentPane().add(BorderLayout.NORTH, buildTool());
     
            frm.setVisible(true);
        }
     
        private JMenuBar buildMenu() {
            JMenuBar menu = new JMenuBar();
            JMenu mfichier = new JMenu("Fichier");
            JMenuItem iquitter = new JMenuItem("Quitter");
     
            iquitter.addActionListener(new ActionListener() {
     
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });
            mfichier.add(iquitter);
            menu.add(mfichier);
     
            return menu;
        }
     
        private JPanel buildMap() {
     
            mappane.setBackground(new Color(157, 201, 255));
     
            try {
     
                MapContext mapcontext = new DefaultMapContext();
                mapcontext.setTitle("Projet");
     
                mappane.setMapContent(mapcontext);
     
                MapLayer maplayer;
     
                URL shapeURL = Chap1Contact.class.getResource("22.shx");
     
                ShapefileDataStore store = new ShapefileDataStore(shapeURL);
                String name = store.getTypeNames()[0];
                FeatureSource source = store.getFeatureSource(name);
                StyleBuilder sb = new StyleBuilder();
     
                PolygonSymbolizer ps = sb.createPolygonSymbolizer(new Color(253, 241, 187), new Color(163, 151, 97), 1);
                Style solstyle = sb.createStyle();
                solstyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(ps));
                maplayer = new DefaultMapLayer(source, solstyle);
                maplayer.setTitle("world_borders.shx");
                maplayer.setVisible(true);
                maplayer.setQuery(Query.ALL);
                mapcontext.addLayer(maplayer);
     
     
                shapeURL = Chap1Contact.class.getResource("D:\\reseau_route.shp");
     
                store = new ShapefileDataStore(shapeURL);
                name = store.getTypeNames()[0];
                source = store.getFeatureSource(name);
     
                sb = new StyleBuilder();
     
                LineSymbolizer ls2 = sb.createLineSymbolizer(Color.RED, 1);
                Style roadsStyle = sb.createStyle();
                roadsStyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(ls2));
     
                maplayer = new DefaultMapLayer(source, roadsStyle);
                maplayer.setTitle("reseau_route.shp");
                maplayer.setVisible(true);
                maplayer.setQuery(Query.ALL);
                mapcontext.addLayer(maplayer);
     
                StreamingRenderer render = new StreamingRenderer();
     
                mappane.setRenderer(render);
                mappane.setDisplayArea(mapcontext.getLayerBounds());
     
     
            } catch (Exception e) {
                e.printStackTrace();
            }
     
            return mappane;
        }
     
         private JPanel buildTool() {
            JPanel outil = new JPanel(new FlowLayout(FlowLayout.LEFT));
     
            JButton plus = new JButton("+");
            plus.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //mappane.setState(JMapPane.ZoomIn);
                }
            });
            outil.add(plus);
     
            JButton moins = new JButton("-");
            moins.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //mappane.setState(JMapPane.ZoomOut);
                }
            });
            outil.add(moins);
     
            JButton pan = new JButton("Pan");
            pan.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //mappane.setState(JMapPane.Pan);
                }
            });
            outil.add(pan);
     
            return outil;
        }
     
     
         public static void main(String[] args){
             new Chap1Contact();
         }
     
    }
    j'ai juste une exception qu'en je veux lire le fichier D:\\reseau_route.shp que je n'ai pas.

    Bon courage
    Page sur Developpez : http://pbriand.developpez.com

  7. #7
    Nouveau membre du Club
    Inscrit en
    Octobre 2010
    Messages
    109
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 109
    Points : 36
    Points
    36
    Par défaut
    j'ai commencer à douter que le probléme réside dans le fichier c'est pour cette raison
    je me demande si je dois donner à mon code souce un fichier d'extension shp ou shx

    puis j'ai telecharger le meme fichier nommé "22-Côtes-d'Armor.shp.tar.gz"
    mais là comme on voit l'extension est "shp.tar.gz" dois_je la renommer


    rassurer moi une chose vous avez des warning quand vous compiler

    par exemple dans cette ligne;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    maplayer.setVisible(true);


    autre chose j'ai telecharger votre version geotools mais là il m'indique que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    import org.geotools.map.MapLayer;
    the type MapLayer is deprecated

    est ce que c'est le cas pour vous ????



    juste une question de plus
    vous avez dis je ne peux pas vous envoyer la carte vous voulez dire par la carte le fichier shp que j'ai telecharger , c'est ça???

  8. #8
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    mais là comme on voit l'extension est "shp.tar.gz" dois_je la renommer
    Non, ne le renomme pas, mais decrompresse le. (deux fois je crois).
    Tu obtiendras alors 4 fichiers avec le même nom, mais 4 extensions différentes(dbf, prj, shp, shx). Pour le décompresser j'utilise 7z , mais il doit en exister d'autre

    Quand je compile, j'obtiens des warning du style deprecated. Cela veut dire que l'on te décourage d'utiliser cette méthode qui va devenir obsolète.


    autre chose j'ai telecharger votre version geotools mais là il m'indique que
    Code :
    Sélectionner tout - Visualiser dans une fenêtre à part

    import org.geotools.map.MapLayer;

    the type MapLayer is deprecated

    est ce que c'est le cas pour vous ????
    Oui, c'est aussi le cas chez moi
    Page sur Developpez : http://pbriand.developpez.com

  9. #9
    Nouveau membre du Club
    Inscrit en
    Octobre 2010
    Messages
    109
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 109
    Points : 36
    Points
    36
    Par défaut
    Au secours, je vai faire une depression depuis une semaine que je teste le meme code et j'obtient les memes resultat meme

    j'ai fait tout ce que vous m'avez dit, et j'aboutis au meme resultat avec les erreurs suivantes :

    RESTE UNE CHOSE JE DOIS PLACER LES 4 FICHIER DANS LE DOSSIER src de mon projet???


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    java.lang.NullPointerException
    	at org.geotools.data.shapefile.ShpFiles.init(ShpFiles.java:147)
    	at org.geotools.data.shapefile.ShpFiles.<init>(ShpFiles.java:141)
    	at org.geotools.data.shapefile.ShapefileDataStore.<init>(ShapefileDataStore.java:199)
    	at org.geotools.data.shapefile.ShapefileDataStore.<init>(ShapefileDataStore.java:171)
    	at org.geotools.data.shapefile.ShapefileDataStore.<init>(ShapefileDataStore.java:161)
    	at geo.Chap1Contact.buildMap(Chap1Contact.java:114)
    	at geo.Chap1Contact.<init>(Chap1Contact.java:75)
    	at geo.Chap1Contact.main(Chap1Contact.java:192)
    SOS

    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
     
     
     
    package geo;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.URL;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import org.geotools.data.FeatureSource;
    import org.geotools.data.Query;
    import org.geotools.data.shapefile.ShapefileDataStore;
    import org.geotools.map.DefaultMapContext;
    import org.geotools.map.DefaultMapLayer;
    import org.geotools.map.MapContext;
    import org.geotools.map.MapLayer;
    import org.geotools.renderer.lite.StreamingRenderer;
    import org.geotools.styling.LineSymbolizer;
    import org.geotools.styling.PolygonSymbolizer;
    import org.geotools.styling.Style;
    import org.geotools.styling.StyleBuilder;
    import org.geotools.swing.JMapPane;
     
     
     
    public class Chap1Contact {
     
       private JMapPane mappane = new JMapPane();
     
       public Chap1Contact() {
           JFrame frm = new JFrame();
           frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frm.setSize(800, 600);
           frm.setTitle("Ma Première carte avec GeoTools");
     
     
           JPanel pfond = new JPanel(new BorderLayout());
           frm.setContentPane(pfond);
     
           frm.setJMenuBar(buildMenu());
           frm.getContentPane().add(BorderLayout.CENTER, buildMap());
           frm.getContentPane().add(BorderLayout.NORTH, buildTool());
     
           frm.setVisible(true);
       }
     
       private JMenuBar buildMenu() {
           JMenuBar menu = new JMenuBar();
           JMenu mfichier = new JMenu("Fichier");
           JMenuItem iquitter = new JMenuItem("Quitter");
     
           iquitter.addActionListener(new ActionListener() {
     
               @Override
               public void actionPerformed(ActionEvent e) {
                   System.exit(0);
               }
           });
           mfichier.add(iquitter);
           menu.add(mfichier);
     
           return menu;
       }
     
       private JPanel buildMap() {
     
           mappane.setBackground(new Color(157, 201, 255));
     
           try {
     
               MapContext mapcontext = new DefaultMapContext();
               mapcontext.setTitle("Projet");
     
               mappane.setMapContent(mapcontext);
     
               MapLayer maplayer;
     
               URL shapeURL = Chap1Contact.class.getResource("22.shx");
     
               ShapefileDataStore store = new ShapefileDataStore(shapeURL);
               String name = store.getTypeNames()[0];
               FeatureSource source = store.getFeatureSource(name);
               StyleBuilder sb = new StyleBuilder();
     
               PolygonSymbolizer ps = sb.createPolygonSymbolizer(new Color(253, 241, 187), new Color(163, 151, 97), 1);
               Style solstyle = sb.createStyle();
               solstyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(ps));
               maplayer = new DefaultMapLayer(source, solstyle);
               maplayer.setTitle("22.shx");
               maplayer.setVisible(true);
               maplayer.setQuery(Query.ALL);
               mapcontext.addLayer(maplayer);
     
     
               shapeURL = Chap1Contact.class.getResource("22.shp");
     
               store = new ShapefileDataStore(shapeURL);
               name = store.getTypeNames()[0];
               source = store.getFeatureSource(name);
     
               sb = new StyleBuilder();
     
               LineSymbolizer ls2 = sb.createLineSymbolizer(Color.RED, 1);
               Style roadsStyle = sb.createStyle();
               roadsStyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(ls2));
     
               maplayer = new DefaultMapLayer(source, roadsStyle);
               maplayer.setTitle("22.shp");
               maplayer.setVisible(true);
               maplayer.setQuery(Query.ALL);
               mapcontext.addLayer(maplayer);
     
               StreamingRenderer render = new StreamingRenderer();
     
               mappane.setRenderer(render);
               mappane.setDisplayArea(mapcontext.getLayerBounds());
     
     
           } catch (Exception e) {
               e.printStackTrace();
           }
     
           return mappane;
       }
     
        private JPanel buildTool() {
           JPanel outil = new JPanel(new FlowLayout(FlowLayout.LEFT));
     
           JButton plus = new JButton("+");
           plus.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                   //mappane.setState(JMapPane.ZoomIn);
               }
           });
           outil.add(plus);
     
           JButton moins = new JButton("-");
           moins.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                   //mappane.setState(JMapPane.ZoomOut);
               }
           });
           outil.add(moins);
     
           JButton pan = new JButton("Pan");
           pan.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                   //mappane.setState(JMapPane.Pan);
               }
           });
           outil.add(pan);
     
           return outil;
       }
     
     
        public static void main(String[] args){
            new Chap1Contact();
     
        }
     
    }

  10. #10
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    Oui, il te faut tous les fichiers dans le répertoire source. La librairie ne lit pas qu'un seul fichier, mais tous les fichiers.

    je pars en week end, retour mercredi, maintenant je ne vais plus pouvoir t'aider
    Page sur Developpez : http://pbriand.developpez.com

  11. #11
    Nouveau membre du Club
    Inscrit en
    Octobre 2010
    Messages
    109
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 109
    Points : 36
    Points
    36
    Par défaut
    Citation Envoyé par bpy1401 Voir le message
    Oui, il te faut tous les fichiers dans le répertoire source. La librairie ne lit pas qu'un seul fichier, mais tous les fichiers.

    je pars en week end, retour mercredi, maintenant je ne vais plus pouvoir t'aider
    est ce quelqu'un d'autre peut m'aider

  12. #12
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2012
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Août 2012
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    bonjour merci pour votre aide,
    bn votre code a marché pour moi avec la version 8 de geotool sauf que quand j’enlève les commentaire de // mappane.setState(JMapPane.ZoomOut);

    ca marche pas merci de m'aider est ce que je dois ajouter qlq chose

Discussions similaires

  1. [AC-2010] Carte Google Maps qui ne s'affiche pas.
    Par baptistol dans le forum IHM
    Réponses: 0
    Dernier message: 08/11/2011, 21h19
  2. [Google Maps] Carte Google Maps ne s'affiche pas entièrement
    Par Kentin64 dans le forum APIs Google
    Réponses: 2
    Dernier message: 19/08/2011, 10h19
  3. Carte ne s'affiche pas sur le téléphone
    Par clege dans le forum Android
    Réponses: 5
    Dernier message: 16/05/2011, 00h24
  4. Réponses: 0
    Dernier message: 21/04/2011, 19h53
  5. [1.x] sfEasyGMapPlugin : La carte ne s'affiche pas
    Par -BTA- dans le forum Symfony
    Réponses: 1
    Dernier message: 21/11/2009, 11h42

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