Java Code Examples for org.osmdroid.bonuspack.overlays.Marker

The following are top voted examples for showing how to use org.osmdroid.bonuspack.overlays.Marker. 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: OPFMaps   File: ConvertUtils.java View source code 7 votes vote down vote up
@NonNull
public static Marker convertMarkerOptions(@NonNull final MapView map, @NonNull final OPFMarkerOptions options) {
    final OPFLatLng position = options.getPosition();
    if (position == null) {
        throw new IllegalArgumentException("no position in marker options");
    }

    final Marker marker = new Marker(map);
    marker.setPosition(new GeoPoint(position.getLat(), position.getLng()));
    marker.setAlpha(options.getAlpha());
    marker.setAnchor(options.getAnchorU(), options.getAnchorV());
    marker.setDraggable(options.isDraggable());
    marker.setFlat(options.isFlat());
    marker.setInfoWindowAnchor(options.getInfoWindowAnchorU(), options.getInfoWindowAnchorV());
    marker.setRotation(options.getRotation());
    marker.setSnippet(options.getSnippet());
    marker.setTitle(options.getTitle());
    marker.setEnabled(options.isVisible());

    final OPFBitmapDescriptor opfBitmapDescriptor = options.getIcon();
    if (opfBitmapDescriptor != null) {
        marker.setIcon(((BitmapDescriptor) options.getIcon()
                .getDelegate().getBitmapDescriptor()).createDrawable(map.getContext()));
    }

    return marker;
}
 
Example 2
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@NonNull
@Override
public OPFMarker addMarker(@NonNull final OPFMarkerOptions options) {
    final Marker marker = ConvertUtils.convertMarkerOptions(map, options);
    map.getOverlays().add(marker);
    map.invalidate();

    final OPFMarker opfMarker = new OPFMarker(new OsmdroidMarkerDelegate(map, marker));

    marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(final Marker marker, final MapView mapView) {
            initMarkerInfoWindows(marker, opfMarker);
            marker.showInfoWindow();
            mapView.getController().animateTo(marker.getPosition());

            if (opfOnMarkerClickListener != null) {
                opfOnMarkerClickListener.onMarkerClick(opfMarker);
            }
            return true;
        }
    });

    marker.setOnMarkerDragListener(new Marker.OnMarkerDragListener() {
        @Override
        public void onMarkerDrag(final Marker marker) {
            if (opfOnMarkerDragListener != null) {
                opfOnMarkerDragListener.onMarkerDrag(opfMarker);
            }
        }

        @Override
        public void onMarkerDragEnd(final Marker marker) {
            if (opfOnMarkerDragListener != null) {
                opfOnMarkerDragListener.onMarkerDragEnd(opfMarker);
            }
        }

        @Override
        public void onMarkerDragStart(final Marker marker) {
            if (opfOnMarkerDragListener != null) {
                opfOnMarkerDragListener.onMarkerDragStart(opfMarker);
            }
        }
    });

    return opfMarker;
}
 
Example 3
Project: GeoChan   File: GetPOITask.java View source code 6 votes vote down vote up
/**
 * Initializes the instance of the task with the information needed to run it.
 * 
 * @param manager the ThreadManager
 * @param location the GeoLocation
 * @param dialog a ProgressDialog inside the fragment to display the task process
 * @param marker OSMDroid Marker overlay
 */
public void initGetPOITask(ThreadManager manager, GeoLocation location, ProgressDialog dialog, 
		Marker marker) {
	this.manager = manager;
	this.dialog= dialog;
	this.location = location;
	this.marker = marker;
}
 
