@collabdt/core 0.0.44 → 0.0.45

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.
@@ -1,5 +1,4 @@
1
1
  import { Feature } from 'geojson';
2
- import { MarkerManager } from './MarkerManager';
3
2
  export declare const getMunicipalityAndProvince: (latitude: string, longitude: string, countryCode?: string) => Promise<{
4
3
  municipality: any;
5
4
  countrySubdivision: any;
@@ -65,8 +64,4 @@ export declare const buildingToFeature: (building: any) => {
65
64
  };
66
65
  is_database_building: boolean;
67
66
  };
68
- export declare const createGeocoderMarker: (coordinates: [number, number], map: any, options?: {
69
- editing?: boolean;
70
- }) => MarkerManager;
71
- export declare const removeGeocoderMarker: () => void;
72
67
  //# sourceMappingURL=geocoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geocoder.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/utils/geocoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAe/C,eAAO,MAAM,0BAA0B,GAAU,UAAU,MAAM,EAAE,WAAW,MAAM,EAAE,cAAc,MAAM;;;EAmBzG,CAAA;AAGD,eAAO,MAAM,gBAAgB,GAAU,OAAO,MAAM,EAAE,cAAc,MAAM;;KAYzE,CAAA;AAGD,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO;;;;CAoC7C,CAAA;AAGD,eAAO,MAAM,oBAAoB,GAAI,SAAS,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqF7G,CAAA;AAGD,eAAO,MAAM,kBAAkB,GAAU,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,MAAM;;GAc3F,CAAA;AAGD,eAAO,MAAM,iBAAiB,GAAI,aAAQ;;;;;;;;;;;;;;;CAgCzC,CAAA;AAGD,eAAO,MAAM,oBAAoB,GAAI,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,kBAK5G,CAAA;AAGD,eAAO,MAAM,oBAAoB,QAAO,IAGvC,CAAA"}
1
+ {"version":3,"file":"geocoder.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/map/utils/geocoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAA;AAgBxC,eAAO,MAAM,0BAA0B,GAAU,UAAU,MAAM,EAAE,WAAW,MAAM,EAAE,cAAc,MAAM;;;EAmBzG,CAAA;AAGD,eAAO,MAAM,gBAAgB,GAAU,OAAO,MAAM,EAAE,cAAc,MAAM;;KAYzE,CAAA;AAGD,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO;;;;CAoC7C,CAAA;AAGD,eAAO,MAAM,oBAAoB,GAAI,SAAS,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqF7G,CAAA;AAGD,eAAO,MAAM,kBAAkB,GAAU,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,MAAM;;GAc3F,CAAA;AAGD,eAAO,MAAM,iBAAiB,GAAI,aAAQ;;;;;;;;;;;;;;;CAgCzC,CAAA"}
@@ -77,7 +77,6 @@ const handleLocationSelect = (feature, map, type, options) => {
77
77
  is_database_building: true
78
78
  };
