1
+ <!--********************************************************************
2
+ * Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.
3
+ *********************************************************************-->
4
+ <!DOCTYPE html>
5
+ < html >
6
+
7
+ < head >
8
+ < meta charset ="UTF-8 ">
9
+ < title data-i18n ="resources.title_editFeatureAttachments "> </ title >
10
+ < script type ="text/javascript " src ="../../dist/leaflet/include-leaflet.js "> </ script >
11
+ < style >
12
+ .editPane {
13
+ position : absolute;
14
+ right : 65px ;
15
+ top : 8px ;
16
+ text-align : center;
17
+ background : # FFF ;
18
+ z-index : 1000 ;
19
+ border-radius : 4px ;
20
+ }
21
+
22
+ .attachmentFile {
23
+ width : 225px ;
24
+ }
25
+
26
+ .leaflet-popup-scrollable {
27
+ overflow : auto;
28
+ }
29
+
30
+ .leaflet-popup {
31
+ width : 280px ;
32
+ font-size : 14px ;
33
+ min-height : 100px ;
34
+ max-height : 200px ;
35
+ }
36
+ </ style >
37
+ </ head >
38
+
39
+ < body style =" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0; ">
40
+ < div id ="map " style ="width: 100%;height:100% "> </ div >
41
+ < div class ="panel panel-primary editPane " id ="editPane ">
42
+ < div class ='panel-heading '>
43
+ < h5 class ='panel-title text-center ' data-i18n ="resources.text_editSingle "> </ h5 >
44
+ </ div >
45
+ < div class ='panel-body content file ' style ="padding-bottom: 0; ">
46
+ < input type ='file ' id ="attachmentFile " class ='btn btn-default attachmentFile '
47
+ data-i18n ="[value]resources.btn_addMarker " />
48
+ </ div >
49
+ < div class ='panel-body content '>
50
+ < input id ="getAttachmentsInput " type ='button ' class ='btn btn-default '
51
+ data-i18n ="[value]resources.text_getAttachments " onclick ='getAttachments() ' />
52
+ < input id ="resetFileInput " type ='button ' class ='btn btn-default ' data-i18n ="[value]resources.btn_undoAdd "
53
+ onclick ='resetFile() ' />
54
+ < input id ="commitInput " type ='button ' class ='btn btn-default '
55
+ data-i18n ="[value]resources.text_input_value_submit " onclick ='commit() ' />
56
+ </ div >
57
+ </ div >
58
+ < script type ="text/javascript " include ="bootstrap,widgets.alert " src ="../js/include-web.js "> </ script >
59
+ < script type ="text/javascript ">
60
+ var map , featureId , vectorSource , resultLayer ,
61
+ host = window . isLocal ? window . server : "https://iserver.supermap.io" ,
62
+ baseUrl = host + "/iserver/services/map-world/rest/maps/World" ,
63
+ url = host + "/iserver/services/data-world/rest/data" ,
64
+ fileDom = document . getElementById ( 'attachmentFile' ) ,
65
+ getAttachmentsInputDom = document . getElementById ( 'getAttachmentsInput' ) ,
66
+ resetFileInputDom = document . getElementById ( 'resetFileInput' ) ,
67
+ commitInputDom = document . getElementById ( 'commitInput' ) ,
68
+ file ,
69
+ showPosition ,
70
+ lastTarget ,
71
+ showPosition ;
72
+ map = L . map ( 'map' , {
73
+ preferCanvas : true ,
74
+ crs : L . CRS . EPSG4326 ,
75
+ center : { lon : 0 , lat : 0 } ,
76
+ maxZoom : 18 ,
77
+ zoom : 2
78
+ } ) ;
79
+ new L . supermap . TiledMapLayer ( baseUrl ) . addTo ( map ) ;
80
+
81
+ initFeature ( )
82
+
83
+ function initFeature ( ) {
84
+ setDisabledAndTips ( true , resources . msg_noFeature ) ;
85
+ var sqlParam = new L . supermap . GetFeaturesBySQLParameters ( {
86
+ queryParameter : {
87
+ name : "Countries@World" ,
88
+ attributeFilter : "SMID > 0"
89
+ } ,
90
+ datasetNames : [ "World:Countries" ]
91
+ } ) ;
92
+ new L . supermap . FeatureService ( url ) . getFeaturesBySQL ( sqlParam ) . then ( serviceResult => {
93
+ resultLayer = L . geoJSON ( serviceResult . result . features , {
94
+ onEachFeature : function ( feature , layer ) {
95
+ layer . on ( {
96
+ click : ( e ) => {
97
+ if ( lastTarget ) {
98
+ resultLayer . resetStyle ( lastTarget ) ;
99
+ } ;
100
+ if ( e . target ) {
101
+ lastTarget = e . target ;
102
+ setDisabledAndTips ( false , '' ) ;
103
+ showPosition = e . target . getCenter ( ) ;
104
+ } ;
105
+ featureId = feature . properties . SMID ;
106
+ let layer = e . target ;
107
+ layer . setStyle ( {
108
+ weight : 3 ,
109
+ color : 'red' ,
110
+ dashArray : '' ,
111
+ } )
112
+ }
113
+ } )
114
+
115
+ }
116
+ } ) . addTo ( map )
117
+ } ) ;
118
+ }
119
+ function getAttachments ( ) {
120
+ new L . supermap . DatasetService ( url ) . getDataset ( "World" , "Countries" , function ( serviceResult ) {
121
+ if ( ! serviceResult . result . supportAttachments ) {
122
+ return widgets . alert . showAlert ( resources . msg_notSupportAttachments , false ) ;
123
+ }
124
+ var params = new L . supermap . AttachmentsParameters ( {
125
+ dataSourceName : "World" ,
126
+ dataSetName : "Countries" ,
127
+ featureId : featureId
128
+ } ) ;
129
+ new L . supermap . FeatureService ( url ) . getFeatureAttachments ( params ) . then ( res => {
130
+ results = res . result ;
131
+ let innerHTML = '' ;
132
+ if ( results . length > 0 ) {
133
+ results . forEach ( function ( result ) {
134
+ var link = `${ url } /datasources/${ params . dataSourceName } /datasets/${ params . dataSetName } /features/${ params . featureId } /attachments/${ result . id } ` ;
135
+ innerHTML += resources . text_attachmentFileName + ": " + "<a href=" + link + ">" + result . name + "</a>" + "<br>" ;
136
+ innerHTML += resources . text_attachmentFileType + ": " + result . contentType + "<br>" ;
137
+ innerHTML += resources . text_attachmentFileSize + ": " + result . size / 1024 + " KB" ;
138
+ innerHTML += "<hr>" ;
139
+ } )
140
+ }
141
+ L . popup ( {
142
+ minWidth : 180 ,
143
+ maxWidth : 800 ,
144
+ minHeight : 100 ,
145
+ maxHeight : 200 ,
146
+ } )
147
+ . setLatLng ( showPosition )
148
+ . setContent ( innerHTML || resources . text_noData )
149
+ . openOn ( map ) ;
150
+ } ) ;
151
+ } )
152
+ }
153
+
154
+ function setDisabledAndTips ( disabled , tooltip ) {
155
+ fileDom . disabled = disabled ;
156
+ getAttachmentsInputDom . disabled = disabled ;
157
+ resetFileInputDom . disabled = disabled ;
158
+ commitInputDom . disabled = disabled ;
159
+
160
+ fileDom . setAttribute ( "title" , tooltip ) ;
161
+ getAttachmentsInputDom . setAttribute ( "title" , tooltip ) ;
162
+ resetFileInputDom . setAttribute ( "title" , tooltip ) ;
163
+ commitInputDom . setAttribute ( "title" , tooltip ) ;
164
+ }
165
+ function resetFile ( ) {
166
+ fileDom . value = '' ;
167
+ file = null ;
168
+ }
169
+ function commit ( ) {
170
+ new L . supermap . DatasetService ( url ) . getDataset ( "World" , "Countries" , function ( serviceResult ) {
171
+ if ( ! serviceResult . result . supportAttachments ) {
172
+ return widgets . alert . showAlert ( resources . msg_notSupportAttachments , false ) ;
173
+ } ;
174
+ file = fileDom . files [ 0 ] ;
175
+ if ( file ) {
176
+ var params = new L . supermap . EditAttachmentsParameters ( {
177
+ dataSourceName : "World" ,
178
+ dataSetName : "Countries" ,
179
+ featureId : featureId ,
180
+ file : file ,
181
+ editType : 'add'
182
+ } ) ;
183
+ new L . supermap . FeatureService ( url ) . editFeatureAttachments ( params ) . then ( serviceResult => {
184
+ resetFile ( ) ;
185
+ return widgets . alert . showAlert ( resources . msg_submitSuccess , true ) ;
186
+ } ) ;
187
+ } else {
188
+ return widgets . alert . showAlert ( resources . msg_noAttachment , false ) ;
189
+ }
190
+ } )
191
+ }
192
+
193
+ </ script >
194
+ </ body >
195
+
196
+ </ html >
0 commit comments