@@ -10,35 +10,14 @@ const PropTypes = require('prop-types');
1010const SharingLinks = require ( './SharingLinks' ) ;
1111const Message = require ( '../I18N/Message' ) ;
1212const { Image, Panel, Button, Glyphicon} = require ( 'react-bootstrap' ) ;
13- const { head, memoize, isObject} = require ( 'lodash' ) ;
14- const assign = require ( 'object-assign' ) ;
13+ const { isObject} = require ( 'lodash' ) ;
1514
1615const CoordinatesUtils = require ( '../../utils/CoordinatesUtils' ) ;
1716const ConfigUtils = require ( '../../utils/ConfigUtils' ) ;
17+ const { getRecordLinks, recordToLayer, extractOGCServicesReferences, buildSRSMap, removeParameters} = require ( '../../utils/CatalogUtils' ) ;
1818
1919const defaultThumb = require ( './img/default.jpg' ) ;
2020
21- const buildSRSMap = memoize ( ( srs ) => {
22- return srs . reduce ( ( previous , current ) => {
23- return assign ( previous , { [ current ] : true } ) ;
24- } , { } ) ;
25- } ) ;
26-
27- const removeParameters = ( url , skip ) => {
28- const urlparts = url . split ( '?' ) ;
29- const params = { } ;
30- if ( urlparts . length >= 2 && urlparts [ 1 ] ) {
31- const pars = urlparts [ 1 ] . split ( / [ & ; ] / g) ;
32- pars . forEach ( ( par ) => {
33- const param = par . split ( '=' ) ;
34- if ( skip . indexOf ( param [ 0 ] . toLowerCase ( ) ) === - 1 ) {
35- params [ param [ 0 ] ] = param [ 1 ] ;
36- }
37- } ) ;
38- }
39- return { url : urlparts [ 0 ] , params} ;
40- } ;
41-
4221require ( "./RecordItem.css" ) ;
4322
4423class RecordItem extends React . Component {
@@ -82,38 +61,6 @@ class RecordItem extends React.Component {
8261 document . removeEventListener ( 'click' , this . handleClick , false ) ;
8362 }
8463
85- getLinks = ( record ) => {
86- let wmsGetCap = head ( record . references . filter ( reference => reference . type &&
87- reference . type . indexOf ( "OGC:WMS" ) > - 1 && reference . type . indexOf ( "http-get-capabilities" ) > - 1 ) ) ;
88- let wfsGetCap = head ( record . references . filter ( reference => reference . type &&
89- reference . type . indexOf ( "OGC:WFS" ) > - 1 && reference . type . indexOf ( "http-get-capabilities" ) > - 1 ) ) ;
90- let wmtsGetCap = head ( record . references . filter ( reference => reference . type &&
91- reference . type . indexOf ( "OGC:WMTS" ) > - 1 && reference . type . indexOf ( "http-get-capabilities" ) > - 1 ) ) ;
92- let links = [ ] ;
93- if ( wmsGetCap ) {
94- links . push ( {
95- type : "WMS_GET_CAPABILITIES" ,
96- url : wmsGetCap . url ,
97- labelId : 'catalog.wmsGetCapLink'
98- } ) ;
99- }
100- if ( wmtsGetCap ) {
101- links . push ( {
102- type : "WMTS_GET_CAPABILITIES" ,
103- url : wmtsGetCap . url ,
104- labelId : 'catalog.wmtsGetCapLink'
105- } ) ;
106- }
107- if ( wfsGetCap ) {
108- links . push ( {
109- type : "WFS_GET_CAPABILITIES" ,
110- url : wfsGetCap . url ,
111- labelId : 'catalog.wfsGetCapLink'
112- } ) ;
113- }
114- return links ;
115- } ;
116-
11764 getTitle = ( title ) => {
11865 return isObject ( title ) ? title [ this . props . currentLocale ] || title . default : title || '' ;
11966 } ;
@@ -131,12 +78,10 @@ class RecordItem extends React.Component {
13178 return null ;
13279 }
13380 // let's extract the references we need
134- let wms = head ( record . references . filter ( reference => reference . type && ( reference . type === "OGC:WMS"
135- || reference . type . indexOf ( "OGC:WMS" ) > - 1 && reference . type . indexOf ( "http-get-map" ) > - 1 ) ) ) ;
136- let wmts = head ( record . references . filter ( reference => reference . type && ( reference . type === "OGC:WMTS"
137- || reference . type . indexOf ( "OGC:WMTS" ) > - 1 && reference . type . indexOf ( "http-get-map" ) > - 1 ) ) ) ;
81+ const { wms, wmts} = extractOGCServicesReferences ( record ) ;
13882 // let's create the buttons
13983 let buttons = [ ] ;
84+ // TODO addLayer and addwmtsLayer do almost the same thing and they should be unified
14085 if ( wms ) {
14186 buttons . push (
14287 < Button
@@ -163,9 +108,9 @@ class RecordItem extends React.Component {
163108 </ Button >
164109 ) ;
165110 }
166- // creating get capbilities links that will be used to share layers info
111+ // create get capabilities links that will be used to share layers info
167112 if ( this . props . showGetCapLinks ) {
168- let links = this . getLinks ( record ) ;
113+ let links = getRecordLinks ( record ) ;
169114 if ( links . length > 0 ) {
170115 buttons . push ( < SharingLinks key = "sharing-links" popoverContainer = { this } links = { links }
171116 onCopy = { this . props . onCopy } buttonSize = { this . props . buttonSize } addAuthentication = { this . props . addAuthentication } /> ) ;
@@ -214,33 +159,16 @@ class RecordItem extends React.Component {
214159 } ;
215160
216161 addLayer = ( wms ) => {
217- const { url, params } = removeParameters ( ConfigUtils . cleanDuplicatedQuestionMarks ( wms . url ) , [ "request" , "layer" , "service" , "version" ] . concat ( this . props . authkeyParamNames ) ) ;
162+ const { url} = removeParameters ( ConfigUtils . cleanDuplicatedQuestionMarks ( wms . url ) , [ "request" , "layer" , "service" , "version" ] . concat ( this . props . authkeyParamNames ) ) ;
218163 const allowedSRS = buildSRSMap ( wms . SRS ) ;
219164 if ( wms . SRS . length > 0 && ! CoordinatesUtils . isAllowedSRS ( this . props . crs , allowedSRS ) ) {
220165 this . props . onError ( 'catalog.srs_not_allowed' ) ;
221166 } else {
222- this . props . onLayerAdd ( {
223- type : "wms" ,
224- url : url ,
225- visibility : true ,
226- dimensions : this . props . record . dimensions || [ ] ,
227- name : wms . params && wms . params . name ,
228- title : this . props . record . title || wms . params && wms . params . name ,
229- description : this . props . record . description || "" ,
230- bbox : {
231- crs : this . props . record . boundingBox . crs ,
232- bounds : {
233- minx : this . props . record . boundingBox . extent [ 0 ] ,
234- miny : this . props . record . boundingBox . extent [ 1 ] ,
235- maxx : this . props . record . boundingBox . extent [ 2 ] ,
236- maxy : this . props . record . boundingBox . extent [ 3 ]
237- }
238- } ,
239- links : this . getLinks ( this . props . record ) ,
240- params : params ,
241- allowedSRS : allowedSRS ,
242- catalogURL : this . props . catalogType === 'csw' ? this . props . catalogURL + "?request=GetRecordById&service=CSW&version=2.0.2&elementSetName=full&id=" + this . props . record . identifier : null
243- } ) ;
167+ this . props . onLayerAdd (
168+ recordToLayer ( this . props . record , "wms" , {
169+ url,
170+ catalogURL : this . props . catalogType === 'csw' && this . props . catalogURL ? this . props . catalogURL + "?request=GetRecordById&service=CSW&version=2.0.2&elementSetName=full&id=" + this . props . record . identifier : null
171+ } ) ) ;
244172 if ( this . props . record . boundingBox && this . props . zoomToLayer ) {
245173 let extent = this . props . record . boundingBox . extent ;
246174 let crs = this . props . record . boundingBox . crs ;
@@ -250,33 +178,14 @@ class RecordItem extends React.Component {
250178 } ;
251179
252180 addwmtsLayer = ( wmts ) => {
253- const { url, params } = removeParameters ( ConfigUtils . cleanDuplicatedQuestionMarks ( wmts . url ) , [ "request" , "layer" ] . concat ( this . props . authkeyParamNames ) ) ;
181+ const { url} = removeParameters ( ConfigUtils . cleanDuplicatedQuestionMarks ( wmts . url ) , [ "request" , "layer" ] . concat ( this . props . authkeyParamNames ) ) ;
254182 const allowedSRS = buildSRSMap ( wmts . SRS ) ;
255183 if ( wmts . SRS . length > 0 && ! CoordinatesUtils . isAllowedSRS ( this . props . crs , allowedSRS ) ) {
256184 this . props . onError ( 'catalog.srs_not_allowed' ) ;
257185 } else {
258- this . props . onLayerAdd ( {
259- type : "wmts" ,
260- url : url ,
261- visibility : true ,
262- name : wmts . params && wmts . params . name ,
263- title : this . props . record . title || wmts . params && wmts . params . name ,
264- matrixIds : this . props . record . matrixIds || [ ] ,
265- description : this . props . record . description || "" ,
266- tileMatrixSet : this . props . record . tileMatrixSet || [ ] ,
267- bbox : {
268- crs : this . props . record . boundingBox . crs ,
269- bounds : {
270- minx : this . props . record . boundingBox . extent [ 0 ] ,
271- miny : this . props . record . boundingBox . extent [ 1 ] ,
272- maxx : this . props . record . boundingBox . extent [ 2 ] ,
273- maxy : this . props . record . boundingBox . extent [ 3 ]
274- }
275- } ,
276- links : this . getLinks ( this . props . record ) ,
277- params : params ,
278- allowedSRS : allowedSRS
279- } ) ;
186+ this . props . onLayerAdd ( recordToLayer ( this . props . record , "wmts" , {
187+ url
188+ } ) ) ;
280189 if ( this . props . record . boundingBox && this . props . zoomToLayer ) {
281190 let extent = this . props . record . boundingBox . extent ;
282191 let crs = this . props . record . boundingBox . crs ;
0 commit comments