0

I'm having difficulty loading this piece of html code, which would load this polygon into mapbox (which works), but trying to get a pop-up box to give the name of the polyogn when the polygon is clicked does not work. The relevant parts of the code are as follows :

map.addLayer({
        'id': 'holmewood_polygon',
        'type': 'fill',
        'source': {
            'type': 'geojson',
            'data': {
                'type': 'Featurecollection',
                'features': [{
                    "type": 'Feature',
'properties':{
'name' : 'E01028546'    },
},          
                'geometry': {
                    'type': 'Polygon','coordinates': [[[-1.268461096612599, 53.185816940492771 ], [ -1.267769482762843, 53.188029235314708 ], [ -1.264123057348978, 53.19092475592759 ], [ -1.261602601626478, 53.190796937917391 ], [ -1.260224935453381, 53.189413577950752 ], [ -1.258944157465988, 53.18783440142974 ], [ -1.257752526221339, 53.18650828330842 ], [ -1.256658256803305, 53.184958299899357 ], [ -1.256549184704025, 53.183161937896763 ], [ -1.263650345989223, 53.183065736547803 ], [ -1.268461096612599, 53.185816940492771 ] ] ] 
                }
            }]
        },
        'layout': {},
        'paint': {
            'fill-color': '#DD2D43',
            'fill-opacity': 0.8
            }
            });
            });
                map.on('click', 'holmewood_polygon', function (e) {
        new mapboxgl.Popup()
            .setLngLat(e.lngLat)
            .setHTML(e.feature[0].properties.name)
            .addTo(map);
    });

    </script>
 </body>      
</html>

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.