@tomtom-org/maps-sdk-plugin-viewport-places 0.1.6 → 0.1.7
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/dist/index.d.ts +1 -1
- package/dist/index.es.js.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export declare type ViewportPlacesAddOptions = ViewportPlacesAddCommonOptions &
|
|
|
111
111
|
/**
|
|
112
112
|
* The search parameters to query places for this place module.
|
|
113
113
|
*/
|
|
114
|
-
searchOptions: FuzzySearchParams
|
|
114
|
+
searchOptions: Omit<FuzzySearchParams, 'boundingBox' | 'position'>;
|
|
115
115
|
/**
|
|
116
116
|
* Optional configuration for the places module, such as styling.
|
|
117
117
|
*/
|
package/dist/index.es.js.js.map
CHANGED
|
@@ -1 +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 *\n * It leverages the SDK search service to maintain place modules that automatically\n * update and stay current as the map viewport changes.\n *\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":"sKAkEO,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"}
|
|
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: Omit<FuzzySearchParams, 'boundingBox' | 'position'>;\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 *\n * It leverages the SDK search service to maintain place modules that automatically\n * update and stay current as the map viewport changes.\n *\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":"sKAkEO,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,E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B,QAC1D"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomtom-org/maps-sdk-plugin-viewport-places",
|
|
3
|
-
"
|
|
3
|
+
"author": "TomTom International B.V.",
|
|
4
|
+
"license": "See in LICENSE.txt",
|
|
5
|
+
"version": "0.1.7",
|
|
4
6
|
"type": "module",
|
|
5
7
|
"description": "Plugin to leverage search to show places on the current viewport that refresh as the map moves",
|
|
6
8
|
"types": "dist/index.d.ts",
|
|
7
9
|
"peerDependencies": {
|
|
8
|
-
"@tomtom-org/maps-sdk": "0.42.
|
|
10
|
+
"@tomtom-org/maps-sdk": "0.42.1"
|
|
9
11
|
},
|
|
10
12
|
"devDependencies": {
|
|
11
13
|
"@microsoft/api-extractor": "^7.56.0",
|