User Manual

Working with the QueryEngine

The Mapzania QueryEngine works side-by-side with the Mapzania Map.

While they have some similarities like the ability to filter features, their distinct difference is that the QueryEngine does not generate any graphic output like the point, line and polygon layers of the Map.

Rather it operates on FeatureCollections from JavaScript objects, layer-sources or map-layers and outputs filtered FeatureCollections.

This can be handy for ad-hoc queries from a map, manipulating a feature-collection or fetching data from a layer-source to manipulate, then add to a layer.

The QueryEngine Object

The QueryEngine Object provides a number of methods for firing-off a query namely:

  • usingFeatureCollection which performs querying and filtering on a client side FeatureCollection object
  • usingLayerSource which performs querying and filtering on a server-side LayerSource
  • usingMapLayer which performs querying and filtering on a layer that has been defined and altered in a Map object.

Example


window.onload = function () {
    var map = new Mapzania.Map("map-div", "LONDON", function () {

        map.addLayer("LOCAL");
        map.setLayerStyle("LOCAL", { 
            fillColor: "#FF0000", 
            size: 8, 
            labelField: "Name" 
       });
    
        map.usingLayer("WARD")
            .filterByText("Like(NAME,'%T%')")
            .update();
    
        var qry = new Mapzania.QueryEngine();
    
        qry.usingMapLayer(map, "WARD")
            .convertToCentroids()
            .apply()
            .then(function (data) {
                console.log(data);
                map.addFeatureCollection("LOCAL", data);
                map.updateLayer("LOCAL");
            });
    
    });
};

The following interactive example shows these methods in action: