Search in sources :

Example 1 with MapListener

use of org.osmdroid.events.MapListener in project Telegram-FOSS by Telegram-FOSS-Team.

the class LocationActivity method onMapInit.

private void onMapInit() {
    if (mapView == null) {
        return;
    }
    // Paris, Tour Eiffel
    GeoPoint initLocation = new GeoPoint(48.85825, 2.29448);
    final IMapController controller = mapView.getController();
    mapView.setMaxZoomLevel(20.0);
    mapView.setMultiTouchControls(true);
    mapView.setBuiltInZoomControls(false);
    controller.setCenter(initLocation);
    controller.setZoom(7.);
    if (chatLocation != null) {
        LiveLocation liveLocation = addUserMarker(chatLocation);
        controller.setCenter(liveLocation.marker.getPosition());
        controller.setZoom(mapView.getMaxZoomLevel() - 2);
    } else if (messageObject != null) {
        if (messageObject.isLiveLocation()) {
            LiveLocation liveLocation = addUserMarker(messageObject.messageOwner);
            if (!getRecentLocations()) {
                controller.setCenter(liveLocation.marker.getPosition());
                controller.setZoom(mapView.getMaxZoomLevel() - 2);
            }
        } else {
            GeoPoint latLng = new GeoPoint(userLocation.getLatitude(), userLocation.getLongitude());
            Marker marker = new Marker(mapView);
            marker.setPosition(latLng);
            // InfoWindow workaround
            marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {

                @Override
                public boolean onMarkerClick(Marker marker, MapView mapView) {
                    return false;
                }
            });
            if (Build.VERSION.SDK_INT >= 21) {
                marker.setIcon(getParentActivity().getDrawable(R.drawable.map_pin));
            } else {
                marker.setIcon(getParentActivity().getResources().getDrawable(R.drawable.map_pin2));
            }
            marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
            mapView.getOverlays().add(marker);
            controller.setCenter(latLng);
            controller.setZoom(mapView.getMaxZoomLevel() - 2);
            firstFocus = false;
            getRecentLocations();
        }
    } else {
        userLocation = new Location("network");
        if (initialLocation != null) {
            GeoPoint latLng = new GeoPoint(initialLocation.geo_point.lat, initialLocation.geo_point._long);
            controller.setCenter(latLng);
            controller.setZoom(mapView.getMaxZoomLevel() - 2);
            userLocation.setLatitude(initialLocation.geo_point.lat);
            userLocation.setLongitude(initialLocation.geo_point._long);
            adapter.setCustomLocation(userLocation);
        } else {
            userLocation.setLatitude(48.85825);
            userLocation.setLongitude(2.29448);
        }
    }
    GpsMyLocationProvider imlp = new GpsMyLocationProvider(getParentActivity());
    imlp.setLocationUpdateMinDistance(10);
    imlp.setLocationUpdateMinTime(10000);
    imlp.addLocationSource(LocationManager.NETWORK_PROVIDER);
    myLocationOverlay = new MyLocationNewOverlay(imlp, mapView) {

        @Override
        public void onLocationChanged(final Location location, IMyLocationProvider source) {
            super.onLocationChanged(location, source);
            if (location != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {

                    @Override
                    public void run() {
                        positionMarker(location);
                        LocationController.getInstance(currentAccount).setGoogleMapLocation(location, isFirstLocation);
                        isFirstLocation = false;
                    }
                });
            }
        }
    };
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.setDrawAccuracyEnabled(true);
    // TODO
    mapView.addMapListener(new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent event) {
            showSearchPlacesButton(true);
            removeInfoView();
            if (!scrolling && (locationType == LOCATION_TYPE_SEND || locationType == LOCATION_TYPE_SEND_WITH_LIVE) && listView.getChildCount() > 0) {
                View view = listView.getChildAt(0);
                if (view != null) {
                    RecyclerView.ViewHolder holder = listView.findContainingViewHolder(view);
                    if (holder != null && holder.getAdapterPosition() == 0) {
                        int min = locationType == LOCATION_TYPE_SEND ? 0 : AndroidUtilities.dp(66);
                        int top = view.getTop();
                        if (top < -min) {
                            // TODO. Strange variable
                            forceUpdate = mapView.getMapCenter();
                            listView.smoothScrollBy(0, top + min);
                        }
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            return false;
        }
    });
    myLocationOverlay.runOnFirstFix(new Runnable() {

        public void run() {
            AndroidUtilities.runOnUIThread(new Runnable() {

                @Override
                public void run() {
                    positionMarker(myLocationOverlay.getLastFix());
                    getLocationController().getInstance(currentAccount).setGoogleMapLocation(myLocationOverlay.getLastFix(), isFirstLocation);
                    isFirstLocation = false;
                }
            });
        }
    });
    mapView.getOverlays().add(myLocationOverlay);
    mapView.addMapListener(new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent event) {
            if (overlayView != null) {
                overlayView.updatePositions();
            }
            return false;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            return false;
        }
    });
    positionMarker(myLocation = getLastLocation());
    attributionOverlay.bringToFront();
    if (checkGpsEnabled && getParentActivity() != null) {
        checkGpsEnabled = false;
        checkGpsEnabled();
    }
    if (proximityButton != null && proximityButton.getVisibility() == View.VISIBLE) {
        LocationController.SharingLocationInfo myInfo = getLocationController().getSharingLocationInfo(dialogId);
        if (myInfo != null && myInfo.proximityMeters > 0) {
            createCircle(myInfo.proximityMeters);
        }
    }
}
Also used : GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) LocationController(org.telegram.messenger.LocationController) Marker(org.osmdroid.views.overlay.Marker) ImageView(android.widget.ImageView) UndoView(org.telegram.ui.Components.UndoView) HintView(org.telegram.ui.Components.HintView) MapView(org.osmdroid.views.MapView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) BackupImageView(org.telegram.ui.Components.BackupImageView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ZoomEvent(org.osmdroid.events.ZoomEvent) IGeoPoint(org.osmdroid.api.IGeoPoint) GeoPoint(org.osmdroid.util.GeoPoint) MapListener(org.osmdroid.events.MapListener) ScrollEvent(org.osmdroid.events.ScrollEvent) MapView(org.osmdroid.views.MapView) IMapController(org.osmdroid.api.IMapController) IMyLocationProvider(org.osmdroid.views.overlay.mylocation.IMyLocationProvider) ImageLocation(org.telegram.messenger.ImageLocation) Location(android.location.Location)

Example 2 with MapListener

use of org.osmdroid.events.MapListener in project iGap-Android by KianIranian-STDG.

the class NewFragmentMap method setListeners.

private void setListeners() {
    mMapView.setMapListener(new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent event) {
            Log.d("osm", "onScroll");
            return true;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            Log.d("osm", "onZoom");
            return true;
        }
    });
    mCurrentLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mLastGeoPoint = mCurrentGeoPoint;
            mMapController.animateTo(mCurrentGeoPoint);
            setAddressStrip(mLastGeoPoint);
            addMarker(mCurrentGeoPoint);
        }
    });
    mSendLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap bitmap = mMapView.getDrawingCache();
            if (mLastGeoPoint.getLatitude() == 0 || mLastGeoPoint.getLongitude() == 0) {
                G.currentActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        HelperError.showSnackMessage(G.fragmentActivity.getResources().getString(R.string.set_position), false);
                    }
                });
            } else {
                try {
                    String path = saveMapToFile(bitmap);
                    popBackStackFragment();
                    if (path.length() > 0) {
                        if (G.iSendPositionChat != null) {
                            G.iSendPositionChat.send(mLastGeoPoint.getLatitude(), mLastGeoPoint.getLongitude(), path);
                        }
                    }
                } catch (Exception e) {
                    // ActivityChat activity = (ActivityChat) mActivity;
                    popBackStackFragment();
                    if (G.iSendPositionChat != null) {
                        G.iSendPositionChat.send(mLastGeoPoint.getLatitude(), mLastGeoPoint.getLongitude(), null);
                    }
                }
            }
        }
    });
    mDriveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Uri location = Uri.parse("geo:" + mLastGeoPoint.getLatitude() + "," + mLastGeoPoint.getLongitude() + "?z=17");
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
            startActivity(mapIntent);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) MapListener(org.osmdroid.events.MapListener) ScrollEvent(org.osmdroid.events.ScrollEvent) Intent(android.content.Intent) View(android.view.View) MapView(org.osmdroid.views.MapView) TextView(android.widget.TextView) Uri(android.net.Uri) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ZoomEvent(org.osmdroid.events.ZoomEvent)

