Skip to content

Commit

Permalink
Merge cc2f57b into 368d1e2
Browse files Browse the repository at this point in the history
  • Loading branch information
akacarlyann committed May 5, 2018
2 parents 368d1e2 + cc2f57b commit c396f42
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 206 deletions.
12 changes: 8 additions & 4 deletions docs-markdown/viz.md
Expand Up @@ -21,7 +21,7 @@
The `MapViz` class is the parent class of the various `mapboxgl-jupyter` visualizations. You can use this class to set default values for all visualizations rather than calling them directly from the other visualization objects.

### Params
**MapViz**(_data, access_token=None, center=(0, 0), below_layer='', opacity=1, div_id='map', height='500px', style='mapbox://styles/mapbox/light-v9?optimize=true', width='100%', zoom=0, min_zoom=0, max_zoom=24, pitch=0, bearing=0_)
**MapViz**(_data, access_token=None, center=(0, 0), below_layer='', opacity=1, div_id='map', height='500px', style='mapbox://styles/mapbox/light-v9?optimize=true', width='100%', zoom=0, min_zoom=0, max_zoom=24, pitch=0, bearing=0, legend=True_)

Parameter | Description
--|--
Expand All @@ -36,6 +36,7 @@ zoom | starting zoom level for map
opacity | opacity of map data layer
pitch | starting pitch (in degrees) for map
bearing | starting bearing (in degrees) for map
legend | controls visibility of map legend | True

### Methods
**as_iframe**(_self, html_data_)
Expand Down Expand Up @@ -258,7 +259,7 @@ viz.show()
The `HeatmapViz` object handles the creation of a heat map and is built on top of the `MapViz` class.

### Params
**HeatmapViz**(_data, weight_property=None, weight_stops=None, color_stops=None, radius_stops=None, intensity_stops=None, \*args, \*\*kwargs_)
**HeatmapViz**(_data, weight_property=None, weight_stops=None, color_stops=None, radius_stops=None, intensity_stops=None, legend=False, \*args, \*\*kwargs_)

Parameter | Description | Example
--|--|--
Expand All @@ -268,6 +269,7 @@ weight_stops | stops to determine heatmap weight. | [[10, 0], [100, 1]]
color_stops | stops to determine heatmap color. | [[0, "red"], [0.5, "blue"], [1, "green"]]
radius_stops | stops to determine heatmap radius based on zoom. | [[0, 1], [12, 30]]
intensity_stops | stops to determine the heatmap intensity based on zoom. EX: [[0, 0.1], [20, 5]]
legend | defaults to no legend for HeatmapViz | False

[View options](https://github.com/mapbox/mapboxgl-jupyter/blob/master/docs-markdown/viz.md#params)

Expand Down Expand Up @@ -381,12 +383,13 @@ viz.show()
The `ImageViz` object handles the creation of a simple image visualization on map and is built on top of the `MapViz` class.

### Params
**ImageViz**(image, coordinates, \*args, \*\*kwargs_)
**ImageViz**(image, coordinates, legend=False, \*args, \*\*kwargs_)

Parameter | Description | Example
--|--|--
image | image url, path or numpy ndarray | "./my_image.png"
coordinates | property to image coordinates (UL, UR, LR, LL) | [[-80.425, 46.437], [-71.516, 46.437], [-71.516, 37.936], [-80.425, 37.936]]
legend | no legend for ImageViz | False

[MapViz options](https://github.com/mapbox/mapboxgl-jupyter/blob/master/docs-markdown/viz.md#params)

Expand Down Expand Up @@ -421,7 +424,7 @@ viz.show()
The `RasterTilesViz` object handles the creation of a simple raster tiles visualization on map and is built on top of the `MapViz` class.

### Params
**RasterTilesViz**(tiles\_url, \*args, \*\*kwargs_)
**RasterTilesViz**(tiles\_url, legend=False, \*args, \*\*kwargs_)

Parameter | Description | Example
--|--|--
Expand All @@ -430,6 +433,7 @@ tiles_size | mapbox-gl tiles size | 256
tiles_bounds | tiles endpoint bounds | [124.97480681619507, 10.876763902260592, 124.99391704636035, 10.888369402219947]
tiles_minzoom | tiles endpoint min zoom | 0
tiles_maxzoom | tiles endpoint max zoom | 22
legend | no legend for RasterTilesViz | False



Expand Down
20 changes: 10 additions & 10 deletions mapboxgl/templates/choropleth.html
Expand Up @@ -8,19 +8,19 @@
{% endblock extra_css %}

{% block legend %}

var legend = document.getElementById('legend');

{% if extrudeChoropleth %}
{% if colorStops and colorProperty and heightProperty %}
{% if colorProperty != heightProperty and extrudeChoropleth %}
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }} vs. {{ heightProperty }}");
{% else %}
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }}");
{% if showLegend %}
{% if extrudeChoropleth %}
{% if colorStops and colorProperty and heightProperty %}
{% if colorProperty != heightProperty and extrudeChoropleth %}
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }} vs. {{ heightProperty }}");
{% else %}
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }}");
{% endif %}
{% endif %}
{% else %}
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }}");
{% endif %}
{% else %}
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }}");
{% endif %}

