Java Code Examples for org.osmdroid.views.overlay.Overlay

The following are top voted examples for showing how to use org.osmdroid.views.overlay.Overlay. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: osmdroid   File: SampleJumboCache.java View source code 6 votes vote down vote up
@Override
protected void addOverlays() {
	super.addOverlays();

	Iterator<Overlay> iterator = mMapView.getOverlays().iterator();
	while(iterator.hasNext()){
		Overlay next = iterator.next();
		if (next instanceof TilesOverlay){
			TilesOverlay x = (TilesOverlay)next;
			x.setOvershootTileCache(x.getOvershootTileCache() * 2);
			Toast.makeText(getActivity(), "Tiles overlay cache set to " + x.getOvershootTileCache(), Toast.LENGTH_LONG).show();
			break;
		}
	}
	//this will set the disk cache size in MB to 1GB , 9GB trim size
	OpenStreetMapTileProviderConstants.setCacheSizes(1000L, 900L);
}
 
Example 2
Project: firetweet   File: OpenStreetMapViewerActivity.java View source code 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Uri uri = getIntent().getData();
    if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) {
        finish();
        return;
    }
    final double latitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN);
    final double longitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN);
    if (Double.isNaN(latitude) || Double.isNaN(longitude)) {
        finish();
        return;
    }
    mLatitude = latitude;
    mLongitude = longitude;
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    setContentView(R.layout.activity_osm_viewer);
    mMapView.setMultiTouchControls(true);
    mMapView.setBuiltInZoomControls(true);
    mMapView.setTilesScaledToDpi(true);
    final List<Overlay> overlays = mMapView.getOverlays();
    final GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
    final Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_marker, null);
    final Itemization markers = new Itemization(d, mMapView.getResourceProxy());
    final OverlayItem overlayitem = new OverlayItem("", "", gp);
    markers.addOverlay(overlayitem);
    overlays.add(markers);
    final IMapController mc = mMapView.getController();
    mc.setZoom(12);
    mc.setCenter(gp);
}
 
Example 3
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@Override
public void clear() {
    final List<Overlay> overlays = map.getOverlays();

    for (Iterator<Overlay> it = overlays.iterator(); it.hasNext();) {
        final Overlay overlay = it.next();
        if (overlay instanceof Marker
                || overlay instanceof Polygon
                || overlay instanceof GroundOverlay
                || overlay instanceof Polyline) {
            it.remove();
        }
    }
    map.invalidate();
}
 
Example 4
Project: AndroFotoFinder   File: LocationMapFragment.java View source code 6 votes vote down vote up
protected void definteOverlays(MapView mapView, DefaultResourceProxyImplEx resourceProxy) {
    final List<Overlay> overlays = mapView.getOverlays();

    this.mCurrrentSelectionMarker = createSelectedItemOverlay(resourceProxy);

    this.mSelectionMarker = getActivity().getResources().getDrawable(R.drawable.marker_blue);
    mFolderOverlaySummaryMarker = createFolderOverlay(overlays);

    mFolderOverlaySelectionMarker = createFolderOverlay(overlays);

    overlays.add(new GuestureOverlay(getActivity()));

    mapView.setMultiTouchControls(true);
}
 
Example 5
Project: invio   File: MapActivity.java View source code 6 votes vote down vote up
/**
 * Show or hide way overlay.
 * TODO: This method is buggy and still does not work properly, because the edges are still the same as in the first
 * loaded the same across all maps show later.
 *
 * @param enabled for enabling or disabling the way overlay
 */
private void setWayOverlayEnabled(final boolean enabled) {
    // If this overlay is added then the snapping-demonstration is activated:
    final Collection<Edge> edges = getWayManager().getEdges();
    showToast("Es wurden " + edges.size() + " Edges hinzugefĆ¼gt.");
    if (wayOverlay == null) {
        wayOverlay = new WayOverlay(this, getWayManager());
    }
    final List<Overlay> overlays = mapView.getOverlays();
    if (overlays.contains(wayOverlay)) {
        if (!enabled) {
            overlays.remove(wayOverlay);
        }
    } else {
        if (enabled) {
            overlays.add(wayOverlay);
        }
    }

    mapView.invalidate();
}
 