Example 3 with MapListener

use of org.osmdroid.events.MapListener in project iGap-Android by KianIranian-STDG.

the class FragmentiGapMap method initMapListener.

private void initMapListener() {
    map.setMapListener(new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent event) {
            final GeoPoint geoPoint = event.getSource().getBoundingBox().getCenter();
            if ((geoPoint.getLatitude() < northLimitation) && (geoPoint.getLatitude() > southLimitation) && (geoPoint.getLongitude() < eastLimitation) && geoPoint.getLongitude() > westLimitation) {
                lastLatitude = geoPoint.getLatitude();
                lastLongitude = geoPoint.getLongitude();
                canUpdate = true;
            } else if (canUpdate) {
                canUpdate = false;
                G.handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        map.getController().animateTo(new GeoPoint(lastLatitude, lastLongitude));
                        G.handler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                canUpdate = true;
                            }
                        }, 2000);
                    }
                }, 100);
            }
            return false;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            return false;
        }
    });
}
Also used : GeoPoint(org.osmdroid.util.GeoPoint) MapListener(org.osmdroid.events.MapListener) ScrollEvent(org.osmdroid.events.ScrollEvent) ZoomEvent(org.osmdroid.events.ZoomEvent)

Example 4 with MapListener

use of org.osmdroid.events.MapListener in project ScanEco by Pepapipi.

