2

I use the example of the official website to load the shpfile file, but the style only works in the frame, it does not work in the jMapPane.

public void openShpFile(JMapPane mapPane) throws Exception {
    File file = JFileDataStoreChooser.showOpenFile("shp", null);
    if (file == null) {
        return;
    }

    FileDataStore store = FileDataStoreFinder.getDataStore(file);
    SimpleFeatureSource featureSource = store.getFeatureSource();
    MapContent map = new MapContent();
    map.setTitle("Quickstart");

    Style style = SLD.createSimpleStyle(featureSource.getSchema());
    Layer layer = new FeatureLayer(featureSource, style);
    //GTRenderer renderer = new StreamingRenderer();
    map.addLayer(layer);
   // mapPane.setRenderer( new StreamingRenderer() );
    mapPane.setMapContent(map);
}

An example of the official website is as follows:

public static void main(String[] args) throws Exception {
    // display a data store file chooser dialog for shapefiles
    File file = JFileDataStoreChooser.showOpenFile("shp", null);
    if (file == null) {
        return;
    }

    FileDataStore store = FileDataStoreFinder.getDataStore(file);
    SimpleFeatureSource featureSource = store.getFeatureSource();

    // Create a map content and add our shapefile to it
    MapContent map = new MapContent();
    map.setTitle("Quickstart");

    Style style = SLD.createSimpleStyle(featureSource.getSchema());
    Layer layer = new FeatureLayer(featureSource, style);
    map.addLayer(layer);

    // Now display the map
    JMapFrame.showMap(map);
}

The result is that I can display it, but there is no toolbar. I want to ask how to display the toolbar or set the style in jMapPane. It seems that the GTrender method has no effect.The picture is the official result. enter image description here

my result:::I just want to show the map and toolbar in the lower right corner, but it didn't work, only the map, no toolbar enter image description here

0

The toolbar is a function of the JMapFrame - you need to call frame.enableToolBar(true); to turn the toolbar on, and frame.enableStatusBar(true); to add the status bar to the frame. Both are off by default.

The style is applied to the layer before it is added to the MapContent object, there should be no need to add a new renderer as there is already one set in the MapPane.

Update

To create your own toolbar in another JComponent you can look at the code in JMapFrame which shows how it is done. It would be a nice enhancement to break that code out into a separate helper class that took a component as input and added a toolbar. If you did that we'd be happy to accept a PR.

  • I want to display the map at the specified location and display the toolbar, so I used JmapPane but the map will be displayed and the toolbar will not be displayed. – merin Sep 7 at 8:45
  • The mapPane has to be in some other container, that will be responsible for the toolbar, look in the JMapFrame to see how it is done – Ian Turton Sep 7 at 9:07
  • I modified my question and you can look at it again. – merin Sep 7 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.