MIT License

项目介绍

stefanocudini/leaflet-panel-layers 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 MIT License 许可证,目前获得 298 个 Star、94 次 Fork。

仓库全名
stefanocudini/leaflet-panel-layers
开源许可证
MIT License
Star 数
298
Fork 数
94
未关闭 Issue
6

README 摘要

Leaflet Panel Layers ============== Leaflet Control Layers extended with support groups and icons Copyright Stefano Cudini If this project helped your work help me to keep this alive by Paypal DONATION ❤ Tested in Leaflet v1.6.x Demo: opengeo.tech/maps/leaflet-panel-layers Source code: Github Use Cases: Interactive tool by researchers from the Australian Antarctic Division EnviroMap by EnvironSensing Leaflet…

完整内容见 GitHub 原始 README 或本页 。

常见问题

leaflet-panel-layers 用什么语言开发?

主要使用 JavaScript 编写,采用 MIT License 许可证,目前有 298 个 Star。

leaflet-panel-layers 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 leaflet-panel-layers 的源码?

可以直接克隆仓库:git clone https://github.com/stefanocudini/leaflet-panel-layers.git,默认分支为 master;安装与运行步骤见仓库 README。

leaflet-panel-layers 最近还在维护吗?

仓库最近一次更新为 2023年8月11日,当前有 6 个未关闭 Issue;Star 数为 298,可作为社区活跃度的参考。

关于

Leaflet Control Layers extended with support groups and icons

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
495
价值分
207
活跃状态
活跃

语言占比

CSS
HTML
JavaScript

README

Leaflet Panel Layers

npm version

Leaflet Control Layers extended with support groups and icons

Copyright Stefano Cudini

If this project helped your work help me to keep this alive by Paypal DONATION ❤

Tested in Leaflet v1.6.x

Demo:

opengeo.tech/maps/leaflet-panel-layers

Source code:

Github

Use Cases:

Image

Options

Option Default Description
compact false panel height minor of map height
collapsed false panel collapsed at startup
autoZIndex true set zindex layer by order definition
collapsibleGroups false groups of layers is collapsible by button
groupCheckboxes false adds a checkbox to the group title to de-/select all layers in the group
selectorGroup false select all layer of a group
buildItem null function that return row item html node(or html string)
title ‘’ title of panel
className ‘’ additional class name for panel
position ‘topright’ position of control

Events

Event Data Description
‘panel:selected’ {layerDef} fired after moved and show markerLocation
‘panel:unselected’ {} fired after control was expanded

Methods

Method Arguments Description
addBaseLayer() layerDef,group,collapsed add new layer item definition to panel as baselayers
addOverlay() ‘Text message’ add new layer item definition to panel as overlay
removeLayer() ‘Text searched’ remove layer item from panel
configToControlLayers() ‘Text searched’ convert config from Control.PanelLayers to Control.Layers

Usage

Panel Item Definition formats

	{
		name: "Bar",
		icon: iconByName('bar'),
		layer: L.geoJson(Bar, {pointToLayer: featureToMarker })
	}

definition in JSON format permit to store simply the configuration type contains a Leaflet method in this case L.geoJson() args is the arguments passed to the method: L.geoJson(river)

	{
		layer: {
			type: "geoJson",
			args: [ river ]
		},
	}

definition of a group

	{
		group: "Title Group",
		collapsed: true,
		layers: [
		...other items...
		]
	}

Multiple active layers with icons

var baseLayers = [
	{
		active: true,
		name: "OpenStreetMap",
		layer: L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
	}
];
var overLayers = [
	{
		name: "Drinking Water",
		icon: '<i class="icon icon-water"></i>',
		layer: L.geoJson(WaterGeoJSON)
	},
	{
		active: true,
		name: "Parking",
		icon: '<i class="icon icon-parking"></i>',
		layer: L.geoJson(ParkingGeoJSON)
	}
];
map.addControl( new L.Control.PanelLayers(baseLayers, overLayers) );

Build panel layers from pure JSON Config

var panelJsonConfig = {
    "baselayers": [
        {
            "active": true,
            "name": "Open Cycle Map",
            "layer": {
                "type": "tileLayer",
                "args": [
                    "https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png"
                ]
            }
        },
        {
            "name": "Landscape",
            "layer": {
                "type": "tileLayer",
                "args": [
                    "https://{s}.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png"
                ]
            }
        },        
        {
            "name": "Transports",
            "layer": {
                "type": "tileLayer",
                "args": [
                    "https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png"
                ]
            }
        }
    ],
    "overlayers": [
        {
            "name": "Terrain",
            "layer": {
            "type": "tileLayer",
            "args": [
                "https://toolserver.org/~cmarqu/hill/{z}/{x}/{y}.png", {
                "opacity": 0.5
                }
            ]
            }
        }
    ]
};
L.control.panelLayers(panelJsonConfig.baseLayers, panelJsonConfig.overLayers).addTo(map);

Grouping of layers

L.control.panelLayers(
	[
		{
			name: "Open Street Map",
			layer: osmLayer
		},
		{
			group: "Walking layers",
			layers: [
				{
					name: "Open Cycle Map",
					layer: L.tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png')
				},
				{
					name: "Hiking",
					layer: L.tileLayer("https://toolserver.org/tiles/hikebike/{z}/{x}/{y}.png")
				}
			]
		},
		{
			group: "Road layers",
			layers: [
				{
					name: "Transports",
					layer: L.tileLayer("https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png")
				}
			]
		}
	],
	{collapsibleGroups: true}
).addTo(map);

Collapse some layers’ groups

L.control.panelLayers([
	{
		name: "Open Street Map",
		layer: osmLayer
	},
	{
		group: "Walking layers",
		layers: [
			{
				name: "Open Cycle Map",
				layer: L.tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png')
			},
			{
				name: "Hiking",
				layer: L.tileLayer("https://toolserver.org/tiles/hikebike/{z}/{x}/{y}.png")
			}			
		]
	},
	{
		group: "Road layers",
		collapsed: true,
		layers: [
			{
				name: "Transports",
				layer: L.tileLayer("https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png")
			}
		]
	}
]).addTo(map);

Add layers dynamically at runtime

var panel = L.control.panelLayers();

$.getJSON('some/url/path.geojson', function(data){
	panel.addOverlay({
		name: "Drinking Water",
		icon: '<i class="icon icon-water"></i>',
		layer: L.geoJson(data)
	});
});

Build

This plugin support Grunt for building process. Therefore the deployment require NPM installed in your system. After you’ve made sure to have npm working, run this in command line:

npm install
grunt

评论

暂无评论