Example 6
Project: nantes-mobi-parkings   File: CustomMapView.java View source code 6 votes vote down vote up
@Override
public int compare(Overlay overlay, Overlay overlay1) {
	if (overlay instanceof EquipementsItemizedOverlay
			&& overlay1 instanceof EquipementsItemizedOverlay) {
		return 0;
	} else if (overlay instanceof EquipementsItemizedOverlay
			&& !(overlay1 instanceof EquipementsItemizedOverlay)) {
		return 1;
	} else {
		return -1;
	}
}
 
Example 7
Project: SmartNavi   File: GenericMapView.java View source code 6 votes vote down vote up
public void setTileProvider(MapTileProviderBase aTileProvider){
	if (mMapView != null){
		this.removeView(mMapView);
	}
	ResourceProxy resourceProxy = new DefaultResourceProxyImpl(this.getContext());
	MapView newMapView = new MapView(this.getContext(), aTileProvider.getTileSource().getTileSizePixels(), resourceProxy, aTileProvider);
	
	if (mMapView != null){
		//restore as much parameters as possible from previous map:
		IMapController mapController = newMapView.getController();
		mapController.setZoom(mMapView.getZoomLevel());
		mapController.setCenter(mMapView.getMapCenter());
		newMapView.setBuiltInZoomControls(true); //no way to get old setting
		newMapView.setMultiTouchControls(true); //no way to get old setting
		newMapView.setUseDataConnection(mMapView.useDataConnection());
		newMapView.setMapOrientation(mMapView.getMapOrientation());
		newMapView.setScrollableAreaLimit(mMapView.getScrollableAreaLimit());
		List<Overlay> overlays = mMapView.getOverlays();
		for (Overlay o:overlays)
			newMapView.getOverlays().add(o);
	}
	
	mMapView = newMapView;
	this.addView(mMapView);
}
 
Example 8
Project: TiOpenStreetMap   File: MapView.java View source code 6 votes vote down vote up
public void doUserLocation(boolean userLocation) {
	org.osmdroid.views.MapView mapView = getView();
	if (mapView != null) {
		if (userLocation) {
			if (myLocation == null) {
				//myLocation = new MyLocationOverlay(proxy.getContext(), mapView);
				return;
			}

			List<Overlay> overlays = mapView.getOverlays();
			synchronized(overlays) {
				if (!overlays.contains(myLocation)) {
					overlays.add(myLocation);
				}
			}

			myLocation.enableMyLocation();

		} else {
			if (myLocation != null) {
				List<Overlay> overlays = mapView.getOverlays();
				synchronized(overlays) {
					if (overlays.contains(myLocation)) {
						overlays.remove(myLocation);
					}
					myLocation.disableMyLocation();
				}
			}
		}
	}
}
 
Example 9
Project: twittnuker   File: OpenStreetMapViewerFragment.java View source code 6 votes vote down vote up
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);
    final Bundle args = getArguments();
    final double latitude = args.getDouble(EXTRA_LATITUDE, Double.NaN);
    final double longitude = args.getDouble(EXTRA_LONGITUDE, Double.NaN);
    if (Double.isNaN(latitude) || Double.isNaN(longitude)) {
        getActivity().finish();
        return;
    }
    mLatitude = latitude;
    mLongitude = longitude;
    mMapView.setMultiTouchControls(true);
    mMapView.setBuiltInZoomControls(true);
    mMapView.setTilesScaledToDpi(true);
    final List<Overlay> overlays = mMapView.getOverlays();
    final GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
    final Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_marker, null);
    final Itemization markers = new Itemization(d, mMapView.getResourceProxy());
    final OverlayItem overlayitem = new OverlayItem("", "", gp);
    markers.addOverlay(overlayitem);
    overlays.add(markers);
    final IMapController mc = mMapView.getController();
    mc.setZoom(12);
    mc.setCenter(gp);
}
 
Example 10
Project: OpenSourceProject   File: OsmLoggerMap.java View source code 6 votes vote down vote up
/**
 * Called when the activity is first created.
 */
