Skip to main content

Display a Popup on Click

Add a popup to the map that opens when a symbol is clicked. Requires Trimble Maps v3.0.0 or later.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.css" />
        <script src="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.js"></script>
        <style>
            body { margin: 0; padding: 0; }

            #map {
                position: absolute;
                top: 0;
                bottom: 0;
                width: 100%;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>

        <script>
            TrimbleMaps.setAPIKey('YOUR_API_KEY_HERE');
                const map = new TrimbleMaps.Map({
        container: 'map',
        style: TrimbleMaps.Common.Style.TRANSPORTATION,
        center: [-77.04, 38.907],
        zoom: 11.15,
      });

      map.on('load', async () => {
        const image = await map.loadImage('https://developer.trimblemaps.com/maps-sdk/img/assets/custom_marker.png');
        // Add an image to use as a custom marker
        map.addImage('custom-marker', image.data);
        map.addSource('places', {
            'type': 'geojson',
            'data': {
                'type': 'FeatureCollection',
                'features': [
                    {
                        'type': 'Feature',
                        'properties': {
                            'description':
                                'Make it Mount Pleasant

Make it Mount Pleasant is a handmade and vintage market and afternoon of live entertainment and kids activities. 12:00-6:00 p.m.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.038659, 38.931567] } }, { 'type': 'Feature', 'properties': { 'description': 'Mad Men Season Five Finale Watch Party

Head to Lounge 201 (201 Massachusetts Avenue NE) Sunday for a Mad Men Season Five Finale Watch Party, complete with 60s costume contest, Mad Men trivia, and retro food and drink. 8:00-11:00 p.m. $10 general admission, $20 admission and two hour open bar.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.003168, 38.894651] } }, { 'type': 'Feature', 'properties': { 'description': 'Big Backyard Beach Bash and Wine Fest

EatBar (2761 Washington Boulevard Arlington VA) is throwing a Big Backyard Beach Bash and Wine Fest on Saturday, serving up conch fritters, fish tacos and crab sliders, and Red Apron hot dogs. 12:00-3:00 p.m. $25.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.090372, 38.881189] } }, { 'type': 'Feature', 'properties': { 'description': 'Ballston Arts & Crafts Market

The Ballston Arts & Crafts Market sets up shop next to the Ballston metro this Saturday for the first of five dates this summer. Nearly 35 artists and crafters will be on hand selling their wares. 10:00-4:00 p.m.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.111561, 38.882342] } }, { 'type': 'Feature', 'properties': { 'description': 'Seersucker Bike Ride and Social

Feeling dandy? Get fancy, grab your bike, and take part in this year\'s Seersucker Social bike ride from Dandies and Quaintrelles. After the ride enjoy a lawn party at Hillwood with jazz, cocktails, paper hat-making, and more. 11:00-7:00 p.m.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.052477, 38.943951] } }, { 'type': 'Feature', 'properties': { 'description': 'Capital Pride Parade

The annual Capital Pride Parade makes its way through Dupont this Saturday. 4:30 p.m. Free.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.043444, 38.909664] } }, { 'type': 'Feature', 'properties': { 'description': 'Muhsinah

Jazz-influenced hip hop artist Muhsinah plays the Black Cat (1811 14th Street NW) tonight with Exit Clov and Gods’illa. 9:00 p.m. $12.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.031706, 38.914581] } }, { 'type': 'Feature', 'properties': { 'description': 'A Little Night Music

The Arlington Players\' production of Stephen Sondheim\'s A Little Night Music comes to the Kogod Cradle at The Mead Center for American Theater (1101 6th Street SW) this weekend and next. 8:00 p.m.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.020945, 38.878241] } }, { 'type': 'Feature', 'properties': { 'description': 'Truckeroo

Truckeroo brings dozens of food trucks, live music, and games to half and M Street SE (across from Navy Yard Metro Station) today from 11:00 a.m. to 11:00 p.m.

' }, 'geometry': { 'type': 'Point', 'coordinates': [-77.007481, 38.876516] } } ] } }); // Add a layer showing the places. map.addLayer({ 'id': 'places', 'type': 'symbol', 'source': 'places', 'layout': { 'icon-image': 'custom-marker', 'icon-overlap': 'always' } }); // Create a popup, but don't add it to the map yet. const popup = new TrimbleMaps.Popup({ closeButton: false, closeOnClick: false }); map.on('mouseenter', 'places', (e) => { // Change the cursor style as a UI indicator. map.getCanvas().style.cursor = 'pointer'; const coordinates = e.features[0].geometry.coordinates.slice(); const description = e.features[0].properties.description; // Ensure that if the map is zoomed out such that multiple // copies of the feature are visible, the popup appears // over the copy being pointed to. while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) { coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360; } // Populate the popup and set its coordinates // based on the feature found. popup.setLngLat(coordinates).setHTML(description).addTo(map); }); map.on('mouseleave', 'places', () => { map.getCanvas().style.cursor = ''; popup.remove(); }); }); </script> </body> </html>
Last updated June 26, 2025.