Programmatically updating LPolyline using v-leaflet-editable with an LMap

Hi,

I am trying to programmatically update a pre-defined polyline that the user has modified using v-leaflet-editable and then to allow the user to re-edit that polyline. My somewhat naive test code is shown below. The problem I have is that the behaviour is correct except that modification that is programmatically made to the polyline is not being noticed. I have looked at the demo code in the test branch but to no avail. Does anyone have any ideas or an example you can point me at?

TIA

Warwick

public class LeafletEditableMapComponent extends CustomComponent {

    private LMap lMap;
    private LEditable lPolylineEditable;
    private LEditableMap lEditableMap;
    private boolean polylineIsEditable = false;

    public LeafletEditableMapComponent() {

        lMap = new LMap();
        lMap.setCustomInitOption("editable", true);
        lMap.setHeight("300px");
        lMap.setCenter(0, 0);
        lMap.setZoomLevel(0);
        lMap.addLayer(new LTileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"));

        LPolyline lPolyline = new LPolyline(new Point(40, -10), new Point(70, 0), new Point(40, 10));
        lPolyline.setId("polyline1");
        lPolyline.setImmediate(true);
        lPolyline.addClickListener(new LeafletClickListener() {

            @Override
            public void onClick(LeafletClickEvent event) {
                if(!polylineIsEditable) {
                    lPolylineEditable = new LEditable(lPolyline);
                    lPolylineEditable.addFeatureModifiedListener(new FeatureModifiedListener() {

                        @Override
                        public void featureModified(FeatureModifiedEvent event) {
                            LPolyline lPolylineTmp = (LPolyline) event.getModifiedFeature();
                            Geometry geometry = lPolylineTmp.getGeometry();
                            LineString lineString = (LineString) geometry;
                            Coordinate coordinate = lineString.getCoordinateN(1);
                            coordinate.x = 0.0;
                            coordinate.y = 0.0;
                            lPolylineTmp.markAsDirty();
                            lMap.markAsDirty();
                            polylineIsEditable = false;
                        }
                    });
                    polylineIsEditable = true;
                }
            }
        });

        lMap.addComponents(lPolyline);
        // More stuff here

Got it working by replacing:

Coordinate coordinate = lineString.getCoordinateN(1); coordinate.x = 0.0; coordinate.y = 0.0; With:

                            Point[] points = lPolylineTmp.getPoints();
                            points[1]
.setLat(0.0);
                            points[1]
.setLon(0.0);

Hi,

Yep, editing the coordinates of JTS data type wont help. You’ll either have to set the points with V-Leaflet specific API or set a completely new JTS data type to the component.

cheers,
matti