Skip to content

Commit

Permalink
Update URL Transform, Zoom behavior (#39)
Browse files Browse the repository at this point in the history
* update url transform to not add parameters to non-Mapbox API requests
* update zoom behavior on click to only increase zoom +1 from current level
  • Loading branch information
ryanbaumann committed Feb 3, 2018
1 parent bae0b6d commit 86f273e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mapboxgl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .viz import CircleViz, GraduatedCircleViz, HeatmapViz, ClusteredCircleViz

__version__ = "0.1.2"
__version__ = "0.1.3"
__all__ = ['CircleViz', 'GraduatedCircleViz', 'HeatmapViz', 'ClusteredCircleViz']
13 changes: 10 additions & 3 deletions mapboxgl/templates/circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
center: {{ center }},
zoom: {{ zoom }},
transformRequest: (url, resourceType)=> {
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
if ( url.slice(0,22) == 'https://api.mapbox.com' ) {
//Add Python Plugin identifier for Mapbox API traffic
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
}
}
else {
//Do not transform URL for non Mapbox GET requests
return {url: url}
}
}
});
Expand Down Expand Up @@ -91,7 +98,7 @@
map.on('click', 'circle', function(e) {
map.flyTo({
center: e.features[0].geometry.coordinates,
zoom: 10
zoom: map.getZoom() + 1
});
});
});
Expand Down
20 changes: 17 additions & 3 deletions mapboxgl/templates/clustered_circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
center: {{ center }},
zoom: {{ zoom }},
transformRequest: (url, resourceType)=> {
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
if ( url.slice(0,22) == 'https://api.mapbox.com' ) {
//Add Python Plugin identifier for Mapbox API traffic
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
}
}
else {
//Do not transform URL for non Mapbox GET requests
return {url: url}
}
}
});
Expand Down Expand Up @@ -106,7 +113,14 @@
map.on('click', 'circle-unclustered', function(e) {
map.flyTo({
center: e.features[0].geometry.coordinates,
zoom: 10
zoom: map.getZoom() + 1
});
});

map.on('click', 'circle-cluster', function(e) {
map.flyTo({
center: map.unproject(e.point),
zoom: map.getZoom() + 1
});
});
});
Expand Down
13 changes: 10 additions & 3 deletions mapboxgl/templates/graduated_circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
center: {{ center }},
zoom: {{ zoom }},
transformRequest: (url, resourceType)=> {
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
if ( url.slice(0,22) == 'https://api.mapbox.com' ) {
//Add Python Plugin identifier for Mapbox API traffic
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
}
}
else {
//Do not transform URL for non Mapbox GET requests
return {url: url}
}
}
});
Expand Down Expand Up @@ -92,7 +99,7 @@
map.on('click', 'circle', function(e) {
map.flyTo({
center: e.features[0].geometry.coordinates,
zoom: 10
zoom: map.getZoom() + 1
});
});
});
Expand Down
11 changes: 9 additions & 2 deletions mapboxgl/templates/heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
center: {{ center }},
zoom: {{ zoom }},
transformRequest: (url, resourceType)=> {
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
if ( url.slice(0,22) == 'https://api.mapbox.com' ) {
//Add Python Plugin identifier for Mapbox API traffic
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
}
}
else {
//Do not transform URL for non Mapbox GET requests
return {url: url}
}
}
});
Expand Down

0 comments on commit 86f273e

Please sign in to comment.