the class RecherchePointDeCollecte method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recherche_point_de_collecte);
    // onde mostra a imagem do mapa
    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
    setOsm(findViewById(R.id.mapView));
    getOsm().setTileSource(TileSourceFactory.MAPNIK);
    getOsm().setMultiTouchControls(true);
    MapListener mapListener = new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent event) {
            Log.i("Script", "onScroll()");
            return false;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            Log.i("Script", "onZoom()");
            return false;
        }
    };
    mc = (MapController) getOsm().getController();
    markerPosition = new Marker(getOsm());
    GeoPoint pointFrance = new GeoPoint(43.48333, -1.48333);
    mc.setCenter(pointFrance);
    mc.setZoom(10);
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
        mPermissionResult.launch(Manifest.permission.ACCESS_FINE_LOCATION);
    else if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
        mPermissionResult.launch(Manifest.permission.ACCESS_COARSE_LOCATION);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    getOsm().addMapListener(mapListener);
    // /////////////Recuperation de la BD en JSON\\\\\\\\\\\\\\\
    try {
        taskRunner.executeAsync(new ConnexionJsonPointDeCollecte("https://api.npoint.io/6696673b4c1fdcfcff8e", MainActivity.USER_AGENT), this::json);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Initialisation de la barre de menu
    BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
    bottomNavigationView.setOnItemSelectedListener(item -> {
        int itemId = item.getItemId();
        if (itemId == R.id.accueilHorRamPoubelles) {
            ouvrirHorRamPoubelles();
        } else if (itemId == R.id.accueilAnimations) {
            ouvrirAnimations();
        }
        return true;
    });
    // Bouton de retour
    ImageButton boutonRetourScan = findViewById(R.id.boutonRetourScan);
    boutonRetourScan.setOnClickListener(v -> ouvrirLeScan());
}
Also used : Context(android.content.Context) LocationManager(android.location.LocationManager) GeoPoint(org.osmdroid.util.GeoPoint) ImageButton(android.widget.ImageButton) MapListener(org.osmdroid.events.MapListener) ScrollEvent(org.osmdroid.events.ScrollEvent) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) Marker(org.osmdroid.views.overlay.Marker) GeoPoint(org.osmdroid.util.GeoPoint) SuppressLint(android.annotation.SuppressLint) ZoomEvent(org.osmdroid.events.ZoomEvent)

