Search in sources :

Example 6 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.

the class LocationLayerAnimator method feedNewLocation.

void feedNewLocation(@NonNull Location newLocation, @NonNull CameraPosition currentCameraPosition, boolean isGpsNorth) {
    if (previousLocation == null) {
        previousLocation = newLocation;
        locationUpdateTimestamp = SystemClock.elapsedRealtime();
    }
    if (invalidUpdateInterval()) {
        return;
    }
    LatLng previousLayerLatLng = getPreviousLayerLatLng();
    float previousLayerBearing = getPreviousLayerGpsBearing();
    LatLng previousCameraLatLng = currentCameraPosition.target;
    float previousCameraBearing = (float) currentCameraPosition.bearing;
    LatLng targetLatLng = new LatLng(newLocation);
    float targetLayerBearing = newLocation.getBearing();
    float targetCameraBearing = newLocation.getBearing();
    targetCameraBearing = checkGpsNorth(isGpsNorth, targetCameraBearing);
    updateLayerAnimators(previousLayerLatLng, targetLatLng, previousLayerBearing, targetLayerBearing);
    updateCameraAnimators(previousCameraLatLng, previousCameraBearing, targetLatLng, targetCameraBearing);
    playAllLocationAnimators(getAnimationDuration());
    previousLocation = newLocation;
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 7 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.

the class RegionSelectionFragment method createRegion.

OfflineTilePyramidRegionDefinition createRegion() {
    if (mapboxMap == null) {
        throw new NullPointerException("MapboxMap is null and can't be used to create Offline region" + "definition.");
    }
    RectF rectF = getSelectionRegion();
    LatLng northEast = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.right, rectF.top));
    LatLng southWest = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.left, rectF.bottom));
    LatLngBounds bounds = new LatLngBounds.Builder().include(northEast).include(southWest).build();
    double cameraZoom = mapboxMap.getCameraPosition().zoom;
    float pixelRatio = getActivity().getResources().getDisplayMetrics().density;
    return new OfflineTilePyramidRegionDefinition(mapboxMap.getStyleUrl(), bounds, cameraZoom - 2, cameraZoom + 2, pixelRatio);
}
Also used : RectF(android.graphics.RectF) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) PointF(android.graphics.PointF) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 8 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.

the class GeoJsonPlugin method parseGeoJsonString.

/**
 * @param geoJson String of the GeoJSON file
 * @return DataModel list of polylines, polygons, and point with bounded
 */
private DataModel parseGeoJsonString(String geoJson) {
    int pointCount = 0;
    DataModel dataModel = new DataModel();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    FeatureCollection featureCollection = FeatureCollection.fromJson(geoJson);
    List<Feature> listFeature = featureCollection.features();
    for (Feature feature : listFeature) {
        String featureType = feature.geometry().type();
        if (!TextUtils.isEmpty(featureType)) {
            if (featureType.equalsIgnoreCase("LineString")) {
                List<LatLng> latLngs = new ArrayList<>();
                LineString lineString = (LineString) feature.geometry();
                List<Point> coordinates = lineString.coordinates();
                for (Point position : coordinates) {
                    LatLng latLng = new LatLng(position.latitude(), position.longitude());
                    latLngs.add(latLng);
                    pointCount++;
                    builder.include(latLng);
                }
                PolyData polylinePolyData = new PolyData();
                polylinePolyData.setPoints(latLngs);
                polylinePolyData.setType(featureType);
                dataModel.addPolyline(polylinePolyData);
            } else if (featureType.equalsIgnoreCase("Point")) {
                Point point = (Point) feature.geometry();
                if (point != null) {
                    LatLng latLng = new LatLng(point.latitude(), point.longitude());
                    MarkerData markerData = new MarkerData();
                    markerData.setPoint(latLng);
                    markerData.setProperties(feature.properties());
                    dataModel.addMarker(markerData);
                    pointCount++;
                    builder.include(latLng);
                }
            } else if (featureType.equalsIgnoreCase("Polygon")) {
                List<LatLng> latLngs = new ArrayList<>();
                Polygon polygon = (Polygon) feature.geometry();
                List<Point> listPosition = polygon.coordinates().get(0);
                for (Point position : listPosition) {
                    LatLng latLng = new LatLng(position.latitude(), position.longitude());
                    latLngs.add(latLng);
                    pointCount++;
                    builder.include(latLng);
                }
                PolyData polygonPolyData = new PolyData();
                polygonPolyData.setPoints(latLngs);
                polygonPolyData.setType(featureType);
                dataModel.addPolygon(polygonPolyData);
            } else {
            // TODO
            }
        }
    }
    if (pointCount > 1) {
        dataModel.setBounds(builder.build());
    }
    return dataModel;
}
Also used : MarkerData(com.mapbox.mapboxsdk.plugins.geojson.model.MarkerData) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) ArrayList(java.util.ArrayList) LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Feature(com.mapbox.geojson.Feature) Point(com.mapbox.geojson.Point) PolyData(com.mapbox.mapboxsdk.plugins.geojson.model.PolyData) FeatureCollection(com.mapbox.geojson.FeatureCollection) LineString(com.mapbox.geojson.LineString) DataModel(com.mapbox.mapboxsdk.plugins.geojson.model.DataModel) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Polygon(com.mapbox.geojson.Polygon)

Example 9 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.

the class PlacePickerActivity method makeReverseGeocodingSearch.

private void makeReverseGeocodingSearch() {
    LatLng latLng = mapboxMap.getCameraPosition().target;
    viewModel.reverseGeocode(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()), accessToken, options);
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 10 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.

the class GeoJsonActivity method onMapReady.

@Override
public void onMapReady(MapboxMap mapboxMap) {
    this.mapboxMap = mapboxMap;
    geoJsonPlugin = new GeoJsonPluginBuilder().withContext(this).withMap(mapboxMap).withOnLoadingURL(this).withOnLoadingFileAssets(this).withOnLoadingFilePath(this).withMarkerClickListener(this).withRandomFillColor().build();
    mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(32.6546, 51.6680), 7));
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) GeoJsonPluginBuilder(com.mapbox.mapboxsdk.plugins.geojson.GeoJsonPluginBuilder)

Aggregations

LatLng (com.mapbox.mapboxsdk.geometry.LatLng)56 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)12 ArrayList (java.util.ArrayList)10 Point (com.mapbox.geojson.Point)7 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)6 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)6 NonNull (android.support.annotation.NonNull)5 PointF (android.graphics.PointF)4 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)4 ValueAnimator (android.animation.ValueAnimator)3 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)3 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)3 Poi (io.jawg.osmcontributor.model.entities.Poi)3 Subscribe (org.greenrobot.eventbus.Subscribe)3 Intent (android.content.Intent)2 Location (android.location.Location)2 View (android.view.View)2 RouteHelper (cl.smartcities.isci.transportinspector.database.RouteHelper)2 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)2