Skip to content

Map Dialog

The map dialog allows users to select and display nearby places with customized icons, labels, and map styling options.

video

Parameters

The editDialog method is configured with the following options for map editing:

  • type: Set to 'map', indicating that the field being edited is an map.
  • path: Specifies the data path to store map dialog response.
  • config: Specifies the configuration for the map within the payload.

Config

The Map Dialog configuration provides options to set the map’s center, define place types, assign custom icons and labels, and control map design options. These settings are optional, except for the lat and lng fields.

  • lat (float, required): Latitude coordinate for the map center.
  • lng (float, required): Longitude coordinate for the map center.
  • language (string, enum: "en"|"de", default: "en"): Sets the language for the dialog UI and search.
  • types (array of strings): List of place types (e.g., "bus_station", "school") to search and display on the map.
  • icons (object): Custom icon URLs for specified place types, using the type as the key and the icon URL as the value (e.g., "school": "https://.../icon.svg").
  • labels (object): Custom labels for specific place types, where the key is the place type, and the value is the display label (e.g., {"golf_course": "Golf Course"}).
  • design (boolean): Enables design mode for advanced map customization.
  • freestyle (boolean): Allows users to apply free styling to the map.
  • downloadable (boolean): Enables downloading the map as a static image.
  • ratio (float, default: 16/9): Defines the aspect ratio for the map image.
  • mapWidth (integer, default: 1280): Specifies the width of the map in design, measured in pixels. (value range from 320 to 3200)
  • iconWidth (integer, default: 32): Specifies the width of icons used in design, measured in pixels. (value range from 5 to 999)
  • iconWidths (object): Specifies the width of each individual icon used in design, measured in pixels. (value range from 5 to 999)
  • styles (array of objects): List of Mapbox styles with URLs and names, allowing customization of map appearance (e.g., [{ url: '...', name: 'Basic Style' }]).

Example Config

Example configuration below outlines the options available for setting up the Map Dialog, including place types, custom icons, map design settings, and Mapbox style integration.

javascript
const config = { 
    // Required: Map center coordinates
    lat: 47.3769, 
    lng: 8.5417,

    // Language setting for the UI and place search (default is 'en')
    language: 'en',
    
    // Array: Place types for nearby search
    types: ["bus_station", "post_office", "school"],                

    // Object: Custom icon URLs for place types
    icons: {
        "home": "https://platform.uhuu.io/docs/dialogs/map/icons/home.svg",
        "bus_station": "https://platform.uhuu.io/docs/dialogs/map/icons/bus_station.svg",
        "golf_course": "https://platform.uhuu.io/docs/dialogs/map/icons/golf_course.svg",
        "kindergarden": "https://platform.uhuu.io/docs/dialogs/map/icons/kindergarden.svg",
        "post_office": "https://platform.uhuu.io/docs/dialogs/map/icons/post.svg",
        "school": "https://platform.uhuu.io/docs/dialogs/map/icons/school.svg",
        "ship_station": "https://platform.uhuu.io/docs/dialogs/map/icons/ship_station.svg",
        "shopping_mall": "https://platform.uhuu.io/docs/dialogs/map/icons/shopping_mall.svg",
        "supermarket": "https://platform.uhuu.io/docs/dialogs/map/icons/shopping_mall.svg",
        "swimming_pool": "https://platform.uhuu.io/docs/dialogs/map/icons/swimming_pool.svg",
        "train_station": "https://platform.uhuu.io/docs/dialogs/map/icons/train_station.svg"
    },

    // Object: Custom labels for specific place types
    labels: {
        "golf_course": "Golf Course",
        "swimming_pool": "Swimming Pool"
    },

    // Boolean: Enables map design customization
    design: true,
    
    // Boolean: Allows free map styling by users
    freestyle: false,
    
    // Boolean: Allows the map to be downloaded as a static image
    downloadable: false,

    // Float: Aspect ratio for the map image (default is 16/9)
    ratio: 16/9,

    // Integer: Defines the width of map on design (in pixels)
    mapWidth: 1280,

    // Integer: Defines the width of icons on design (in pixels)
    iconWidth: 32,

    // Object: Defines the width of each individual icon on design (in pixels)
    iconWidths: {
        "home": 48,
        "bus_station": 32,
        "post_office": 32,
        "school": 32
    },

    // Array of objects: Mapbox style URLs and names for customizing map appearance
    styles: [            
        { url: 'mapbox://styles/mapboxuhuu/cm2wkiku7003001qtbpx2dmg9', name: 'B&W Minimal' }, 
        { url: 'mapbox://styles/mapboxuhuu/cm2n3fjcc002h01pmbdyv84et', name: 'Blueprint' }, 
        { url: 'mapbox://styles/mapboxuhuu/cm2uoqo6k005r01pq7ct6f6ei', name: 'Frank' }
    ]
};

