Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
dont require map as option
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinabrokwa committed May 21, 2017
1 parent 57eb894 commit a2908d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ Constructor

**Parameters**

- `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The url for fectching vector tiles
- `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The template url for fectching vector tiles
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `options.map` **L.Map?**
- `options.getFeatureId` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?**
- `options.debug` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
- `options.style` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
Expand Down
15 changes: 8 additions & 7 deletions Leaflet.VectorTiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ L.VectorTiles = L.GridLayer.extend({
* Constructor
*
* @constructs
* @param {string} url The url for fectching vector tiles
* @param {string} url The template url for fectching vector tiles
* @param {Object} options
* @param {L.Map} [options.map]
* @param {Function} [options.getFeatureId]
* @param {boolean} [options.debug]
* @param {Object} [options.style]
Expand All @@ -35,12 +34,8 @@ L.VectorTiles = L.GridLayer.extend({

this._url = url;

// TODO: figure out how to do without this
this._map = options.map;

// the FeatureGroup that holds per tile FeatureGroups
this._featureGroup = L.featureGroup()
.addTo(this._map);
this._featureGroup = L.featureGroup();

// show tile boundaries
this._debug = options.debug;
Expand Down Expand Up @@ -102,6 +97,12 @@ L.VectorTiles = L.GridLayer.extend({
});
},

onAdd(map) {
L.GridLayer.prototype.onAdd.call(this, map);
this._map = map;
this._featureGroup.addTo(this._map);
},

/**
* Returns an array of feature ids near a given point
*
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var vtLayer = new L.VectorTiles(url, {
getFeatureId: function(feature) {
return feature.properties.id;
},
map: map,
debug: true, // to show tile boundaries
style: {
treeType: {
Expand Down
1 change: 0 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function main(geojson) {
const url = '/{z}/{x}/{y}';

const vtLayer = new L.VectorTiles(url, {
map,
getFeatureId: f => f.properties.name.toLowerCase(),
style: {}
}).addTo(map);
Expand Down

0 comments on commit a2908d7

Please sign in to comment.