Example 5 with MapListener

use of org.osmdroid.events.MapListener in project I5_GPS_Tracks by RaphaelNeubert.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // handle permissions
    requestPermissionsIfNecessary(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE });
    // will hide the title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // hide the title bar
    getSupportActionBar().hide();
    // load/initialize the osmdroid configuration
    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
    // inflate and create the map
    setContentView(R.layout.activity_main);
    map = (MapView) findViewById(R.id.map);
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setMultiTouchControls(true);
    map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
    IMapController mapController = map.getController();
    mapController.setZoom(15.5);
    mapController.setCenter(new GeoPoint(51.0374, 13.7638));
    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(getApplicationContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(5.0f);
    gpsMyLocationProvider.startLocationProvider(new IMyLocationConsumer() {

        @Override
        public void onLocationChanged(Location location, IMyLocationProvider source) {
            String position = "Location changed to: " + new GeoPoint(location).toDoubleString();
            Log.i("onLocationChanged: ", position);
        }
    });
    locationOverlay = new MyLocationNewOverlay(map);
    locationOverlay.enableFollowLocation();
    map.getOverlays().add(locationOverlay);
    toPosButton = (ImageButton) findViewById(R.id.posButton);
    toPosButton.setVisibility(View.INVISIBLE);
    toPosButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            locationOverlay.enableFollowLocation();
            toPosButton.setVisibility(View.INVISIBLE);
        }
    });
    MapListener mapListener = new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent event) {
            if (locationOverlay.isFollowLocationEnabled() == false && map.isAnimating() == false) {
                toPosButton.setVisibility(View.VISIBLE);
            }
            return false;
        }

        @Override
        public boolean onZoom(ZoomEvent event) {
            return false;
        }
    };
    map.addMapListener(mapListener);
    Marker m = new Marker(map);
    m.setPosition(new GeoPoint(51.051899, 13.768021));
    m.setIcon(getResources().getDrawable(R.drawable.ic_location_map_marker));
    m.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER);
    map.getOverlays().add(m);
}
Also used : Context(android.content.Context) GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) IMyLocationConsumer(org.osmdroid.views.overlay.mylocation.IMyLocationConsumer) Marker(org.osmdroid.views.overlay.Marker) View(android.view.View) MapView(org.osmdroid.views.MapView) ZoomEvent(org.osmdroid.events.ZoomEvent) GeoPoint(org.osmdroid.util.GeoPoint) MapListener(org.osmdroid.events.MapListener) ScrollEvent(org.osmdroid.events.ScrollEvent) IMapController(org.osmdroid.api.IMapController) IMyLocationProvider(org.osmdroid.views.overlay.mylocation.IMyLocationProvider) Location(android.location.Location)

Aggregations

MapListener (org.osmdroid.events.MapListener)12 ScrollEvent (org.osmdroid.events.ScrollEvent)12 ZoomEvent (org.osmdroid.events.ZoomEvent)12 GeoPoint (org.osmdroid.util.GeoPoint)9 GpsMyLocationProvider (org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider)7 MyLocationNewOverlay (org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay)7 View (android.view.View)4 MapEventsReceiver (org.osmdroid.events.MapEventsReceiver)4 MapView (org.osmdroid.views.MapView)4 RotationGestureOverlay (org.osmdroid.views.overlay.gestures.RotationGestureOverlay)4 Location (android.location.Location)3 TextView (android.widget.TextView)3 IMapController (org.osmdroid.api.IMapController)3 Marker (org.osmdroid.views.overlay.Marker)3 TilesOverlay (org.osmdroid.views.overlay.TilesOverlay)3 IMyLocationProvider (org.osmdroid.views.overlay.mylocation.IMyLocationProvider)3 Context (android.content.Context)2 Intent (android.content.Intent)2 LocationManager (android.location.LocationManager)2 ImageView (android.widget.ImageView)2