1+ /* COPYRIGHT 2017 SUPERMAP
2+ * 本程序只能在有效的授权许可下使用。
3+ * 未经许可,不得以任何手段擅自使用或传播。*/
4+
5+ /**
6+ * Class: SuperMap.REST.ComputeWeightMatrixService
7+ * 耗费矩阵分析服务类。
8+ * 耗费矩阵是根据交通网络分析参数中的耗费字段来计算一个二维数组,
9+ * 用来存储指定的任意两点间的资源消耗。
10+ * 耗费矩阵分析结果通过该类支持的事件的监听函数参数获取
11+ * Inherits from:
12+ * - <SuperMap.CoreServiceBase>
13+ */
14+ require ( './CoreServiceBase' ) ;
15+
16+ SuperMap . REST . ComputeWeightMatrixService = SuperMap . Class ( SuperMap . CoreServiceBase , {
17+
18+ /**
19+ * Constructor: SuperMap.REST.ComputeWeightMatrixService
20+ * 耗费矩阵分析服务类构造函数。
21+ *
22+ * 例如:
23+ * (start code)
24+ * var mycomputeWeightMatrixService = new SuperMap.REST.ComputeWeightMatrixService(url,{
25+ * eventListeners: {
26+ * "processCompleted": computeWeightMatrixCompleted,
27+ * "processFailed": computeWeightMatrixnError
28+ * }
29+ * });
30+ * (end)
31+ *
32+ * Parameters:
33+ * url - {String} 耗费矩阵分析服务地址。请求服务的URL应为:
34+ * http://{服务器地址}:{服务端口号}/iserver/services/{网络分析服务名}/rest/networkanalyst/{网络数据集@数据源 };
35+ * 例如:"http://localhost:8090/iserver/services/components-rest/rest/networkanalyst/RoadNet@Changchun"。
36+ * options - {Object} 参数。
37+ *
38+ * Allowed options properties:
39+ * eventListeners - {Object} 需要被注册的监听器对象。
40+ */
41+
42+ initialize : function ( url , options ) {
43+ SuperMap . CoreServiceBase . prototype . initialize . apply ( this , arguments ) ;
44+ } ,
45+
46+ /**
47+ * APIMethod: destroy
48+ * 释放资源,将引用的资源属性置空。
49+ */
50+ destroy : function ( ) {
51+ SuperMap . CoreServiceBase . prototype . destroy . apply ( this , arguments ) ;
52+ } ,
53+
54+ /**
55+ * APIMethod: processAsync
56+ * 负责将客户端的查询参数传递到服务端。
57+ *
58+ * Parameters:
59+ * params - {<SuperMap.REST.ComputeWeightMatrixParameters>}
60+ */
61+ processAsync : function ( params ) {
62+ if ( ! params ) {
63+ return ;
64+ }
65+ var me = this , jsonObject ,
66+ end = me . url . substr ( me . url . length - 1 , 1 ) ;
67+ me . url = me . url + ( ( end === "/" ) ? "weightmatrix" : "/weightmatrix" ) + ( this . isInTheSameDomain ? ".json?" : ".jsonp?" ) ;
68+ jsonObject = {
69+ parameter : SuperMap . Util . toJSON ( params . parameter ) ,
70+ nodes : me . getJson ( params . isAnalyzeById , params . nodes )
71+ } ;
72+ me . request ( {
73+ method : "GET" ,
74+ params : jsonObject ,
75+ scope : me ,
76+ success : me . serviceProcessCompleted ,
77+ failure : me . serviceProcessFailed
78+ } ) ;
79+ } ,
80+
81+ /**
82+ * Method: getJson
83+ * 将对象转化为JSON字符串。
84+ *
85+ * Parameters:
86+ * isAnalyzeById - {Boolean}
87+ * params - {Array}
88+ *
89+ * Returns:
90+ * {Object} 转化后的JSON字符串。
91+ */
92+ getJson : function ( isAnalyzeById , params ) {
93+ var jsonString = "[" ,
94+ len = params ? params . length : 0 ;
95+
96+ if ( isAnalyzeById === false ) {
97+ for ( var i = 0 ; i < len ; i ++ ) {
98+ if ( i > 0 ) jsonString += "," ;
99+ jsonString += '{"x":' + params [ i ] . x + ',"y":' + params [ i ] . y + '}' ;
100+ }
101+ } else if ( isAnalyzeById == true ) {
102+ for ( var i = 0 ; i < len ; i ++ ) {
103+ if ( i > 0 ) jsonString += "," ;
104+ jsonString += params [ i ] ;
105+ }
106+ }
107+ jsonString += ']' ;
108+ return jsonString ;
109+ } ,
110+
111+ CLASS_NAME : "SuperMap.REST.ComputeWeightMatrixService"
112+ } ) ;
113+
114+ module . exports = function ( url , options ) {
115+ return new SuperMap . REST . ComputeWeightMatrixService ( url , options ) ;
116+ } ;
0 commit comments