summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MarkerViewLayout.java
blob: 7f07f30ff9eb9a2c9dd1ccdc187a4b358f13c47a (plain)
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
package com.mapbox.mapboxsdk.maps.widgets;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class MarkerViewLayout extends FrameLayout {

    private MarkerViewManager markerViewManager;

    public MarkerViewLayout(Context context) {
        super(context);
        init();
    }

    public MarkerViewLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MarkerViewLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public MarkerViewLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        setChildrenDrawingOrderEnabled(true);
    }

    public void setMarkerViewManager(MarkerViewManager markerViewManager) {
        this.markerViewManager = markerViewManager;
    }

    @Override
    protected int getChildDrawingOrder(int childCount, int index) {
        if (markerViewManager != null) {
            HashMap<MarkerView,View> markerViewMap = markerViewManager.getMarkers();

            assert markerViewMap.keySet().size() == childCount;

            Iterator<MarkerView> iterator = markerViewMap.keySet().iterator();
            while (iterator.hasNext()) {
                MarkerView markerView = iterator.next();
                Log.v(MapboxConstants.TAG, "Z index markers" + markerView.getzIndex()+ "MarkerView get class "+markerView.getClass().getSimpleName());
            }
            Log.e(MapboxConstants.TAG, "-------------------------");
            TreeMap<MarkerView, View> sortedMarkerViewMap = new TreeMap<>(markerViewMap);
            Iterator<MarkerView> iteratorSorted = sortedMarkerViewMap.keySet().iterator();

            while (iteratorSorted.hasNext()) {
                MarkerView markerView = iteratorSorted.next();
                Log.v(MapboxConstants.TAG, "Z index markers" + markerView.getzIndex()+ "MarkerView get class "+markerView.getClass().getSimpleName());
            }

            Log.v(MapboxConstants.TAG, "getChildDrawingOrder: childcount  " + childCount + "- index " + "i");
            Log.v(MapboxConstants.TAG, "getChildDrawingOrder: childcount  " + markerViewManager.getMarkers() + "- index " + "i");

            // TODO insert correct index
            return index;
        }
        return index;
    }
}