Last active
July 6, 2019 17:18
-
-
Save evmcheb/29a867264016d7707611d0aa3114d108 to your computer and use it in GitHub Desktop.
Nodejs functions for sending static mapbox images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const apiEndpoint = "https://api.mapbox.com"; | |
const accessToken="?access_token=[redacted]"; | |
function sendPostcodeCameras(recipientID, postcode){ | |
const no_cache = (Math.random() * (0.0005 - 0.0001) + 0.0001) | |
const suburbLat = (postcodes[postcode]["lat"] + no_cache).toFixed(4) | |
const suburbLon = (postcodes[postcode]["lon"] + no_cache).toFixed(4) | |
const allUrl = `/styles/v1/cheb/cjxmvvcys26wx1cogeo3ybh7j/static/${suburbLon},${suburbLat},12,0,0/1000x1000@2X`; | |
console.log(apiEndpoint+allUrl+accessToken); | |
var messageData = { | |
recipient: { | |
id:recipientID | |
}, | |
message: { | |
attachment: { | |
type:"image", | |
payload: { | |
url: apiEndpoint+allUrl+accessToken | |
} | |
} | |
} | |
}; | |
callSendAPI(messageData); | |
} | |
function sendAllCameras(recipientId){ | |
const no_cache = (Math.random() * (0.0005 - 0.0001) + 0.0001) | |
const perthLat = (-31.9506 + no_cache).toFixed(4) | |
const perthLon = (115.8605 + no_cache).toFixed(4) | |
const allUrl = `/styles/v1/cheb/cjxmvvcys26wx1cogeo3ybh7j/static/${perthLon},${perthLat},11,0,0/800x1000@2X`; | |
console.log(apiEndpoint+allUrl+accessToken); | |
var messageData = { | |
recipient: { | |
id:recipientId | |
}, | |
message: { | |
attachment: { | |
type:"image", | |
payload: { | |
url: apiEndpoint+allUrl+accessToken | |
} | |
} | |
} | |
}; | |
callSendAPI(messageData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment