class Condition


The Condition class is a wrapper around the powerful Maptimize Query Language (MQL), it allows to easily build conditions from UI controls state.

When a condition is given to MapController#setCondition, only points matching this condition will be retrieved and displayed on the map when performing a request.

The Big Picture

In this example, points represent real estate.

var condition = new com.maptimize.Condition({ country: $("country").value })
  .appendAnd(["rooms_count > ?", parseInt($("minimum_rooms").value)])
  .appendAnd(["rooms_count < ?", parseInt($("maximum_rooms").value)]);
 if ($("with_garden").checked) {
  condition.appendAnd({ garden: true });
} else if ($("without_garden").checked) {
  condition.appendAnd({ garden: false });
// => 'country = "Spain" AND rooms_count > 3 AND rooms_count < 5 AND garden = true'
 // Assign the condition to the map and refresh markers and clusters.

Condition creation

Condition objects can be assembled in two forms : either with a JavaScript object whose properties represent points properties and expected values, or with an array containing the query string with placeholders as first element, followed by values for interpolation. Given values are sanitized to avoid query injection from user input.

Object form

The JavaScript object:

{ firstName: "Bob", single: true }

yields the following condition string:

'firstName = "Bob" AND single = true'

Array form: string interpolation

When an array is used as argument, its first element represents the query string where question marks (?) will be interpolated by values of following elements. The string "name LIKE ? AND category IN ?" expects 2 values for interpolation, hence the array will have 3 elements.

new Condition(["name LIKE ? AND category IN ?", "mapti", ["geo", "web"]]).toString()
// => 'name LIKE "mapti" AND category IN ["geo", "web"]'

Escape question mark with an antislash character (\?) to insert a question mark without interpolation.

new Condition(['language = ? AND title LIKE "\\?"', "en"]).toString();
// => 'language = "en" AND title LIKE "?"'


Instance methods