Spatial APIs

Learn how to enable and query your Mapster WP Maps API endpoints

This is a feature that can help you connect your Wordpress site to other applications, external users, or other management platforms. Mapster has built in a query endpoint that can receive a variety of queries and perform these queries on your spatial database.

Responses will return as a full GeoJSON, with found posts as GeoJSON features.

Endpoint & Query Parameters

The endpoint for your queryable endpoint will be

yourwordpressinstall.com/wp-json/mapster-wp-maps/query

This is a POST endpoint. Available query parameters include:

Parameter
Input Type

category

integer

ID for a Mapster WP Maps category

query_type

string

pip for Point-in-Polygon, polygon-overlap for Polygon Overlap

query_feature

geoJSON feature object

Point or Polygon depending on the query

bounds_only

boolean

Output the whole feature (false) or only the feature bounds (true)

custom_fields

array of strings

An array of the names of Advanced Custom Fields you want to include as feature properties

Example Queries

Point in Polygon

The following query performs a point-in-polygon query on category 8, returning the full feature geoJSONs along with feature properties school_name and activities.

Query

fetch('http://localhost:8888/wp-json/mapster-wp-maps/query', {
    method : "POST",
    body : JSON.stringify({
        "category" : 8, // A Mapster WP Maps Category
        "query_type" : "pip",
        "query_feature" : {
            "type" : "Feature",
            "properties" : {},
            "geometry" : {
                "type" : "Point",
                "coordinates" : [79.804687, 60.930432202923335]
            }
        },
        "bounds_only" : false,
        "custom_fields" : ["school_name", "activities"]
    })
}).then(resp => resp.json()).then(response => {
    console.log(response)
});

Response

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "post_id": "1687",
                "title": "Russia",
                "permalink": "http://localhost:8888/mapster-wp-polygon/russia/",
                "excerpt": "",
                "school_name": null,
                "activities": null
            },
            "geometry": {
                "type": "MultiPolygon",
                "coordinates": [
                    [
                        ...
                    ]
                ]
            }
        }
    ]
}

Polygon Overlap

This will check for intersecting polygons in category 8, and return the full feature geoJSON.

fetch('http://localhost:8888/wp-json/mapster-wp-maps/query', {
    method : "POST",
    body : JSON.stringify({
      "category" : 8,
      "query_type" : "polygon-overlap",
      "query_feature" : {
        "type": "Feature",
        "properties": {},
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [ 
              ...
            ]
          ]
        }
      }
  })
}).then(resp => resp.json()).then(response => {
    console.log(response)
});

Last updated