Search in sources :

Example 1 with TilesOverlay

use of org.osmdroid.views.overlay.TilesOverlay in project collect by opendatakit.

the class MapHelper method showLayersDialog.

public void showLayersDialog(final Context context) {
    AlertDialog.Builder layerDialod = new AlertDialog.Builder(context);
    layerDialod.setTitle(context.getString(R.string.select_offline_layer));
    layerDialod.setSingleChoiceItems(offilineOverlays, selectedLayer, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            switch(item) {
                case 0:
                    if (googleMap != null) {
                        if (googleTileOverlay != null) {
                            googleTileOverlay.remove();
                        }
                    } else {
                        // OSM
                        if (osmTileOverlay != null) {
                            osmMap.getOverlays().remove(osmTileOverlay);
                            osmMap.invalidate();
                        }
                    }
                    selectedLayer = item;
                    break;
                default:
                    File[] spFiles = getFileFromSelectedItem(item);
                    if (spFiles.length == 0) {
                        break;
                    } else {
                        File spfile = spFiles[0];
                        if (isFileFormatSupported(spfile)) {
                            if (googleMap != null) {
                                try {
                                    // googleMap.clear();
                                    if (googleTileOverlay != null) {
                                        googleTileOverlay.remove();
                                    }
                                    TileOverlayOptions opts = new TileOverlayOptions();
                                    GoogleMapsMapBoxOfflineTileProvider provider = new GoogleMapsMapBoxOfflineTileProvider(spfile);
                                    opts.tileProvider(provider);
                                    googleTileOverlay = googleMap.addTileOverlay(opts);
                                } catch (Exception e) {
                                    break;
                                }
                            } else {
                                if (osmTileOverlay != null) {
                                    osmMap.getOverlays().remove(osmTileOverlay);
                                    osmMap.invalidate();
                                }
                                osmMap.invalidate();
                                OsmMBTileProvider mbprovider = new OsmMBTileProvider(iregisterReceiver, spfile);
                                osmTileOverlay = new TilesOverlay(mbprovider, context);
                                osmTileOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
                                osmMap.getOverlays().add(0, osmTileOverlay);
                                osmMap.invalidate();
                            }
                            selectedLayer = item;
                        } else {
                            ToastUtils.showLongToast(R.string.not_supported_offline_layer_format);
                        }
                    }
                    break;
            }
            dialog.dismiss();
        }
    });
    layerDialod.show();
}
Also used : AlertDialog(android.app.AlertDialog) TileOverlayOptions(com.google.android.gms.maps.model.TileOverlayOptions) DialogInterface(android.content.DialogInterface) TilesOverlay(org.osmdroid.views.overlay.TilesOverlay) File(java.io.File)

Example 2 with TilesOverlay

use of org.osmdroid.views.overlay.TilesOverlay in project android-sdk-examples by IndoorAtlas.

the class OpenStreetMapOverlay method onResume.

@Override
protected void onResume() {
    super.onResume();
    if (mOsmv == null) {
        mOsmv = new MapView(this);
        mOsmv.setTilesScaledToDpi(true);
        mOsmv.setBuiltInZoomControls(true);
        mOsmv.getController().setZoom(18);
        mProvider = new MapTileProviderBasic(getApplicationContext());
        mProvider.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
        mTilesOverlay = new TilesOverlay(mProvider, getBaseContext());
        mOsmv.getOverlays().add(mTilesOverlay);
        mLayout = new RelativeLayout(this);
        mLayout.addView(mOsmv, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        setContentView(mLayout);
    }
    // start receiving location updates & monitor region changes
    mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mListener);
    mIALocationManager.registerRegionListener(mRegionListener);
}
Also used : MapTileProviderBasic(org.osmdroid.tileprovider.MapTileProviderBasic) RelativeLayout(android.widget.RelativeLayout) MapView(org.osmdroid.views.MapView) TilesOverlay(org.osmdroid.views.overlay.TilesOverlay) LayoutParams(android.widget.RelativeLayout.LayoutParams)

Example 3 with TilesOverlay

use of org.osmdroid.views.overlay.TilesOverlay in project collect by opendatakit.

the class OsmDroidMapFragment method loadReferenceOverlay.

/**
 * Updates the map to reflect the value of referenceLayerFile.
 */
private void loadReferenceOverlay() {
    if (referenceOverlay != null) {
        map.getOverlays().remove(referenceOverlay);
        referenceOverlay = null;
    }
    if (referenceLayerFile != null) {
        OsmMBTileProvider mbprovider = new OsmMBTileProvider(this, referenceLayerFile);
        referenceOverlay = new TilesOverlay(mbprovider, getContext());
        referenceOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
        map.getOverlays().add(0, referenceOverlay);
    }
    map.invalidate();
}
Also used : TilesOverlay(org.osmdroid.views.overlay.TilesOverlay)

Aggregations

TilesOverlay (org.osmdroid.views.overlay.TilesOverlay)3 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 RelativeLayout (android.widget.RelativeLayout)1 LayoutParams (android.widget.RelativeLayout.LayoutParams)1 TileOverlayOptions (com.google.android.gms.maps.model.TileOverlayOptions)1 File (java.io.File)1 MapTileProviderBasic (org.osmdroid.tileprovider.MapTileProviderBasic)1 MapView (org.osmdroid.views.MapView)1