Example Usage

The following react component renders a Map Dialog with the above configuration. When the “Select Map” link is clicked, the dialog opens, allowing users to view nearby places and adjust the map based on the selected configuration.

javascript
export default ({ payload }) => {
    const { map_data } = payload;    
    const image = map_data?.image ?? null;
    const list = map_data?.list ?? [];

    return (
        <div>    
            <div className="text-4xl pt-7 mb-14">Nearby Places</div>            
            <div className="w-full" onClick={() => $uhuu.editDialog({ path: "map_data", type: "map", config })}>                                    
                {/* Display Map Image */}
                {image && <img src={image} alt="Map" className="w-full h-auto mt-4" />}

                {/* Display List of Nearby Places */}
                <div className="flex flex-col gap-2 text-sm">
                    { list.map((place) => (
                        <div key={place.reference} className="pl-3 py-1.5 border-b border-black flex items-center justify-between">
                            <div>{place.name}</div>
                            <div className="text-gray-500">{place.vicinity}</div>                    
                        </div>
                    ))}
                </div>                     
            </div>    
        </div>    
    );
};

Response Fields

  • list: An array of nearby places selected in the Map Dialog. Each place object contains:

    • reference: A unique identifier for the place.
    • name: The name of the place (e.g., "Zurich HB").
    • vicinity: Address or general location description.
    • lat and lng: Latitude and longitude coordinates of the place.
    • type: Type of the place, such as train_station or town_square.
    • distance: Distance from the map center to the location, in meters.
  • image: A URL to the generated map image that visualizes the selected places on a map. This image can be directly embedded within the template to provide a visual representation of the nearby locations.

Example Response

After users interact with map dialog, the response data is structured as following:

json
{ 
    "list": [
        {
            "reference": "ChIJQW4OzAgKkEcRp1KMX7aYxvU",
            "name": "Zurich HB",
            "vicinity": "Bahnhofplatz, 8001 Zürich, Svizzera",
            "lat": 47.3781458,
            "lng": 8.540251699999999,
            "type": "train_station",
            "distance": 176
        },
        {
            "reference": "ChIJAzjwR6ugmkcRp5p8Ovu2-rM",
            "name": "Bellevueplatz",
            "vicinity": "Bellevueplatz, 8001 Zürich, Svizzera",
            "lat": 47.3671349,
            "lng": 8.5449292,
            "type": "town_square",
            "distance": 1113
        }
    ],
    "image": "https://example.com/path-to-generated-map-image.jpg"
}

Usage Summary

  • Map Dialog provides an interactive way to add location data and a custom map to documents.
  • Location List: Allows users to review and display selected places with relevant details.
  • Map Image: Embeds a generated map image that visually represents the selected locations.

Style with Mapbox Studio

  1. Navigate to Mapbox Studio. Create a new map style or open an existing one.
  2. In the style editor, click on the “Share” button (or “Publish” if it’s unpublished). A modal will appear with the style URL.
  3. Copy the mapbox://styles/... URL and use it in your Mapbox project to apply the custom style to your map.