Example 4
Project: SmartNavi   File: GridMarkerClusterer.java View source code 6 votes vote down vote up
/** Grid-based clustering algorithm */
@Override public ArrayList<StaticCluster> clusterer(MapView mapView){
	Rect mScreenRect = mapView.getIntrinsicScreenRect(null);
	
	BoundingBoxE6 bb = mapView.getBoundingBox();
	double latSpan = bb.getLatitudeSpanE6()*1E-6;
	double lonSpan = bb.getLongitudeSpanE6()*1E-6;
	//Log.d("ZOOM", "latSpan="+latSpan+"  lonSpan="+lonSpan);
	
	//convert grid size from pixels to degrees:
	double gridSizeX, gridSizeY;
	gridSizeX = lonSpan * (double)mGridSize / (double)(mScreenRect.right - mScreenRect.left);
	gridSizeY = latSpan * (double)mGridSize / (double)(mScreenRect.bottom - mScreenRect.top);
	
	int numCellsW = (int)(360.0f/gridSizeX);
	//Log.d("ZOOM", "zoomlevel="+mapView.getZoomLevel()+"  cells="+numCellsW);
	//Log.d("ZOOM", "gridSizeX="+gridSizeX+"  gridSizeY="+gridSizeY);
	
	ArrayList<StaticCluster> clusters = new ArrayList<StaticCluster>();
	LongSparseArray<StaticCluster> sparseArray = new LongSparseArray<StaticCluster>();
	for (Marker item:mItems){
		//TODO - add 180 Degree to prevent negative values
		long gridX = (long)(item.getPosition().getLongitude() / gridSizeX);
		long gridY = (long)(item.getPosition().getLatitude() / gridSizeY);
		long coord = numCellsW * gridX + gridY;
		StaticCluster cluster = sparseArray.get(coord);
		//Log.d("ZOOM", "coord="+coord+" =>cluster:"+(cluster==null?"new":"add"));
		if (cluster == null) {
			//GeoPoint clusterCorner = new GeoPoint(gridSizeY*(double)gridY, gridSizeX*(double)gridX);
               cluster = new StaticCluster(item.getPosition() /*clusterCorner*/);
               sparseArray.put(coord, cluster);
               clusters.add(cluster);
		}
           cluster.add(item);
	}
	return clusters;
}
 
Example 5
Project: SmartNavi   File: GridMarkerClusterer.java View source code 6 votes vote down vote up
/** Build the marker for a cluster. 
 * Uses the cluster icon, and displays inside the number of markers it contains. <br/>
 * In the standard Google coordinate system for Marker icons: <br/>
 * - The cluster icon is anchored at mAnchorU, mAnchorV. <br/>
 * - The text showing the number of markers is anchored at mTextAnchorU, mTextAnchorV. 
 * This text is centered horizontally and vertically. */
@Override public Marker buildClusterMarker(StaticCluster cluster, MapView mapView){
	Marker m = new Marker(mapView);
	m.setPosition(cluster.getPosition());
	m.setInfoWindow(null);
	m.setAnchor(mAnchorU, mAnchorV);
	Bitmap finalIcon = Bitmap.createBitmap(mClusterIcon.getWidth(), mClusterIcon.getHeight(), mClusterIcon.getConfig());
	Canvas iconCanvas = new Canvas(finalIcon);
	iconCanvas.drawBitmap(mClusterIcon, 0, 0, null);
	String text = ""+cluster.getSize();
    int textHeight = (int) (mTextPaint.descent() + mTextPaint.ascent());
	iconCanvas.drawText(text, 
			mTextAnchorU*finalIcon.getWidth(), 
			mTextAnchorV*finalIcon.getHeight() - textHeight/2, 
			mTextPaint);
	m.setIcon(new BitmapDrawable(mapView.getContext().getResources(), finalIcon));
	return m;
}
 
Example 6
Project: Android-IMSI-Catcher-Detector   File: CellTowerMarker.java View source code 6 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker, MapView mapView) {
    CellTowerMarker cellTowerMarker = (CellTowerMarker) marker;
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setTitle(cellTowerMarker.getTitle());
    dialog.setView(getInfoContents(cellTowerMarker.getMarkerData()));
    dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    dialog.show();

    return true;
}
 
Example 7
Project: Mapsforge-OsmDroid-GraphHopper   File: NewPoiInfoWindow.java View source code 6 votes vote down vote up
public NewPoiInfoWindow(int layoutResId, final MFMapView mapView, Marker marker) {
    super(layoutResId, mapView);

    this.marker = marker;


    mView.setOnTouchListener(new View.OnTouchListener() {
        @Override public boolean onTouch(View v, MotionEvent e) {
            //default behavior: close it when clicking on the bubble:
            //if (e.getAction() == MotionEvent.ACTION_UP)
            //	close();
            mView.findViewById(R.id.title_textedit).clearFocus();
            EditText desc_textedit = (EditText)mView.findViewById(R.id.desc_textedit);
            InputMethodManager imm = (InputMethodManager)mapView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(desc_textedit.getWindowToken(), 0);
            return true;
        }
    });
}
 
Example 8
Project: Mapsforge-OsmDroid-GraphHopper   File: CurrentPosInfoWindow.java View source code 6 votes vote down vote up
public CurrentPosInfoWindow(int layoutResId, final MapView mapView, Marker marker, Location location) {
	super(layoutResId, mapView);

	this.marker = marker;
	this.location = location;


	mView.setOnTouchListener(new View.OnTouchListener() {
		@Override public boolean onTouch(View v, MotionEvent e) {
			//default behavior: close it when clicking on the bubble:
			if (e.getAction() == MotionEvent.ACTION_UP)
				close();
			
			return true;
		}
	});
}
 
