Skip to content

CarMi0Proggramer/leaflet-labels-renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leaflet - Plugin LabelsRenderer

This is a plugin for leaflet.js that adds support for rendering labels along the path of Polylines. It is based on the popular plugins L.StreetLabels and L.LabelTextCollision. This plugin aims to provide faster rendering times for drawing labels.

Installation

To install and use the plugin, choose one of these methods:

Using package managers

npm install leaflet-labels-renderer
# or
bun add leaflet-labels-renderer
# or
pnpm add leaflet-labels-renderer

Manual installation

Follow these steps if you prefer not to use a package manager:

1. Generate the build

First, you need to generate the plugin build by running the following command:

npm run build

2. Include the plugin in your project

Make sure to include the leaflet-labels.js file from the dist folder in your project. You can do this by adding the following line to your HTML:

<script src="/path/to/leaflet.js"></script>
<script src="/path/to/leaflet-labels.js"></script>

3. Use the plugin

To use the plugin, simply create an instance of L.LabelsRenderer or use the L.labelsRenderer function and add it to your map. Here's a basic example:

const renderer = L.labelsRenderer({
  propertyName: "name", // Property containing the label text,
  font: {
    size: 13, // Font size in pixels,
    fill: "black",
    stroke: "transparent",
    lineWidth: 4,
  },
  showLabelIf: (feature) => feature.properties.isPrimary == true,
});

const map = L.map({ renderer });

// Additional map setup...

About

A leaflet.js plugin that provides a Canvas renderer to show labels on polylines along the path

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors