It is often said that plans cannot catch up with changes. Similarly, in the project, the data used is also changing, especially the change of attribute information. For example, the figure on the map, its spatial information in a relatively long period of time, will not change, his property information in the initial incomplete or inconsistent with the information later, you can use Supermap iclient for JavaScript Association query.
So how do you correlate queries? No hurry, let's find the class or interface related to the associated query in IClient for JavaScript first.
First, within the JavaScript client, the query from the distribution of service categories can be divided into two categories, one is based on map service query, one is based on data service query, according to the different query parameters can be divided into SQL, geometry, range, distance, buffer query. Here we will mainly share the query based on the map service.
The base class of query parameters based on map service is SuperMap.REST.QueryParameters, which shows the property interface of the class.
Through the above chart, we can intuitively understand the meaning of each attribute parameter, here does not explain, the main point of the red box is marked by the queryparams of the corresponding query filter condition parameter class –supermap.rest.filterparameter. First, we also look at a chart to see which property interfaces the class contains
Yes, the interface that the associated query is going to use is here. Well, let's study Joinitem and linkitem .
the data set to be queried belongs to the same data source as the external table
SuperMap.REST.JoinItem, connection information class. This class is used to define the connection information of a vector dataset to an external table. An external table can be either a DBMS (database Management system, data management Systems) table for another vector dataset (where there is no spatial geometry information in a purely data set), or a user-built business table. It is important to note that the vector dataset must belong to the same data source as the external table. The names of the fields used to connect two tables are not necessarily the same, but the types must be identical. That is, the same as the integer type, or the same as the character type.
This view of this chart, may feel some cumbersome, then we directly through the following section of code, the intuitive feeling of the use of Joinitem, the code used by the data is iserver bring their own map-world.
1 functionQuerybysql () {2 vectorlayer.removeallfeatures ();3 //setting connection information for external tables4 varjoinitem=NewSuperMap.REST.JoinItem ({5 //name of the external table6Foreigntablename: "Capitals",7 //Establish a connection field between the query data and the external table8Joinfilter: "Capitals.smid = Countries.smid",9 //There are two kinds of connection type one is the left connection ("Leftjoin") two is the equivalent connection ("Innerjoin")TenJoinType: "Leftjoin" One }); A varQueryparam, Querybysqlparams, Querybysqlservice; -Queryparam =NewSuperMap.REST.FilterParameter ({ - //layer name to query theName: "[email protected]", -Attributefilter: "Countries.smid=5", - Joinitems:[joinitem] - //you can set the returned field array to return all property fields without setting it + //fields:[] - }); +Querybysqlparams =NewSuperMap.REST.QueryBySQLParameters ({ A queryparams: [Queryparam] at }); -Querybysqlservice =NewSuperMap.REST.QueryBySQLService (URL, { - eventlisteners: { -"Processcompleted": processcompleted, -"Processfailed": Processfailed}}); - Querybysqlservice.processasync (querybysqlparams); in}
Here we need to remind you that when the external table is also a vector dataset in the data source, do not confuse the Foreigntablename parameter and query parameters queryparam the name of this property, Foreigntablename is the data set name, Instead of the layer name in the map, the external table in the above code is capitals, not [email protected].
After the query succeeds, the figures in the returned results have not only the property information of the figure itself, but also the attribute information contained in the external table.
the data set to be queried belongs to a different data source than the external table
SuperMap.REST.LinkItem Association information class, which defines the association information between a vector dataset and an external table. Constraints using Linkitem: Spatial data and attribute data must have an associated condition, that is, there is an associated field between the primary spatial dataset and the external attribute table. Primary spatial DataSet: the dataset that is used to associate with an external table. The following two charts are the parameter information used by Linkitem.
In the same way, we understand linkitem directly through the code.
1 functionQuerybysql () {2 //sets the associated external database information, alias represents the database alias3 varDC =NewSuperMap.REST.DatasourceConnectionInfo ({4DataBase: "Relquery",5Server: "192.168.168.39",6User: "SA",7Password: "Map",8Driver: "SQL Server",9Connecttrue,TenOpenlinktable:false, OneAlias: "Relquery", A EngineType:SuperMap.REST.EngineType.SQLPLUS, -ReadOnly:false, -Exclusivefalse the }); - //Setting Association information - varLinkitem =NewSuperMap.REST.LinkItem ({ - DATASOURCECONNECTIONINFO:DC, +ForeignKeys: ["Name"], -ForeignTable: "pop_2011", +Linkfields: ["Smid as Pid", "Pop"], AName: "Link", atPrimatrykeys: ["Name"], - }); - //set query parameters, add Linkitem association condition information in query parameters - varQueryparam, Querybysqlparams, Querybysqlservice; -Queryparam =NewSuperMap.REST.FilterParameter ({ -Name: "[email protected]", inFields: ["Smid", "name"], -Attributefilter: "Smid<7", to linkitems: [Linkitem] + }), -Querybysqlparams =NewSuperMap.REST.QueryBySQLParameters ({ the queryparams: [Queryparam] * }), $Querybysqlservice =NewSuperMap.REST.QueryBySQLService (URL, {Panax Notoginseng eventlisteners: { -"Processcompleted": processcompleted, the"Processfailed": processfailed + } A }); the Querybysqlservice.processasync (querybysqlparams); +}
You need to be aware of both the server and driver parameters
In addition to using the Linkitem Association to query data from different data sources, you can actually use Joinitem, at which point you might say that the joinitem described earlier must have conflicts within the same data source. However, when using Joinitem, it is necessary to create a new view within the data source where the dataset is to be queried, so the query is a view, not a table within another data source. So how to create a view, probably a lot of friends already know, here is an example of Oracle database, give you a brief introduction. In the Sqlplus window, enter the following code:
1 // Create or replace a view that is named Link 2 // fields to find 3 from // External Table 4 where // Find condition
Once the view is established, you can use Joinitem to correlate the query directly, see the following code
1 var joinitem=New SuperMap.REST.JoinItem ({2 // fill in the View name 3 // correlation field 4 jointype: "Innerjoin" 5
Here, you have learned how to use Supermap iclient for JavaScript Association queries. Go to your project and practice it.
Supermap iclient for JavaScript Association query