@tomtom-org/maps-sdk-plugin-viewport-places 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.txt ADDED
@@ -0,0 +1,164 @@
1
+ TOMTOM MAPS SDK FOR JAVASCRIPT LICENSE AGREEMENT (“AGREEMENT”)
2
+
3
+
4
+
5
+ By downloading, accessing this the “TomTom Maps SDK for JavaScript, you are entering into a binding agreement with TomTom Global Content B.V. (“TomTom”). Your agreement with TomTom includes the following terms and conditions and the Privacy Policy (https://www.tomtom.com/privacy/ ). You should not use the TomTom Maps SDK for JavaScript if you cannot agree to this Agreement and the Privacy Policy.
6
+
7
+
8
+
9
+ You may not use the TomTom Maps SDK for JavaScript and may not accept the Agreement if you are a person barred from receiving the TomTom Maps SDK for JavaScript under the laws of the European Union or other countries, including the country in which you are resident or from which you use the TomTom Maps SDK for JavaScript. If you agree to be bound by the Agreement on behalf of your employer or other entity, you represent and warrant that you have full legal authority to bind your employer or such entity to the Agreement. If you do not have the requisite authority, you may not accept the Agreement or use the TomTom Maps SDK for JavaScript on behalf of your employer or other entity.
10
+
11
+
12
+
13
+ 1. GRANT OF LICENSE: Subject to and conditional upon your compliance at all times with this Agreement, TomTom grants to you a limited, non-exclusive, non-transferable and non-sublicensable, revocable, royalty-free license during the Term (as defined in Clause 9) to use the TomTom Maps SDK for JavaScript in connection with the development of web based applications or mobile applications to be used in connection with the TomTom Maps APIs and, in addition, third party online APIs (“Permitted Applications”). For the avoidance of doubt, you must use the TomTom Maps APIs in connection with the TomTom Maps SDK for JavaScript. Any such Permitted Application and use of the TomTom Maps APIs shall be subject to TomTom's standard terms of use applicable to the TomTom Maps APIs as made available on the TomTom developer portal or any other specific written agreement that you and TomTom have executed regarding the use of the TomTom Maps APIs.
14
+
15
+
16
+
17
+ 2. UPDATES AND CHANGES TO THE TOMTOM MAPS SDK FOR JAVASCRIPT AND THIS AGREEMENT: TomTom reserves the right, with or without notice and at its sole discretion, to discontinue, update, modify, upgrade and supplement any of the TomTom Maps SDK for JavaScript or any features within the TomTom Maps SDK for JavaScript and to modify this Agreement. You agree that future versions of the TomTom Maps SDK for JavaScript may be incompatible with applications that were developed on previous versions of the TomTom Maps SDK for JavaScript.
18
+
19
+
20
+
21
+ 3. YOUR FURTHER OBLIGATIONS:
22
+
23
+
24
+
25
+ 3.1. You agree to use the TomTom Maps SDK for JavaScript only for purposes that are permitted by (a) this Agreement and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions (including any laws regarding the export of data or software to and from the United States or other relevant countries).
26
+
27
+
28
+
29
+ 3.2. Other than as permitted by applicable legislation, you are prohibited from copying (except for backup purposes), modifying, adapting, (re)distributing, renting, lending, publicly presenting, decompiling, reverse engineering, disassembling, or creating derivative works of the TomTom Maps SDK for JavaScript or any part of the TomTom Maps SDK for JavaScript.
30
+
31
+
32
+
33
+ 3.3. You may not use the TomTom Maps SDK for JavaScript in connection with any illegal, fraudulent, dishonest or unethical activity or behaviour.
34
+
35
+
36
+
37
+ 3.4. You shall be permitted to display TomTom Maps APIs results (“Results”) on third party content or map data provided that nothing shall entitle you to add or incorporate Results into the OSM or any other open source database. You shall also be permitted to display Results from third party content or map data on a TomTom map as a separate layer.
38
+
39
+
40
+
41
+ 3.5. The TomTom Maps SDK for JavaScript may include data which TomTom licenses from third parties or open source software. You shall comply with all requirements and restrictions which such third parties may require TomTom to impose on you (and as may be updated and amended by TomTom from time to time). All applicable ODbL Licenses are included within the TomTom Maps SDK for JavaScript download package. It shall be your responsibility to check, review and comply with any updated or amended terms that would apply to the TomTom Maps SDK for JavaScript licensed to you under this Agreement. For the avoidance of doubt, any such software is made available to you under the terms and conditions of the applicable licenses.
42
+
43
+
44
+
45
+
46
+
47
+ 4. PRIVACY: In order to improve the TomTom Developer Portal and TomTom Maps SDK for JavaScript, TomTom may collect certain usage related information from the software including but not limited to the general SDK and product identifiers, version numbers, and information on which tools and/or services in the TomTom Maps SDK for JavaScript are being used and how they are being used by you. In addition, TomTom may collect your unique identifier and associated IP address for legitimate business reasons (such as without limitation the processing of invoices). This data will be retained for a maximum period of 120 days. The information collected is maintained in accordance with our Privacy Policy.
48
+
49
+
50
+
51
+ 5. INTELLECTUAL PROPERTY RIGHTS AND COPYRIGHT NOTICES:
52
+
53
+
54
+
55
+ 5.1. All intellectual property rights related to the TomTom Maps SDK for JavaScript and to the TomTom Maps APIs are owned by TomTom and/or its licensors and suppliers. However, TomTom agrees that it obtains no intellectual property rights under this Agreement in or to any Permitted Application that you develop using the TomTom Maps SDK for JavaScript and the TomTom Maps APIs.
56
+
57
+
58
+
59
+ 5.2. Your use of any trade names, logos, trademarks, service marks and other marks of TomTom is subject to TomTom’s prior written approval. Any goodwill arising out of the use thereof shall inure to the benefit of TomTom. In addition, you agree not to remove, obscure, mask or change any logo and/or copyright notice placed on or automatically generated by the TomTom Maps SDK for JavaScript or the TomTom Maps APIs.
60
+
61
+
62
+
63
+
64
+
65
+ 6. WARRANTIES:
66
+
67
+
68
+
69
+ 6.1. YOU ACKNOWLEDGE THAT THE TOMTOM MAPS SDK FOR JAVASCRIPT HAS NOT BEEN DEVELOPED TO MEET YOUR INDIVIDUAL REQUIREMENTS AND THAT IT IS THEREFORE YOUR RESPONSIBILITY TO ENSURE THAT THE FACILITIES AND FUNCTIONS OF THE TOMTOM MAPS SDK FOR JAVASCRIPT MEET YOUR REQUIREMENTS. TOMTOM DOES NOT AND CANNOT WARRANT THAT THE TOMTOM MAPS SDK FOR JAVASCRIPT OPERATES UNINTERRUPTED OR ERROR-FREE. TOMTOM DOES NOT WARRANT THAT THE TOMTOM MAPS SDK FOR JAVASCRIPT IS CAPABLE OF INTEROPERATING WITH ANY OTHER SYSTEM, DEVICE OR PRODUCT (EITHER SOFTWARE OR HARDWARE).
70
+
71
+
72
+
73
+ 6.2. YOUR USE OF THE TOMTOM MAPS SDK FOR JAVASCRIPT AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE TOMTOM MAPS SDK FOR JAVASCRIPT IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICES OR ANY LOSS OF DATA THAT RESULTS FROM SUCH USE.
74
+
75
+
76
+
77
+ 6.3. WITHOUT LIMITING CLAUSES 6.1 AND 6.2 ABOVE, THE TOMTOM MAPS SDK FOR JAVASCRIPT IS PROVIDED ON AN “AS IS” AND WITH “ALL FAULTS BASIS” AND TOMTOM EXPRESSLY DISCLAIMS ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, SATISFACTORY QUALITY, ACCURACY, TITLE AND FITNESS FOR A PARTICULAR PURPOSE.
78
+
79
+
80
+
81
+ 6.4. THE PROVISIONS OF THIS CLAUSE DO NOT AFFECT ANY OF YOUR LEGAL RIGHTS UNDER APPLICABLE MANDATORY NATIONAL LEGISLATION, INCLUDING BUT NOT LIMITED TO ANY MANDATORY STATUTORY WARRANTIES. IF ANY PART OF THIS LIMITED WARRANTY IS HELD TO BE INVALID OR UNENFORCEABLE, THE REMAINDER OF THE LIMITED WARRANTY SHALL NONETHELESS REMAIN IN FULL FORCE AND EFFECT.
82
+
83
+
84
+
85
+
86
+
87
+ 7. LIMITATION OF LIABILITY:
88
+
89
+
90
+
91
+ 7.1. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, NEITHER TOMTOM NOR ITS LICENSORS, SUPPLIERS, OFFICERS, DIRECTORS OR EMPLOYEES SHALL BE LIABLE TO YOU OR TO ANY THIRD PARTY FOR ANY DAMAGES, WHETHER DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL (INCLUDING BUT NOT LIMITED TO DAMAGES FOR THE INABILITY TO USE OR ACCESS THE TOMTOM MAPS SDK FOR JAVASCRIPT OR TOMTOM MAPS APIS, LOSS OF DATA, LOSS OF BUSINESS, LOSS OF PROFITS, BUSINESS INTERRUPTION OR THE LIKE) ARISING OUT OF OR RELATED TO THE USE OF, THE INABILITY TO USE OR ACCESS, OR OTHERWISE THE PERFORMANCE OF THE TOMTOM MAPS SDK FOR JAVASCRIPT, EVEN IF TOMTOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
92
+
93
+
94
+
95
+ 7.2. TO THE EXTENT TOMTOM IS NOT PERMITTED UNDER APPLICABLE LAW TO EXCLUDE ITS LIABILITY PURSUANT TO CLAUSE 7.1 ABOVE, TOMTOM’S TOTAL AGGREGATE LIABILITY TO YOU SHALL BE LIMITED TO THE AMOUNT OF US $100.00.
96
+
97
+
98
+
99
+ 7.3. THE ABOVE LIMITATIONS OF LIABILITY UNDER THIS CLAUSE 7 DO NOT: (I) AFFECT YOUR RIGHTS UNDER ANY APPLICABLE MANDATORY NATIONAL LEGISLATION; (II) EXCLUDE OR LIMIT ANY LIABILITY THAT CANNOT BE EXCLUDED OR LIMITED UNDER APPLICABLE LAW.
100
+
101
+
102
+
103
+
104
+
105
+ 8. IPR INDMENITY: To the maximum extent permitted by law, you agree to defend, indemnify and hold TomTom and its respective directors, officers, employees, affiliates, agents and suppliers harmless from and against any and all claims, actions, suits or proceedings, as well as any and all losses, liabilities, damages, costs and expenses (including reasonable attorney’s fees) arising out of or accruing from (a) your use of the TomTom Maps SDK for JavaScript, (b) any application you develop on the TomTom Maps SDK for JavaScript that infringes any copyright, trademark, trade secret, trade dress, patent or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy, and (c) any non-compliance by you with this Agreement.
106
+
107
+
108
+
109
+ 9. TERM AND TERMINATION AND DIRECT ENFORCEMENT:
110
+
111
+
112
+
113
+ 9.1. This Agreement begins on either (a) the date you demonstrate your acceptance of the terms and conditions of this Agreement or (b) when you first use the TomTom Maps SDK for JavaScript and shall continue until terminated (jointly the “Term”) by either TomTom or you subject to and in accordance with this Agreement. The provisions of this Agreement, which by their nature are intended to survive termination, will remain in effect after termination of this Agreement. Furthermore, you agree that TomTom may directly enforce these provisions against you.
114
+
115
+
116
+
117
+ 9.2. Without prejudice to any other rights, TomTom may immediately terminate this Agreement if (i) you fail to comply with any of its terms and conditions, or (ii) the agreement governing the use of TomTom Maps APIs between you and TomTom you has terminated, or (iii) TomTom decides to no longer provide the TomTom Maps SDK for JavaScript or certain parts of the TomTom Maps SDK for JavaScript either entirely or in certain territories related to your use.
118
+
119
+
120
+
121
+ 9.3. You may terminate this Agreement by ceasing your use of the TomTom Maps SDK for JavaScript at any time.
122
+
123
+
124
+
125
+
126
+
127
+ 10. GOVERNING LAW AND DISPUTE RESOLUTION:
128
+
129
+
130
+
131
+ 10.1. If you, your employer or the entity on whose behalf you act is incorporated in the European Union then this Agreement and any dispute arising under or in connection with it, including any non-contractual claims and disputes, shall be governed by and construed in accordance with the laws of the Netherlands. The applicability of the United Nations Convention on Contracts for the International Sale of Goods is explicitly excluded. You and TomTom hereby irrevocably submit to the exclusive jurisdiction of the courts of Amsterdam, the Netherlands in respect of any dispute arising under or in connection with this Agreement, including any non-contractual claims or disputes.
132
+
133
+
134
+
135
+ 10.2. If you, your employer or the entity on whose behalf you act is incorporated outside of European Union, then this Agreement and any dispute arising under or in connection with it, including any non-contractual claims and disputes, shall be governed by and construed in accordance with the laws of the Netherlands. All disputes arising in connection with the Agreement, including any non-contractual claims or disputes, shall be settled in accordance with the Arbitration Rules of the Netherlands Arbitration Institute. The arbitral tribunal shall be composed of three (3) arbitrators. The place or arbitration shall be Amsterdam and the language of the arbitration shall be English. Consolidation of the arbitral proceedings with other arbitral proceedings, as provided for in Article 1046 of the Dutch Code of Civil Procedure and Article 39 of the Arbitration Rules of the Netherlands Arbitration Institute, is excluded.
136
+
137
+
138
+
139
+ 10.3. Notwithstanding this, TomTom shall still be allowed to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction.
140
+
141
+ --
142
+
143
+
144
+
145
+ 11. OTHER LEGAL TERMS:
146
+
147
+
148
+
149
+ 11.1. No failure or delay by TomTom to exercise any right or remedy provided under this Agreement or by law shall constitute a waiver of that or any other right or remedy, nor shall it preclude or restrict the further exercise of that or any other right or remedy. No single or partial exercise of such right or remedy shall preclude or restrict the further exercise of that or any other right or remedy.
150
+
151
+
152
+
153
+ 11.2. Should for any reason, or to any extent, any provision of this Agreement be held invalid or unenforceable, such invalidity or enforceability shall not affect or render invalid or unenforceable the remaining provisions of this Agreement and the application of that provision shall be enforced to the extent permitted by law.
154
+
155
+
156
+
157
+ 11.3. The rights granted to you in this Agreement may not be assigned or transferred by you without TomTom’s prior written approval.
158
+
159
+
160
+
161
+ 11.4. The TomTom Maps APIs and TomTom Maps SDK for JavaScript are provided as “Commercial Computer Software” or “restricted computer software”. Use, duplication, or disclosure by the U.S. Government or U.S. Government subcontractor is subject to the restrictions set forth in 48.C.F.R. Section 12.212 or 48 C.F.R.227.2702, as applicable or successor provisions. In respect of the Map API and Search API, the manufacturer is TomTom Global Content B.V.
162
+
163
+
164
+
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Viewport Places Plugin
2
+
3
+ Lightweight plugin for the [TomTom Maps SDK for Javascript](https://docs.tomtom.com/maps-sdk-js/introduction/overview) that keeps places in sync with the current map viewport by creating and managing "place modules" that refresh as the map moves.
4
+
5
+ ## Docs & examples
6
+
7
+ - Developer guide: https://docs.tomtom.com/maps-sdk-js/guides/plugins/viewport-places
8
+ - Example: https://docs.tomtom.com/maps-sdk-js/examples/viewport-places-plugin
9
+
10
+ ## Quickstart
11
+
12
+ Note: SDK plugins `@tomtom-org/maps-sdk` as a peer dependency — ensure the SDK is installed in your project.
13
+
14
+ ```bash
15
+ npm install @tomtom-org/maps-sdk maplibre-gl @tomtom-org/maps-sdk-plugin-viewport-places
16
+ ```
17
+
18
+ 1. Follow the SDK [Project setup](https://docs.tomtom.com/maps-sdk-js/guides/introduction/project-setup) or the Map [quickstart](https://docs.tomtom.com/maps-sdk-js/guides/map/quickstart) to create and initialize a `TomTomMap`.
19
+
20
+ 2. Import and use the plugin (plugin-specific steps only):
21
+
22
+ ```ts
23
+ import { ViewportPlaces } from '@tomtom-org/maps-sdk-plugin-viewport-places';
24
+
25
+ // assume `map` is your initialized TomTomMap instance
26
+ const viewportPlaces = new ViewportPlaces(map);
27
+
28
+ await viewportPlaces.add({
29
+ id: 'restaurants',
30
+ searchOptions: { query: 'restaurant', limit: 40 },
31
+ minZoom: 12,
32
+ });
33
+ ```
34
+
35
+ Place modules are rendered bottom-up in the order they are added: the first added module appears at the bottom and later modules are stacked on top.
36
+
37
+ ## License
38
+
39
+ See `LICENSE.txt`.
@@ -0,0 +1 @@
1
+ No third parties dependencies
@@ -0,0 +1,132 @@
1
+ import { FuzzySearchParams } from '../../services/dist';
2
+ import { PlacesModule } from '../../map/dist';
3
+ import { PlacesModuleConfig } from '../../map/dist';
4
+ import { POICategory } from '../../core/dist';
5
+ import { TomTomMap } from '../../map/dist';
6
+
7
+ /**
8
+ * A class for managing dynamic searched place modules on a TomTom map.
9
+ * It leverages the SDK search service to maintain place modules that automatically update and stay current as the map moves.
10
+ * @group Viewport Places
11
+ */
12
+ export declare class ViewportPlaces {
13
+ private readonly map;
14
+ /**
15
+ * Internal map of registered place modules, keyed by their `id`.
16
+ * @private
17
+ */
18
+ private registeredModules;
19
+ private readonly mapLibreMap;
20
+ /**
21
+ * Creates an instance of ViewportPlaces bound to a TomTom map.
22
+ * @param map - The TomTom map instance to attach place modules to.
23
+ */
24
+ constructor(map: TomTomMap);
25
+ /**
26
+ * Performs the update logic for a PlacesModule with given options.
27
+ * @param placesModule - The PlacesModule to update.
28
+ * @param options - The options containing search parameters and zoom constraints.
29
+ */
30
+ private searchAndDisplay;
31
+ /**
32
+ * Adds a PlacesModule that displays places based on fuzzy search parameters and automatically updates as the map moves.
33
+ *
34
+ * @remarks
35
+ * * Each call to "add" creates a new place module and places it above previously added modules.
36
+ * * Place modules are rendered bottom-up in the order they are added: the first added module is displayed at the bottom, and later modules are stacked on top of earlier ones.
37
+ * * The default places module theme is 'base-map' unless overridden in the options.
38
+ *
39
+ * @param options - The options for the place module.
40
+ * @returns A promise that resolves to the PlacesModule instance managing the module.
41
+ */
42
+ add(options: ViewportPlacesAddOptions): Promise<PlacesModule>;
43
+ /**
44
+ * Adds a PlacesModule for specific POI categories that updates automatically as the map moves.
45
+ * The POIs are shown in the same style as the base map.
46
+ *
47
+ * @remarks
48
+ * * This is a convenience wrapper over `add` that configures a category-based search for a PlacesModule.
49
+ * * Each call creates a new place module that will be stacked on top of previously added modules.
50
+ *
51
+ * @param options - The options for the category-based place module.
52
+ * @returns A promise that resolves to the PlacesModule instance managing the module.
53
+ */
54
+ addPOICategories(options: ViewportPlacesAddCommonOptions & {
55
+ categories: POICategory[];
56
+ }): Promise<PlacesModule>;
57
+ /**
58
+ * Removes a specific place module by its ID, stopping its updates and clearing the displayed places.
59
+ * @remarks
60
+ * If the id does not exist, an error is logged into console.
61
+ *
62
+ * @param id - The unique identifier of the PlacesModule to remove.
63
+ */
64
+ remove(id: string): void;
65
+ /**
66
+ * Removes all registered place modules, stopping their updates and clearing all displayed places.
67
+ */
68
+ removeAll(): void;
69
+ /**
70
+ * Updates the search and display options for an existing place module identified by its ID.
71
+ * This will immediately apply the new options and refresh the place module accordingly.
72
+ * @param newOptions - The new options to apply.
73
+ * @throws Error if the place module with the given ID does not exist.
74
+ */
75
+ update(newOptions: ViewportPlacesOptions): Promise<void>;
76
+ }
77
+
78
+ /**
79
+ * Common Options when adding a viewport places module.
80
+ *
81
+ * @group Viewport Places
82
+ */
83
+ export declare type ViewportPlacesAddCommonOptions = {
84
+ /**
85
+ * Optional unique identifier for the viewport places module.
86
+ *
87
+ * @remarks
88
+ * * If not provided, a random ID will be generated.
89
+ * * If you need to keep updating or removing this place module later, provide a fixed ID.
90
+ */
91
+ id?: string;
92
+ /**
93
+ * Minimum zoom level at which the place module is visible.
94
+ */
95
+ minZoom?: number;
96
+ /**
97
+ * Maximum zoom level at which the place module is visible.
98
+ */
99
+ maxZoom?: number;
100
+ };
101
+
102
+ /**
103
+ * Full Options when adding a viewport places module.
104
+ *
105
+ * @group Viewport Places
106
+ */
107
+ export declare type ViewportPlacesAddOptions = ViewportPlacesAddCommonOptions & {
108
+ /**
109
+ * The search parameters to query places for this place module.
110
+ */
111
+ searchOptions: FuzzySearchParams;
112
+ /**
113
+ * Optional configuration for the places module, such as styling.
114
+ */
115
+ placesModuleConfig?: PlacesModuleConfig;
116
+ };
117
+
118
+ /**
119
+ * Options when updating a viewport places module.
120
+ *
121
+ * @group Viewport Places
122
+ */
123
+ export declare type ViewportPlacesOptions = Omit<ViewportPlacesAddOptions, 'id'> & {
124
+ /**
125
+ * The unique identifier of the place module to update.
126
+ * @remarks
127
+ * * This ID must correspond to an existing place module added via an "add" method.
128
+ */
129
+ id: string;
130
+ };
131
+
132
+ export { }
@@ -0,0 +1,2 @@
1
+ import{generateId as e}from"@tomtom-org/maps-sdk/core";import{PlacesModule as o}from"@tomtom-org/maps-sdk/map";import{search as s}from"@tomtom-org/maps-sdk/services";class i{constructor(e){this.map=e,this.mapLibreMap=e.mapLibreMap}registeredModules={};mapLibreMap;async searchAndDisplay(e,o){const i=this.mapLibreMap.getZoom();o.minZoom&&i<o.minZoom||o.maxZoom&&i>o.maxZoom?await e.clear():await e.show(await s({boundingBox:this.map.getBBox(),limit:100,...o.searchOptions}))}async add(s){const i=s.id??e(),t={...s,placesModuleConfig:{theme:"base-map",...s.placesModuleConfig}},a=await o.get(this.map,t.placesModuleConfig),r=async()=>{const e=this.registeredModules[i];await this.searchAndDisplay(e.placesModule,e.options)},p=this.mapLibreMap.on("moveend",r);return this.registeredModules[i]={placesModule:a,subscription:p,options:t},await r(),a}async addPOICategories(e){return this.add({...e,searchOptions:{query:"",poiCategories:e.categories}})}remove(e){const o=this.registeredModules[e];o?(o.placesModule.clear(),o.subscription.unsubscribe(),delete this.registeredModules[e]):console.error(`Viewport places module ${e} not found`)}removeAll(){Object.keys(this.registeredModules).forEach(e=>this.remove(e))}async update(e){const o=this.registeredModules[e.id];if(!o)throw new Error(`Place module with id ${e.id} not found`);const s=o.options;o.options={...s,...e,searchOptions:{...s.searchOptions,...e.searchOptions},placesModuleConfig:{...s.placesModuleConfig,...e.placesModuleConfig}},o.placesModule.applyConfig(o.options.placesModuleConfig),await this.searchAndDisplay(o.placesModule,o.options)}}export{i as ViewportPlaces};
2
+ //# sourceMappingURL=index.es.js.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js.js","sources":["../src/viewportPlaces.ts"],"sourcesContent":["import { generateId, POICategory } from '@tomtom-org/maps-sdk/core';\nimport { PlacesModule, type PlacesModuleConfig, TomTomMap } from '@tomtom-org/maps-sdk/map';\nimport { type FuzzySearchParams, search } from '@tomtom-org/maps-sdk/services';\n\n/**\n * Common Options when adding a viewport places module.\n *\n * @group Viewport Places\n */\nexport type ViewportPlacesAddCommonOptions = {\n /**\n * Optional unique identifier for the viewport places module.\n *\n * @remarks\n * * If not provided, a random ID will be generated.\n * * If you need to keep updating or removing this place module later, provide a fixed ID.\n */\n id?: string;\n /**\n * Minimum zoom level at which the place module is visible.\n */\n minZoom?: number;\n /**\n * Maximum zoom level at which the place module is visible.\n */\n maxZoom?: number;\n};\n\n/**\n * Full Options when adding a viewport places module.\n *\n * @group Viewport Places\n */\nexport type ViewportPlacesAddOptions = ViewportPlacesAddCommonOptions & {\n /**\n * The search parameters to query places for this place module.\n */\n searchOptions: FuzzySearchParams;\n /**\n * Optional configuration for the places module, such as styling.\n */\n placesModuleConfig?: PlacesModuleConfig;\n};\n\n/**\n * Options when updating a viewport places module.\n *\n * @group Viewport Places\n */\nexport type ViewportPlacesOptions = Omit<ViewportPlacesAddOptions, 'id'> & {\n /**\n * The unique identifier of the place module to update.\n * @remarks\n * * This ID must correspond to an existing place module added via an \"add\" method.\n */\n id: string;\n};\n\n/**\n * A class for managing dynamic searched place modules on a TomTom map.\n * It leverages the SDK search service to maintain place modules that automatically update and stay current as the map moves.\n * @group Viewport Places\n */\nexport class ViewportPlaces {\n /**\n * Internal map of registered place modules, keyed by their `id`.\n * @private\n */\n private registeredModules: Record<\n string,\n { options: ViewportPlacesAddOptions; placesModule: PlacesModule; subscription: any }\n > = {};\n private readonly mapLibreMap;\n\n /**\n * Creates an instance of ViewportPlaces bound to a TomTom map.\n * @param map - The TomTom map instance to attach place modules to.\n */\n constructor(private readonly map: TomTomMap) {\n this.mapLibreMap = map.mapLibreMap;\n }\n\n /**\n * Performs the update logic for a PlacesModule with given options.\n * @param placesModule - The PlacesModule to update.\n * @param options - The options containing search parameters and zoom constraints.\n */\n private async searchAndDisplay(placesModule: PlacesModule, options: ViewportPlacesAddOptions): Promise<void> {\n const zoom = this.mapLibreMap.getZoom();\n if ((options.minZoom && zoom < options.minZoom) || (options.maxZoom && zoom > options.maxZoom)) {\n await placesModule.clear();\n return;\n }\n await placesModule.show(\n await search({\n boundingBox: this.map.getBBox(),\n limit: 100,\n ...options.searchOptions,\n }),\n );\n }\n\n /**\n * Adds a PlacesModule that displays places based on fuzzy search parameters and automatically updates as the map moves.\n *\n * @remarks\n * * Each call to \"add\" creates a new place module and places it above previously added modules.\n * * Place modules are rendered bottom-up in the order they are added: the first added module is displayed at the bottom, and later modules are stacked on top of earlier ones.\n * * The default places module theme is 'base-map' unless overridden in the options.\n *\n * @param options - The options for the place module.\n * @returns A promise that resolves to the PlacesModule instance managing the module.\n */\n async add(options: ViewportPlacesAddOptions): Promise<PlacesModule> {\n const id = options.id ?? generateId();\n const effectiveOptions = {\n ...options,\n placesModuleConfig: { theme: 'base-map', ...options.placesModuleConfig } as PlacesModuleConfig,\n };\n\n const placesModule = await PlacesModule.get(this.map, effectiveOptions.placesModuleConfig);\n const searchAndDisplay = async () => {\n const entry = this.registeredModules[id];\n await this.searchAndDisplay(entry.placesModule, entry.options);\n };\n\n const subscription = this.mapLibreMap.on('moveend', searchAndDisplay);\n this.registeredModules[id] = { placesModule, subscription, options: effectiveOptions };\n await searchAndDisplay();\n return placesModule;\n }\n\n /**\n * Adds a PlacesModule for specific POI categories that updates automatically as the map moves.\n * The POIs are shown in the same style as the base map.\n *\n * @remarks\n * * This is a convenience wrapper over `add` that configures a category-based search for a PlacesModule.\n * * Each call creates a new place module that will be stacked on top of previously added modules.\n *\n * @param options - The options for the category-based place module.\n * @returns A promise that resolves to the PlacesModule instance managing the module.\n */\n async addPOICategories(\n options: ViewportPlacesAddCommonOptions & { categories: POICategory[] },\n ): Promise<PlacesModule> {\n return this.add({\n ...options,\n searchOptions: { query: '', poiCategories: options.categories },\n });\n }\n\n /**\n * Removes a specific place module by its ID, stopping its updates and clearing the displayed places.\n * @remarks\n * If the id does not exist, an error is logged into console.\n *\n * @param id - The unique identifier of the PlacesModule to remove.\n */\n remove(id: string): void {\n const entry = this.registeredModules[id];\n if (entry) {\n entry.placesModule.clear();\n entry.subscription.unsubscribe();\n delete this.registeredModules[id];\n } else {\n console.error(`Viewport places module ${id} not found`);\n }\n }\n\n /**\n * Removes all registered place modules, stopping their updates and clearing all displayed places.\n */\n removeAll(): void {\n Object.keys(this.registeredModules).forEach((key) => this.remove(key));\n }\n\n /**\n * Updates the search and display options for an existing place module identified by its ID.\n * This will immediately apply the new options and refresh the place module accordingly.\n * @param newOptions - The new options to apply.\n * @throws Error if the place module with the given ID does not exist.\n */\n async update(newOptions: ViewportPlacesOptions): Promise<void> {\n const entry = this.registeredModules[newOptions.id];\n if (!entry) {\n throw new Error(`Place module with id ${newOptions.id} not found`);\n }\n const currentOptions = entry.options;\n\n // Update the options by merging current and new options:\n entry.options = {\n ...currentOptions,\n ...newOptions,\n // search and places display options are merged incrementally:\n searchOptions: { ...currentOptions.searchOptions, ...newOptions.searchOptions },\n placesModuleConfig: { ...currentOptions.placesModuleConfig, ...newOptions.placesModuleConfig },\n };\n // Update the places module configuration and refresh the display:\n entry.placesModule.applyConfig(entry.options.placesModuleConfig);\n await this.searchAndDisplay(entry.placesModule, entry.options);\n }\n}\n"],"names":["ViewportPlaces","constructor","map","this","mapLibreMap","registeredModules","searchAndDisplay","placesModule","options","zoom","getZoom","minZoom","maxZoom","clear","show","search","boundingBox","getBBox","limit","searchOptions","add","id","generateId","effectiveOptions","placesModuleConfig","theme","PlacesModule","get","async","entry","subscription","on","addPOICategories","query","poiCategories","categories","remove","unsubscribe","console","error","removeAll","Object","keys","forEach","key","update","newOptions","Error","currentOptions","applyConfig"],"mappings":"sKA+DO,MAAMA,EAeT,WAAAC,CAA6BC,GAAAC,KAAAD,IAAAA,EACzBC,KAAKC,YAAcF,EAAIE,WAC3B,CAZQC,kBAGJ,CAAA,EACaD,YAejB,sBAAcE,CAAiBC,EAA4BC,GACvD,MAAMC,EAAON,KAAKC,YAAYM,UACzBF,EAAQG,SAAWF,EAAOD,EAAQG,SAAaH,EAAQI,SAAWH,EAAOD,EAAQI,cAC5EL,EAAaM,cAGjBN,EAAaO,WACTC,EAAO,CACTC,YAAab,KAAKD,IAAIe,UACtBC,MAAO,OACJV,EAAQW,gBAGvB,CAaA,SAAMC,CAAIZ,GACN,MAAMa,EAAKb,EAAQa,IAAMC,IACnBC,EAAmB,IAClBf,EACHgB,mBAAoB,CAAEC,MAAO,cAAejB,EAAQgB,qBAGlDjB,QAAqBmB,EAAaC,IAAIxB,KAAKD,IAAKqB,EAAiBC,oBACjElB,EAAmBsB,UACrB,MAAMC,EAAQ1B,KAAKE,kBAAkBgB,SAC/BlB,KAAKG,iBAAiBuB,EAAMtB,aAAcsB,EAAMrB,UAGpDsB,EAAe3B,KAAKC,YAAY2B,GAAG,UAAWzB,GAGpD,OAFAH,KAAKE,kBAAkBgB,GAAM,CAAEd,eAAcuB,eAActB,QAASe,SAC9DjB,IACCC,CACX,CAaA,sBAAMyB,CACFxB,GAEA,OAAOL,KAAKiB,IAAI,IACTZ,EACHW,cAAe,CAAEc,MAAO,GAAIC,cAAe1B,EAAQ2B,aAE3D,CASA,MAAAC,CAAOf,GACH,MAAMQ,EAAQ1B,KAAKE,kBAAkBgB,GACjCQ,GACAA,EAAMtB,aAAaM,QACnBgB,EAAMC,aAAaO,qBACZlC,KAAKE,kBAAkBgB,IAE9BiB,QAAQC,MAAM,0BAA0BlB,cAEhD,CAKA,SAAAmB,GACIC,OAAOC,KAAKvC,KAAKE,mBAAmBsC,QAASC,GAAQzC,KAAKiC,OAAOQ,GACrE,CAQA,YAAMC,CAAOC,GACT,MAAMjB,EAAQ1B,KAAKE,kBAAkByC,EAAWzB,IAChD,IAAKQ,EACD,MAAM,IAAIkB,MAAM,wBAAwBD,EAAWzB,gBAEvD,MAAM2B,EAAiBnB,EAAMrB,QAG7BqB,EAAMrB,QAAU,IACTwC,KACAF,EAEH3B,cAAe,IAAK6B,EAAe7B,iBAAkB2B,EAAW3B,eAChEK,mBAAoB,IAAKwB,EAAexB,sBAAuBsB,EAAWtB,qBAG9EK,EAAMtB,aAAa0C,YAAYpB,EAAMrB,QAAQgB,0BACvCrB,KAAKG,iBAAiBuB,EAAMtB,aAAcsB,EAAMrB,QAC1D"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tomtom-org/maps-sdk-plugin-viewport-places",
3
+ "version": "0.1.4",
4
+ "type": "module",
5
+ "description": "Plugin to leverage search to show places on the current viewport that refresh as the map moves",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "vite build --config ../plugin-vite-config.ts",
9
+ "build:watch": "vite build --watch --config ../plugin-vite-config.ts",
10
+ "type-check": "tsc --noEmit"
11
+ },
12
+ "peerDependencies": {
13
+ "@tomtom-org/maps-sdk": "workspace:*"
14
+ },
15
+ "devDependencies": {
16
+ "@microsoft/api-extractor": "catalog:",
17
+ "@tsconfig/recommended": "catalog:",
18
+ "@types/node": "catalog:",
19
+ "ts-node": "catalog:",
20
+ "typescript": "catalog:",
21
+ "vite": "catalog:",
22
+ "vite-plugin-dts": "catalog:"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "package.json",
27
+ "README.md",
28
+ "LICENSE.txt"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.es.js"
34
+ }
35
+ }
36
+ }