Appearance
Geocoder (Geocoding Service)
Create and manage geocoding services for address and landmark search.
Constructor
ts
new ge3d.Geocoder(options?: GeocoderOptions): GeocoderParameters (GeocoderOptions)
| Parameter | Type | Default | Description |
|---|---|---|---|
| key | String | defaultToken | API key for geocoding service |
| core | Core | - | Map core instance (required for camera height calculation) |
Properties
| Property | Type | Description |
|---|---|---|
| options | Object | Configuration options |
| key | String | API key for geocoding service |
| core | Core | Map core instance |
Methods
| Method | Parameters | Return Value | Description |
|---|---|---|---|
| geocode | (query: string) | Promise<GeocoderResult[]> | Search for addresses and landmarks |
GeocoderResult
| Property | Type | Description |
|---|---|---|
| displayName | String | Display name of the location |
| destination | Cesium.Cartesian3 | 3D coordinates of the location |
| data | Object | Raw data from the geocoding service |
Usage Example
javascript
// Create map core
const core = new ge3d.Core("cesiumContainer", {
scene: {
center: { lat: 39.9087, lng: 116.3975, alt: 20000000 },
geocoder: true
},
baseImages: [
{
id: 'tdtLayerId',
name: "Tianditu Imagery",
type: "tdt",
layer: "img_d",
show: true
}
]
});
// Create geocoder instance
const geocoder = new ge3d.Geocoder({
// core: core // Optional, used for camera height calculation
});
// Search for a location
const data = geocoder.geocode('Riyadh');
// Handle the result
data.then((results) => {
console.log(results);
if (results.length > 0) {
// Fly to the first result
core.flyToPoint(results[0].destination);
}
});Notes
- The geocoder uses OpenStreetMap's Nominatim service for geocoding
- Results are automatically converted from WGS84 to the correct coordinate system
- Camera height is automatically calculated based on current view or defaults to 3000 meters
- The geocoder can be integrated into the map's built-in geocoder widget by setting
geocoder: truein scene options - Results include both display information and raw data from the geocoding service