Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
add standard cards with static api images
Browse files Browse the repository at this point in the history
  • Loading branch information
zugaldia committed Jul 4, 2017
1 parent 8e75633 commit 0b348d5
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 33 deletions.
5 changes: 2 additions & 3 deletions skill/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sourceCompatibility = 1.7

repositories {
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}

dependencies {
Expand All @@ -17,15 +16,15 @@ dependencies {
compile ('com.amazonaws:aws-lambda-java-log4j:1.0.0')

// Alexa skills kit
compile ('com.amazon.alexa:alexa-skills-kit:1.2')
compile ('com.amazon.alexa:alexa-skills-kit:1.4.0')

// Logging
compile 'log4j:log4j:1.2.17'
compile 'org.slf4j:slf4j-api:1.7.0'
compile 'org.slf4j:slf4j-log4j12:1.7.0'

// MAS
compile ('com.mapbox.mapboxsdk:mapbox-java-services:2.0.0-SNAPSHOT@jar') {
compile ('com.mapbox.mapboxsdk:mapbox-java-services:2.1.3@jar') {
transitive=true
}

Expand Down
85 changes: 85 additions & 0 deletions skill/src/main/java/com/mapbox/alexa/ImageComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.mapbox.alexa;

import com.mapbox.services.api.staticimage.v1.MapboxStaticImage;
import com.mapbox.services.api.staticimage.v1.models.StaticMarkerAnnotation;
import com.mapbox.services.api.staticimage.v1.models.StaticPolylineAnnotation;
import com.mapbox.services.commons.models.Position;

/**
* Create static maps for cards.
*/
public class ImageComponent {

// 720w x 480h
private static final int smallWidth = 720;
private static final int smallHeight = 480;

// 1200w x 800h
private static final int largeWidth = 1200;
private static final int largeHeight = 800;

// https://www.mapbox.com/base/styling/color/
private static final String COLOR_GREEN = "56b881";
private static final String COLOR_RED = "e55e5e";
private static final String COLOR_BLUE = "3887be";

public static String getWelcomeMap(boolean isSmall) {
MapboxStaticImage client = new MapboxStaticImage.Builder()
.setAccessToken(Constants.MAPBOX_ACCESS_TOKEN)
.setWidth(isSmall ? smallWidth : largeWidth)
.setHeight(isSmall ? smallHeight : largeHeight)
.setStyleId(com.mapbox.services.Constants.MAPBOX_STYLE_SATELLITE)
.setLat(0.0).setLon(0.0)
.setZoom(0)
.build();
return client.getUrl().toString();
}

public static String getLocationMap(Position position, boolean isSmall) {
StaticMarkerAnnotation marker = new StaticMarkerAnnotation.Builder()
.setName(com.mapbox.services.Constants.PIN_LARGE)
.setPosition(position)
.setColor(COLOR_RED)
.build();
MapboxStaticImage client = new MapboxStaticImage.Builder()
.setAccessToken(Constants.MAPBOX_ACCESS_TOKEN)
.setWidth(isSmall ? smallWidth : largeWidth)
.setHeight(isSmall ? smallHeight : largeHeight)
.setStyleId(com.mapbox.services.Constants.MAPBOX_STYLE_STREETS)
.setPosition(position)
.setStaticMarkerAnnotations(marker)
.setZoom(15)
.build();
return client.getUrl().toString();
}

public static String getRouteMap(Position origin, Position destination, String geometry, boolean isSmall) {
StaticMarkerAnnotation markerOrigin = new StaticMarkerAnnotation.Builder()
.setName(com.mapbox.services.Constants.PIN_LARGE)
.setPosition(origin)
.setColor(COLOR_GREEN)
.build();
StaticMarkerAnnotation markerDestination = new StaticMarkerAnnotation.Builder()
.setName(com.mapbox.services.Constants.PIN_LARGE)
.setPosition(destination)
.setColor(COLOR_RED)
.build();
StaticPolylineAnnotation route = new StaticPolylineAnnotation.Builder()
.setPolyline(geometry)
.setStrokeColor(COLOR_BLUE)
.setStrokeOpacity(1)
.setStrokeWidth(5)
.build();
MapboxStaticImage client = new MapboxStaticImage.Builder()
.setAccessToken(Constants.MAPBOX_ACCESS_TOKEN)
.setWidth(isSmall ? smallWidth : largeWidth)
.setHeight(isSmall ? smallHeight : largeHeight)
.setStyleId(com.mapbox.services.Constants.MAPBOX_STYLE_TRAFFIC_DAY)
.setAuto(true)
.setStaticMarkerAnnotations(markerOrigin, markerDestination)
.setStaticPolylineAnnotations(route)
.setZoom(15)
.build();
return client.getUrl().toString();
}
}
Loading

0 comments on commit 0b348d5

Please sign in to comment.