From 101493b39fa576b7893bdda9eabe73a7249e836c Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Thu, 1 Aug 2019 11:41:32 -0400 Subject: [PATCH] Working on lat/lon parameter filter processing on pointsofinterest route --- setup/routes/pointsOfInterest.php | 116 ++++++++++++++++-------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/setup/routes/pointsOfInterest.php b/setup/routes/pointsOfInterest.php index 417f6d0..53a7d1b 100644 --- a/setup/routes/pointsOfInterest.php +++ b/setup/routes/pointsOfInterest.php @@ -57,66 +57,74 @@ class GLMA_POI_Rest_Controller $this->resource_name , // resource_name array( // array of arrays for multiple methods. Add more arrays for different endpoints. array( // endpoint for getting members - 'methods' => WP_REST_Server::CREATABLE, + 'methods' => WP_REST_Server::READABLE, 'callback' => function( $request ) { // Callback function can be a lot shorter. // You could just create a new model to get the results in an array // and use return rest_ensure_response( $data ); // Check if there's new area at the top of the map - // if ($latMax > $lastLatMax) { - // $poiAreas[] = array( - // 'area' => 'New at top', - // 'latMax' => $latMax, - // 'latMin' => $lastLatMax, - // 'lonMax' => $lonMax, - // 'lonMin' => $lonMin - // ); - // } - - // // Check if there's new area at the bottom of the map - // if ($latMin < $lastLatMin) { - // $poiAreas[] = array( - // 'area' => 'New at bottom', - // 'latMax' => $lastLatMin, - // 'latMin' => $latMin, - // 'lonMax' => $lonMax, - // 'lonMin' => $lonMin - // ); - // } - - // // Check if there's new area at the left of the map - // if ($lonMin < $lastLonMin) { - // $poiAreas[] = array( - // 'area' => 'New at left', - // 'latMax' => $latMax, - // 'latMin' => $latMin, - // 'lonMax' => $lastLonMin, - // 'lonMin' => $lonMin - // ); - // } - - // // Check if there's new area at the right of the map - // if ($lonMax > $lastLonMax) { - // $poiAreas[] = array( - // 'area' => 'New at right', - // 'latMax' => $latMax, - // 'latMin' => $latMin, - // 'lonMax' => $lonMax, - // 'lonMin' => $lastLonMax - // ); - // } - // $poiData = apply_filters( - // 'glm-hook-list-map-items-by-latlon', - // array( - // 'request' => $request, - // 'filter' => $searchText, - // 'area' => $poiAreas, - // 'sources' => array(), - // 'mapItems' => array() - // ) - // ); + if ($latMax > $lastLatMax) { + $poiAreas[] = array( + 'area' => 'New at top', + 'latMax' => $latMax, + 'latMin' => $lastLatMax, + 'lonMax' => $lonMax, + 'lonMin' => $lonMin + ); + } + + // Check if there's new area at the bottom of the map + if ($latMin < $lastLatMin) { + $poiAreas[] = array( + 'area' => 'New at bottom', + 'latMax' => $lastLatMin, + 'latMin' => $latMin, + 'lonMax' => $lonMax, + 'lonMin' => $lonMin + ); + } + + // Check if there's new area at the left of the map + if ($lonMin < $lastLonMin) { + $poiAreas[] = array( + 'area' => 'New at left', + 'latMax' => $latMax, + 'latMin' => $latMin, + 'lonMax' => $lastLonMin, + 'lonMin' => $lonMin + ); + } + + // Check if there's new area at the right of the map + if ($lonMax > $lastLonMax) { + $poiAreas[] = array( + 'area' => 'New at right', + 'latMax' => $latMax, + 'latMin' => $latMin, + 'lonMax' => $lonMax, + 'lonMin' => $lastLonMax + ); + } + $poiData = apply_filters( + 'glm-hook-list-map-items-by-latlon', + array( + 'request' => $request, + // 'filter' => $searchText, + 'area' => $poiAreas, + 'sources' => array(), + 'mapItems' => array() + ) + ); + + $this->params = $request->get_params(); + $test = json_encode($request['latMax']); - return rest_ensure_response( $test ); + $response['params'] = $this->params; + $response['poiData'] = $poiData; + $response['poiAreas'] = $poiAreas; + + return rest_ensure_response( $response ); + //return rest_ensure_response( get_object_vars ( (object) $response ) ); }, ) ) -- 2.17.1