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);
}
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();
}
}
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;
}
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);
}
}
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);
}
Aggregations