mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Markers dissappear when style is changed [Android]

Open andreinass opened this issue 10 years ago • 3 comments

Hello.

I have an Activity that shows mapbox map with some markers and a button that let user to change styles to Satellite or regular view . The markers are loaded from a web service that I paint once the map is loaded.Here's my code:

        mv.setStyle(Style.MAPBOX_STREETS);
        mv.setMyLocationEnabled(true);

        mv.setZoom(14);
        mv.setLatLng(locationCurrent);
        mv.onCreate(savedInstanceState);

 mv.addOnMapChangedListener(new MapView.OnMapChangedListener() {
            @Override
            public void onMapChanged(int change) {

                if (change == MapView.REGION_DID_CHANGE) {

                    LatLng current = mv.getLatLng();

                    if (current.distanceTo(locationCurrent) > 5000) {

//Method that calls web service and paint markers
                        performMapList();

                        locationCurrent = current;
                        Log.v("MAP", "current now is" + locationCurrent.getLatitude() + "/" + locationCurrent.getLongitude());
                    }
                }
            }
        });

Then I have an OnClick method that change this layout. According with the docs I understand that the only thing I need to do is to set the new style to mapView.

The weirdest thing happend when I change my style to MAPBOX_STREET , the markers dissappears.

This is what I do to change the style

@Override
    public void onClick(View v) {

        switch ( v.getId()){

            case R.id.mapMode:

                mv.setStyle(Style.MAPBOX_STREETS);

                break;

            case R.id.satMode:

                mv.setStyle(Style.SATELLITE_STREETS);

                break;
        }

        if(mv.getStyleUrl().equals(Style.MAPBOX_STREETS)){

            map.setTextColor(getResources().getColor(R.color.smartsea_blue_light));
            satellite.setTextColor(getResources().getColor(R.color.smartsea_gray_medium_profile));

        }else{

            map.setTextColor(getResources().getColor(R.color.smartsea_gray_medium_profile));
            satellite.setTextColor(getResources().getColor(R.color.smartsea_blue_light));
        }
    }

"map" and "satellite" are the buttons in layout that allows user to change map style. No matter what I do, markers don't appear in map with street view.

I'm attaching two screenshots, in one you can appreciate the marker, and the other one is gone.

screenshot_2016-02-17-17-03-34 screenshot_2016-02-17-17-03-38

Please help :( I guess this could be something silly but I can't figure out the problem.

Thanks

andreinass avatar Feb 17 '16 16:02 andreinass

I changed the Style to EMERALD and this doesn't happen anymore. I think there is an issue with Style MAPBOX_STREET

Regards

andreinass avatar Feb 18 '16 10:02 andreinass

@andreinass Thank you for reporting this issue and adding clear steps to reproduce with screenshots. Will look into this in the upcoming days.

tobrun avatar Feb 18 '16 10:02 tobrun

@andreinass

I have been trying to reproduce this issue locally but fail to do so, see this clip:

https://www.dropbox.com/s/nzlt3cperpvttz5/device-2016-03-01-142101.mp4?dl=0

The only thing that comes to mind now is there is a problem with the used image of that marker.

Would you be able to do a small test?

add the following:


  mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
                    @Override
                    public void onMapLongClick(@NonNull LatLng point) {
                        MarkerOptions marker = new MarkerOptions()
                                .position(point)
                                .title("Dropped Pin")
                                .icon(IconFactory.getInstance(MainActivity.this).fromResource());
                        mapboxMap.addMarker(marker);
                    }
                });

and afterwards switch styles?

tobrun avatar Mar 01 '16 13:03 tobrun