Search in sources :

Example 1 with MapView

use of org.mapsforge.map.android.view.MapView in project satstat by mvglasow.

the class MapSectionFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) this.getContext();
    View rootView = inflater.inflate(R.layout.fragment_main_map, container, false);
    float density = this.getContext().getResources().getDisplayMetrics().density;
    String versionName;
    try {
        versionName = mainActivity.getPackageManager().getPackageInfo(mainActivity.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        versionName = "unknown";
    }
    mapReattach = (ImageButton) rootView.findViewById(R.id.mapReattach);
    mapAttribution = (TextView) rootView.findViewById(R.id.mapAttribution);
    mapReattach.setVisibility(View.GONE);
    isMapViewAttached = true;
    OnClickListener clis = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (v == mapReattach) {
                isMapViewAttached = true;
                mapReattach.setVisibility(View.GONE);
                updateMap();
            }
        }
    };
    mapReattach.setOnClickListener(clis);
    // Initialize controls
    mapMap = new MapView(rootView.getContext());
    ((FrameLayout) rootView).addView(mapMap, 0);
    mapMap.setClickable(true);
    mapMap.getMapScaleBar().setVisible(true);
    mapMap.getMapScaleBar().setMarginVertical((int) (density * 16));
    mapMap.setBuiltInZoomControls(true);
    mapMap.getMapZoomControls().setZoomLevelMin((byte) 10);
    mapMap.getMapZoomControls().setZoomLevelMax((byte) 20);
    mapMap.getMapZoomControls().setZoomControlsOrientation(Orientation.VERTICAL_IN_OUT);
    mapMap.getMapZoomControls().setZoomInResource(R.drawable.zoom_control_in);
    mapMap.getMapZoomControls().setZoomOutResource(R.drawable.zoom_control_out);
    mapMap.getMapZoomControls().setMarginHorizontal((int) (density * 8));
    mapMap.getMapZoomControls().setMarginVertical((int) (density * 16));
    providerLocations = new HashMap<String, Location>();
    mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(Const.LOCATION_PROVIDER_STYLES));
    providerStyles = new HashMap<String, String>();
    providerAppliedStyles = new HashMap<String, String>();
    providerInvalidationHandler = new Handler();
    providerInvalidators = new HashMap<String, Runnable>();
    onlineTileSource = new OnlineTileSource(Const.TILE_SERVER_OSM, 80);
    onlineTileSource.setUserAgent(String.format("%s/%s (%s)", "SatStat", versionName, System.getProperty("http.agent")));
    onlineTileSource.setName(Const.TILE_CACHE_OSM).setAlpha(false).setBaseUrl(Const.TILE_URL_OSM).setExtension(Const.TILE_EXTENSION_OSM).setParallelRequestsLimit(8).setProtocol("http").setTileSize(256).setZoomLevelMax((byte) 18).setZoomLevelMin((byte) 0);
    GestureDetector gd = new GestureDetector(rootView.getContext(), new GestureDetector.SimpleOnGestureListener() {

        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            mapReattach.setVisibility(View.VISIBLE);
            isMapViewAttached = false;
            return false;
        }
    });
    mapMap.setGestureDetector(gd);
    mainActivity.mapSectionFragment = this;
    float lat = mainActivity.mSharedPreferences.getFloat(Const.KEY_PREF_MAP_LAT, 360.0f);
    float lon = mainActivity.mSharedPreferences.getFloat(Const.KEY_PREF_MAP_LON, 360.0f);
    if ((lat < 360.0f) && (lon < 360.0f)) {
        mapMap.getModel().mapViewPosition.setCenter(new LatLong(lat, lon));
    }
    int zoom = mainActivity.mSharedPreferences.getInt(Const.KEY_PREF_MAP_ZOOM, 16);
    mapMap.getModel().mapViewPosition.setZoomLevel((byte) zoom);
    createLayers(true);
    return rootView;
}
Also used : OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) View(android.view.View) TextView(android.widget.TextView) MapView(org.mapsforge.map.android.view.MapView) Point(org.mapsforge.core.model.Point) Paint(org.mapsforge.core.graphics.Paint) MotionEvent(android.view.MotionEvent) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) MapView(org.mapsforge.map.android.view.MapView) LatLong(org.mapsforge.core.model.LatLong) Location(android.location.Location)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Location (android.location.Location)1 Handler (android.os.Handler)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 Paint (org.mapsforge.core.graphics.Paint)1 LatLong (org.mapsforge.core.model.LatLong)1 Point (org.mapsforge.core.model.Point)1 MapView (org.mapsforge.map.android.view.MapView)1 OnlineTileSource (org.mapsforge.map.layer.download.tilesource.OnlineTileSource)1