项目作者: moravcik

项目描述 :
Custom icon for Leaflet with dynamic text
高级语言: HTML
项目地址: git://github.com/moravcik/Leaflet.TextIcon.git
创建时间: 2015-10-07T22:14:31Z
项目社区:https://github.com/moravcik/Leaflet.TextIcon

开源协议:

下载


TODO - rewrite to TypeScript

Leaflet.TextIcon

Custom icon for Leaflet with dynamic text

Adapted from: https://gist.github.com/comp615/2288108

Usage

Install with bower: bower install Leaflet.TextIcon

Link script and css into html (or use wiredep):

  1. <link rel="stylesheet" href="bower_components/Leaflet.TextIcon/leaflet-text-icon.css" />
  2. <script src="bower_components/Leaflet.TextIcon/leaflet-text-icon.js"></script>

Create marker with L.TextIcon:

  1. var icon = new L.TextIcon({ text: '12', color: 'red' });
  2. var marker = L.marker([lat, lng], { icon: icon }).addTo(map);

Options

  • color base color of icon; available values: blue (default), green, red
  • text text to display inside marker icon; alhough not restricted, should not be longer than 2 characters
  • other leaflet icon options; icon and shadow URLs are ignored

Methods

  • setColor(color) change icon base color; one of blue, green, red
  • setText(text) change icon text
  1. marker.options.icon.setColor('green');
  2. marker.options.icon.setText('21');

Demo