Skip to content

Commit 314b041

Browse files
committed
new components
1 parent 79c60e1 commit 314b041

File tree

8 files changed

+195
-258
lines changed

8 files changed

+195
-258
lines changed

components/mapbox/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/mapbox/actions/create-tileset/create-tileset.mjs

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,98 @@
11
import mapbox from "../../mapbox.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import fs from "fs";
3+
import FormData from "form-data";
34

45
export default {
56
key: "mapbox-create-tileset",
67
name: "Create Tileset",
7-
description: "Uploads and creates a new tileset from a data source. [See the documentation]()",
8-
version: "0.0.{{ts}}",
8+
description: "Uploads and creates a new tileset from a data source. [See the documentation](https://docs.mapbox.com/api/maps/mapbox-tiling-service/)",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
mapbox,
12-
sourceFile: {
13-
propDefinition: [
14-
"mapbox",
15-
"sourceFile",
16-
],
13+
username: {
14+
type: "string",
15+
label: "Username",
16+
description: "The Mapbox username of the account for which to create a tileset source",
1717
},
1818
tilesetName: {
19-
propDefinition: [
20-
"mapbox",
21-
"tilesetName",
22-
],
19+
type: "string",
20+
label: "Tileset Name",
21+
description: "A unique name for the tileset source to be created. Limited to 32 characters. The only allowed special characters are - and _.",
22+
},
23+
filePath: {
24+
type: "string",
25+
label: "File Path",
26+
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
27+
},
28+
recipe: {
29+
type: "object",
30+
label: "Recipe",
31+
description: "A recipe that describes how the GeoJSON data you uploaded should be transformed into tiles. For more information on how to create and format recipes, see the ]Recipe reference](https://docs.mapbox.com/mapbox-tiling-service/reference/) and [Recipe examples](https://docs.mapbox.com/mapbox-tiling-service/examples/).",
2332
},
2433
description: {
25-
propDefinition: [
26-
"mapbox",
27-
"description",
28-
],
34+
type: "string",
35+
label: "Description",
36+
description: "A description of the tileset",
37+
optional: true,
2938
},
30-
privacySettings: {
31-
propDefinition: [
32-
"mapbox",
33-
"privacySettings",
34-
],
39+
private: {
40+
type: "boolean",
41+
label: "Private",
42+
description: "Describes whether the tileset must be used with an access token from your Mapbox account. Default is `true`.",
43+
optional: true,
3544
},
3645
},
3746
async run({ $ }) {
38-
const response = await this.mapbox.uploadTileset({
39-
sourceFile: this.sourceFile,
40-
tilesetName: this.tilesetName,
41-
description: this.description,
42-
privacySettings: this.privacySettings,
47+
const filePath = this.filePath.includes("tmp/")
48+
? this.filePath
49+
: `/tmp/${this.filePath}`;
50+
51+
// Create Tileset Source
52+
try {
53+
const fileData = new FormData();
54+
const content = fs.createReadStream(filePath);
55+
fileData.append("file", content);
56+
57+
await this.mapbox.createTilesetSource({
58+
$,
59+
username: this.username,
60+
id: this.tilesetName,
61+
data: fileData,
62+
headers: fileData.getHeaders(),
63+
});
64+
} catch (e) {
65+
throw new Error(`Error uploading file: \`${filePath}\`. Error: ${e}`);
66+
}
67+
68+
const recipe = typeof this.recipe === "string"
69+
? JSON.parse(this.recipe)
70+
: this.recipe;
71+
72+
// Validate Recipe
73+
const {
74+
valid, errors,
75+
} = await this.mapbox.validateRecipe({
76+
$,
77+
data: recipe,
4378
});
79+
80+
if (!valid) {
81+
throw new Error(`Error validating recipe: ${errors}`);
82+
}
83+
84+
// Create Tileset
85+
const response = await this.mapbox.createTileset({
86+
$,
87+
tilesetId: `${this.username}.${this.tilesetName}`,
88+
data: {
89+
recipe,
90+
name: this.tilesetName,
91+
description: this.description,
92+
private: this.private,
93+
},
94+
});
95+
4496
$.export("$summary", `Created tileset ${this.tilesetName}`);
4597
return response;
4698
},

components/mapbox/actions/generate-directions/generate-directions.mjs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,55 @@ import mapbox from "../../mapbox.app.mjs";
33
export default {
44
key: "mapbox-generate-directions",
55
name: "Generate Directions",
6-
description: "Generates directions between two or more locations using Mapbox API. [See the documentation]().",
7-
version: "0.0.{{ts}}",
6+
description: "Generates directions between two or more locations using Mapbox API. [See the documentation](https://docs.mapbox.com/api/navigation/directions/).",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
mapbox,
1111
startCoordinate: {
12-
propDefinition: [
13-
mapbox,
14-
"startCoordinate",
15-
],
12+
type: "string",
13+
label: "Start Coordinate",
14+
description: "The starting point in the format `longitude,latitude`",
1615
},
1716
endCoordinate: {
18-
propDefinition: [
19-
mapbox,
20-
"endCoordinate",
21-
],
22-
},
23-
waypoints: {
24-
propDefinition: [
25-
mapbox,
26-
"waypoints",
27-
],
17+
type: "string",
18+
label: "End Coordinate",
19+
description: "The ending point in the format `longitude,latitude`",
2820
},
2921
transportationMode: {
3022
propDefinition: [
3123
mapbox,
3224
"transportationMode",
3325
],
3426
},
35-
routeType: {
27+
steps: {
28+
type: "boolean",
29+
label: "Steps",
30+
description: "Whether to return steps and turn-by-turn instructions (`true`) or not (`false`, default)",
31+
},
32+
alternatives: {
33+
type: "boolean",
34+
label: "Alternatives",
35+
description: "Whether to try to return alternative routes (`true`) or not (`false`, default). An alternative route is a route that is significantly different from the fastest route, but still close in time.",
36+
optional: true,
37+
},
38+
exclude: {
3639
propDefinition: [
3740
mapbox,
38-
"routeType",
41+
"exclude",
3942
],
4043
},
4144
},
4245
async run({ $ }) {
4346
const directions = await this.mapbox.getDirections({
44-
startCoordinate: this.startCoordinate,
45-
endCoordinate: this.endCoordinate,
46-
waypoints: this.waypoints,
47+
$,
4748
transportationMode: this.transportationMode,
48-
routeType: this.routeType,
49+
coordinates: `${this.startCoordinate};${this.endCoordinate}`,
50+
params: {
51+
steps: this.steps,
52+
alternatives: this.alternatives,
53+
exclude: this.exclude && this.exclude.join(","),
54+
},
4955
});
5056
$.export("$summary", "Generated directions successfully.");
5157
return directions;

components/mapbox/actions/geocode-address/geocode-address.mjs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@ import mapbox from "../../mapbox.app.mjs";
33
export default {
44
key: "mapbox-geocode-address",
55
name: "Geocode Address",
6-
description: "Retrieves the geocoded location for a given address. [See the documentation]()",
7-
version: "0.0.{{ts}}",
6+
description: "Retrieves the geocoded location for a given address. [See the documentation](https://docs.mapbox.com/api/search/geocoding/)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
mapbox,
1111
address: {
12-
propDefinition: [
13-
mapbox,
14-
"address",
15-
],
12+
type: "string",
13+
label: "Address",
14+
description: "The address (or partial address) to geocode. This could be an address, a city name, etc. Must consist of at most 20 words and numbers separated by spacing and punctuation, and at most 256 characters.",
1615
},
1716
boundingBox: {
18-
propDefinition: [
19-
mapbox,
20-
"boundingBox",
21-
],
17+
type: "string",
18+
label: "Bounding Box",
19+
description: "Limit results to only those contained within the supplied bounding box. Bounding boxes should be supplied as four numbers separated by commas, in `minLon,minLat,maxLon,maxLat` order. The bounding box cannot cross the 180th meridian. You can use the [Location Helper](https://labs.mapbox.com/location-helper) to find a bounding box for use with this API.",
2220
optional: true,
2321
},
2422
proximity: {
25-
propDefinition: [
26-
mapbox,
27-
"proximity",
28-
],
23+
type: "string",
24+
label: "Proximity",
25+
description: "Bias the response to favor results that are closer to this location. Provided as two comma-separated coordinates in `longitude,latitude` order.",
2926
optional: true,
3027
},
3128
},
3229
async run({ $ }) {
3330
const response = await this.mapbox.geocode({
34-
address: this.address,
35-
boundingBox: this.boundingBox,
36-
proximity: this.proximity,
31+
$,
32+
params: {
33+
q: this.address,
34+
bBox: this.boundingBox,
35+
proximity: this.proximity,
36+
},
3737
});
38-
$.export("$summary", `Geocoded location for address "${this.address}" retrieved successfully`);
38+
$.export("$summary", `Geocoded location for "${this.address}" retrieved successfully`);
3939
return response;
4040
},
4141
};

components/mapbox/app/mapbox.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const TRANSPORTATION_MODES = [
2+
"driving",
3+
"walking",
4+
"cycling",
5+
"driving-traffic",
6+
];
7+
8+
const EXCLUDE_OPTIONS = [
9+
"motorway",
10+
"toll",
11+
"ferry",
12+
"unpaved",
13+
"cash_only_tolls",
14+
"country_border",
15+
"state_border",
16+
];
17+
18+
export default {
19+
TRANSPORTATION_MODES,
20+
EXCLUDE_OPTIONS,
21+
};

0 commit comments

Comments
 (0)