Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mapbox sdk 7.2.0 #274

Merged
merged 22 commits into from Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 7 additions & 53 deletions README.md
@@ -1,6 +1,6 @@
# Kujaku (Peacock) [![Build Status](https://travis-ci.org/onaio/kujaku.svg?branch=master)](https://travis-ci.org/onaio/kujaku) [ ![Download](https://api.bintray.com/packages/ona/kujaku/library/images/download.svg) ](https://bintray.com/ona/kujaku/library/_latestVersion) [![Coverage Status](https://coveralls.io/repos/github/onaio/kujaku/badge.svg)](https://coveralls.io/github/onaio/kujaku)

A mapping and check-in library for Android using MapBox SDK.
A mapping and check-in library for Android using **MapBox SDK (Version 7.2.0)**

# Table of Contents

Expand All @@ -9,6 +9,7 @@ A mapping and check-in library for Android using MapBox SDK.
* [Importing the Library](#importing-the-library)
* [How to publish artifacts](#how-to-publish-artifacts)
* [How to import the library](#how-to-import-the-library)
* [How to use the library](#how-to-use-the-library)
* [License](#license)
* [Acknowledgements](#acknowledgements)
* [Specification](SPECIFICATION.md)
Expand Down Expand Up @@ -71,63 +72,16 @@ android {
dependencies {
...
// Kujaku dependencies
implementation 'io.ona.kujaku:library:0.5.5'
implementation 'io.ona.kujaku:library:0.6.3'
...
}
```

## WMTS Layers
## How to use the library

### WmtsService

This class reads the capabilities Xml stream and deserialize it into a WMTSCapabilities object.
You need to provide a Capabilities URL as argument to the constructor.

```
WmtsCapabilitiesService wmtsService = new WmtsCapabilitiesService(getString(R.string.wmts_capabilities_url));
```

Call the requestData method to retrieve the Capabilities information and set a listener that will be called as soon as the async task returns the result.

```
wmtsService.requestData();

wmtsService.setListener(new WmtsCapabilitiesListener() {
@Override
public void onCapabilitiesReceived(WmtsCapabilities capabilities) {
try {
// kujakuMapView.addWmtsLayer(capabilities);
}
catch (Exception ex) {
//throw ex;
}
}
});
```

### Add WMTS layers to the map

The kujakuMapView has 4 public methods to add WMTS Layers onto the map :

* This method will add the first layer of the Capabilities file with the default style and first tileMatrixSet :
```
public void addWmtsLayer(WmtsCapabilities capabilities) throws Exception
```

* This method will add the layer identified by the layerIdentifier argument of the Capabilities file with the default style and first tileMatrixSet :
```
public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier) throws Exception
```

* This method will add the layer identified by the layerIdentifier argument of the Capabilities file with the style identified by the styleIdentifier argument and first tileMatrixSet:
```
public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier, String styleIdentifier) throws Exception
```

* This method will add the layer identified by the layerIdentifier argument of the Capabilities file with the style identified by the styleIdentifier argument and the tileMatrixSet identified by the tileMatrixSetLinkIdentifier argument:
```
public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier, String styleIdentifier, String tileMatrixSetLinkIdentifier) throws Exception
```
The library offers a view `KujakuMapView` that provides more functionality than Mapbox.
- For Mapbox related functionality, [go here](https://docs.mapbox.com/android/maps/overview/)
- For extra features provided by this library [go here](./SPECIFICATION.md)


## License
Expand Down
66 changes: 64 additions & 2 deletions SPECIFICATION.md
Expand Up @@ -5,9 +5,10 @@
* [What is a Geospatial Widget?](#what-is-a-geospatial-widget)
* [Specification](#specification)
* [Map Activity](#mapactivity)
* [How to create a Mapbox style with Kujaku configuration](#how-to-create-a-mapbox-style-with-kujaku-configuration)
* [Offline Maps Downloader Service](#offline-maps-downloader-service)
* [How to create a Mapbox style with Kujaku configuration](#how-to-create-a-mapbox-style-with-kujaku-configuration)
* [Kujaku Map View](#kujaku-map-view)
* [Adding WMTS Layers](#1-adding-wmts-layers)
* [Offline Maps Downloader Service](#offline-maps-downloader-service)
* [Helper Classes](#helper-classes)
* [MapBoxStyleHelper class](#1-mapboxstylehelper)
* [CoordinateUtils class](#2-coordinateutils)
Expand All @@ -25,6 +26,12 @@ The Geospatial widget library provides a map widget and has a map download servi

# Specification

The Geospatial widget is available in two forms:
- Activity
- View

The view has is actively under development and directly extends the Mapbox `MapView` while the `Activity` just provides a wrapper for displaying data

## MapActivity

The Geospatial widget SHOULD provide a `MapActivity` activity that is used to display a map view given a Mapbox API access token and an array of Mapbox styles url. The `MapActivity` WILL be initialized through an intent request.
Expand Down Expand Up @@ -174,6 +181,61 @@ The Kujaku config is a JSON Object with the following:
}
```

## Kujaku Map View

## 1. Adding WMTS Layers

### WmtsService

This class reads the capabilities Xml stream and deserialize it into a WMTSCapabilities object.
You need to provide a Capabilities URL as argument to the constructor.

```
WmtsCapabilitiesService wmtsService = new WmtsCapabilitiesService(getString(R.string.wmts_capabilities_url));
```

Call the requestData method to retrieve the Capabilities information and set a listener that will be called as soon as the async task returns the result.

```
wmtsService.requestData();

wmtsService.setListener(new WmtsCapabilitiesListener() {
@Override
public void onCapabilitiesReceived(WmtsCapabilities capabilities) {
try {
// kujakuMapView.addWmtsLayer(capabilities);
}
catch (Exception ex) {
//throw ex;
}
}
});
```

### Add WMTS layers to the map

The `KujakuMapView` has 4 public methods to add WMTS Layers onto the map :

* This method will add the first layer of the Capabilities file with the default style and first tileMatrixSet :
```
public void addWmtsLayer(WmtsCapabilities capabilities) throws Exception
```

* This method will add the layer identified by the layerIdentifier argument of the Capabilities file with the default style and first tileMatrixSet :
```
public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier) throws Exception
```

* This method will add the layer identified by the layerIdentifier argument of the Capabilities file with the style identified by the styleIdentifier argument and first tileMatrixSet:
```
public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier, String styleIdentifier) throws Exception
```

* This method will add the layer identified by the layerIdentifier argument of the Capabilities file with the style identified by the styleIdentifier argument and the tileMatrixSet identified by the tileMatrixSetLinkIdentifier argument:
```
public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier, String styleIdentifier, String tileMatrixSetLinkIdentifier) throws Exception
```


## Offline Maps Downloader Service

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -42,6 +42,7 @@ ext {
volleyVersion = "1.1.0"
targetSdkVersion = 27
jacocoVersion = "0.7.9"
mapboxSdkVersion = "7.2.0"
}

coveralls {
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Expand Up @@ -160,8 +160,8 @@ android {
}

dependencies { configuration ->
implementation "com.android.support:support-v4:${rootProject.ext.supportVersion}"
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.2') {
implementation "com.android.support:support-v4:${supportVersion}"
implementation ("com.mapbox.mapboxsdk:mapbox-android-sdk:${mapboxSdkVersion}") {
transitive = true;
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
Expand Down
52 changes: 33 additions & 19 deletions library/src/main/java/io/ona/kujaku/activities/MapActivity.java
Expand Up @@ -28,6 +28,7 @@
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -211,37 +212,49 @@ private void initMapBoxSdk(Bundle savedInstanceState, String mapBoxStylePath,

kujakuMapView.onCreate(savedInstanceState);

if (mapBoxStylePath != null && !mapBoxStylePath.isEmpty()) {
kujakuMapView.setStyleUrl(mapBoxStylePath);
}
kujakuMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
//Set listener for markers
MapActivity.this.mapboxMap = mapboxMap;
mapboxMap.addOnMapClickListener(MapActivity.this);

if (minZoom != -1) {
mapboxMap.setMinZoomPreference(minZoom);
if (mapBoxStylePath != null && !mapBoxStylePath.isEmpty()) {
mapboxMap.setStyle(new Style.Builder().fromUrl(mapBoxStylePath), new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
setupMapPosition(mapboxMap);
}
});
} else {
setupMapPosition(mapboxMap);
}

if (maxZoom != -1) {
mapboxMap.setMaxZoomPreference(maxZoom);
}

CameraPosition.Builder cameraPositionBuilder = new CameraPosition.Builder();
boolean cameraPositionChanged = false;
}
});
}

private void setupMapPosition(@NonNull MapboxMap mapboxMap) {
if (minZoom != -1) {
mapboxMap.setMinZoomPreference(minZoom);
}

if (cameraPositionChanged) {
mapboxMap.setCameraPosition(cameraPositionBuilder.build());
}
if (maxZoom != -1) {
mapboxMap.setMaxZoomPreference(maxZoom);
}

if (!mapboxStyleJSON.has(MapBoxStyleHelper.KEY_MAP_CENTER)) {
kujakuMapView.focusOnUserLocation(true);
}
}
});
CameraPosition.Builder cameraPositionBuilder = new CameraPosition.Builder();
boolean cameraPositionChanged = false;


if (cameraPositionChanged) {
mapboxMap.setCameraPosition(cameraPositionBuilder.build());
}

if (!mapboxStyleJSON.has(MapBoxStyleHelper.KEY_MAP_CENTER)) {
kujakuMapView.focusOnUserLocation(true);
}
}

