Exemple #1
0
 public void initialmap() {
   mapview = (MapView) this.findViewById(R.id.mapview);
   mapview.setTileSource(TileSourceFactory.MAPQUESTOSM);
   mapview.setBuiltInZoomControls(true);
   mapview.setMultiTouchControls(true);
   mcontrol = (MapController) this.mapview.getController();
   mcontrol.setZoom(15);
 }
  private void config() {
    mMap.setTileSource(TileSourceFactory.MAPQUESTOSM);
    mMap.setMultiTouchControls(true);
    mMap.setBuiltInZoomControls(true);

    mController = mMap.getController();
    mController.setZoom(18);

    mTreasureMapTileSource =
        new XYTileSource(
            "mbtiles",
            ResourceProxy.string.offline_mode,
            1,
            20,
            256,
            ".png",
            "http://appquest.hsr.ch/hsr.mbtiles");

    try {
      setOfflineMap("hsr.mbtiles");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    ResourceProxy resourceProxy = new DefaultResourceProxyImpl(mContext);
    Drawable drawableMarker = mContext.getResources().getDrawable(R.drawable.marker);
    int markerWidth = drawableMarker.getIntrinsicWidth();
    int markerHeight = drawableMarker.getIntrinsicHeight();
    drawableMarker.setBounds(0, markerHeight, markerWidth, 0);

    mMarkerOverlay = new MarkerOverlay(drawableMarker, resourceProxy);

    mMap.getOverlays().add(mMarkerOverlay);

    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.commit();

    List<GeoPoint> points = new ArrayList<GeoPoint>();

    try {
      String mapPointsString = sharedPreferences.getString(MAP_POINTS, "");

      JSONObject mapPointsJson = new JSONObject(mapPointsString);
      JSONArray array = mapPointsJson.getJSONArray("points");

      for (int i = 0; i < array.length(); i++) {
        JSONObject mapPoint = array.getJSONObject(i);
        points.add(new GeoPoint(mapPoint.getDouble("lat"), mapPoint.getDouble("lon")));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    for (GeoPoint point : points) {
      addMarker(point);
    }
  }
  @NonNull
  private MapView setupDefaultMapView() {
    final MapView mapView =
        new MapView(
            getContext(),
            getTileSize(),
            new DefaultResourceProxyImpl(getContext().getApplicationContext()));
    mapView.setTileSource(TileSourceFactory.MAPNIK);

    return mapView;
  }
Exemple #4
0
  public void setBasemap() {
    if (mGoogleMap != null) {
      String basemap = _getGoogleBasemap();
      if (basemap.equals(GOOGLE_MAP_STREETS)) {
        mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      } else if (basemap.equals(GOOGLE_MAP_SATELLITE)) {
        mGoogleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
      } else if (basemap.equals(GOOGLE_MAP_TERRAIN)) {
        mGoogleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
      } else if (basemap.equals(GOOGLE_MAP_HYBRID)) {
        mGoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
      } else {
        mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      }
    } else {
      // OSMMAP
      String basemap = _getOsmBasemap();

      ITileSource tileSource = null;

      switch (basemap) {
        case OPENMAP_USGS_TOPO:
          tileSource = tileFactory.getUSGSTopo();
          break;

        case OPENMAP_USGS_SAT:
          tileSource = tileFactory.getUsgsSat();
          break;

        case OPENMAP_STAMEN_TERRAIN:
          tileSource = tileFactory.getStamenTerrain();
          break;

        case OPENMAP_CARTODB_POSITRON:
          tileSource = tileFactory.getCartoDbPositron();
          break;

        case OPENMAP_CARTODB_DARKMATTER:
          tileSource = tileFactory.getCartoDbDarkMatter();
          break;

        case OPENMAP_STREETS:
        default:
          tileSource = TileSourceFactory.MAPNIK;
          break;
      }

      if (tileSource != null) {
        mOsmMap.setTileSource(tileSource);
      }
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.fragment_osm_map, container, false);
    map = (MapView) layout.findViewById(R.id.osmmap);
    map.setTileSource(TileSourceFactory.MAPNIK);
    // map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    // Default location and zoom level
    IMapController mapController = map.getController();
    mapController.setZoom(12);
    GeoPoint startPoint = new GeoPoint(37.4333, 127.1500);
    mapController.setCenter(startPoint);
    // MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(getActivity(), new
    // GpsMyLocationProvider(getActivity()),map);
    // map.getOverlays().add(mLocationOverlay);

    Marker startMarker = new Marker(map);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    map.getOverlays().add(startMarker);

    RoadManager roadManager = new OSRMRoadManager(getActivity());
    waypoints = new ArrayList<GeoPoint>();
    waypoints.add(startPoint);
    GeoPoint endPoint = new GeoPoint(37.4314, 127.1297);
    waypoints.add(endPoint);

    Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    myLocationOverlay = new DirectedLocationOverlay(getActivity());
    map.getOverlays().add(myLocationOverlay);
    myLocationOverlay.setLocation(new GeoPoint(location));
    map.invalidate();

    handler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            GeoPoint geo = (GeoPoint) msg.obj;
            map.getController().animateTo(geo);
            map.invalidate();
          }
        };

    return layout;
  }
  @Override
  public boolean onOptionsItemSelected(
      final MenuItem pItem, final int pMenuIdOffset, final MapView pMapView) {

    final int menuId = pItem.getItemId() - pMenuIdOffset;
    if ((menuId >= MENU_TILE_SOURCE_STARTING_ID)
        && (menuId < MENU_TILE_SOURCE_STARTING_ID + TileSourceFactory.getTileSources().size())) {
      pMapView.setTileSource(
          TileSourceFactory.getTileSources().get(menuId - MENU_TILE_SOURCE_STARTING_ID));
      return true;
    } else if (menuId == MENU_OFFLINE) {
      final boolean useDataConnection = !pMapView.useDataConnection();
      pMapView.setUseDataConnection(useDataConnection);
      return true;
    } else {
      return false;
    }
  }
Exemple #7
0
  @Override
  public void onStart() {
    super.onStart();
    Log.d(TAG, "onStart():  ");

    mapView = (MapView) getView().findViewById(R.id.mapView);

    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setUseDataConnection(true);
    mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

    IMapController mapViewController = mapView.getController();
    mapViewController.setZoom(15);
    mapViewController.setCenter(new GeoPoint(54.7866382, 9.4350427));

    onUpDate();
  }
Exemple #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    MapView map = (MapView) findViewById(R.id.activityGame_MapView_map);
    map.setTileSource(TileSourceFactory.MAPNIK);
    //        map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    IMapController mapController = map.getController();
    mapController.setZoom(20);
    mapController.setCenter(new GeoPoint(54.318684, 48.403570));

    RotationGestureOverlay rotationGestureOverlay = new RotationGestureOverlay(this, map);
    rotationGestureOverlay.setEnabled(true);
    map.setMultiTouchControls(true);
    map.getOverlays().add(rotationGestureOverlay);
  }
  // You should not need to touch this method
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mapView == null) {
      mapView = new MapView(getActivity(), null);

      mapView.setTileSource(TileSourceFactory.MAPNIK);
      mapView.setClickable(true);
      mapView.setBuiltInZoomControls(true);
      mapView.setMultiTouchControls(true);

      mapController = mapView.getController();
      mapController.setZoom(mapView.getMaxZoomLevel() - 2);
      mapController.setCenter(UBC_MARTHA_PIPER_FOUNTAIN);
    }

    return mapView;
  }
  @Override
  public boolean onMenuItemSelected(final int featureId, final MenuItem item) {
    switch (item.getItemId()) {
      case MENU_ZOOMIN_ID:
        this.mOsmvController.zoomIn();
        return true;

      case MENU_ZOOMOUT_ID:
        this.mOsmvController.zoomOut();
        return true;

      case MENU_TILE_SOURCE_ID:
        this.mOsmv.invalidate();
        return true;

      case MENU_MINIMAP_ID:
        mMiniMapOverlay.setEnabled(!mMiniMapOverlay.isEnabled());
        this.mOsmv.invalidate();
        return true;

      case MENU_ANIMATION_ID:
        // this.mOsmv.getController().animateTo(52370816, 9735936,
        // MapControllerOld.AnimationType.MIDDLEPEAKSPEED,
        // MapControllerOld.ANIMATION_SMOOTHNESS_HIGH,
        // MapControllerOld.ANIMATION_DURATION_DEFAULT); // Hannover
        // Stop the Animation after 500ms (just to show that it works)
        // new Handler().postDelayed(new Runnable(){
        // @Override
        // public void run() {
        // SampleExtensive.this.mOsmv.getController().stopAnimation(false);
        // }
        // }, 500);
        return true;

      default:
        ITileSource tileSource = TileSourceFactory.getTileSource(item.getItemId() - 1000);
        mOsmv.setTileSource(tileSource);
        mMiniMapOverlay.setTileSource(tileSource);
    }
    return false;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_osm);
    MyLocationNewOverlay mLocationOverlay;

    MapView map = (MapView) findViewById(R.id.map);
    map.setTileSource(TileSourceFactory.MAPNIK);

    IMapController mapController = map.getController();
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    mapController.setZoom(18);
    GeoPoint startPoint = new GeoPoint(41.10867, 16.87886);
    mapController.setCenter(startPoint);

    mLocationOverlay =
        new MyLocationNewOverlay(
            getApplicationContext(), new GpsMyLocationProvider(getApplicationContext()), map);
    map.getOverlays().add(mLocationOverlay);
  }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    // File file = new File(getFilesDir() + "/osmdroid/tiles/" + "tiles.zip");

    File folder =
        new File(
            Environment.getExternalStorageDirectory().toString() + "/osmdroid/tiles/MapquestOSM");

    if (folder.exists()) {
      Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icono);

      mapView = (MapView) findViewById(R.id.mapview);
      mapView.setTilesScaledToDpi(true);
      mapView.setTilesScaledToDpi(true);
      mapView.setClickable(true);
      mapView.setBuiltInZoomControls(true);
      mapView.setMultiTouchControls(true);
      mapView.setUseDataConnection(false);
      mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
      // mapView.setUseDataConnection(false);

      IMapController mapViewController = mapView.getController();
      mapViewController.setZoom(10);
      mapViewController.setCenter(ROSARIO);
      Marker startMarker = new Marker(mapView);
      LocationManager locationManager =
          (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
      GeoPoint currentLocation = new GeoPoint(location);

      if (location != null) {
        currentLocation = new GeoPoint(location.getLatitude(), location.getLongitude());
      }

      startMarker.setPosition(Fabrica);
      // startMarker.setPosition(new GeoPoint(-32.940380, -60.665102));
      startMarker.setPosition(currentLocation);
      /*int lat= 30;
              int lng=20;
              startMarker.setPosition(new GeoPoint(lat, lng));
      */
      startMarker.setIcon(getDrawable(R.drawable.icono));
      startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
      startMarker.setTitle("Fabrica");
      startMarker.setSnippet("chicos");
      mapView.getOverlays().add(startMarker);
    } else {
      new CopyData().execute();
    }
    /*String FILENAME = "hello_file";
    String string = "hello world!";
    File mydir = this.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;*/
    /*   try {
        FileOutputStream fos = new FileOutputStream(myInternalFile);
        fos.write(myInputText.getText().toString().getBytes());
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }*/
    /*  File wallpaperDirectory = new File("/sdcard/");
    File folder = new File(Environment.getExternalStorageDirectory().toString()+"/sdcard/");
    folder.mkdirs();*/
    /*String filename = "prueba";
            String string = "dsdfsd";
            FileOutputStream outputStream;
            File wallpaperDirectory = new File("/sdcard2/");
            File folder = new File(Environment.getExternalStorageDirectory().toString()+"/sdcard2/");
            folder.mkdirs();
            //Save the path as a string value
            String extStorageDirectory = folder.toString();
    try{
            //File file = new File(extStorageDirectory, "demo.txt");
        File file = new File(extStorageDirectory, "demo.txt");
            FileOutputStream outStream = new FileOutputStream(file);
             outStream.write(string.getBytes());

                outStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }*/

    /* try {
        File wallpaperDirectory = new File("/sdcard2/");
        File folder = new File(Environment.getExternalStorageDirectory().toString()+"/osmdroid/");
        folder.mkdirs();
        AssetManager assetManager = getAssets();
        InputStream inputStream = null;

        InputStream in = assetManager.open("/tiles-example/tiles.zip");

        AssetFileDescriptor descriptor = assetManager.openFd("/tiles-example/tiles.zip");
        File outFile = new File(folder, String.valueOf(descriptor));

        FileOutputStream outStream = new FileOutputStream(String.valueOf(descriptor));
        outStream.write(outStream.getBytes());

    } catch (IOException e) {
        e.printStackTrace();
    }*/

    // Create New file and name it Image2.PNG
    // File file = new File(extStorageDirectory, "Image2.PNG");

    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icono);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setTilesScaledToDpi(true);
    mapView.setTilesScaledToDpi(true);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setUseDataConnection(true);
    mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

    IMapController mapViewController = mapView.getController();
    mapViewController.setZoom(10);
    mapViewController.setCenter(ROSARIO);
    Marker startMarker = new Marker(mapView);
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    GeoPoint currentLocation = new GeoPoint(location);

    if (location != null) {
      currentLocation = new GeoPoint(location.getLatitude(), location.getLongitude());
    }

    // startMarker.setPosition(Fabrica);
    // startMarker.setPosition(new GeoPoint(-32.940380, -60.665102));
    startMarker.setPosition(currentLocation);
    /*int lat= 30;
    int lng=20;
    startMarker.setPosition(new GeoPoint(lat, lng));*/

    startMarker.setIcon(getDrawable(R.drawable.icono));
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    startMarker.setTitle("Fabrica");
    startMarker.setSnippet("chicos");
    mapView.getOverlays().add(startMarker);
    /*  public void setTileSource(final ITileSource aTileSource) {
    mTileProvider.setTileSource(aTileSource);
    float density = getResources().getDisplayMetrics().density;
    TileSystem.setTileSize((int) (aTileSource.getTileSizePixels() * density));
    this.checkZoomButtons();
    this.setZoomLevel(mZoomLevel); // revalidate zoom level
    mapView.postInvalidate();*/
    /*ArrayList<OverlayItem> anotherOverlayItemArray;
    anotherOverlayItemArray = new ArrayList<OverlayItem>();

    anotherOverlayItemArray.add(new OverlayItem("0, 0", "0, 0", new GeoPoint(0, 0)));*/

    MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
    mapView.getOverlays().add(0, mapEventsOverlay);
  }