video

That’s it! Now you can style your maps with your chosen design.

Sample Mapbox Style URL:

mapbox://styles/mapboxuhuu/cm2n3fjcc002h01pmbdyv84et

You can quickly preview styles using: Dialog Map Style Preview

Place Types and Customizing Icons

You can specify place types for searches, which are supported in Place Details results and as part of autocomplete place predictions. When making a Place Details request, include the desired types in the types field. For autocomplete, check the Places Autocomplete documentation for guidance on using these values.

To customize icons for specific place types, use the exact keys from the Place Types API. For example, to change the default icon for a spa, set the key to spa in your configuration. This ensures accurate mapping and display of custom icons for each place type.

Accounting
accounting
Airport
airport
Amusement Park
amusement_park
Aquarium
aquarium
Art Gallery
art_gallery
ATM
atm
Bakery
bakery
Bank
bank
Bar
bar
Beauty Salon
beauty_salon
Bicycle Store
bicycle_store
Book Store
book_store
Bowling Alley
bowling_alley
Bus Station
bus_station
Cafe
cafe
Campground
campground
Car Dealer
car_dealer
Car Rental
car_rental
Car Repair
car_repair
Car Wash
car_wash
Casino
casino
Cemetery
cemetery
Church
church
City Hall
city_hall
Clothing Store
clothing_store
Convenience Store
convenience_store
Courthouse
courthouse
Dentist
dentist
Department Store
department_store
Doctor
doctor
Drugstore
drugstore
Electrician
electrician
Electronics Store
electronics_store
Embassy
embassy
Fire Station
fire_station
Florist
florist
Funeral Home
funeral_home
Furniture Store
furniture_store
Gas Station
gas_station
Gym
gym
Hair Care
hair_care
Hardware Store
hardware_store
Hindu Temple
hindu_temple
Home Goods Store
home_goods_store
Hospital
hospital
Insurance Agency
insurance_agency
Jewelry Store
jewelry_store
Laundry
laundry
Lawyer
lawyer
Library
library
Light Rail Station
light_rail_station
Liquor Store
liquor_store
Local Government Office
local_government_office
Locksmith
locksmith
Lodging
lodging
Meal Delivery
meal_delivery
Meal Takeaway
meal_takeaway
Mosque
mosque
Movie Rental
movie_rental
Movie Theater
movie_theater
Moving Company
moving_company
Museum
museum
Night Club
night_club
Painter
painter
Park
park
Parking
parking
Pet Store
pet_store
Pharmacy
pharmacy
Physiotherapist
physiotherapist
Plumber
plumber
Police
police
Post Office
post_office
Primary School
primary_school
Real Estate Agency
real_estate_agency
Restaurant
restaurant
Roofing Contractor
roofing_contractor
RV Park
rv_park
School
school
Secondary School
secondary_school
Shoe Store
shoe_store
Shopping Mall
shopping_mall
Spa
spa
Stadium
stadium
Storage
storage
Store
store
Subway Station
subway_station
Supermarket
supermarket
Synagogue
synagogue
Taxi Stand
taxi_stand
Tourist Attraction
tourist_attraction
Train Station
train_station
Transit Station
transit_station
Travel Agency
travel_agency
University
university
Veterinary Care
veterinary_care
Zoo
zoo

Additional Place Types

As part of the result of a Place search request those type of place results may return.

The types below are not supported in the type filter of a place search.