private LatLng getBoundsCenter(LatLng topLeftBound, LatLng bottomRightBound) {
Expand Down Expand Up @@ -492,7 +505,7 @@ private void checkPermissions(Bundle savedInstanceState) {
}

@Override
public void onMapClick(@NonNull LatLng point) {
public boolean onMapClick(@NonNull LatLng point) {
// Convert LatLng coordinates to screen pixel and only query the rendered features.
final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
List<Feature> features = mapboxMap.queryRenderedFeatures(pixel);
Expand All @@ -512,6 +525,7 @@ public void onMapClick(@NonNull LatLng point) {
}
}

return false;
}

private void showInfoWindowListAndScrollToPosition(final int position, final boolean informInfoWindowAdapter) {
Expand Down
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
Expand All @@ -23,7 +22,7 @@ public class MapboxLocationComponentWrapper {
@SuppressWarnings( {"MissingPermission"})
public void init(@NonNull MapboxMap mapboxMap, @NonNull Context context) {
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(context, (LocationEngine) null);
locationComponent.activateLocationComponent(context, mapboxMap.getStyle(), false);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.NONE);
locationComponent.setRenderMode(RenderMode.NORMAL);
Expand Down
Expand Up @@ -246,4 +246,13 @@ public interface IKujakuMapView extends IKujakuMapViewLowLevel {
* @return if the location update was applied to the location client
*/
boolean changeLocationUpdates(long updateInterval, long fastestUpdateInterval, int accuracyLevel);

/**
* Checks if the {@link com.mapbox.mapboxsdk.maps.Style} contains the {@link KujakuLayer} so
* as to determine whether to add it to the newly loaded {@link com.mapbox.mapboxsdk.maps.Style}
*
* @param kujakuLayer
* @return {@code true} if the layer IDs for the {@link KujakuLayer} are present, {@code false} otherwise
*/
boolean isKujakuLayerAdded(@NonNull KujakuLayer kujakuLayer);
}