How can i clear all mapview items in Nutiteq?

174 views Asked by At

I'm developing a traffic application with using nutiteq map. There is over 500 traffic lines, lot of markers about traffic. I drew traffic lines with this way;

public void drawlines(){
    ArrayList<MapPos> arr_lat_long1 = new ArrayList<MapPos>();
    for(int i = 0; i < arr_lat_long1.size(); i ++){
        MapPos lineMapPos = new MapPos(arr_lat_long1.get(i).x,arr_lat_long1.get(i).y);
        arr_lat_long1.add(lineMapPos);
        geoLayer = new GeometryLayer(new EPSG4326());
        mapView.getLayers().addLayer(geoLayer);
        LineStyle lineStyle = null;
        lineStyle =LineStyle.builder().setWidth(0.14f).setColor(Color.RED).build();

        //Label label = new DefaultLabel("Line", "Here is a line");
        Line line = new Line(arr_lat_long1, null, lineStyle, null);
        line.setVertexList(arr_lat_long1);
        geoLayer.add(line);
        lines.add(line);

    }

and i add markers same way;

Bitmap pointMarker = UnscaledBitmapLoader.decodeResource(activity.getResources(), R.drawable.marker3);
        MarkerStyle markerStyle = MarkerStyle.builder().setBitmap(pointMarker).setSize(0.5f).setColor(Color.WHITE).build();

        Label markerLabel = new DefaultLabel("Here", "Blabla");
        MapPos markerLocation = MainActivity.mapLayer.getProjection().fromWgs84(log, lat);

        marker = new Marker(markerLocation, markerLabel, markerStyle, null);

        markerLayer.add(marker);
        MainActivity.mapView.getLayers().addLayer(markerLayer);

there is no problem for drawing. When i want to delete lines or markers, firstly deleted item but when i want to slide map, all items come back and shown on mapview. I'm deleting items iteratively. My deleting code is here:

for(int i = 0; i <lines.size(); i++){
                geoLayer.remove(lines.get(i));

                geoLayer.clear();

            }

and also i tried this again:

geoLayer.removeAll(lines);

How can i delete all my map items properly on Nutiteq?? Is there any way to clear or remove?

1

There are 1 answers

0
MarkT On

From the code above it seems you are creating a new layer for each line and you are 'forgetting' the references to these layers. Simply move geoLayer construction outside of the loop. For removing all the lines, you can call either geoLayer.clear() or geoLayer.removeAll(lines). Both should work. No need to use the for-cycle loop.