debug("path not array: ".print_r($path, true)); continue; } $path_enc_polyline = self::encodeCoordArrayToPolyline($path); if(!$path_enc_polyline) continue; $path_parts[] = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity+$path_fill_color-$path_fill_opacity($path_enc_polyline)"; } } // build url $url_opt_parts = []; if($pin_part) $url_opt_parts[] = $pin_part; if(count($path_parts)) { foreach($path_parts as $path_part) { $url_opt_parts[] = $path_part; } } if(is_array($url_opt_parts)) { $url .= "/".implode(",", $url_opt_parts); } $url .= "/auto/{$size_x}x{$size_y}?access_token=$access_token"; mfLoghandler::singleton()->debug($url); //exit; $ctx_opts = [ 'http' => [ 'method' => 'GET', 'header' => 'accept: application/json' ] ]; $ctx = stream_context_create($ctx_opts); $response = file_get_contents($url, false, $ctx); if($response === false) { return null; } return $response; } public static function encodeCoordArrayToPolyline($coords, $precision = 5) { //if(!is_array($coords)) return false; $points = []; array_walk_recursive( $coords, function ($current) use (&$points) { $points[] = $current; } ); mfLoghandler::singleton()->debug(__METHOD__.": flattened path: ".print_r($points, true)); $encodedString = ''; $index = 0; $previous = array(0,0); foreach ( $points as $number ) { $number = (float)($number); $number = (int)round($number * pow(10, $precision)); $diff = $number - $previous[$index % 2]; $previous[$index % 2] = $number; $number = $diff; $index++; $number = ($number < 0) ? ~($number << 1) : ($number << 1); $chunk = ''; while ( $number >= 0x20 ) { $chunk .= chr((0x20 | ($number & 0x1f)) + 63); $number >>= 5; } $chunk .= chr($number + 63); $encodedString .= $chunk; } mfLoghandler::singleton()->debug(__METHOD__.": encoded polyline: $encodedString"); return str_replace("?", "%3f", $encodedString); } }