The features Javascript API enables access to your data stored within the MapData Services’ spatial databases.
For testing purposes, developers have access to a limited feature set of POIs (Points Of Interest). Talk to us to gain access to over 20 categories and 52,000 predefined "sets" of locations e.g. fast food outlets, ATM's, Schools.
To get started using this API, you will first need credentials (register here) and then follow this simple step for referencing the API within your JavaScript.
<script type="text/javascript"
src="http://apps.nowwhere.com.au/MDSQuickMap/FeaturesControl.ashx?key=YOUR_API_KEY_HERE">
</script>
Examples
Here's some examples to show how to create spatial queries the features service supports.
Find nearest items to a point
Here's a basic radial search, finding the nearest 5 items to a given point.
var featuresClient = new MapDS.Features.ServiceClient();
var ll = new MapDS.LatLng(-33, 151);
var p = new MapDS.Features.PointsQuery(ll, { buffer: 5000, items: 5, page: 1});
//execute query on service and display result
featuresClient.getFeatures(p, "MyPOIset", function(results) {
alert(results);
});Find nearest items along a line
Our next example, gets a bit more complex. Here we retrieve 5 features this time within a 1000 metre buffer along the line.
var featuresClient = new MapDS.Features.ServiceClient();
var ll = [new MapDS.LatLng(-33.831958,151.186129),
new MapDS.LatLng(-33.831958,151.186129),
new MapDS.LatLng(-33.830477,151.187088),
new MapDS.LatLng(-33.83022,151.187275)];
var p = new MapDS.Features.PointsQuery(ll, { buffer: 1000, items: 5, page: 1});
//execute query on service and display result
featuresClient.getFeatures(p, "MyFeatureSet", function(results) {
alert(results);
});Find items within a bounding box
This next example defines a bounding box and then returns the first 10 items that are either inside or touch the bounding box.
var featuresClient = new MapDS.Features.ServiceClient();
var bb = new MapDS.Bounds(-33, 151, -34, 152);
var p = new MapDS.Features.BBOXQuery(bb, { items: 10, page: 1});
//execute query on service and display result
featuresClient.getFeatures(p, "MyFeatureSet", function(results) {
alert(results);
});Finding features within another feature
If we have already retrieved a feature and have the unique identifier, for example a postcode boundary. We can then make a request to retrieve features within that boundary.
var featuresClient = new MapDS.Features.ServiceClient();
var f = -98473869834; //the postcode boundary
var p = new MapDS.Features.FromFeatureQuery(f, { items: 10, page: 1});
//execute query on service and display result
featuresClient.getFeatures(p, "FastFoodStoresAU", function(results) {
alert(results);
});Using the filter
The filter option allows a query to be further refined using custom query syntax. The filter syntax explains the options available.
For example, if we have a Fast Food POI dataset and you only want to retrieve the features where the name = "McDonald's" or the name = "Hungry Jack's". You would write the following:
var featuresClient = new MapDS.Features.ServiceClient();
var ll = new MapDS.LatLng(-33, 151);
var p = new MapDS.Features.PointsQuery(ll, { buffer: 5000, items: 5, page: 1,
filter:"(company = \"McDonald's\" or company = \"Hungry Jack's\")"});
//execute query on service and display result
featuresClient.getFeatures(p, "MyPOIset", function(results) {
alert(results);
});Retrieving a specified feature
To retrieve an individual feature that you already have the unique identifier for, you can request this using the getFeature method.
var featuresClient = new MapDS.Features.ServiceClient();
var type = "TESTTrafficCamerasAU";
var id = -9223372036854775807;
//execute query on service and display result
featuresClient.getFeature(type, id, function(results) {
alert(results);
});
If you would like to see an example that is missing, please contact mailto:support@mapds.com.au with your suggestion!
Response Format
The format is dependent upon the requested response type.
- JSON, the response is in GeoJSON 1.0 format.
- RSS
- ATOM
- XML
Response (in default GeoJSON format):
{"type":"FeatureCollection",
"features":[{"type":"Feature",
"geometry":{"type":"Point", "coordinates":[151.211941,-33.850258]},
"properties":{
"Country":"AU",
"State":"NSW",
"ExternalUri":"http://www.rta.nsw.gov.au/trafficreports/innersydcameras/harbourbridge.html",
"Postcode":"2000",
"CameraLocation":"Sydney Harbour Bridge",
"DisplayName":"",
"FeatureId":"-9223372036854775807",
"Street":"Bradfield Highway",
"Suburb":"Sydney",
"LastUpdated":"17/09/2009 12:27:42 PM",
"FeatureTypeId":"-2147483648",
"Company":"Roads and Traffic Authority NSW"}}],
"properties":{"total":"1", "items":"1"}
}