Query by SQL

SQL Query is based on attributes of the spatial data. SQL Query finds features through operations such as equal to, greater than, smaller than, etc. based on attributes.

This example takes World map as an examples. This example finds all countries whose population and area satisfy certain conditions (Pop_1994>1000000000 and SmArea>900) and add results to the map in vector layer.

var map, local, layer, vectorLayer,
        style = {
            strokeColor: "#304DBE",
            strokeWidth: 1,
            fillColor: "#304DBE",
            fillOpacity: "0.8"
        url = "http://www.supermapol.com/iserver/services/vm3sbiax/rest/maps/World";
var value = "VZ88xbrMEMpGv4yiisTojgVq",
    name = "ak";
SuperMap.Credential.CREDENTIAL = new SuperMap.Credential(value, "ak");

function init(){
    map = new SuperMap.Map("map",{controls: [
        new SuperMap.Control.LayerSwitcher(),
        new SuperMap.Control.ScaleLine(),
        new SuperMap.Control.Zoom(),
        new SuperMap.Control.Navigation({
            dragPanOptions: {
                enableKinetic: true
    layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
    //Define a vector layer to store query results
    vectorLayer = new SuperMap.Layer.Vector("Vector Layer");

function addLayer() {
    map.addLayers([layer, vectorLayer]);
    map.setCenter(new SuperMap.LonLat(0, 0), 0);
function queryBySQL() {

    var queryParam, queryBySQLParams, queryBySQLService;
    //The query condition: Countries whose population and area satisfy ceratain conditions
    queryParam = new SuperMap.REST.FilterParameter({
        name: "Countries@World.1",
        attributeFilter: "Pop_1994>1000000000 and SmArea>900"
    queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
        queryParams: [queryParam]
    //Implement SQL query according to defined condition
    queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
        eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}});
//Return query results and add results to vector layer
function processCompleted(queryEventArgs) {
    var i, j, feature,
            result = queryEventArgs.result;
    if (result && result.recordsets) {
        for (i=0; i<result.recordsets.length; i++) {
            if (result.recordsets[i].features) {
                for (j=0; j<result.recordsets[i].features.length; j++) {
                    feature = result.recordsets[i].features[j];
                    feature.style = style;
function processFailed(e) {
function clearFeatures() {
    //Clear the previous results

Online Demo and Code Editing

You can access complete source code, experience results, and edit source code to see results in real time.