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

Improve the addPolyline color option #50

Merged
merged 3 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Draw a polyline. Connect the points given as parameters.
// Draw a two segment line near Amsterdam Central Station
mapbox.addPolyline({
id: 1, // optional, can be used in 'removePolylines'
color: 0xff29a025, //Set the color of the line (default black)
color: '#336699', // Set the color of the line (default black)
width: 7, //Set the width of the line (default 5)
points: [
{
Expand Down
12 changes: 11 additions & 1 deletion mapbox.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var utils = require("utils/utils");
var application = require("application");
var frame = require("ui/frame");
var fs = require("file-system");
var Color = require("color").Color;
var mapbox = require("./mapbox-common");
mapbox._markers = [];
mapbox._polylines = [];
Expand Down Expand Up @@ -606,7 +607,16 @@ mapbox.addPolyline = function (arg, nativeMap) {

var polylineOptions = new com.mapbox.mapboxsdk.annotations.PolylineOptions();
polylineOptions.width(arg.width || 5); // default 5
polylineOptions.color(arg.color || 0xff000000); // default black

// Create android color && default black
var androidColor;
if (arg.color && Color.isValid(arg.color)) {
androidColor = arg.color ? new Color(arg.color).android : new Color('#000').android;
} else {
androidColor = new Color('#000').android;
}

polylineOptions.color(androidColor);
for (var p in points) {
var point = points[p];
polylineOptions.add(new com.mapbox.mapboxsdk.geometry.LatLng(point.lat, point.lng));
Expand Down
6 changes: 3 additions & 3 deletions mapbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ declare module "nativescript-mapbox" {
*/
width?: number;
/**
* Color of the lone, default black (0xff000000).
* Color of the line, default black.
*/
color?: any;
color?: string;
points: LatLng[];
}

Expand Down Expand Up @@ -247,4 +247,4 @@ declare module "nativescript-mapbox" {
export function downloadOfflineRegion(arg: DownloadOfflineRegionOptions): Promise<any>;
export function listOfflineRegions(arg: ListOfflineRegionsOptions): Promise<Array<OfflineRegion>>;
export function deleteOfflineRegion(arg: DeleteOfflineRegionOptions): Promise<any>;
}
}