WIP 2025-01-16 ConstructionConsent Rimo Plan
This commit is contained in:
@@ -11,6 +11,7 @@ class Mapbox_StaticImageApi {
|
||||
$size_y = $params["size_y"];
|
||||
$style = $params["style"];
|
||||
$pin = $params["pin"];
|
||||
$paths = $params["paths"];
|
||||
|
||||
$pin_part = "";
|
||||
|
||||
@@ -23,12 +24,50 @@ class Mapbox_StaticImageApi {
|
||||
$pin_color = $pin["color"];
|
||||
$pin_icon = $pin["icon"];
|
||||
|
||||
$pin_part .= "/pin-$pin_size";
|
||||
$pin_part .= "pin-$pin_size";
|
||||
if($pin_icon) $pin_part .= "-$pin_icon";
|
||||
$pin_part .= "+$pin_color($pin_gps_long,$pin_gps_lat)";
|
||||
}
|
||||
|
||||
$url .= "$pin_part/$gps_long,$gps_lat,$zoom/{$size_x}x{$size_y}?access_token=$access_token";
|
||||
$path_parts = [];
|
||||
if(is_array($paths) && count($paths)) {
|
||||
$path_stroke_width = $paths["line_width"];
|
||||
$path_stroke_color = $paths["line_color"];
|
||||
$path_stroke_opacity = $paths["line_opacity"];
|
||||
$path_fill_color = $paths["line_fill_color"];
|
||||
$path_fill_opacity = $paths["line_fill_opacity"];
|
||||
|
||||
foreach($paths["coords"] as $path) {
|
||||
if(!is_array($path)) {
|
||||
mfLoghandler::singleton()->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' => [
|
||||
@@ -47,4 +86,43 @@ class Mapbox_StaticImageApi {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user