Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit dae3498

Browse files
author
Josh Erb
authored
ensure logo appears for tileLayers added after map init (#1324)
1 parent a637e5c commit dae3498

6 files changed

Lines changed: 94 additions & 2 deletions

File tree

src/map.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ var LMap = L.Map.extend({
207207
this._zoomBoundLayers[L.stamp(layer)] = layer;
208208
}
209209

210+
// ensure logo appears even when mapbox layer added after map is initialized
211+
var mapboxLogoControl = this._mapboxLogoControl.getContainer();
212+
if (!L.DomUtil.hasClass(mapboxLogoControl, 'mapbox-logo-true')) {
213+
var tileJSON = layer.getTileJSON();
214+
this._mapboxLogoControl._setTileJSON(tileJSON);
215+
}
216+
210217
this._updateMapFeedbackLink();
211218
this._updateZoomLevels();
212219
}

src/mapbox_logo.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ var MapboxLogoControl = L.Control.extend({
2222
if (json.mapbox_logo) {
2323
L.DomUtil.addClass(this._container, 'mapbox-logo-true');
2424
}
25+
26+
// account for usage of styleJSON as functional tileJSON for defaults
27+
if (!json.tilejson && json.owner === 'mapbox') {
28+
L.DomUtil.addClass(this._container, 'mapbox-logo-true');
29+
}
2530
}
2631
});
2732

test/helper.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,23 @@ helpers.tileJSON_malicious = {
869869
"webpage":"http://tiles.mapbox.com/examples/map/map-8ced9urs"
870870
}
871871

872+
helpers.tileJSON_mapboxlogoMissing = {
873+
"attribution": "<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox &copy; OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/feedback/' target='_blank'>Improve this map</a>",
874+
"autoscale": true,
875+
"bounds": [-180, -85.0511, 180, 85.0511],
876+
"data": ["http://a.tiles.mapbox.com/v3/examples.h8e9h88l/markers.geojsonp"],
877+
"geocoder": "http://a.tiles.mapbox.com/v3/examples.h8e9h88l/geocode/{query}.jsonp",
878+
"id": "examples.h8e9h88l",
879+
"maxzoom": 22,
880+
"minzoom": 0,
881+
"name": "My Mapbox Streets Map",
882+
"private": true,
883+
"scheme": "xyz",
884+
"tilejson": "2.0.0",
885+
"tiles": ["http://some.external.source.com/v3/examples.h8e9h88l/{z}/{x}/{y}.png"],
886+
"webpage": "http://a.tiles.mapbox.com/v3/examples.h8e9h88l/page.html",
887+
};
888+
872889
helpers.tileJSON_mapboxlogoFalse = {
873890
"attribution": "<a href='https://www.mapbox.com/about/maps/' target='_blank'>&copy; Mapbox &copy; OpenStreetMap</a> <a class='mapbox-improve-map' href='https://www.mapbox.com/feedback/' target='_blank'>Improve this map</a>",
874891
"autoscale": true,

test/manual/later-layer-logo.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset='UTF-8' />
6+
<link rel="stylesheet" href="../../dist/mapbox.css" />
7+
<meta name='viewport' content='initial-scale=1.0 maximum-scale=1.0'>
8+
<link rel="stylesheet" href="embed.css" />
9+
<script src="../../dist/mapbox.js"></script>
10+
<script src="access_token.js"></script>
11+
<style>
12+
body {
13+
margin: 0;
14+
padding: 0;
15+
}
16+
17+
#map {
18+
position: absolute;
19+
top: 0;
20+
bottom: 0;
21+
width: 100%;
22+
}
23+
</style>
24+
</head>
25+
26+
<body>
27+
28+
<div id='map'></div>
29+
30+
<script>
31+
var map = L.mapbox.map('map', null, {
32+
maxZoom: 18
33+
}).setView([22.76, -25.84], 3);
34+
35+
L.mapbox.tileLayer('mapbox.streets').addTo(map);
36+
</script>
37+
38+
</body>
39+
40+
</html>

test/manual/tooltips-on-hover.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Hide popup when user's cursor leaves marker.
2525
// We add a timeout to make it a little more visually graceful
2626
// in case of rapid cursor movement.
27-
mapfeatureLayerr.on('mouseout', function(e) {
27+
map.featureLayer.on('mouseout', function(e) {
2828
e.layer._closeTimeout = window.setTimeout(function() {
2929
e.layer.closePopup();
3030
}, 300);

test/spec/mapbox_logo.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ describe('mapbox_logo', function() {
1717
});
1818

1919
it('is not on tilejson map without mapbox_logo flag', function() {
20-
var map = L.mapbox.map(element, tileJSON);
20+
var map = L.mapbox.map(element, helpers.tileJSON_mapboxlogoMissing);
2121
var mapboxLogoControl = map._mapboxLogoControl.getContainer();
2222
expect(L.DomUtil.hasClass(mapboxLogoControl, 'mapbox-logo-true')).to.be(false);
2323
});
2424

25+
it('is on map when tilejson is mapbox styleJSON without mapbox_logo flag', function() {
26+
var map = L.mapbox.map(element, helpers.styleJSON);
27+
var mapboxLogoControl = map._mapboxLogoControl.getContainer();
28+
expect(L.DomUtil.hasClass(mapboxLogoControl, 'mapbox-logo-true')).to.be(true);
29+
});
30+
2531
it('is on tilejson map with mapbox_logo === true', function() {
2632
var map = L.mapbox.map(element, helpers.tileJSON_mapboxlogo);
2733
var mapboxLogoControl = map._mapboxLogoControl.getContainer();
@@ -60,4 +66,21 @@ describe('mapbox_logo', function() {
6066
[200, { "Content-Type": "application/json" }, JSON.stringify(helpers.tileJSON_mapboxlogoFalse)]);
6167
server.respond();
6268
});
69+
70+
it('is on mapid map when layer added after map initialization', function (done) {
71+
var layer = L.mapbox.tileLayer('mapbox.map-0l53fhk2');
72+
var map = L.mapbox.map(element)
73+
.setView([0, 0], 3)
74+
.addLayer(layer);
75+
76+
layer.on('ready', function() {
77+
var mapboxLogoControl = map._mapboxLogoControl.getContainer();
78+
expect(L.DomUtil.hasClass(mapboxLogoControl, 'mapbox-logo-true')).to.be(true);
79+
done();
80+
});
81+
82+
server.respondWith("GET", "https://api.mapbox.com/v4/mapbox.map-0l53fhk2.json?access_token=key&secure",
83+
[200, { "Content-Type": "application/json" }, JSON.stringify(helpers.tileJSON_mapboxlogo)]);
84+
server.respond();
85+
});
6386
});

0 commit comments

Comments
 (0)