Search in sources :

Example 11 with GeoJsonSource

use of com.mapbox.mapboxsdk.style.sources.GeoJsonSource in project androidApp by InspectorIncognito.

the class BusStopPlugin method setupBusSource.

private void setupBusSource() {
    busesSource = new GeoJsonSource(SOURCE_BUSES, busesFeatures);
    mapboxMap.addSource(busesSource);
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource)

Example 12 with GeoJsonSource

use of com.mapbox.mapboxsdk.style.sources.GeoJsonSource in project androidApp by InspectorIncognito.

the class BusUserPlugin method updateUserEvents.

public void updateUserEvents(ArrayList<ServerSentEvent> newEvents, String reporterId) {
    if (currentUserBus != null && reporterId.equals(currentUserBus.getId())) {
        currentUserBus.setEvents(newEvents);
        final GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
        ArrayList<IconBuilder> buildingList = new ArrayList<>();
        buildingList.add(new UserBusIconsBuilder(currentUserBus).toBuilder());
        GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

            @Override
            public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
                mapboxMap.addImages(bitmapHashMap);
                if (locationGeoJsonSource != null) {
                    locationGeoJsonSource.setGeoJson(userLocationFeature);
                }
            }
        }, viewMap, buildingList);
        task.execute();
    }
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) UserBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.UserBusIconsBuilder) MapView(com.mapbox.mapboxsdk.maps.MapView) View(android.view.View) Bitmap(android.graphics.Bitmap)

Example 13 with GeoJsonSource

use of com.mapbox.mapboxsdk.style.sources.GeoJsonSource in project androidApp by InspectorIncognito.

the class UserPlugin method setLocation.

/**
 * Updates the user location icon.
 *
 * @param location the latest user location
 * @since 0.1.0
 */
protected boolean setLocation(final Location location) {
    GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
    if (locationGeoJsonSource == null) {
        Log.e("UserPlugin", "Location GeoJSON source missing from map style, this should never occur.");
        return true;
    }
    // Convert the new location to a Point object.
    Point newPoint = Point.fromCoordinates(new double[] { location.getLongitude(), location.getLatitude() });
    // If the source doesn't have geometry, a Point gets added.
    if (previousPoint == null) {
        userLocationFeature = Feature.fromGeometry(newPoint, new JsonObject(), LocationLayerConstants.USER_LOCATION_ICON);
        userLocationFeature.addBooleanProperty(LocationLayerConstants.PROPERTY_ON_BUS, false);
        userLocationFeature.addStringProperty(LocationLayerConstants.PROPERTY_ORIENTATION, "NONE");
        locationGeoJsonSource.setGeoJson(userLocationFeature);
        previousPoint = newPoint;
        return true;
    }
    // Do nothing if the location source's current Point is identical to the new location Point.
    if (previousPoint.getCoordinates().equals(newPoint.getCoordinates())) {
        return true;
    }
    // Or if the distance between the two points is less than 10 meters
    if (MapboxUtil.distanceTo(previousPoint.getCoordinates(), newPoint.getCoordinates()) < 10) {
        return true;
    }
    locationChangeAnimate(locationGeoJsonSource, previousPoint, newPoint);
    return false;
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) JsonObject(com.google.gson.JsonObject) Point(com.mapbox.services.commons.geojson.Point)

Example 14 with GeoJsonSource

use of com.mapbox.mapboxsdk.style.sources.GeoJsonSource in project androidApp by InspectorIncognito.

the class UserPlugin method mapStyleFinishedLoading.

/**
 * If the location layer was being displayed before the style change, it will need to be displayed in the new style.
 */
@SuppressWarnings({ "MissingPermission" })
void mapStyleFinishedLoading() {
    Source source = mapboxMap.getSource(LocationLayerConstants.LOCATION_SOURCE);
    if (source == null) {
        locationLayer = new LocationLayer(mapView, mapboxMap);
        setLocationLayerEnabled(getLocationLayerMode());
    } else {
        locationLayer.setLayerVisibility(locationLayerMode != LocationLayerMode.NONE);
    }
    GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
    if (locationGeoJsonSource != null) {
        locationGeoJsonSource.setGeoJson(previousPoint);
    }
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) Source(com.mapbox.mapboxsdk.style.sources.Source) GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource)

Example 15 with GeoJsonSource

use of com.mapbox.mapboxsdk.style.sources.GeoJsonSource in project androidApp by InspectorIncognito.

the class OnBusEngine method setupBusStopRouteLayer.

private void setupBusStopRouteLayer() {
    busStopSource = new GeoJsonSource(SOURCE_BUS_STOPS, FeatureCollection.fromFeatures(new Feature[] {}));
    mapboxMap.addSource(busStopSource);
    Layer routeLayer = new SymbolLayer("BUS_STOP_ROUTE_ID", SOURCE_BUS_STOPS).withProperties(iconImage("routeBusIcon"), iconSize(0.8f), /* allows show all icons */
    iconAllowOverlap(true), iconOffset(new Float[] { BusStopMarker.MARKER_DX_OFFSET, BusStopMarker.MARKER_DY_OFFSET }));
    routeLayer.setMinZoom(15);
    mapboxMap.addLayerAbove(routeLayer, BUS_STOP_SELECTED_MARKER_LAYER_ID);
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer) Layer(com.mapbox.mapboxsdk.style.layers.Layer) SymbolLayer(com.mapbox.mapboxsdk.style.layers.SymbolLayer)

Aggregations

GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)15 Bitmap (android.graphics.Bitmap)3 View (android.view.View)3 UserBusIconsBuilder (cl.smartcities.isci.transportinspector.map.model.bus.UserBusIconsBuilder)3 IconBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder)3 GenerateViewIconTask (cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask)3 MapView (com.mapbox.mapboxsdk.maps.MapView)3 ArrayList (java.util.ArrayList)3 GeoJsonOptions (com.mapbox.mapboxsdk.style.sources.GeoJsonOptions)2 Feature (com.mapbox.services.commons.geojson.Feature)2 PointF (android.graphics.PointF)1 NonNull (android.support.annotation.NonNull)1 BearingEngine (cl.smartcities.isci.transportinspector.map.engine.BearingEngine)1 DirectionEngine (cl.smartcities.isci.transportinspector.map.engine.DirectionEngine)1 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)1 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)1 PeriodicRequestHandler (cl.smartcities.isci.transportinspector.periodicRequest.PeriodicRequestHandler)1 JsonObject (com.google.gson.JsonObject)1 FeatureCollection (com.mapbox.geojson.FeatureCollection)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1