@Override
protected void onCreate(Bundle load)
{
   super.onCreate(load);
   setContentView(R.layout.map_osm);
   
   mMapView = (MapView) findViewById(R.id.myMapView);
   TextView[] speeds = { (TextView) findViewById(R.id.speedview05), (TextView) findViewById(R.id.speedview04), (TextView) findViewById(R.id.speedview03),
         (TextView) findViewById(R.id.speedview02), (TextView) findViewById(R.id.speedview01), (TextView) findViewById(R.id.speedview00) };
   mSpeedtexts = speeds;
   mLastGPSSpeedView = (TextView) findViewById(R.id.currentSpeed);
   mLastGPSAltitudeView = (TextView) findViewById(R.id.currentAltitude);
   mDistanceView = (TextView) findViewById(R.id.currentDistance);

   mHelper = new LoggerMapHelper(this);
   mMapView.setBuiltInZoomControls(true);
   mProjecton = mMapView.getProjection();
   mHelper.onCreate(load);
   
   mMylocation = new MyLocationOverlay(this, mMapView);
   mMapView.getOverlays().add( new Overlay(this)
   {
      
      @Override
      protected void draw(Canvas arg0, MapView map, boolean arg2)
      {
         Projection projecton = map.getProjection();
         mProjecton = projecton;
         IGeoPoint gepoint = map.getMapCenter();
         Point point = projecton.toPixels(gepoint, null);
         Log.d(TAG, "Found center ("+gepoint.getLatitudeE6()+","+gepoint.getLongitudeE6()+") matching screen point ("+point.x+","+point.y+") ");
      }
   } );
}
 
Example 11
Project: osmbonuspack   File: MapActivity.java View source code 6 votes vote down vote up
public void updateUIWithPolygon(ArrayList<GeoPoint> polygon, String name){
	List<Overlay> mapOverlays = map.getOverlays();
	int location = -1;
	if (mDestinationPolygon != null)
		location = mapOverlays.indexOf(mDestinationPolygon);
	mDestinationPolygon = new Polygon(this);
	mDestinationPolygon.setFillColor(0x15FF0080);
	mDestinationPolygon.setStrokeColor(0x800000FF);
	mDestinationPolygon.setStrokeWidth(5.0f);
	mDestinationPolygon.setTitle(name);
	BoundingBoxE6 bb = null;
	if (polygon != null){
		mDestinationPolygon.setPoints(polygon);
		bb = BoundingBoxE6.fromGeoPoints(polygon);
	}
	if (location != -1)
		mapOverlays.set(location, mDestinationPolygon);
	else
		mapOverlays.add(1, mDestinationPolygon); //insert just above the MapEventsOverlay. 
	setViewOn(bb);
	map.invalidate();
}
 
Example 12
Project: Pin-Fever-Android   File: Map.java View source code 6 votes vote down vote up
private void addMarker(GeoPoint point) {
    ArrayList<OverlayItem> overlaysItems = new ArrayList<OverlayItem>();
    overlaysItems.add(new OverlayItem("Marker", "Marker", point));
    DefaultResourceProxyImpl resourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
    ItemizedIconOverlay myLocationOverlay = new ItemizedIconOverlay<OverlayItem>(overlaysItems, null, resourceProxy);
    List<Overlay> overlays = mapView.getOverlays();
    overlays.add(myLocationOverlay);
    this.mapView.invalidate();
}
 
Example 13
Project: piraten_map_app   File: PirateMap.java View source code 6 votes vote down vote up
public void buildMap(PlakatOverlayItemFilter mFilter) {
  	final List<Overlay> overlays = mMapView.getOverlays();
overlays.clear();
  	
  	new PlakatLoadingTask(this).execute(mFilter);
  	
  	mMyPosOverlay = new CurrentPositionOverlay(PirateMap.this, mMapView);
  	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean returnToMyLocation = initialMoveToLocationPerformed ? prefs.getBoolean(SettingsActivity.KEY_RETURN_TO_MY_LOCATION, true) : true;
mMyPosOverlay.moveToMyPosition(this, returnToMyLocation );
initialMoveToLocationPerformed = true; // couldn't think of a better way :/
mMyPosOverlay.enable();
mMapView.invalidate();
  }
 
Example 14
Project: Data4All   File: MapPreviewActivity.java View source code 6 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.return_to_actual_Position:
        mapController.animateTo(MapUtil.getCenterFromOsmElement(element));
        break;
    case R.id.switch_maps:
        List<Overlay> list = new ArrayList<Overlay>();
        list.addAll(mapView.getOverlays());
        switchMaps();
        mapView.getOverlays().clear();
        mapView.getOverlays().addAll(list);
        mapView.postInvalidate();
        break;
    case R.id.okay:
        this.accept();
        break;
    case R.id.rect:
        this.startRectangularPreview((ImageButton) v);
        break;
    default:
        break;
    }
}
 
