1

After adding a new layer it doesn't show inside JMapPane, is there a way to force this? I already tried using MapLayerEvent

styleSld = Stil.createFromSLD(inputStream);
layer = new FeatureLayer(pointCollection, styleSld);
layer.setTitle("G_POINT");

getMapPane().getMapContent().addLayer(layer);
MapLayerEvent mple = new MapLayerEvent(layer, MapLayerEvent.DATA_CHANGED);
MapLayerListEvent mplle = new MapLayerListEvent(getMapPane().getMapContent(), layer,
    getMapPane().getMapContent().layers().indexOf(layer), mple);
getMapPane().layerChanged(mplle);

The same code is used for refreshing content when drawing new feature and it works normaly.

I also tried running new ResetAction and nothing happens. If I interacted with a map by (zoom change or by clicking ResetButton or Drag) it will render the layer.

EDIT

The problem is caused by,

getMapPane().getMapContent().getViewport().setBounds(new ReferencedEnvelope(-100, 100, -100, 100,
                getMapPane().getMapContent().getCoordinateReferenceSystem()));

after I remove this it works nicely, but then need to go through the code and manually create bounds if a return is null, but it will be much easier with this part in the code.

3
  • is -100, 100, -100, 100 a valid bounding box in your coordinate system? I would use the bounds of my layer
    – Ian Turton
    Commented Aug 5, 2017 at 9:12
  • The coordinate system is not set yet, there is a possibility to open a WMS in WGS84, GK6 or some other coordinate system, the same is with other details. When loading a WMS without any bounds set in MapContent it returns 2017-08-05T11:34:25.234+0200 SEVERE The scale denominator must be positive. java.lang.IllegalArgumentException: The scale denominator must be positive. Solved this by adding getMapPane().getMapContent().getViewport().setBounds(wmsLayer.getBounds()) Commented Aug 5, 2017 at 9:38
  • This should propbably be a new question but given a layer l from a WMS use the following ReferencedEnvelope envelope2 = new ReferencedEnvelope(l.getEnvelope(crs)); System.out.println(crs.getName() + " [ " + envelope2.getMinX() + "," + envelope2.getMinY() + "," + envelope2.getMaxX() + "," + envelope2.getMaxY() + " ]");
    – Ian Turton
    Commented Aug 5, 2017 at 9:42

1 Answer 1

1

Without more of your code it is hard to tell what is happening.

But you shouldn't need to send your own event. If you look in MapContent you will see the addIfAbsent method:

    @Override
    public boolean addIfAbsent(Layer element) {
        boolean added = super.addIfAbsent(element);
        if (added) {
            if (layerListener != null) {
                element.addMapLayerListener(layerListener);
            }
            checkViewportCRS();
            fireLayerAdded(element, size() - 1, size() - 1);
        }
        return added;
    }

I would put a breakpoint in there and see if it is firing the event to the listeners. This should end up calling layerAdded in AbstractMapPane. This method should set the full extent and force a redraw.

If everything is working to there then the last place to look is in JMapPane.drawLayers() which is called with false for createNewImage and thus only clears the part of the map in view before it forces a redraw of all the layers at line 204. So I would put a final breakpoint there and check your new layer is in the mapContent.layers().

1
  • I edited my question. Commented Aug 4, 2017 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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