using Leaflet.Label with GeoJSON points

JasonRDalton

There are numerous references to leaflet.label working fine with GeoJSON points, but I've yet to find one example.
Here's what i've tried so far:

//Add labels layer
var labelStyle = {
    color: '#CCC',
    opacity: 1
};

var labelMarkerOptions = {
        opacity: 0,
        fillOpacity: 0
};

var labelLayer = L.geoJson(labels, {
        pointToLayer: function (feature, latlng) {
                return L.Marker(latlng, labelMarkerOptions);
        },
        onEachFeature: function (feature, layer) {
                layer.bindLabel(feature.properties.Name, {noHide:true});
        }
});
labelLayer.eachLayer(function(l) {l.showLabel();});
map.addLayer(labelLayer);
layerControl.addOverlay(labelLayer, 'Site Labels');

This adds a layer of my points, but with the default larkers, and no labels. Thanks for any help you can provide.

mattesCZ

If you want to show only the label, return L.circleMarker instead of L.Marker:

pointToLayer: function (feature, latlng) {
    return L.circleMarker(latlng, labelMarkerOptions);
},

If you need L.Marker for some other reason, bind the label directly to marker:

pointToLayer: function (feature, latlng) {
    return L.Marker(latlng, labelMarkerOptions).bindLabel(feature.properties.Name, {noHide:true});
},

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Simple label on a leaflet (geojson) polygon

Using fontawesome with leaflet markers and geojson

leaflet .bindLabel using geojson feature

react-leaflet GeoJSON with typescript not rendering geojson Points

Unable to use GeoJSON using leaflet package in R

Using Geojson with tons of data in react leaflet

view multiple geoJSon files into view using LEaflet

Leaflet: How to style 2000+ points in a GeoJSON object with no style properties?

Cannot plot GeoJSON points in D3/Leaflet app

Failing to draw points obtained from geoJson on Leaflet map

loading external geojson file into leaflet map by using leaflet ajax

'Invalid GeoJSON object.' Using Leaflet and leaflet-ajax

Rendering geoJSON using D3 and Leaflet using imageOverlay

Multipolygons in GeoJSON file parsed with jsonlite are not visualized using leaflet

How to add markers to different layers in leaflet using onEachFeature and geojson

Add Leaflet GeoJSON layers from GeoServer to an Array using a Javascript loop

React: How to map a geojson via fetch call to state using leaflet?

How to style each Geometry of a GeoJSON GeometryCollection individually using Leaflet

react-leaflet: Using a Component as a popup on a GeoJSON feature

Export leaflet map to geojson

Show geojson featureCollection with Leaflet

R Leaflet GeoJSON Coloring

Leaflet GeoJson addToMap Loader

Leaflet geojson search and zoom

Leaflet MarkerCluster with GeoJson

How do you change the offset for a leaflet popup using angular leaflet directive and geojson?

Getting GeoJSON Data to Leaflet Map using ngx-leaflet, HTTPClient and Angular2+

Leaflet GeoJSON type not associating with GeoJSON object

Leaflet - geoJSON integration (Creating buttons from GeoJSON)