@@ -69,9 +69,9 @@ const groupGLLayer = new maptalks.GroupGLLayer("gl", [layer], {
6969 type : "lit"
7070 } ,
7171 symbol : {
72- polygonOpacity : 1 ,
72+ polygonOpacity : 0.6 ,
7373 material : {
74- baseColorFactor : [ 0.48235 , 0.48235 , 0.48235 , 1 ] ,
74+ baseColorFactor : [ 0.48235 , 0.48235 , 0.48235 , 0.8 ] ,
7575 hsv : [ 0 , 0 , - 0.532 ] ,
7676 roughnessFactor : 0.22 ,
7777 metallicFactor : 0.58
@@ -80,36 +80,70 @@ const groupGLLayer = new maptalks.GroupGLLayer("gl", [layer], {
8080 }
8181 }
8282} ) . addTo ( map ) ;
83+ const polygonLayer = new maptalks . PolygonLayer ( 'polygonlayer' ) . addTo ( groupGLLayer ) ;
84+ function AddPipeLine ( ) {
85+ const style = {
86+ style : [
87+ {
88+ filter : true ,
89+ renderPlugin : {
90+ dataConfig : {
91+ type : "round-tube" ,
92+ radialSegments : 16 ,
93+ metric : "cm" ,
94+ } ,
95+ sceneConfig : { } ,
96+ type : "tube" ,
97+ } ,
98+ symbol : {
99+ lineColor : {
100+ type : 'identity' ,
101+ property : 'type'
102+ } ,
103+ lineWidth : {
104+ type : 'identity' ,
105+ property : 'width'
106+ } ,
107+ metallicFactor : 1 ,
108+ roughnessFactor : 0.3 ,
109+ } ,
110+ } ,
111+ ] ,
112+ } ;
113+ const pipeline = new maptalks . GeoJSONVectorTileLayer ( "vt" , {
114+ geometryEvents : false ,
115+ data : "{res}/geojson/pipeline.geojson" ,
116+ style,
117+ } ) ;
118+ pipeline . addTo ( groupGLLayer ) ;
119+ }
83120
84121/**start**/
85- let excavateAnalysis = null ;
86- const urlMap = {
122+ const textureMap = {
87123 ground : "{res}/images/ground.jpg" ,
88124 brick : "{res}/images/brick.png"
89125} ;
90126layer . once ( "loadtileset" , ( e ) => {
91127 const extent = layer . getExtent ( e . index ) ;
92128 map . fitExtent ( extent , 1 , { animation : false } ) ;
93- const boundary = [
94- [ 108.95888623345706 , 34.220502132776204 ] ,
95- [ 108.9582019833017 , 34.21987192350153 ] ,
96- [ 108.95866479224173 , 34.21879554904879 ] ,
97- [ 108.95976365662978 , 34.21870809810403 ] ,
98- [ 108.96043811487289 , 34.219454268264116 ] ,
99- [ 108.96030941797153 , 34.2204038033789 ]
129+ AddPipeLine ( ) ;
130+ currentBoundary = [
131+ [ 108.95865940298586 , 34.220313399352875 , 28.80102335256866 ] ,
132+ [ 108.95800903947134 , 34.219513250141034 , 19.39458248077016 ] ,
133+ [ 108.9590190943693 , 34.218511956616425 , 34.85025747659524 ] ,
134+ [ 108.96027856333137 , 34.21884767081414 , 11.344320208363127 ] ,
135+ [ 108.96067915752451 , 34.21973628032711 , 29.715621078772948 ] ,
136+ [ 108.96067997002967 , 34.21974168369681 , 29.741613094044347 ] ,
137+ [ 108.95865940298586 , 34.220313399352875 , 28.80102335256866 ]
100138 ] ;
101- excavateAnalysis = new maptalks . ExcavateAnalysis ( {
102- boundary,
103- textureUrl : urlMap [ "ground" ] ,
104- height : 5
105- } ) . addTo ( groupGLLayer ) ;
139+ ExcavateAnalysis ( currentBoundary , 0 ) ;
106140} ) ;
107141
108142const vLayer = new maptalks . VectorLayer ( "vector" , {
109143 enableAltitude : true
110144} ) . addTo ( map ) ;
111145
112- let coordinates = [ ] ,
146+ let coordinates = [ ] , currentBoundary = null , currentBottomTexture = null , currentSideTexture = null ,
113147 first = true ;
114148const drawTool = new maptalks . DrawTool ( {
115149 mode : "LineString" ,
@@ -165,18 +199,47 @@ drawTool.on("drawend", () => {
165199 coordinates . push ( coordinates [ 0 ] ) ;
166200 new maptalks . LineString ( coordinates , {
167201 symbol : {
168- lineColor : "#f00"
202+ lineColor : "#aa0" ,
203+ lineWidth : 1
169204 }
170205 } ) . addTo ( vLayer ) ;
171- excavateAnalysis . update ( "boundary" , coordinates ) ;
206+ console . log ( coordinates ) ;
207+ ExcavateAnalysis ( coordinates , 0 , currentBottomTexture , currentSideTexture ) ;
208+ currentBoundary = coordinates ;
172209 coordinates = [ ] ;
173210} ) ;
174211
175212function getPickedCoordinate ( coordinate ) {
176- const identifyData = groupGLLayer . identify ( coordinate ) [ 0 ] ;
213+ const identifyData = groupGLLayer . identify ( coordinate , { orderByCamera : true } ) [ 0 ] ;
177214 return ( identifyData && identifyData . coordinate ) || coordinate ;
178215}
179216
217+ function ExcavateAnalysis ( coordinates , height , bottomTexture , sideTexture ) {
218+ polygonLayer . clear ( ) ;
219+ let bottomCoords = [ ] ;
220+ for ( let i = 0 ; i < coordinates . length - 1 ; i ++ ) {
221+ const coord1 = coordinates [ i ] , coord2 = coordinates [ i + 1 ] , coord3 = [ coord2 [ 0 ] , coord2 [ 1 ] , height ] , coord4 = [ coord1 [ 0 ] , coord1 [ 1 ] , height ] ;
222+ const extrudeCoordinates = [ coord1 , coord2 , coord3 , coord4 , coord1 ] ;
223+ bottomCoords [ i ] = [ coordinates [ i ] [ 0 ] , coordinates [ i ] [ 1 ] , height ] ;
224+ new maptalks . Polygon ( extrudeCoordinates , {
225+ symbol : {
226+ polygonFill : '#770' ,
227+ polygonPatternFile : sideTexture
228+ }
229+ } ) . addTo ( polygonLayer ) ;
230+ }
231+ const idx = coordinates . length - 1 ;
232+ bottomCoords [ coordinates . length - 1 ] = [ coordinates [ idx ] [ 0 ] , coordinates [ idx ] [ 1 ] , height ] ;
233+ const p = new maptalks . Polygon ( bottomCoords , {
234+ symbol : {
235+ polygonFill : '#aa0' ,
236+ polygonPatternFile : bottomTexture
237+ }
238+ } ) . addTo ( polygonLayer ) ;
239+ const mask = new maptalks . ClipInsideMask ( coordinates ) ;
240+ layer . setMask ( [ mask ] ) ;
241+ }
242+
180243const gui = new mt . GUI ( ) ;
181244
182245gui
@@ -199,15 +262,44 @@ gui
199262 step : 1
200263 } )
201264 . onChange ( ( value ) => {
202- excavateAnalysis . update ( "height" , value ) ;
265+ ExcavateAnalysis ( currentBoundary , value , currentBottomTexture , currentSideTexture ) ;
203266 } ) ;
204267
205268gui
206269 . add ( {
207270 type : "select" ,
208- label : "挖方纹理 " ,
209- value : "ground" ,
271+ label : "底面纹理 " ,
272+ value : 'null' ,
210273 options : [
274+ {
275+ label : '无纹理' ,
276+ value : 'null'
277+ } ,
278+ {
279+ label : "地面" ,
280+ value : "ground"
281+ } ,
282+ {
283+ label : "砖块" ,
284+ value : "brick"
285+ }
286+ ]
287+ } )
288+ . onChange ( ( value ) => {
289+ currentBottomTexture = textureMap [ value ] ;
290+ ExcavateAnalysis ( currentBoundary , value , currentBottomTexture , currentSideTexture ) ;
291+ } ) ;
292+
293+ gui
294+ . add ( {
295+ type : "select" ,
296+ label : "侧边纹理" ,
297+ value : 'null' ,
298+ options : [
299+ {
300+ label : '无纹理' ,
301+ value : 'null'
302+ } ,
211303 {
212304 label : "地面" ,
213305 value : "ground"
219311 ]
220312 } )
221313 . onChange ( ( value ) => {
222- excavateAnalysis . update ( "textureUrl" , urlMap [ value ] ) ;
314+ currentSideTexture = textureMap [ value ] ;
315+ ExcavateAnalysis ( currentBoundary , value , currentBottomTexture , currentSideTexture ) ;
223316 } ) ;
224317/**end**/
0 commit comments