@@ -27,6 +27,8 @@ import { MapService } from 'src/app/services/map.service';
2727import { Message } from '@angular/compiler/src/i18n/i18n_ast' ;
2828import { ReadOptions } from 'src/app/home/map/readoptions' ;
2929import { environment } from 'src/environments/environment' ;
30+ import { SearchComponent } from './search/search.component' ;
31+ import { AppCostants } from 'src/app/app-costants' ;
3032
3133
3234@Component ( {
@@ -74,7 +76,7 @@ export class MapComponent implements OnInit {
7476 ngOnInit ( ) {
7577
7678 // definisco i layers
77- this . beVectSource = new VectorSource ( { format : this . geoJsonFormat } ) ;
79+ this . beVectSource = new VectorSource ( { format : this . geoJsonFormat } ) ;
7880 this . feVectorLayer = new VectorLayer ( { source : this . vectSource , style : this . markerStyle , renderBuffer : 200 } ) ;
7981 this . beVectorLayer = new VectorLayer ( { source : this . beVectSource , style : this . markerStyle } ) ;
8082 this . feImageLayer = new ImageLayer ( {
@@ -106,7 +108,9 @@ export class MapComponent implements OnInit {
106108 } ) ;
107109 this . addEventsControlToMap ( ) ;
108110 this . addButtonOrotophoto ( ) ;
109- this . getBePoints ( ) ;
111+ this . addButtonRicerca ( ) ;
112+ this . addButtonExitSearch ( ) ;
113+ this . getBeUserPoints ( ) ;
110114 }
111115
112116
@@ -118,19 +122,21 @@ export class MapComponent implements OnInit {
118122 this . map . on ( 'click' , ( e : MapBrowserEvent ) => {
119123 this . map . forEachFeatureAtPixel ( e . pixel , ( feature : Feature ) => {
120124 console . log ( feature ) ;
121- this . mapService . getLocationById ( feature . getId ( ) as number ) . subscribe (
122- ( data : VgiPoint ) => {
123- if ( ! ( data instanceof Message ) ) {
124- const dialogConf : MatDialogConfig = this . getDialogConfig ( e . pixel , 'Modifica posizione' , data , false ) ;
125- const dialogRef : MatDialogRef < AddpointComponent > = this . dialogService . openDialog ( AddpointComponent , dialogConf ) ;
126- const pointSubscription = dialogRef . componentInstance . pointEvent . subscribe (
127- ( ) => {
128- this . getBePoints ( ) ;
129- pointSubscription . unsubscribe ( ) ;
130- } ) ;
131- }
132- } ,
133- ) ;
125+ if ( ! feature . getId ( ) . toString ( ) . startsWith ( AppCostants . unselectablePointId ) ) {
126+ this . mapService . getLocationById ( feature . getId ( ) as number ) . subscribe (
127+ ( data : VgiPoint ) => {
128+ if ( ! ( data instanceof Message ) ) {
129+ const dialogConf : MatDialogConfig = this . getDialogConfig ( e . pixel , 'Modifica posizione' , data , false ) ;
130+ const dialogRef : MatDialogRef < AddpointComponent > = this . dialogService . openDialog ( AddpointComponent , dialogConf ) ;
131+ const pointSubscription = dialogRef . componentInstance . pointEvent . subscribe (
132+ ( ) => {
133+ this . getBeUserPoints ( ) ;
134+ pointSubscription . unsubscribe ( ) ;
135+ } ) ;
136+ }
137+ } ,
138+ ) ;
139+ }
134140 }
135141 ) ;
136142 }
@@ -150,30 +156,49 @@ export class MapComponent implements OnInit {
150156 const dialogConfig : MatDialogConfig = this . getDialogConfig ( pixels , 'Salva posizione' , pointVgi , true ) ;
151157 const dialogRef : MatDialogRef < AddpointComponent > = this . dialogService . openDialog ( AddpointComponent , dialogConfig ) ;
152158 const pointSubscription = dialogRef . componentInstance . pointEvent . subscribe ( ( ) => {
153- this . getBePoints ( ) ;
159+ this . getBeUserPoints ( ) ;
154160 pointSubscription . unsubscribe ( ) ;
155161 }
156162 ) ;
157163 } ) ;
158164 }
159165
160- getBePoints ( ) {
166+ getBeUserPoints ( ) {
161167 this . removeAllMarkers ( ) ;
162168 this . beVectSource . clear ( ) ;
163169 this . mapService . getUserLocations ( ) . subscribe (
164170 ( data : VgiPoint [ ] ) => {
165171 if ( data instanceof Array ) {
172+ const features : Feature [ ] = [ ] ;
166173 for ( const point of data as VgiPoint [ ] ) {
167174 const feature : Feature = this . geoJsonFormat . readFeature ( point . location , new ReadOptions ( this . map ) ) ;
168175 feature . setStyle ( this . getStyle ( point . legenda . colore ) ) ;
169176 feature . setId ( point . id ) ;
170- this . beVectSource . addFeature ( feature ) ;
177+ features . push ( feature ) ;
171178 }
179+ this . beVectSource . addFeatures ( features ) ;
172180 }
173181 } ,
174182 ) ;
175183 }
176184
185+ getSearchedPoints ( ) {
186+ this . removeAllMarkers ( ) ;
187+ this . beVectSource . clear ( ) ;
188+ const points : VgiPoint [ ] = this . mapService . points ;
189+ const features : Feature [ ] = [ ] ;
190+ for ( const point of points as VgiPoint [ ] ) {
191+ const feature : Feature = this . geoJsonFormat . readFeature ( point . location , new ReadOptions ( this . map ) ) ;
192+ feature . setStyle ( this . getStyle ( point . legenda . colore ) ) ;
193+ feature . setId ( AppCostants . unselectablePointId + point . id ) ;
194+ features . push ( feature ) ;
195+ }
196+ console . log ( features ) ;
197+ console . log ( this . beVectSource . getFeatures ( ) ) ;
198+ this . beVectSource . addFeatures ( features ) ;
199+ console . log ( this . beVectSource . getFeatures ( ) ) ;
200+ }
201+
177202 getPointById ( id : number | string ) : VgiPoint | void {
178203 id = id as number ;
179204 this . mapService . getLocationById ( id ) . subscribe (
@@ -187,10 +212,10 @@ export class MapComponent implements OnInit {
187212 fill : new OlFill ( {
188213 color : color ,
189214 } ) ,
190- radius : 5 ,
215+ radius : 3. 5,
191216 stroke : new OlStroke ( {
192217 color : color ,
193- width : 3 ,
218+ width : 3.5 ,
194219 } ) ,
195220 } ) )
196221 } ) ;
@@ -210,6 +235,54 @@ export class MapComponent implements OnInit {
210235 this . map . addControl ( control ) ;
211236 }
212237
238+
239+ addButtonRicerca ( ) {
240+ const search : Element = document . createElement ( 'button' ) ;
241+ search . innerHTML = 'R' ;
242+ // search.setAttribute('style', 'top: 60px; left: .5em;');
243+ search . addEventListener ( 'click' , ( ) => this . openSearchModal ( ) ) ;
244+ const divEl : Element = document . createElement ( 'div' ) ;
245+ divEl . setAttribute ( 'style' , 'top: 97px; left: .5em;' ) ;
246+ divEl . className = 'ol-control ol-unselectable' ;
247+ divEl . appendChild ( search ) ;
248+ const control : OlControl = new OlControl ( {
249+ element : divEl ,
250+ } ) ;
251+ this . map . addControl ( control ) ;
252+ }
253+
254+ addButtonExitSearch ( ) {
255+ const exit : Element = document . createElement ( 'button' ) ;
256+ exit . innerHTML = 'E' ;
257+ // search.setAttribute('style', 'top: 60px; left: .5em;');
258+ exit . addEventListener ( 'click' , ( ) => this . getBeUserPoints ( ) ) ;
259+ const divEl : Element = document . createElement ( 'div' ) ;
260+ divEl . setAttribute ( 'style' , 'top: 129px; left: .5em;' ) ;
261+ divEl . className = 'ol-control ol-unselectable' ;
262+ divEl . appendChild ( exit ) ;
263+ const control : OlControl = new OlControl ( {
264+ element : divEl ,
265+ } ) ;
266+ this . map . addControl ( control ) ;
267+ }
268+
269+ openSearchModal ( ) {
270+ const dialogConfig : MatDialogConfig = new MatDialogConfig ( ) ;
271+ dialogConfig . autoFocus = true ;
272+ dialogConfig . position = {
273+ top : '' ,
274+ bottom : '' ,
275+ left : '' ,
276+ right : '' ,
277+ } ;
278+ const dialogRef : MatDialogRef < SearchComponent > = this . dialogService . openDialog ( SearchComponent , dialogConfig ) ;
279+ const searchSubscription = dialogRef . componentInstance . searchCompleted . subscribe ( ( ) => {
280+ this . getSearchedPoints ( ) ;
281+ searchSubscription . unsubscribe ( ) ;
282+ }
283+ ) ;
284+ }
285+
213286 getPointFromLonLat ( lonlat : string [ ] ) : OlPoint {
214287 const longitude = parseFloat ( lonlat [ 0 ] ) ;
215288 const latitude = parseFloat ( lonlat [ 1 ] ) ;
0 commit comments