Example 9
Project: osmbonuspack   File: MapActivity.java View source code 6 votes vote down vote up
@Override protected void onActivityResult (int requestCode, int resultCode, Intent intent) {
	switch (requestCode) {
	case ROUTE_REQUEST : 
		if (resultCode == RESULT_OK) {
			int nodeId = intent.getIntExtra("NODE_ID", 0);
			map.getController().setCenter(mRoads[mSelectedRoad].mNodes.get(nodeId).mLocation);
			Marker roadMarker = (Marker)mRoadNodeMarkers.getItems().get(nodeId);
			roadMarker.showInfoWindow();
		}
		break;
	case POIS_REQUEST:
		if (resultCode == RESULT_OK) {
			int id = intent.getIntExtra("ID", 0);
			map.getController().setCenter(mPOIs.get(id).mLocation);
			Marker poiMarker = mPoiMarkers.getItem(id);
			poiMarker.showInfoWindow();
		}
		break;
	case KmlTreeActivity.KML_TREE_REQUEST:
		mKmlStack.pop();
		updateUIWithKml();
		if (intent == null)
			break;
		KmlFeature selectedFeature = intent.getParcelableExtra("KML_FEATURE");
		if (selectedFeature == null)
			break;
		BoundingBoxE6 bb = selectedFeature.getBoundingBox();
		if (bb == null)
			break;
		map.zoomToBoundingBox(bb);
		break;
	case KmlStylesActivity.KML_STYLES_REQUEST:
		updateUIWithKml();
		break;
	default: 
		break;
	}
}
 
Example 10
Project: osmbonuspack   File: MapActivity.java View source code 6 votes vote down vote up
@Override public void onMarkerDragEnd(Marker marker) {
	int index = (Integer)marker.getRelatedObject();
	if (index == START_INDEX)
		startPoint = marker.getPosition();
	else if (index == DEST_INDEX)
		destinationPoint = marker.getPosition();
	else 
		viaPoints.set(index, marker.getPosition());
	//update location:
	new ReverseGeocodingTask().execute(marker);
	//update route:
	getRoadAsync();
}
 
Example 11
Project: OpenBikeSharing   File: MapActivity.java View source code 6 votes vote down vote up
private Marker createStationMarker(Station station) {
    GeoPoint stationLocation = new GeoPoint((int) (station.getLatitude() * 1000000),
            (int) (station.getLongitude() * 1000000));
    Marker marker = new Marker(map);
    marker.setRelatedObject(station);
    marker.setInfoWindow(stationMarkerInfoWindow);
    marker.setPosition(stationLocation);
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER);
    marker.setTitle(station.getName());
    marker.setSnippet(String.valueOf(station.getFreeBikes())); // free bikes
    if (station.getEmptySlots() != -1) {
        marker.setSubDescription(String.valueOf(station.getEmptySlots())); // empty slots
    }

    /* Marker icon */
    int emptySlots = station.getEmptySlots();
    int freeBikes = station.getFreeBikes();

    if ((emptySlots == 0 && freeBikes == 0) || station.getStatus() == StationStatus.CLOSED) {
        marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker_unavailable));
    } else {
        double ratio = (double) freeBikes / (double) (freeBikes + emptySlots);
        if (freeBikes == 0) {
            marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker0));
        } else if (freeBikes >= 1 && ratio <= 0.3) {
            marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker25));
        } else if (ratio > 0.3 && ratio < 0.7) {
            marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker50));
        } else if (ratio >= 0.7 && emptySlots >= 1) {
            marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker75));
        } else if (emptySlots == 0 || emptySlots == -1) {
            marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker100));
        }
    }

    return marker;
}
 
Example 12
Project: OpenBikeSharing   File: MapActivity.java View source code 6 votes vote down vote up
@Override
public void onOpen(Object item) {
    Marker marker = (Marker) item;
    final Station markerStation = (Station) marker.getRelatedObject();
    super.onOpen(item);
    closeAllInfoWindowsOn(map);

    LinearLayout layout = (LinearLayout) getView().findViewById(R.id.map_bubble_layout);
    if (markerStation.getEmptySlots() == -1) {
        ImageView emptySlotsLogo = (ImageView) getView().findViewById(R.id.bubble_emptyslots_logo);
        emptySlotsLogo.setVisibility(View.GONE);
    }
    layout.setClickable(true);
    layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MapActivity.this, StationActivity.class);
            intent.putExtra("station", markerStation);
            startActivity(intent);
        }
    });
}
 