Example 15
Project: openmonitor-android-agent   File: OSMMaps.java View source code 5 votes vote down vote up
public MapView getView(Context context, double lat, double lon){
	final  MapView osmMapView = new MapView(context, 256);
	this.context = context;
	this.geoPoint = OSMMaps.getGeoPoint(lat, lon);
	this.resourceProxy = new DefaultResourceProxyImpl(context);
	Drawable drawable = context.getResources().getDrawable(R.drawable.dot);
	
	
	mapController = osmMapView.getController();
	osmMapView.setBuiltInZoomControls(true);
	osmMapView.setMultiTouchControls(true);
	mapController.setZoom(14);
	mapController.setCenter(this.geoPoint);  		
       osmMapView.invalidate();
       
       List<Overlay> overlayList = osmMapView.getOverlays();
       this.osmOverlay = new ItemizedIconOverlay<OverlayItem>(getOSMOverlayList(context),
               drawable, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                   @Override
                   public boolean onItemSingleTapUp(final int index,
                           final OverlayItem item) {
                   	AlertDialog.Builder dialog 
                   	= new AlertDialog.Builder(OSMMaps.this.context);
       		        dialog.setTitle(item.getTitle());
       		        dialog.setMessage(item.getSnippet());
       		        dialog.setPositiveButton("Okay", new OnClickListener() {    
       		            public void onClick(DialogInterface dialog, int which) {
       		                dialog.dismiss();
       		            }
       		        });
       		        dialog.show();
                       return true; 
                   }
                   @Override
                   public boolean onItemLongPress(final int index,
                           final OverlayItem item) {    
                   	AlertDialog.Builder dialog 
                   	= new AlertDialog.Builder(OSMMaps.this.context);
       		        dialog.setTitle(item.getTitle());
       		        dialog.setMessage(item.getSnippet());
       		        dialog.setPositiveButton("Okay", new OnClickListener() {    
       		            public void onClick(DialogInterface dialog, int which) {
       		                dialog.dismiss();
       		            }
       		        });
       		        dialog.show();
                   	return true;
                   }
               }, resourceProxy);
     
       overlayList.add(osmOverlay);
       osmMapView.invalidate();
	return osmMapView;
}
 
Example 16
Project: smartnavi   File: OsmMapActivity.java View source code 5 votes vote down vote up
@Override
protected void onPostExecute(Polyline roadOverlay) {
    FolderOverlay myMarkersFolder = new FolderOverlay(OsmMapActivity.this);
    AbstractList<Overlay> list = myMarkersFolder.getItems();
    list.add(roadOverlay);

    showRouteInfo(false);

    //Show Route Steps on the map
    Drawable nodeIcon = getResources().getDrawable(R.drawable.finish2);
    for (int i = 0; i < road.mNodes.size(); i++) {
        RoadNode node = road.mNodes.get(i);
        Marker nodeMarker = new Marker(map);
        nodeMarker.setPosition(node.mLocation);
        nodeMarker.setIcon(nodeIcon);
        nodeMarker.setTitle("Step " + i);
        nodeMarker.setSnippet(node.mInstructions);
        nodeMarker.setSubDescription(Road.getLengthDurationText(node.mLength, node.mDuration));
        Drawable icon = getResources().getDrawable(R.drawable.ic_continue);
        if (node.mManeuverType == 1) {
            icon = getResources().getDrawable(R.drawable.ic_continue);
        } else if (node.mManeuverType == 3) {
            icon = getResources().getDrawable(R.drawable.ic_slight_left);
        } else if (node.mManeuverType == 4 || node.mManeuverType == 5) {
            icon = getResources().getDrawable(R.drawable.ic_turn_left);
        } else if (node.mManeuverType == 6) {
            icon = getResources().getDrawable(R.drawable.ic_slight_right);
        } else if (node.mManeuverType == 7 || node.mManeuverType == 8) {
            icon = getResources().getDrawable(R.drawable.ic_turn_right);
        } else if (node.mManeuverType == 24 || node.mManeuverType == 25 || node.mManeuverType == 26) {
            icon = getResources().getDrawable(R.drawable.ic_arrived);
        }
        nodeMarker.setImage(icon);
        nodeMarker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker, MapView mapView) {
                marker.showInfoWindow();
                return true;
            }
        });

        //put into FolderOverlay list
        list.add(nodeMarker);
    }

    OverlayManager om = map.getOverlayManager();

    if (om.size() > 2) {
        om.remove(1);
        om.remove(1);
    } else {
        om.remove(1);
    }

    map.getOverlays().add(myMarkersFolder);
    setNewPositionMarker();
    map.invalidate();
}