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

Locate - locationfound: Add check if map container has leaflet_id / is existing #7813

Merged
merged 6 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 18 additions & 0 deletions spec/suites/map/MapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,4 +1318,22 @@ describe("Map", function () {
expect(map.getZoom()).to.be(undefined);
});
});

describe("#Geolocation", function () {
it("don't throw error if location is found and map is not existing", function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
var fn = L.Util.bind(map._handleGeolocationResponse, map);
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
map.remove();
expect(function () {
fn({coords: {latitude: 40.415296, longitude: 10.7419264, accuracy: 1129.5646101470752}});
}).to.not.throwException();
});
it("don't throw error if location is not found and map is not existing", function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
map._locateOptions = {setView: true};
var fn = L.Util.bind(map._handleGeolocationError, map);
map.remove();
expect(function () {
fn({coords: {latitude: 40.415296, longitude: 10.7419264, accuracy: 1129.5646101470752}});
}).to.not.throwException();
});
});
});
4 changes: 4 additions & 0 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ export var Map = Evented.extend({
},

_handleGeolocationError: function (error) {
if (!this._container._leaflet_id) { return; }

var c = error.code,
message = error.message ||
(c === 1 ? 'permission denied' :
Expand All @@ -684,6 +686,8 @@ export var Map = Evented.extend({
},

_handleGeolocationResponse: function (pos) {
if (!this._container._leaflet_id) { return; }

var lat = pos.coords.latitude,
lng = pos.coords.longitude,
latlng = new LatLng(lat, lng),
Expand Down