Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mapboxgl.util.inherit #63

Merged
merged 5 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v1.3.2

- Eliminate reliance on mapboxgl.util in preparation for [mapbox-gl-js#1408](https://github.com/mapbox/mapbox-gl-js/issues/1408)

### v1.3.1

- [BUG] Bump `[email protected]` to fix lagged results [#48](https://github.com/mapbox/mapbox-gl-geocoder/issues/48)
Expand Down
2 changes: 1 addition & 1 deletion dist/mapbox-gl-geocoder.js

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ function Geocoder(options) {
this.options = extend({}, this.options, options);
}

Geocoder.prototype = mapboxgl.util.inherit(mapboxgl.Control, {
function inherit(parent, props) {
var parentProto = typeof parent === 'function' ? parent.prototype : parent,
proto = Object.create(parentProto);
for (var i in props) {
Object.defineProperty(proto, i, Object.getOwnPropertyDescriptor(props, i));
}
return proto;
}

Geocoder.prototype = inherit(mapboxgl.Control, {

options: {
position: 'top-left',
Expand Down Expand Up @@ -194,10 +203,8 @@ Geocoder.prototype = mapboxgl.util.inherit(mapboxgl.Control, {
_query: function(input) {
if (!input) return;
if (typeof input === 'object' && input.length) {
input = [
mapboxgl.util.wrap(input[0], -180, 180),
mapboxgl.util.wrap(input[1], -180, 180)
].join();
// wrap to [-180, 180]
input = mapboxgl.LngLat.convert(input).wrap().toArray().join();
}

this._geocode(input, function(results) {
Expand All @@ -213,10 +220,8 @@ Geocoder.prototype = mapboxgl.util.inherit(mapboxgl.Control, {
_setInput: function(input) {
if (!input) return;
if (typeof input === 'object' && input.length) {
input = [
mapboxgl.util.wrap(input[0], -180, 180),
mapboxgl.util.wrap(input[1], -180, 180)
].join();
// wrap to [-180, 180]
input = mapboxgl.LngLat.convert(input).wrap().toArray().join();
}

// Set input value to passed value and clear everything else.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"envify": "^3.4.1",
"eslint": "^2.13.1",
"lodash.once": "^4.0.0",
"mapbox-gl": "^0.20.1",
"mapbox-gl": "0.26.0",
"smokestack": "^3.3.1",
"tap-status": "^1.0.1",
"tape": "^4.6.0",
Expand Down
6 changes: 3 additions & 3 deletions test/test.geocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ test('geocoder', function(tt) {
]
});

geocoder.query('Paris');
geocoder.query('London');
geocoder.on('results', once(function(e) {
t.ok(e.results.length, 'Event for results emitted');
t.equals(e.results[0].text, 'Paris Jewelry', 'Result is returned within a bbox');
t.equals(e.results[0].text, 'London Sole', 'Result is returned within a bbox');
}));
});

Expand All @@ -78,7 +78,7 @@ test('geocoder', function(tt) {
geocoder.query('1714 14th St NW');
geocoder.on('result', once(function() {
map.once(map.on('moveend', function() {
t.equals(map.getZoom(), 12, 'Custom zoom is supported');
t.equals(parseInt(map.getZoom()), 12, 'Custom zoom is supported');
}));
}));
});
Expand Down
8 changes: 7 additions & 1 deletion test/test.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('Geocoder#inputControl', function(tt) {

tt.test('input', function(t) {
setup();
t.plan(8);
t.plan(10);
var inputEl = container.querySelector('.mapboxgl-ctrl-geocoder input');
var clearEl = container.querySelector('.mapboxgl-ctrl-geocoder button');
inputEl.addEventListener('change', once(function() {
Expand All @@ -42,6 +42,12 @@ test('Geocoder#inputControl', function(tt) {
t.equals(inputEl.value, 'Paris', 'value populates in input');
t.ok(clearEl.classList.contains('active'), 'clear link is active');
t.notOk(geocoder.getResult(), 'input is set but result is null');

geocoder.setInput([90, 45]);
t.equals(inputEl.value, '90,45', 'valid LngLat value populates in input');

geocoder.setInput([270, 45]);
t.equals(inputEl.value, '-90,45', 'LngLat wraps if need be');
}));

geocoder.query([-79, 43]);
Expand Down