diff options
author | Christopher Baines <mail@cbaines.net> | 2015-03-13 14:46:17 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2015-03-13 14:46:17 +0000 |
commit | 33a084e511cb71ca1ea71f48389560e82ed879ec (patch) | |
tree | 53cb746520a023a2d4913e7e5a3bc70779301ea0 | |
parent | 27155d0bbc31ad7431478a5dedfaaeeecb8aee54 (diff) | |
download | leaflet-indoor-33a084e511cb71ca1ea71f48389560e82ed879ec.tar leaflet-indoor-33a084e511cb71ca1ea71f48389560e82ed879ec.tar.gz |
Add some more usage documentation
-rw-r--r-- | README.md | 87 |
1 files changed, 87 insertions, 0 deletions
@@ -41,6 +41,93 @@ levelControl.addEventListener("levelchange", indoorLayer.setLevel, indoorLayer); levelControl.addTo(map); ``` +### Usage Instructions + +The data should be a GeoJSON feature collection (or an array of GeoJSON +features). With the standard configuration, each feature must have a property +attribute "level", which can be a integer, string or array of either (or both). + +```javascript +{ + type: "FeatureCollection", + features: [ + { + type: "Feature", + geometry: ..., + properties: { + ... + level: 1 + .... + } + }, + { + type: "Feature", + geometry: ..., + properties: { + ... + level: [2, 3] + .... + } + } + ] +} +``` + +If the data is not in this format, you can pass in a replacement getLevel +function, that will be used to get the level for each Feature. + +```javascript +var indoorLayer = new L.Indoor(data, { + getLevel: function(feature) { + return feature.properties.otherLevel; + } + onEachFeature + + markerForFeature +}); +``` + +L.Control.Level is the user interface component that allows for the easy +switching of levels. It takes in some levels (which you can get from the indoor +layer by using getLevels()), and displays a list. + +```javascript +var levelControl = new L.Control.Level({ + level: "0", + levels: indoorLayer.getLevels() +}); +``` + +When using the L.Control.Indoor, if the levels are not integers, by default, +the levels will be converted to integers for the ordering in the control. If +the levels given to the control are not integers, then the parseLevel option +can be used to replace the default function that uses parseInt(level, 10). + +```javascript +var levelControl = new L.Control.Level({ + level: "1A", + levels: indoorLayer.getLevels() + parseLevel: function(level) { + var levels = { + "1A": 1, + "1B": 2, + "1C": 3, + "2": 4 + }; + return levels[level]; + } +}); +``` + +You can then bind the "levelchange" event, to change the level displayed by the +layer. Note that the levels that the control has must match that used by the +layer, if the levels in the control have been set via getLevels), this should +be the case. + +```javascript +levelControl.addEventListener("levelchange", indoorLayer.setLevel, indoorLayer); +``` + ## Events L.Control.Level will fire levelchange events when a level is selected. |