nnngrach / strava_auto_auth

Node.JS: Script for scraping Strava authorization cookies
30 stars 6 forks source link

Version with Basemap? #1

Open rkantos opened 5 years ago

rkantos commented 5 years ago

Is it possible to get a version with basemap and labels like this? https://www.strava.com/heatmap#13.06/2.32788/48.84984/gray/ride

Thanks!

Luen commented 3 years ago

You could run the following php script on your own server which outputs these tiles: Custom Tiles

Here's the Strava tile for comparison: Strava heatmap grey tile

Tweak the code to suit your style.

<?php //For Personal Use

//error_reporting(0); // DISABLE ERRORS

parse_str($_SERVER['QUERY_STRING']); // parse query string

// check query for abuse
if (!isset($z) || !isset($x) || !isset($y) || !is_numeric($z) || $z <= 4 || $z > 16 || !is_numeric($x) || !is_numeric($y)) { // Limit zoom to level 16
   die(http_response_code(404));
}

$seconds_to_cache = 3600 * 24 * 7; // browser cache only for 7 days - Cache browser results temporarily
$ts = gmdate("D, d M Y H:i:s", time()+$seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");
header('Content-type: image/png');

$lablesURL = "https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/".$z."/".$y."/".$x;
//if ($z < 12) {
//  $heatmapURL = "https://heatmap-external-a.strava.com/tiles/ride/grey/".$z."/".$x."/".$y.".png?px=265"; // displays normal hot mode
//} else {
  //$heatmapURL = "https://anygis.ru/api/v1/Tracks_Strava_Ride_Gray/".$x."/".$y."/".$z;
  $heatmapURL = "https://heatmap-external-a.strava.com/tiles-auth/ride/gray/".$z."/".$x."/".$y.".png?px=256&Signature=hBtkUuRYtcZzCCeRMKr103r-fID-t8yXkCP6JwjaDVnJkVTkRhrYAJ8AJ2793xKGjllRdFCesnugkKHOoaF~aBLvENxvpjrFXrVoeE0WL0JehEY5Ng8htSaAPWk75mJUJa-RHKZq5uX-oO05f4VWFLg7yLWR2akjGDa72NjCnMhFUh-1ar0VxtzhyquhFAx49N8P~0BTW2U~mYDwBSTys7lxKz2~b5J8c41Ss9g3U-WoJHcR7T5sgIWboZrePljbvHMmnK2kfPwOQJHk4-7tSN1CHRmavIbHYPTU6e9zdN7sNnozyLNrGnH0El6tEJR3ijdtHoHtGE-rgir3aXAG4w__&Key-Pair-Id=APKAIDPUN4QMG7VUQPSA&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHBzOi8vaGVhdG1hcC1leHRlcm5hbC0qLnN0cmF2YS5jb20vKiIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTYwNjk4NDQ4M30sIkRhdGVHcmVhdGVyVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNjA1NzYwNDgzfX19XX0_";
//}
$basemapURL = "https://a.basemaps.cartocdn.com/light_nolabels/".$z."/".$x."/".$y.".png";
//$basemapURL = "https://a.basemaps.cartocdn.com/rastertiles/voyager_nolabels/".$z."/".$x."/".$y.".png";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $lablesURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$lables = imagecreatefromstring($data);
//die(imagepng($lables));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $heatmapURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$heatmap = imagecreatefromstring($data);
//die(imagepng($heatmap));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $basemapURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$basemap = imagecreatefromstring($data);
//die(imagepng($basemap));

imagealphablending($lables, true);
imagesavealpha($lables, true);
imagealphablending($heatmap, true);
imagesavealpha($heatmap, true);

imagecopymerge_alpha($basemap, $heatmap, 0, 0, 0, 0, 256, 265, 75);
imagecopymerge_alpha($basemap, $lables, 0, 0, 0, 0, 256, 265, 75);

die(imagepng($basemap));

function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
    // creating a cut resource
    $cut = imagecreatetruecolor($src_w, $src_h);

    // copying relevant section from background to the cut resource
    imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);

    // copying relevant section from watermark to the cut resource
    imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);

    // insert cut resource to destination image
    imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}

?>