The standard Leaflet marker icon, but in different color variations, for simple use cases.
This is a modernized fork of patrickp-rthinfo/leaflet-color-markers, which is in turn a fork of pointhi/leaflet-color-markers. With this, the first commit to this project can be traced back to late 2013.
Note that the Leaflet marker icon is originally contributed to the Leaflet project, and is not the work of this library. The work here is to make that colored marker icon available in some additional colors for easier simple multi-color marker usages.
via NPM:
npm install @vectorial1024/leaflet-color-markers
✔️ TypeScript definitions available as of 3.0.0.
This library is a successor of leaflet-color-markers. In particular, this library supports modern NodeJS import syntax, which is not supported by that library.
A demo is included in the same repo. It showcases a simple Leaflet map with colored markers from this package.
You may try it locally with the following steps:
- Clone this repo
npm run build-demo- Open
demo.htmlin your internet browser - See a minimally usable Leaflet map with a ring of colored markers in it
Add a simple marker using the green icon template to a Leaflet map:
import { greenIcon } from "@vectorial1024/leaflet-color-markers";
// we assume the map is already defined
const map = L.map('theMap');
L.marker([51.5, -0.09], { icon: greenIcon }).addTo(map);No extra CSS mess; it just works!
It even works with existing NodeJS frameworks very easily:
import { greenIcon } from '@vectorial1024/leaflet-color-markers';
return (
<MapContainer>
<Marker position={[51.505, -0.09]} icon={greenIcon} />
</MapContainer>
)import { Component } from '@angular/core';
import { greenIcon } from '@vectorial1024/leaflet-color-markers';
@Component({
imports: [LeafletDirective, LeafletLayersDirective],
})
export class AngularLeafletDemoMap {
layers = [
L.marker([51.505, -0.09], {
icon: greenIcon
})
];
}<script setup>
import { greenIcon } from '@vectorial1024/leaflet-color-markers';
</script>
<template>
<l-map>
<l-marker :lat-lng="[51.505, -0.09]" :icon="greenIcon" />
</l-map>
</template>As of 3.0.0, support for CJS (require()) has been removed. We strongly recommend you migrate to use the standard ESM style (import, available since 2018) to handle dependencies.
For 2.x, if CJS (require()) is required, you can still do this:
// require() also works, but we recommend using the import if possible
const LCM = require("@vectorial1024/leaflet-color-markers");
const greenIcon = LCM.greenIcon;The color table for 3.x.
Note that some preset color names are reassigned during the 2.x to 3.x upgrade.
