1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | import ObjId from '../../data/ObjId.js'; |
26 | import theConfig from '../../data/Config.js'; |
27 | import theEventDispatcher from '../../core/lib/EventDispatcher.js'; |
28 | import theTravelNotesData from '../../data/TravelNotesData.js'; |
29 | import theOsmSearchEngine from '../../core/osmSearch/OsmSearchEngine.js'; |
30 | import { INVALID_OBJ_ID } from '../../main/Constants.js'; |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | class OsmSearchLimits { |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | #previousSearchLimitObjId; |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | #searchLimitObjId; |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | #drawSearchLimit ( ) { |
60 | if ( INVALID_OBJ_ID === this.#searchLimitObjId ) { |
61 | this.#searchLimitObjId = ObjId.nextObjId; |
62 | } |
63 | else { |
64 | theEventDispatcher.dispatch ( 'removeobject', { objId : this.#searchLimitObjId } ); |
65 | } |
66 | |
67 | theEventDispatcher.dispatch ( |
68 | 'addrectangle', |
69 | { |
70 | objId : this.#searchLimitObjId, |
71 | bounds : theOsmSearchEngine.searchBounds, |
72 | properties : theConfig.osmSearch.nextSearchLimit |
73 | } |
74 | ); |
75 | } |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | #drawPreviousSearchlimit ( ) { |
82 | const previousSearchBounds = theOsmSearchEngine.previousSearchBounds; |
83 | if ( ! previousSearchBounds ) { |
84 | return; |
85 | } |
86 | if ( INVALID_OBJ_ID === this.#previousSearchLimitObjId ) { |
87 | this.#previousSearchLimitObjId = ObjId.nextObjId; |
88 | } |
89 | else { |
90 | theEventDispatcher.dispatch ( 'removeobject', { objId : this.#previousSearchLimitObjId } ); |
91 | } |
92 | theEventDispatcher.dispatch ( |
93 | 'addrectangle', |
94 | { |
95 | objId : this.#previousSearchLimitObjId, |
96 | bounds : [ |
97 | [ previousSearchBounds.getSouthWest ( ).lat, previousSearchBounds.getSouthWest ( ).lng ], |
98 | [ previousSearchBounds.getNorthEast ( ).lat, previousSearchBounds.getNorthEast ( ).lng ] |
99 | ], |
100 | properties : theConfig.osmSearch.previousSearchLimit |
101 | } |
102 | ); |
103 | } |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | constructor ( ) { |
110 | Object.freeze ( this ); |
111 | this.#previousSearchLimitObjId = INVALID_OBJ_ID; |
112 | this.#searchLimitObjId = INVALID_OBJ_ID; |
113 | } |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | show ( ) { |
120 | theTravelNotesData.map.on ( 'zoom', this.#drawSearchLimit, this ); |
121 | theTravelNotesData.map.on ( 'move', this.#drawSearchLimit, this ); |
122 | this.#drawSearchLimit ( ); |
123 | this.#drawPreviousSearchlimit ( ); |
124 | } |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | hide ( ) { |
131 | theTravelNotesData.map.off ( 'zoom', this.#drawSearchLimit, this ); |
132 | theTravelNotesData.map.off ( 'move', this.#drawSearchLimit, this ); |
133 | if ( INVALID_OBJ_ID !== this.#searchLimitObjId ) { |
134 | theEventDispatcher.dispatch ( 'removeobject', { objId : this.#searchLimitObjId } ); |
135 | this.#searchLimitObjId = INVALID_OBJ_ID; |
136 | } |
137 | if ( INVALID_OBJ_ID !== this.#previousSearchLimitObjId ) { |
138 | theEventDispatcher.dispatch ( 'removeobject', { objId : this.#previousSearchLimitObjId } ); |
139 | this.#previousSearchLimitObjId = INVALID_OBJ_ID; |
140 | } |
141 | } |
142 | } |
143 | |
144 | export default OsmSearchLimits; |
145 | |
146 | |
147 | |