Guide to Retrieve POIs of a Type with Pagination (JS API)
Summary
This supplemental guide provides instructions on how to retrieve all Points of Interest (POIs) of a specific type from a particular campus using the getPoisByTypeIdAndCampusIdAsGeoJSONWithPagination
function from the MazeMap JavaScript API. This function is designed for handling large datasets that exceed the single-response limit by enabling pagination.
This document aims to clarify the correct usage of the function, emphasizing the correct function call format and detailing the pagination process.
This support document is intended to supplement the official MazeMap JS API documentation. For comprehensive details and further guidance, please refer to the MazeMap JS API documentation available at MazeMap JS API Docs.
Skill Level
Intermediate / JavaScript (JS) programming
Basic to intermediate understanding of JavaScript and web development concepts.
Familiarity with handling events and manipulating objects in JavaScript.
Prerequisites
Before you begin, ensure that:
You have integrated the MazeMap JavaScript API into your project.
You are familiar with JavaScript promises and asynchronous operations.
Have a need to visualise any POI’s of a POI Type that exceed 100 POI’s.
Correct Usage of getPoisByTypeIdAndCampusIdAsGeoJSONWithPagination
The function getPoisByTypeIdAndCampusIdAsGeoJSONWithPagination
should be invoked using separate parameters for poiTypeId
& campusId
(and oother variables) contrary to previous examples that suggested passing an object.
Step-by-Step Guide to Retrieve POIs with Pagination
Step 1: Define the Function to Handle POI Retrieval
Start by defining a function to manage the fetching and accumulation of POIs through recursive calls, handling pagination seamlessly.
Example:
function getAllPoisOfType(poiTypeId, campusId) {
let pois = [];
function recursivelyAddPois(res) {
pois = pois.concat(res.geojson.features); // Concatenate features array
if (!res.getNextPage) {
return pois; // Return all POIs if there's no next page
}
// Fetch the next page of POIs if available
return res.getNextPage().then(recursivelyAddPois);
}
return Mazemap.Data.getPoisByTypeIdAndCampusIdAsGeoJSONWithPagination(poiTypeId, campusId).then(recursivelyAddPois);
}
This example function uses .forEach()
to iterate over the features
array from the GeoJSON response, and .push()
to add each item to the pois
array, ensuring that all POIs are retained across pagination.
Troubleshooting
Incorrect Function Call: Ensure the function is called with two separate arguments (
poiTypeId
andcampusId
), not as a single object.Pagination Issues: Make sure to handle the possibility of a
getNextPage
method being part of the response to manage additional data fetching.Data Handling Errors: Verify that the accumulation process is correct and that no POIs are being overwritten during pagination.
Conclusion
Using getPoisByTypeIdAndCampusIdAsGeoJSONWithPagination
properly allows for effective visualisation of POI’s, especially with a Type that has over 100 POIs.
This guide clarifies the function's correct usage and outlines the process for handling pagination, correcting the previously documented inaccuracies and ensuring data integrity through correct array handling.
This support document is intended to supplement the official MazeMap JS API documentation. For comprehensive details and further guidance, please refer to the MazeMap JS API documentation available at MazeMap JS API Docs.