{% endblock legend %}
Expand Down
10 changes: 5 additions & 5 deletions mapboxgl/templates/circle.html
Expand Up @@ -2,12 +2,12 @@

{% block legend %}

{% if colorStops and colorProperty %}
calcCircleColorLegend({{ colorStops }} , "{{ colorProperty }}");
{% else %}
document.getElementById('legend').style.visibility='hidden'
{% if showLegend %}
{% if colorStops and colorProperty %}
calcCircleColorLegend({{ colorStops }} , "{{ colorProperty }}");
{% endif %}
{% endif %}

{% endblock legend %}

{% block map %}
Expand Down
268 changes: 126 additions & 142 deletions mapboxgl/templates/clustered_circle.html
@@ -1,157 +1,141 @@
{% extends "main.html" %}

{% block javascript %}
mapboxgl.accessToken = '{{ accessToken }}';

var map = new mapboxgl.Map({
container: 'map',
style: {{ style }},
center: {{ center }},
zoom: {{ zoom }},
transformRequest: (url, resourceType)=> {
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}
}
}
});

map.addControl(new mapboxgl.NavigationControl());

calcCircleColorLegend({{ colorStops }}, "Point Density");
{% extends "base.html" %}

map.on('style.load', function() {
{% block legend %}

map.addSource("data", {
"type": "geojson",
"data": {{ geojson_data }}, //data from dataframe output to geojson
"buffer": 0,
"maxzoom": {{ clusterMaxZoom }} + 1,
"cluster": true,
"clusterMaxZoom": {{ clusterMaxZoom }},
"clusterRadius": {{ clusterRadius }}
});
{% if showLegend %}
calcCircleColorLegend({{ colorStops }}, "Point Density");
{% endif %}

{% endblock legend %}

{% block map %}

map.on('style.load', function() {

map.addSource("data", {
"type": "geojson",
"data": {{ geojson_data }}, //data from dataframe output to geojson
"buffer": 0,
"maxzoom": {{ clusterMaxZoom }} + 1,
"cluster": true,
"clusterMaxZoom": {{ clusterMaxZoom }},
"clusterRadius": {{ clusterRadius }}
});

map.addLayer({
"id": "label",
"source": "data",
"type": "symbol",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"layout": {
"text-field": "{point_count_abbreviated}",
"text-size" : generateInterpolateExpression('zoom', [[0, {{ labelSize }}],[22, 3* {{ labelSize }}]] ),
},
"paint": {
"text-halo-color": "{{ labelHaloColor }}",
"text-halo-width": generatePropertyExpression('interpolate', 'zoom', [[0,{{ labelHaloWidth }}], [18,5* {{ labelHaloWidth }}]]),
"text-color": "{{ labelColor }}"
}
}, "{{belowLayer}}" )

map.addLayer({
"id": "circle-cluster",
"source": "data",
"type": "circle",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"filter": ["has", "point_count"],
"paint": {
"circle-color": generateInterpolateExpression( "point_count", {{ colorStops }} ),
"circle-radius" : generateInterpolateExpression( "point_count", {{ radiusStops }} ),
"circle-stroke-color": "{{ strokeColor }}",
"circle-stroke-width": generatePropertyExpression('interpolate', 'zoom', [[0,{{ strokeWidth }}], [18,5* {{ strokeWidth }}]]),
"circle-opacity" : {{ opacity }},
"circle-stroke-opacity" : {{ opacity }}
}
}, "label");

map.addLayer({
"id": "circle-unclustered",
"source": "data",
"type": "circle",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"filter": ["!has", "point_count"],
"paint": {
"circle-color": "{{ colorDefault }}",
"circle-radius" : generateInterpolateExpression( 'zoom', [[0, {{ radiusDefault }} ], [22,10 * {{ radiusDefault }}]]),
"circle-stroke-color": "{{ strokeColor }}",
"circle-stroke-width": generatePropertyExpression('interpolate', 'zoom', [[0,{{ strokeWidth }}], [18,5* {{ strokeWidth }}]]),
"circle-opacity" : {{ opacity }},
"circle-stroke-opacity" : {{ opacity }}
}
}, "circle-cluster");

// Create a popup
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});

// Show the popup on mouseover
map.on('mousemove', 'circle-unclustered', function(e) {
map.getCanvas().style.cursor = 'pointer';
let f = e.features[0];
let popup_html = '<div><li><b>Location</b>: ' + f.geometry.coordinates[0].toPrecision(6) +
', ' + f.geometry.coordinates[1].toPrecision(6) + '</li>';

for (key in f.properties) {
popup_html += '<li><b> ' + key + '</b>: ' + f.properties[key] + ' </li>'
}

popup_html += '</div>'

popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(popup_html)
.addTo(map);
});
map.addLayer({
"id": "label",
"source": "data",
"type": "symbol",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"layout": {
"text-field": "{point_count_abbreviated}",
"text-size" : generateInterpolateExpression('zoom', [[0, {{ labelSize }}],[22, 3* {{ labelSize }}]] ),
},
"paint": {
"text-halo-color": "{{ labelHaloColor }}",
"text-halo-width": generatePropertyExpression('interpolate', 'zoom', [[0,{{ labelHaloWidth }}], [18,5* {{ labelHaloWidth }}]]),
"text-color": "{{ labelColor }}"
}
}, "{{belowLayer}}" )

map.addLayer({
"id": "circle-cluster",
"source": "data",
"type": "circle",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"filter": ["has", "point_count"],
"paint": {
"circle-color": generateInterpolateExpression( "point_count", {{ colorStops }} ),
"circle-radius" : generateInterpolateExpression( "point_count", {{ radiusStops }} ),
"circle-stroke-color": "{{ strokeColor }}",
"circle-stroke-width": generatePropertyExpression('interpolate', 'zoom', [[0,{{ strokeWidth }}], [18,5* {{ strokeWidth }}]]),
"circle-opacity" : {{ opacity }},
"circle-stroke-opacity" : {{ opacity }}
}
}, "label");

map.addLayer({
"id": "circle-unclustered",
"source": "data",
"type": "circle",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"filter": ["!has", "point_count"],
"paint": {
"circle-color": "{{ colorDefault }}",
"circle-radius" : generateInterpolateExpression( 'zoom', [[0, {{ radiusDefault }} ], [22,10 * {{ radiusDefault }}]]),
"circle-stroke-color": "{{ strokeColor }}",
"circle-stroke-width": generatePropertyExpression('interpolate', 'zoom', [[0,{{ strokeWidth }}], [18,5* {{ strokeWidth }}]]),
"circle-opacity" : {{ opacity }},
"circle-stroke-opacity" : {{ opacity }}
}
}, "circle-cluster");
// Create a popup
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
// Show the popup on mouseover
map.on('mousemove', 'circle-unclustered', function(e) {
map.getCanvas().style.cursor = 'pointer';
let f = e.features[0];
let popup_html = '<div><li><b>Location</b>: ' + f.geometry.coordinates[0].toPrecision(6) +
', ' + f.geometry.coordinates[1].toPrecision(6) + '</li>';

for (key in f.properties) {
popup_html += '<li><b> ' + key + '</b>: ' + f.properties[key] + ' </li>'
}

popup_html += '</div>'

popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(popup_html)
.addTo(map);
});

map.on('mousemove', 'circle-cluster', function(e) {
map.getCanvas().style.cursor = 'pointer';
let f = e.features[0];
let popup_html = '<div><li><b>Location</b>: ' + f.geometry.coordinates[0].toPrecision(6) +
', ' + f.geometry.coordinates[1].toPrecision(6) + '</li>';
map.on('mousemove', 'circle-cluster', function(e) {
map.getCanvas().style.cursor = 'pointer';
let f = e.features[0];
let popup_html = '<div><li><b>Location</b>: ' + f.geometry.coordinates[0].toPrecision(6) +
', ' + f.geometry.coordinates[1].toPrecision(6) + '</li>';

popup_html += '<li><b>Point Count:</b>: ' + f.properties.point_count + ' </li>'
popup_html += '<li><b>Point Count:</b>: ' + f.properties.point_count + ' </li>'

popup_html += '</div>'
popup_html += '</div>'

popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(popup_html)
.addTo(map);
});
popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(popup_html)
.addTo(map);
});

map.on('mouseleave', 'circle-unclustered', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});
map.on('mouseleave', 'circle-unclustered', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});

map.on('mouseleave', 'circle-cluster', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});

map.on('mouseleave', 'circle-cluster', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});

map.on('click', 'circle-unclustered', function(e) {
map.easeTo({
center: e.features[0].geometry.coordinates,
zoom: map.getZoom() + 1
map.on('click', 'circle-unclustered', function(e) {
map.easeTo({
center: e.features[0].geometry.coordinates,
zoom: map.getZoom() + 1
});
});
});

map.on('click', 'circle-cluster', function(e) {
map.easeTo({
center: e.features[0].geometry.coordinates,
zoom: map.getZoom() + 1
map.on('click', 'circle-cluster', function(e) {
map.easeTo({
center: e.features[0].geometry.coordinates,
zoom: map.getZoom() + 1
});
});
});
});

{% endblock %}
{% endblock map %}

0 comments on commit c396f42

Please sign in to comment.