Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, June 21
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Dynamic Image Map in Salesforce Lightning

    Dynamic Image Map in Salesforce Lightning

    Dhanik Lal SahniBy Dhanik Lal SahniAugust 1, 2020Updated:January 12, 20252 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Dynamic Image Map in Salesforce Lightning
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Images are best to showcase products or brands on websites. These images can be divided into multiple sections using an image map to show specific products or brand information.

    We can use HTML image maps to create clickable areas on an image. Image maps are used hyperlink parts of an image to a different destination.

    HTML Elements Used to Create Image Maps

    There are three HTML elements used to create image maps:

    • img: specifies the product or brand image. usemap attribute is required for map creation.
    • map: is used to create a map of clickable image areas.
    • area: is used within the map element to define the clickable areas.

    Example:

    <img src="brand.jpg" alt="Workplace" usemap="#workmap">
    <map name="workmap">
      <area shape="rect" coords="34,44,270,350" alt="Wipro" href="https://www.wipro.com/">
      <area shape="rect" coords="290,172,333,250" alt="iPhone" href="https://www.flipkart.com/apple-iphone-5-white-16-gb/">
    </map>

    Let us build this as a dynamic Lightning Web Component in Salesforce. We need image and image coordinates to make a clickable image component. We can create a new image and image detail object or can use any existing object to store field information.

    Image Object:

    This object will store image detail. Enable attachment while creating an object. The image will be stored as an attachment. Fields for this object is

    Image NameNameText(80)

    Image Detail Object

    This object will store image detail. This will hold all coordinate of the image, the link of page which will be opened when that coordinate area clicked and detail if textual information needs to show in another area. This will be the child object for the above image object.

    NameAPIType
    CoordinateCoordinate__cText(50)
    DetailDetail__cText(255)
    ImageImage__cMaster-Detail(Image)
    Image Detail NumbeNameAuto Number
    LinkUrlLinkUrl__cURL(255)
    ShapeShape__cPicklist
    Values: default, rect, poly, circle

    Sample Record:

    Sample Image Object Record

    Dynamic Image Map in Salesforce

    Sample Image Detail Object Record

    Image Map in Salesforce

    Getting Area Coordinates in Image:

    MS-Paint will show correct co-ordinates of image area/section.

    Image Coordinate | Image Map | SalesforceCodex

    Apex Code to retrieve image and detail:

    getAllImages : This method will return all image detail.

    getImage : This will get public url for selected image info and its map location from image detail object.

    LWC Code for building image map:

    Below code will create clickable section on image. Number of clickable area is depend on image detail records for image.

    CSS class .area is used to remove pointer events.

    <template for:each={maps} for:item="map">
        <area key={map.Id}  data-item={map.Id} shape={map.Shape__c} coords={map.Coordinate__c} href='' target="_blank" class="area" onclick={handleMap}>
    </template>               

    On component load, all images will be loaded and stored in the combo-box. On selection of combo box, handleImageChange handler is called to get image detail. This will also show an image in the image section with clickable areas.

    handleMap handler will handle click event of clickable area. If link url is present then it will open page/link in new tab. If link is for showing detail then it will show detail in new section.

    Demo Video:

    References:

    HTML Image Map

    Related Posts

    • How to Use Image Cropper in Salesforce Lightning Web Component
    • Configurable Record Picker in Lightning Web Component
    • Displaying Tabular Data with GraphQL in Lightning Web Component
    • Export Data from Lightning Web Component to Excel Sheet
    • Generate PDF using jsPDF in Lightning Web Component
    • Custom Image Slider in Lightning Web Component
    • File Related List in Lightning Web Component
    • Stop deselecting lightning-dual-listbox list
    • Adding table row dynamically in Lightning Web Component

    apex Lightning web component lwc salesforce
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleLogo Recognition using Google Cloud Vision in Salesforce
    Next Article Object Identification using Google Cloud Vision in Salesforce
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni9 Mins Read

    10 Salesforce Chrome Extensions to Boost Your Productivity

    June 1, 2025
    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    View 2 Comments

    2 Comments

    1. Salman on April 4, 2023 9:12 am

      Hi, I have tried to copy all this but it does not work. Could you provide more in detail how you implement it especially on displaying it after selecting the picklist? my situation is I can pick among the option but the picture will not appear.

      Reply
      • Dhanik Lal Sahni on April 4, 2023 10:46 am

        Hello Salman,
        You can debug (handleMap method) why the image is not showing after the picklist selection. If not working, then ping me on Linked-In.

        Thank You,
        Dhanik

        Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins June 5, 2025
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code analysis (3) code optimization (8) custom metadata types (5) design principle (9) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (65) lightning-combobox (5) lightning-datatable (10) lightning component (31) Lightning web component (63) lwc (52) named credential (8) news (4) optimize apex code (4) optimize apex trigger (3) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (142) salesforce apex (47) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.