Display a popup on hover
When a user hovers over a custom marker, show a Popup
containing more information.
<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Display a popup on hover</title><meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /><script src="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.js"></script><link href="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.css" rel="stylesheet" /><style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; }</style></head><body><style>.trackasiagl-popup {max-width: 400px;font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;}</style><div id="map"></div><script>var map = new trackasiagl.Map({container: 'map',style: 'https://maps.track-asia.com/styles/v1/streets.json?key=public_key',center: {"lat":10.762622,"lng":106.660172},zoom: 13}); map.on('load', function () {map.loadImage('https://docs.track-asia.com/assets/custom_marker.png',// Add an image to use as a custom markerfunction (error, image) {if (error) throw error;map.addImage('custom-marker', image); map.addSource('places', { "type": "geojson", "data": { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "description": "<strong>Make it Mount Pleasant</strong><p>Make it Mount Pleasant is a handmade and vintage market and afternoon of live entertainment and kids activities. 12:00-6:00 p.m.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.668659, 10.761567 ] } }, { "type": "Feature", "properties": { "description": "<strong>Mad Men Season Five Finale Watch Party</strong><p>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.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.663168, 10.764651 ] } }, { "type": "Feature", "properties": { "description": "<strong>Big Backyard Beach Bash and Wine Fest</strong><p>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.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.660372, 10.761189 ] } }, { "type": "Feature", "properties": { "description": "<strong>Ballston Arts & Crafts Market</strong><p>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.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.661561, 10.762342 ] } }, { "type": "Feature", "properties": { "description": "<strong>Seersucker Bike Ride and Social</strong><p>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.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.662477, 10.763951 ] } }, { "type": "Feature", "properties": { "description": "<strong>Capital Pride Parade</strong><p>The annual Capital Pride Parade makes its way through Dupont this Saturday. 4:30 p.m. Free.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.663444, 10.769664 ] } }, { "type": "Feature", "properties": { "description": "<strong>Muhsinah</strong><p>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.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.661706, 10.764581 ] } }, { "type": "Feature", "properties": { "description": "<strong>A Little Night Music</strong><p>The Arlington Players\" production of Stephen Sondheim\"s <em>A Little Night Music</em> comes to the Kogod Cradle at The Mead Center for American Theater (1101 6th Street SW) this weekend and next. 8:00 p.m.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.660945, 10.768241 ] } }, { "type": "Feature", "properties": { "description": "<strong>Truckeroo</strong><p>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.</p>" }, "geometry": { "type": "Point", "coordinates": [ 106.667481, 10.766516 ] } } ] }} ); // 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.var popup = new trackasiagl.Popup({closeButton: false,closeOnClick: false}); map.on('mouseenter', 'places', function (e) {// Change the cursor style as a UI indicator.map.getCanvas().style.cursor = 'pointer'; var coordinates = e.features[0].geometry.coordinates.slice();var 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', function () {map.getCanvas().style.cursor = '';popup.remove();});});</script> </body></html>