Data Query on Server

The data querying function of iMobile components products is based on SuperMap iServer Rest data service. The query results of the server need to return by the way of Featureset elements set. Users need to set the response callback function, through the callback function, getting the operation results and server response, etc.

Based on the Changchun map service built in the first chapter, this section will elaborate the detailed process of querying data, by using iMobile to realize the interaction of mobile terminal and SuperMap iServer server-side.

First step: Visiting map service, and adding it to map window in the way of layer

private boolean openMap(){
    m_woWorkspace = new Workspace();
	// Associating the map displaying controls with work space     
    m_mapView = (MapView)findViewById(R.id.mapview);
    m_mapControl = m_mapView.getMapControl();
    m_mapControl.getMap().setWorkspace(m_woWorkspace);
    DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
	dsInfo.setServer("http://localhost:8090/iserver/services/map-Changchun/rest/maps/ city map of Changchun ");
    dsInfo.setEngineType(EngineType.Rest);
    dsInfo.setAlias("ChinaRest");
    Datasource ds = m_woWorkspace.getDatasources().open(dsInfo);
    if(ds != null){
        m_mapControl.getMap().getLayers().add(ds.getDatasets().get(0), true);
        m_mapControl.getMap().refresh();
        return true;
    }
    Log.e(this.getClass().getName(), " open data source failed ");
    return true;
}

Second step: Querying server-side data

private void Query() {
    m_mapView.removeAllCallOut();
    final ProgressDialog progress = new ProgressDialog(MainFrame.this);
	// Constructing querying service object Queryservice
	m_strServer ="http://localhost:8090/iserver";
	QueryService service = new QueryService(m_strServer);
	// Constructing querying service object ServiceQueryParameter
    ServiceQueryParameter parameter = new ServiceQueryParameter();
    // Setting querying parameter
    parameter.setQueryMapName(m_edtMapName.getText().toString());
    parameter.setQueryServiceName(m_edtServerName.getText().toString());
    parameter.setQueryLayerName(m_edtLayerName.getText().toString());      
    parameter.setExpectRecordCount(100);
    parameter.setQueryRecordStart(0);
    parameter.setQueryOption(QueryOption.GEOMETRY);
    parameter.setAttributeFilter(m_edtSql.getText().toString());
    service.setResponseCallback(new ResponseCallback() {
		@Override
		//The response callback function, is to call back when failing to request to the server
		public void requestSuccess() {
			// Destroying the progress showing bar
			progress.dismiss();
			Toast.makeText(MainFrame.this, " query successfully ", Toast.LENGTH_LONG).show();
		}
		@Override
		//The response callback function, is to call back when failing to request to the server
		public void requestFailed(String arg0) {
			// Destroying the progress showing bar
			progress.dismiss();
			Toast.makeText(MainFrame.this, " query failed ", Toast.LENGTH_LONG).show();
			System.out.println(" error information " + arg0);
		}
		@Override
		//The response callback function, is to call back when receiving response results of the server
		public void receiveResponse(FeatureSet arg0) {
			if (arg0 instanceof FeatureSet) {
				FeatureSet featureSet = (FeatureSet)arg0;
				int nCount = 0;
				featureSet.moveFirst();
				while (!featureSet.isEOF()) {
					Geometry geo = featureSet.getGeometry();
					if (geo == null) {
						featureSet.moveNext();
						continue;
					}
					nCount++;
					Point2D pt = featureSet.getGeometry().getInnerPoint();
					LayoutInflater lfCallOut = getLayoutInflater();
					View calloutLayout = lfCallOut.inflate(R.layout.callout, null);
					CallOut callout = new CallOut(MainFrame.this);
					// Setting display contents
					callout.setContentView(calloutLayout);             
					// Setting custom background photos
					callout.setCustomize(true);
					// Setting displaying location
					callout.setLocation(pt.getX(), pt.getY());             
					m_mapView.addCallout(callout);
					featureSet.moveNext();
				}
				System.out.println("count is " + nCount);
				System.out.println("featureSet count is " + featureSet.getFeatureCount());
			}          
		}
        // Displaying the progress bar of querying service, destroyed inside the callback
        progress.setMessage(" querying service ...");
        progress.show();
        // Executing query operation
        service.query(parameter, QueryMode.SqlQuery);
	}
}