OSMDROID displays multiple maps with polylines in Android

泄露秘密 提交于 2021-01-29 12:39:25

问题


I see multiple maps with polyline when I start my android application. How can I show only one map?

MainActivity:

public class MainActivity extends AppCompatActivity {

    MapView map;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context ctx = getApplicationContext();
        Configuration.getInstance().load(ctx,    PreferenceManager.getDefaultSharedPreferences(ctx));
        setContentView(R.layout.activity_main);



       map = findViewById(R.id.mapViewMain);
       map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
       map.setBuiltInZoomControls(true);
       map.setMultiTouchControls(true);

    }

    protected void onResume() {
        super.onResume();       
        map.onPause();  
    }

    protected void onPause() {
        super.onPause();
        map.onPause();
    }


}

Layout activity_main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <org.osmdroid.views.MapView
        android:id="@+id/mapViewMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

I want to see only one map on my device.


回答1:


I solved that with this:

MapView map = (MapView) findViewById(R.id.map);
map.setScrollableAreaLimitDouble(new BoundingBox(85, 180, -85, -180));
map.setMaxZoomLevel(20.0);
map.setMinZoomLevel(4.0);
map.setHorizontalMapRepetitionEnabled(false);
map.setVerticalMapRepetitionEnabled(false);
map.setScrollableAreaLimitLatitude(MapView.getTileSystem().getMaxLatitude(), MapView.getTileSystem().getMinLatitude(), 0);



回答2:


Your code is correct and you actually see only one map - meaning only on map component. The map is zoomed out too much and is smaller then the view. The osmdroid library solves this problem by repeating the map in the viewport. I don't think there is a way to turn this feature off.

You can solve the problem by setting some reasonable zoom level.

map.setZoomLevel(12)



回答3:


MapView map;
map.setHorizontalMapRepetitionEnabled(true);
map.setVerticalMapRepetitionEnabled(false);
map.setScrollableAreaLimitLatitude(MapView.getTileSystem().getMaxLatitude(), MapView.getTileSystem().getMinLatitude(), 0); 


来源:https://stackoverflow.com/questions/52212951/osmdroid-displays-multiple-maps-with-polylines-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!