Example 13
Project: Data4All   File: MapPreviewActivity.java View source code 6 votes vote down vote up
private void setUpOverlays() {
    if (getIntent().hasExtra("LOCATION")) {
        final Location l = (Location) getIntent().getParcelableExtra(
                "LOCATION");
        final Marker m = new Marker(mapView);
        m.setPosition(new GeoPoint(l));
        m.setIcon(new DefaultResourceProxyImpl(this)
                .getDrawable(ResourceProxy.bitmap.person));
        m.setInfoWindow(null);
        mapView.getOverlays().add(m);
    }
    final DataBaseHandler db = new DataBaseHandler(this);
    final List<DataElement> list = db.getAllDataElements();
    list.remove(element);
    mapView.addOsmElementsToMap(this, list);
    db.close();
    mapView.addOsmElementToMap(this, element, true);
}
 
Example 14
Project: Data4All   File: MapMarker.java View source code 6 votes vote down vote up
@Override
protected boolean onMarkerClickDefault(Marker marker, MapView mapView) {
    if (!editable) {
        marker.showInfoWindow();
        mapView.getController().animateTo(marker.getPosition());
        return true;
    } else {
        return super.onMarkerClickDefault(marker, mapView);
    }
}
 
Example 15
Project: wikijourney_app   File: CustomInfoWindow.java View source code 6 votes vote down vote up
@Override
public void onOpen(Object item){
    super.onOpen(item);
    // The button is in the bubble, but hidden; we need to make it visible
    mView.findViewById(R.id.bubble_moreinfo).setVisibility(View.VISIBLE);

    // When the Marker is tapped, get the related POI, so the Listener set before works
    Marker marker = (Marker)item;
    mSelectedPoi = (POI)marker.getRelatedObject();
}
 
Example 16
Project: wikijourney_app   File: Map.java View source code 6 votes vote down vote up
/**
 * Displays on the map the POIs found by the WikiJourney API.<br/>
 * They are represented by a marker, with an info bubble containing the name of the page, its URL,
 * and a "More info" arrow button, which opens the default browser to the Wikipedia page.
 * @param pMapFragment The Fragment containing the MapView
 * @param pPoiArrayList The ArrayList of POIs, once it has been handled by the parseApiJson method
 */
public static void drawPOI(MapFragment pMapFragment, ArrayList<POI> pPoiArrayList) {
    MapView mMap = null;
    try {
        mMap = (MapView) pMapFragment.getActivity().findViewById(R.id.map);
    } catch (Exception e) {
        // If we cannot find the MapView (the Fragment was destroyed), abort.
        return;
    }
    Context mContext = pMapFragment.getActivity();

    // We create an Overlay Folder to store every POI, so that they are grouped in clusters
    // if there are too many of them
    final RadiusMarkerClusterer poiMarkers = new RadiusMarkerClusterer(mContext);
    Drawable mClusterIconDrawable = ContextCompat.getDrawable(mContext, R.drawable.marker_cluster);
    Bitmap mClusterIcon = ((BitmapDrawable)mClusterIconDrawable).getBitmap();
    poiMarkers.setIcon(mClusterIcon);
    mMap.getOverlays().add(poiMarkers);

    // We create only one info window and one marker icon, and we will set it for each Marker
    CustomInfoWindow mCustomInfoWindow = new CustomInfoWindow(mMap);
    Drawable mMarkerIcon = ContextCompat.getDrawable(mContext, R.drawable.ic_place);

    // We add each POI to the Overlay Folder, with a custom icon, and the description bubble
    for (POI poi:pPoiArrayList) {
        double mLat = poi.getLatitude();
        double mLong = poi.getLongitude();
        GeoPoint poiWaypoint = new GeoPoint(mLat, mLong);

        Marker marker = new Marker(mMap);
        marker.setPosition(poiWaypoint);
        marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        marker.setRelatedObject(poi); // This stores the POI related to each Marker, and allows to get it back in CustomInfoWindow.java
        marker.setInfoWindow(mCustomInfoWindow); // The CustomInfoWindow, with the More Info arrow
        marker.setTitle(poi.getName());
        marker.setSnippet(poi.getSitelink());
        marker.setIcon(mMarkerIcon);
        poiMarkers.add(marker);
    }
    mMap.invalidate();
}
 
Example 17
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();
}