ConstructionConsent: Plan from Mapbox with Rimo coords

This commit is contained in:
Frank Schubert
2025-01-20 13:59:22 +01:00
parent 27cc45e23c
commit 269456eed6
4 changed files with 207 additions and 26 deletions

View File

@@ -37,19 +37,60 @@ class Mapbox_StaticImageApi {
$path_fill_color = $paths["line_fill_color"];
$path_fill_opacity = $paths["line_fill_opacity"];
$path_count = 0;
$initial_path_count = 0;
foreach($paths["coords"] as $path) {
if(!is_array($path)) {
mfLoghandler::singleton()->debug("path not array: ".print_r($path, true));
$initial_path_count++;
//mfLoghandler::singleton()->debug(print_r($paths, true));
$skip_path = false;
// skip if coordinates are outside of 111 meters of middle point
// because mapbox only allows 100 paths max
foreach($path as $coords) {
$lat_less = $gps_lat;
$lat_more = $coords[0];
$long_less = $gps_long;
$long_more = $coords[1];
if($coords[0] < $gps_lat) {
$lat_less = $coords[0];
$lat_more = $gps_lat;
}
if($coords[1] < $gps_long) {
$long_less = $coords[1];
$long_more = $gps_long;
}
mfLoghandler::singleton()->debug(__METHOD__.": lat_more($lat_more) - lat_less($lat_less) = ".($lat_more - $lat_less));
mfLoghandler::singleton()->debug(__METHOD__.": long_more($long_more) - long_less($long_less) = ".($long_more - $long_less));
if($lat_more - $lat_less > 0.0005 || $long_more - $long_less > 0.0005) {
mfLoghandler::singleton()->debug(__METHOD__.": Skipping path");
$skip_path = true;
}
}
if($skip_path) continue;
if(!is_array($path) || !count($path)) {
mfLoghandler::singleton()->debug("path not array or empty: ".print_r($path, true));
continue;
}
$path_enc_polyline = self::encodeCoordArrayToPolyline($path);
if(!$path_enc_polyline) continue;
if($path_count > 99) break;
$path_count++;
$path_parts[] = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity+$path_fill_color-$path_fill_opacity($path_enc_polyline)";
$path_enc_polyline = urlencode(self::encodeCoordArrayToPolyline($path));
//$path_enc_polyline = self::encodeCoordArrayToPolyline($path);
//if(!$path_enc_polyline) continue;
//$pp = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity+$path_fill_color-$path_fill_opacity($path_enc_polyline)"
$pp = "path-$path_stroke_width+$path_stroke_color-$path_stroke_opacity($path_enc_polyline)";
$path_parts[] = $pp;
}
}
mfLoghandler::singleton()->debug(__METHOD__.": path count: $path_count | initial path count: $initial_path_count");
// build url
$url_opt_parts = [];
if($pin_part) $url_opt_parts[] = $pin_part;
@@ -64,7 +105,8 @@ class Mapbox_StaticImageApi {
$url .= "/".implode(",", $url_opt_parts);
}
$url .= "/auto/{$size_x}x{$size_y}?access_token=$access_token";
$url .= "/$gps_long,$gps_lat,$zoom/{$size_x}x{$size_y}?access_token=$access_token";
//$url .= "/auto/{$size_x}x{$size_y}?access_token=$access_token";
mfLoghandler::singleton()->debug($url);
//exit;
@@ -78,6 +120,7 @@ class Mapbox_StaticImageApi {
$ctx = stream_context_create($ctx_opts);
$response = file_get_contents($url, false, $ctx);
//fLoghandler::singleton()->debug(print_r($response, true));
if($response === false) {
return null;
@@ -123,6 +166,7 @@ class Mapbox_StaticImageApi {
mfLoghandler::singleton()->debug(__METHOD__.": encoded polyline: $encodedString");
return str_replace("?", "%3f", $encodedString);
//return str_replace("?", "%3f", $encodedString);
return $encodedString;
}
}