79
79
  if (map && center2) {
80
- markerManager.create(center2, map);
81
80
  map.flyTo({
82
81
  center: addressData2.coordinates,
83
82
  zoom: 18,
@@ -122,7 +121,6 @@ const handleLocationSelect = (feature, map, type, options) => {
122
121
  // How well the result matches the query
123
122
  };
124
123
  if (map && center) {
125
- markerManager.create(center, map, { editing });
126
124
  if (feature.bbox) {
127
125
  map.fitBounds(feature.bbox, { speed: 2 });
128
126
  } else {
@@ -175,24 +173,12 @@ const buildingToFeature = (building) => {
175
173
  is_database_building: true
176
174
  };
177
175
  };
178
- const createGeocoderMarker = (coordinates, map, options) => {
179
- const editing = (options == null ? void 0 : options.editing) || false;
180
- const markerManager = getGeocoderMarkerManager();
181
- markerManager.create(coordinates, map, { editing });
182
- return markerManager;
183
- };
184
- const removeGeocoderMarker = () => {
185
- const markerManager = getGeocoderMarkerManager();
186
- markerManager.remove();
187
- };
188
176
  export {
189
177
  buildingToFeature,
190
- createGeocoderMarker,
191
178
  fetchSuggestions,
192
179
  getDetailedAddress,
193
180
  getMunicipalityAndProvince,
194
181
  handleLocationSelect,
195
- parseLocation,
196
- removeGeocoderMarker
182
+ parseLocation
197
183
  };
198
184
  //# sourceMappingURL=geocoder.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/core/components/viewers/map/utils/geocoder.ts"],"sourcesContent":["import { Feature, Point } from 'geojson'\r\nimport { MarkerManager } from './MarkerManager'\r\nimport { autocompleteGeocode, reverseGeocode } from './geocoding'\r\n\r\n// Global marker manager instance for geocoder\r\nlet geocoderMarkerManager: MarkerManager | null = null\r\n\r\n// Helper function to get or create the marker manager\r\nconst getGeocoderMarkerManager = (): MarkerManager => {\r\n if (!geocoderMarkerManager) {\r\n geocoderMarkerManager = new MarkerManager()\r\n }\r\n return geocoderMarkerManager\r\n}\r\n\r\n// Convert longitude and latitude into Municipality and Country Subdivision\r\nexport const getMunicipalityAndProvince = async (latitude: string, longitude: string, countryCode?: string) => {\r\n try {\r\n const features = await reverseGeocode(latitude, longitude, countryCode, { size: 1, coarse: true })\r\n\r\n if (features.length > 0) {\r\n const properties = features[0].properties as any\r\n\r\n const municipality = properties.locality || properties.neighbourhood || properties.county || ''\r\n const countrySubdivision = properties.region_a || properties.region || '' // region_a gives abbreviation like \"ON\", \"BC\"\r\n\r\n return { municipality, countrySubdivision }\r\n }\r\n\r\n return { municipality: '', countrySubdivision: '' }\r\n }\r\n catch (error) {\r\n console.error('Error fetching municipality and country subdivision:', error)\r\n return { municipality: '', countrySubdivision: '' }\r\n }\r\n}\r\n\r\n// Fetch address suggestions from the active autocomplete provider\r\nexport const fetchSuggestions = async (input: string, countryCode?: string) => {\r\n if (!input || input.length < 3) {\r\n return []\r\n }\r\n\r\n try {\r\n return await autocompleteGeocode(input, countryCode, 5)\r\n }\r\n catch (error) {\r\n console.error('Error fetching address suggestions:', error)\r\n return []\r\n }\r\n}\r\n\r\n// Parse location details for better display\r\nexport const parseLocation = (feature: Feature) => {\r\n const locationName = feature.properties?.name || ''\r\n const fullLabel = feature.properties?.label || ''\r\n\r\n // Try to extract location details from properties\r\n const properties = feature.properties\r\n let regionDetails = ''\r\n\r\n if (properties) {\r\n const locality = properties.locality\r\n const region = properties.region // Full countrySubdivision name\r\n const region_a = properties.region_a // CountrySubdivision abbreviation (ON, BC, etc.)\r\n const country = properties.country\r\n const country_a = properties.country_a // Country abbreviation (CA)\r\n\r\n // Build region details similar to your original format\r\n if (locality && region_a && country_a) {\r\n regionDetails = `${locality}, ${region_a}, ${country_a}`\r\n }\r\n else if (locality && region && country) {\r\n regionDetails = `${locality}, ${region}, ${country}`\r\n }\r\n else {\r\n // Fallback: try to extract from the full label\r\n const parts = fullLabel.split(', ')\r\n if (parts.length > 1) {\r\n regionDetails = parts.slice(1, 3).join(', ')\r\n }\r\n }\r\n }\r\n\r\n return {\r\n name: locationName,\r\n region: regionDetails,\r\n fullLabel: fullLabel,\r\n }\r\n}\r\n\r\n// Handle suggestion selection and map movement\r\nexport const handleLocationSelect = (feature: Feature, map: any, type: string, options?: { editing?: boolean }) => {\r\n const editing = options?.editing || false\r\n const markerManager = getGeocoderMarkerManager()\r\n\r\n // Handle feature with is_database_building flag\r\n if (type === 'dbBuilding') {\r\n const geometry = feature.geometry as Point\r\n const center = geometry.coordinates\r\n const addressData = {\r\n formatted_address: feature.properties?.label || '',\r\n coordinates: center,\r\n properties: feature.properties,\r\n building_id: feature.properties.gid?.replace('building-', ''),\r\n is_database_building: true,\r\n }\r\n\r\n if (map && center) {\r\n // Add marker to the center with editing capability\r\n markerManager.create(center as [number, number], map)\r\n\r\n map.flyTo({\r\n center: addressData.coordinates,\r\n zoom: 18,\r\n speed: 1.5,\r\n })\r\n }\r\n\r\n return addressData\r\n }\r\n\r\n // Calculate center coordinates\r\n let center\r\n\r\n // Use bbox if available (more precise for areas)\r\n if (feature.bbox) {\r\n center = [\r\n feature.bbox[0] + (feature.bbox[2] - feature.bbox[0]) / 2,\r\n feature.bbox[1] + (feature.bbox[3] - feature.bbox[1]) / 2,\r\n ]\r\n }\r\n // Otherwise extract coordinates based on geometry type\r\n else if (feature.geometry?.type === 'Point') {\r\n center = (feature.geometry as any).coordinates\r\n }\r\n\r\n const addressData = {\r\n formatted_address: feature.properties?.label || feature.properties?.name || '',\r\n coordinates: center,\r\n properties: feature.properties,\r\n address_details: {\r\n name: feature.properties?.name,\r\n label: feature.properties?.label,\r\n locality: feature.properties?.locality,\r\n neighbourhood: feature.properties?.neighbourhood,\r\n region: feature.properties?.region,\r\n region_a: feature.properties?.region_a,\r\n country: feature.properties?.country,\r\n country_a: feature.properties?.country_a,\r\n postalcode: feature.properties?.postalcode,\r\n housenumber: feature.properties?.housenumber,\r\n street: feature.properties?.street,\r\n },\r\n geocode_earth_id: feature.properties?.gid, // Geocode Earth's unique id\r\n layer: feature.properties?.layer, // Type of place (address, venue, locality, etc.)\r\n confidence: feature.properties?.confidence, // Geocode Earth's confidence score\r\n match_type: feature.properties?.match_type, // How well the result matches the query\r\n }\r\n\r\n if (map && center) {\r\n // Add marker to the center with editing capability\r\n markerManager.create(center as [number, number], map, { editing })\r\n\r\n if (feature.bbox) {\r\n map.fitBounds(feature.bbox, { speed: 2 })\r\n }\r\n else {\r\n map.flyTo({\r\n center: addressData.coordinates,\r\n zoom: 14, // Might be good idea to set zoom level depending on layer / type of place\r\n speed: 2,\r\n })\r\n }\r\n }\r\n\r\n return addressData\r\n}\r\n\r\n// Util function to get detailed address information\r\nexport const getDetailedAddress = async (coordinates: [number, number], countryCode?: string) => {\r\n const [longitude, latitude] = coordinates\r\n\r\n try {\r\n // Restrict to address-layer results (the original popover used layers=address) so\r\n // callers get a street address rather than the nearest venue/POI. Nominatim's zoom-18\r\n // reverse is already building-level, so this only refines the Pelias path.\r\n const features = await reverseGeocode(latitude.toString(), longitude.toString(), countryCode, { size: 1, layers: 'address' })\r\n return features.length > 0 ? features[0] : null\r\n }\r\n catch (error) {\r\n console.error('Error fetching detailed address:', error)\r\n return null\r\n }\r\n}\r\n\r\n// Convert a building object to a GeoJSON feature format compatible with handleLocationSelect\r\nexport const buildingToFeature = (building) => {\r\n const name = building.buildingName || ''\r\n\r\n // Validate coordinates - use the correct property names\r\n const longitude = Number.parseFloat(building.buildingLongitude)\r\n const latitude = Number.parseFloat(building.buildingLatitude)\r\n\r\n if (isNaN(longitude) || isNaN(latitude)) {\r\n console.error('Invalid building coordinates:', {\r\n longitude: building.buildingLongitude,\r\n latitude: building.buildingLatitude,\r\n buildingId: building.id,\r\n })\r\n return null\r\n }\r\n\r\n return {\r\n properties: {\r\n name: name,\r\n label: `${name}, ${[building.buildingAddress, building.buildingMunicipality, building.buildingCountrySubdivision].filter(Boolean).join(', ')}`,\r\n address: building.buildingAddress,\r\n municipality: building.buildingMunicipality,\r\n countrySubdivision: building.buildingCountrySubdivision,\r\n postalCode: building.buildingPostalCode,\r\n gid: `building-${building.id}`,\r\n },\r\n geometry: {\r\n type: 'Point',\r\n coordinates: [longitude, latitude],\r\n },\r\n is_database_building: true,\r\n }\r\n}\r\n\r\n// Enhanced marker creation with editing capabilities\r\nexport const createGeocoderMarker = (coordinates: [number, number], map: any, options?: { editing?: boolean }) => {\r\n const editing = options?.editing || false\r\n const markerManager = getGeocoderMarkerManager()\r\n markerManager.create(coordinates, map, { editing })\r\n return markerManager\r\n}\r\n\r\n// Helper function to remove the current marker\r\nexport const removeGeocoderMarker = (): void => {\r\n const markerManager = getGeocoderMarkerManager()\r\n markerManager.remove()\r\n}\r\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB,sBAAsB;AAGpD,IAAI,wBAA8C;AAGlD,MAAM,2BAA2B,MAAqB;AACpD,MAAI,CAAC,uBAAuB;AAC1B,4BAAwB,IAAI,cAAc;AAAA,EAC5C;AACA,SAAO;AACT;AAGO,MAAM,6BAA6B,OAAO,UAAkB,WAAmB,gBAAyB;AAC7G,MAAI;AACF,UAAM,WAAW,MAAM,eAAe,UAAU,WAAW,aAAa,EAAE,MAAM,GAAG,QAAQ,KAAK,CAAC;AAEjG,QAAI,SAAS,SAAS,GAAG;AACvB,YAAM,aAAa,SAAS,CAAC,EAAE;AAE/B,YAAM,eAAe,WAAW,YAAY,WAAW,iBAAiB,WAAW,UAAU;AAC7F,YAAM,qBAAqB,WAAW,YAAY,WAAW,UAAU;AAEvE,aAAO,EAAE,cAAc,mBAAmB;AAAA,IAC5C;AAEA,WAAO,EAAE,cAAc,IAAI,oBAAoB,GAAG;AAAA,EACpD,SACO,OAAO;AACZ,YAAQ,MAAM,wDAAwD,KAAK;AAC3E,WAAO,EAAE,cAAc,IAAI,oBAAoB,GAAG;AAAA,EACpD;AACF;AAGO,MAAM,mBAAmB,OAAO,OAAe,gBAAyB;AAC7E,MAAI,CAAC,SAAS,MAAM,SAAS,GAAG;AAC9B,WAAO,CAAC;AAAA,EACV;AAEA,MAAI;AACF,WAAO,MAAM,oBAAoB,OAAO,aAAa,CAAC;AAAA,EACxD,SACO,OAAO;AACZ,YAAQ,MAAM,uCAAuC,KAAK;AAC1D,WAAO,CAAC;AAAA,EACV;AACF;AAGO,MAAM,gBAAgB,CAAC,YAAqB;AArDnD;AAsDE,QAAM,iBAAe,aAAQ,eAAR,mBAAoB,SAAQ;AACjD,QAAM,cAAY,aAAQ,eAAR,mBAAoB,UAAS;AAG/C,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AAA,MACN,aAAa,CAAC,WAAW,QAAQ;AAAA,IACnC;AAAA,IACA,sBAAsB;AAAA,EACxB;AACF;AAGO,MAAM,uBAAuB,CAAC,aAA+B,KAAU,YAAoC;AAChH,QAAM,WAAU,mCAAS,YAAW;AACpC,QAAM,gBAAgB,yBAAyB;AAC/C,gBAAc,OAAO,aAAa,KAAK,EAAE,QAAQ,CAAC;AAClD,SAAO;AACT;AAGO,MAAM,uBAAuB,MAAY;AAC9C,QAAM,gBAAgB,yBAAyB;AAC/C,gBAAc,OAAO;AACvB;","names":["center","addressData"]}
1
+ {"version":3,"sources":["../../../../../../src/core/components/viewers/map/utils/geocoder.ts"],"sourcesContent":["import { Feature, Point } from 'geojson'\r\nimport { MarkerManager } from './MarkerManager'\r\nimport { autocompleteGeocode, reverseGeocode } from './geocoding'\r\n\r\n// Global marker manager instance for geocoder\r\nlet geocoderMarkerManager: MarkerManager | null = null\r\n\r\n// Helper function to get or create the marker manager\r\nconst getGeocoderMarkerManager = (): MarkerManager => {\r\n if (!geocoderMarkerManager) {\r\n geocoderMarkerManager = new MarkerManager()\r\n }\r\n return geocoderMarkerManager\r\n}\r\n\r\n// Convert longitude and latitude into Municipality and Country Subdivision\r\nexport const getMunicipalityAndProvince = async (latitude: string, longitude: string, countryCode?: string) => {\r\n try {\r\n const features = await reverseGeocode(latitude, longitude, countryCode, { size: 1, coarse: true })\r\n\r\n if (features.length > 0) {\r\n const properties = features[0].properties as any\r\n\r\n const municipality = properties.locality || properties.neighbourhood || properties.county || ''\r\n const countrySubdivision = properties.region_a || properties.region || '' // region_a gives abbreviation like \"ON\", \"BC\"\r\n\r\n return { municipality, countrySubdivision }\r\n }\r\n\r\n return { municipality: '', countrySubdivision: '' }\r\n }\r\n catch (error) {\r\n console.error('Error fetching municipality and country subdivision:', error)\r\n return { municipality: '', countrySubdivision: '' }\r\n }\r\n}\r\n\r\n// Fetch address suggestions from the active autocomplete provider\r\nexport const fetchSuggestions = async (input: string, countryCode?: string) => {\r\n if (!input || input.length < 3) {\r\n return []\r\n }\r\n\r\n try {\r\n return await autocompleteGeocode(input, countryCode, 5)\r\n }\r\n catch (error) {\r\n console.error('Error fetching address suggestions:', error)\r\n return []\r\n }\r\n}\r\n\r\n// Parse location details for better display\r\nexport const parseLocation = (feature: Feature) => {\r\n const locationName = feature.properties?.name || ''\r\n const fullLabel = feature.properties?.label || ''\r\n\r\n // Try to extract location details from properties\r\n const properties = feature.properties\r\n let regionDetails = ''\r\n\r\n if (properties) {\r\n const locality = properties.locality\r\n const region = properties.region // Full countrySubdivision name\r\n const region_a = properties.region_a // CountrySubdivision abbreviation (ON, BC, etc.)\r\n const country = properties.country\r\n const country_a = properties.country_a // Country abbreviation (CA)\r\n\r\n // Build region details similar to your original format\r\n if (locality && region_a && country_a) {\r\n regionDetails = `${locality}, ${region_a}, ${country_a}`\r\n }\r\n else if (locality && region && country) {\r\n regionDetails = `${locality}, ${region}, ${country}`\r\n }\r\n else {\r\n // Fallback: try to extract from the full label\r\n const parts = fullLabel.split(', ')\r\n if (parts.length > 1) {\r\n regionDetails = parts.slice(1, 3).join(', ')\r\n }\r\n }\r\n }\r\n\r\n return {\r\n name: locationName,\r\n region: regionDetails,\r\n fullLabel: fullLabel,\r\n }\r\n}\r\n\r\n// Handle suggestion selection and map movement\r\nexport const handleLocationSelect = (feature: Feature, map: any, type: string, options?: { editing?: boolean }) => {\r\n const editing = options?.editing || false\r\n const markerManager = getGeocoderMarkerManager()\r\n\r\n // Handle feature with is_database_building flag\r\n if (type === 'dbBuilding') {\r\n const geometry = feature.geometry as Point\r\n const center = geometry.coordinates\r\n const addressData = {\r\n formatted_address: feature.properties?.label || '',\r\n coordinates: center,\r\n properties: feature.properties,\r\n building_id: feature.properties.gid?.replace('building-', ''),\r\n is_database_building: true,\r\n }\r\n\r\n if (map && center) {\r\n // Add marker to the center with editing capability\r\n // markerManager.create(center as [number, number], map)\r\n\r\n map.flyTo({\r\n center: addressData.coordinates,\r\n zoom: 18,\r\n speed: 1.5,\r\n })\r\n }\r\n\r\n return addressData\r\n }\r\n\r\n // Calculate center coordinates\r\n let center\r\n\r\n // Use bbox if available (more precise for areas)\r\n if (feature.bbox) {\r\n center = [\r\n feature.bbox[0] + (feature.bbox[2] - feature.bbox[0]) / 2,\r\n feature.bbox[1] + (feature.bbox[3] - feature.bbox[1]) / 2,\r\n ]\r\n }\r\n // Otherwise extract coordinates based on geometry type\r\n else if (feature.geometry?.type === 'Point') {\r\n center = (feature.geometry as any).coordinates\r\n }\r\n\r\n const addressData = {\r\n formatted_address: feature.properties?.label || feature.properties?.name || '',\r\n coordinates: center,\r\n properties: feature.properties,\r\n address_details: {\r\n name: feature.properties?.name,\r\n label: feature.properties?.label,\r\n locality: feature.properties?.locality,\r\n neighbourhood: feature.properties?.neighbourhood,\r\n region: feature.properties?.region,\r\n region_a: feature.properties?.region_a,\r\n country: feature.properties?.country,\r\n country_a: feature.properties?.country_a,\r\n postalcode: feature.properties?.postalcode,\r\n housenumber: feature.properties?.housenumber,\r\n street: feature.properties?.street,\r\n },\r\n geocode_earth_id: feature.properties?.gid, // Geocode Earth's unique id\r\n layer: feature.properties?.layer, // Type of place (address, venue, locality, etc.)\r\n confidence: feature.properties?.confidence, // Geocode Earth's confidence score\r\n match_type: feature.properties?.match_type, // How well the result matches the query\r\n }\r\n\r\n if (map && center) {\r\n // Add marker to the center with editing capability\r\n // markerManager.create(center as [number, number], map, { editing })\r\n\r\n if (feature.bbox) {\r\n map.fitBounds(feature.bbox, { speed: 2 })\r\n }\r\n else {\r\n map.flyTo({\r\n center: addressData.coordinates,\r\n zoom: 14, // Might be good idea to set zoom level depending on layer / type of place\r\n speed: 2,\r\n })\r\n }\r\n }\r\n\r\n return addressData\r\n}\r\n\r\n// Util function to get detailed address information\r\nexport const getDetailedAddress = async (coordinates: [number, number], countryCode?: string) => {\r\n const [longitude, latitude] = coordinates\r\n\r\n try {\r\n // Restrict to address-layer results (the original popover used layers=address) so\r\n // callers get a street address rather than the nearest venue/POI. Nominatim's zoom-18\r\n // reverse is already building-level, so this only refines the Pelias path.\r\n const features = await reverseGeocode(latitude.toString(), longitude.toString(), countryCode, { size: 1, layers: 'address' })\r\n return features.length > 0 ? features[0] : null\r\n }\r\n catch (error) {\r\n console.error('Error fetching detailed address:', error)\r\n return null\r\n }\r\n}\r\n\r\n// Convert a building object to a GeoJSON feature format compatible with handleLocationSelect\r\nexport const buildingToFeature = (building) => {\r\n const name = building.buildingName || ''\r\n\r\n // Validate coordinates - use the correct property names\r\n const longitude = Number.parseFloat(building.buildingLongitude)\r\n const latitude = Number.parseFloat(building.buildingLatitude)\r\n\r\n if (isNaN(longitude) || isNaN(latitude)) {\r\n console.error('Invalid building coordinates:', {\r\n longitude: building.buildingLongitude,\r\n latitude: building.buildingLatitude,\r\n buildingId: building.id,\r\n })\r\n return null\r\n }\r\n\r\n return {\r\n properties: {\r\n name: name,\r\n label: `${name}, ${[building.buildingAddress, building.buildingMunicipality, building.buildingCountrySubdivision].filter(Boolean).join(', ')}`,\r\n address: building.buildingAddress,\r\n municipality: building.buildingMunicipality,\r\n countrySubdivision: building.buildingCountrySubdivision,\r\n postalCode: building.buildingPostalCode,\r\n gid: `building-${building.id}`,\r\n },\r\n geometry: {\r\n type: 'Point',\r\n coordinates: [longitude, latitude],\r\n },\r\n is_database_building: true,\r\n }\r\n}\r\n\r\n// // Enhanced marker creation with editing capabilities\r\n// export const createGeocoderMarker = (coordinates: [number, number], map: any, options?: { editing?: boolean }) => {\r\n// const editing = options?.editing || false\r\n// const markerManager = getGeocoderMarkerManager()\r\n// markerManager.create(coordinates, map, { editing })\r\n// return markerManager\r\n// }\r\n\r\n// Helper function to remove the current marker\r\n// export const removeGeocoderMarker = (): void => {\r\n// const markerManager = getGeocoderMarkerManager()\r\n// markerManager.remove()\r\n// }\r\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB,sBAAsB;AAGpD,IAAI,wBAA8C;AAGlD,MAAM,2BAA2B,MAAqB;AACpD,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,eAAe,SAAS,SAAS,GAAG,UAAU,SAAS,GAAG,aAAa,EAAE,MAAM,GAAG,QAAQ,UAAU,CAAC;AAC5H,WAAO,SAAS,SAAS,IAAI,SAAS,CAAC,IAAI;AAAA,EAC7C,SACO,OAAO;AACZ,YAAQ,MAAM,oCAAoC,KAAK;AACvD,WAAO;AAAA,EACT;AACF;AAGO,MAAM,oBAAoB,CAAC,aAAa;AAC7C,QAAM,OAAO,SAAS,gBAAgB;AAGtC,QAAM,YAAY,OAAO,WAAW,SAAS,iBAAiB;AAC9D,QAAM,WAAW,OAAO,WAAW,SAAS,gBAAgB;AAE5D,MAAI,MAAM,SAAS,KAAK,MAAM,QAAQ,GAAG;AACvC,YAAQ,MAAM,iCAAiC;AAAA,MAC7C,WAAW,SAAS;AAAA,MACpB,UAAU,SAAS;AAAA,MACnB,YAAY,SAAS;AAAA,IACvB,CAAC;AACD,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,YAAY;AAAA,MACV;AAAA,MACA,OAAO,GAAG,IAAI,KAAK,CAAC,SAAS,iBAAiB,SAAS,sBAAsB,SAAS,0BAA0B,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI,CAAC;AAAA,MAC5I,SAAS,SAAS;AAAA,MAClB,cAAc,SAAS;AAAA,MACvB,oBAAoB,SAAS;AAAA,MAC7B,YAAY,SAAS;AAAA,MACrB,KAAK,YAAY,SAAS,EAAE;AAAA,IAC9B;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aAAa,CAAC,WAAW,QAAQ;AAAA,IACnC;AAAA,IACA,sBAAsB;AAAA,EACxB;AACF;","names":["center","addressData"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collabdt/core",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "description": "CDT Core contains all the core technology for your CDT platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",