Home
home
Administrative Area Level 1
administrative_area_level_1
Administrative Area Level 2
administrative_area_level_2
Administrative Area Level 3
administrative_area_level_3
Administrative Area Level 4
administrative_area_level_4
Administrative Area Level 5
administrative_area_level_5
Administrative Area Level 6
administrative_area_level_6
Administrative Area Level 7
administrative_area_level_7
Archipelago
archipelago
Colloquial Area
colloquial_area
Continent
continent
Country
country
Establishment
establishment
Finance
finance
Floor
floor
Food
food
General Contractor
general_contractor
Geocode
geocode
Health
health
Intersection
intersection
Landmark
landmark
Locality
locality
Natural Feature
natural_feature
Neighborhood
neighborhood
Place of Worship
place_of_worship
Plus Code
plus_code
Point of Interest
point_of_interest
Political
political
Post Box
post_box
Postal Code
postal_code
Postal Code Prefix
postal_code_prefix
Postal Code Suffix
postal_code_suffix
Postal Town
postal_town
Premise
premise
Room
room
Route
route
Street Address
street_address
Street Number
street_number
Sublocality
sublocality
Sublocality Level 1
sublocality_level_1
Sublocality Level 2
sublocality_level_2
Sublocality Level 3
sublocality_level_3
Sublocality Level 4
sublocality_level_4
Sublocality Level 5
sublocality_level_5
Subpremise
subpremise
Town Square
town_square

Multiple Types

When you have multiple dialog types available in an editable area, or you want to provide multiple dialog types for the same field, you can use the types parameter to pass an array of dialog options. This lets users choose the preferred way for editing the payload.

video

In the example below, we have two dialog types available for the same field. The first one is an image dialog type. The second one is a map dialog type.

javascript
$uhuu.editDialog({types: [
    { path: 'uhuu_restore.my_data', type: 'image', ratio: 1 },
    { path: 'uhuu_restore.my_data', type: 'map', config: { ...baseMapConfig, lat, lng, ratio: 1 } },
  ]});

FAQ

(e.g., https://platform.uhuu.io/docs/dialogs/map/icons/home.svg)

You can upload SVG icons to any accessible server, such as S3, Google Drive, or an FTP server, and load them from there.

Q: How does backward compatibility work when adding map-generated images?

The map dialog will set the generated map image and list values to dialog's path. Before users interact with the map dialog, this value will be empty.

For backward compatibility, you can implement a fallback mechanism to check empty path value and handle accordingly.

Here’s an example of how to handle this:
javascript
export default ({ payload }) => {
    const { map_data, fallbackImage } = payload;    
    const image = map_data?.image || fallbackImage;    

    return (
        <div className="w-full" onClick={() => $uhuu.editDialog({ path: "map_data", type: "map", config })}>                                                    
            {image && <img src={image} alt="Map" />}                 
        </div>
    );
};

In this example:

  • If map_data?.image exists, it will be used.
  • If not, the fallbackImage will be used instead, ensuring the application functions smoothly with older templates.

Q: Should I initialize the first value in the template setup?

No, initializing the first value (e.g., map_path) in the payload is not necessary unless you need default values.

If default values are not required, you can omit them in the template setup. Uhuu dialogs will automatically set the necessary values when users interact with the dialog.

Are you using with uhuu_restore?

This also applies to the reserved variable uhuu_restore, which is used for maintaining the state. For example, you can define the path uhuu_restore.map_path without initializing it in the template setup and values will be set when users interact with the dialog.

javascript
export default ({ payload }) => {
    const { uhuu_restore } = payload;    
    const image = uhuu_restore?.map_data?.image || null;    

    return (
        <div className="w-full" onClick={() => $uhuu.editDialog({ path: "uhuu_restore.map_data", type: "map", config })}>                                                    
            {image && <img src={image} alt="Map" />}                 
        </div>
    );
};

uhuu_restore reserved key storage helps you keep the assigned values even after fresh data is fetched from integration.

Q: Why aren’t all types defined in the code shown in the selector?

(e.g., ship_station, kindergarten, or golf_course)

Only Google Place Types are displayed in the place type selector. These are the standard types supported by the Google Places API for querying and fetching nearby locations.

For custom types like ship_station, kindergarten, or golf_course, you can add them manually. First, use the place search to select a location, then change the type to your custom value afterwards.

Here’s a video demonstrating how to add and customize place types:

video