|
24 | 24 | from folium.six import text_type, binary_type#, iteritems |
25 | 25 | from .map import Map as _Map |
26 | 26 | from .element import Element, Figure, JavascriptLink, CssLink, Div, MacroElement |
27 | | -from .map import Map, TileLayer, Icon, Marker, Popup |
| 27 | +from .map import Map, TileLayer, Icon, Marker, Popup, FitBounds |
28 | 28 | from .features import WmsTileLayer, RegularPolygonMarker, Vega, GeoJson, GeoJsonStyle, MarkerCluster, DivIcon,\ |
29 | 29 | CircleMarker, LatLngPopup, ClickForMarker, ColorScale, TopoJson, PolyLine, MultiPolyLine |
30 | 30 | from .utilities import color_brewer |
@@ -477,22 +477,6 @@ def multiline(self, locations, line_color=None, line_opacity=None, |
477 | 477 |
|
478 | 478 | self.add_children(p) |
479 | 479 |
|
480 | | -# count = self.mark_cnt['multiline'] |
481 | | -# |
482 | | -# multiline_temp = self.env.get_template('multi_polyline.js') |
483 | | -# |
484 | | -# multiline_opts = {'color': line_color, 'weight': line_weight, |
485 | | -# 'opacity': line_opacity} |
486 | | -# |
487 | | -# varname = 'multiline_{}'.format(count) |
488 | | -# multiline_rendered = multiline_temp.render({'multiline': varname, |
489 | | -# 'locations': locations, |
490 | | -# 'options': multiline_opts}) |
491 | | -# |
492 | | -# add_multiline = 'map.addLayer({});'.format(varname) |
493 | | -# append = (multiline_rendered, add_multiline) |
494 | | -# self.template_vars.setdefault('multilines', []).append(append) |
495 | | -# |
496 | 480 | # @iter_obj('circle') |
497 | 481 | def circle_marker(self, location=None, radius=500, popup=None, |
498 | 482 | line_color='black', fill_color='black', |
@@ -632,50 +616,39 @@ def click_for_marker(self, popup=None): |
632 | 616 | FutureWarning, stacklevel=2) |
633 | 617 | self.add_children(ClickForMarker(popup=popup)) |
634 | 618 |
|
635 | | -# def fit_bounds(self, bounds, padding_top_left=None, |
636 | | -# padding_bottom_right=None, padding=None, max_zoom=None): |
637 | | -# """Fit the map to contain a bounding box with the maximum zoom level possible. |
638 | | -# |
639 | | -# Parameters |
640 | | -# ---------- |
641 | | -# bounds: list of (latitude, longitude) points |
642 | | -# Bounding box specified as two points [southwest, northeast] |
643 | | -# padding_top_left: (x, y) point, default None |
644 | | -# Padding in the top left corner. Useful if some elements in |
645 | | -# the corner, such as controls, might obscure objects you're zooming |
646 | | -# to. |
647 | | -# padding_bottom_right: (x, y) point, default None |
648 | | -# Padding in the bottom right corner. |
649 | | -# padding: (x, y) point, default None |
650 | | -# Equivalent to setting both top left and bottom right padding to |
651 | | -# the same value. |
652 | | -# max_zoom: int, default None |
653 | | -# Maximum zoom to be used. |
654 | | -# |
655 | | -# Example |
656 | | -# ------- |
657 | | -# >>> map.fit_bounds([[52.193636, -2.221575], [52.636878, -1.139759]]) |
658 | | -# |
659 | | -# """ |
660 | | -# options = { |
661 | | -# 'paddingTopLeft': padding_top_left, |
662 | | -# 'paddingBottomRight': padding_bottom_right, |
663 | | -# 'padding': padding, |
664 | | -# 'maxZoom': max_zoom, |
665 | | -# } |
666 | | -# fit_bounds_options = {} |
667 | | -# for key, opt in options.items(): |
668 | | -# if opt: |
669 | | -# fit_bounds_options[key] = opt |
670 | | -# fit_bounds = self.env.get_template('fit_bounds.js') |
671 | | -# fit_bounds_str = fit_bounds.render({ |
672 | | -# 'bounds': json.dumps(bounds), |
673 | | -# 'fit_bounds_options': json.dumps(fit_bounds_options, |
674 | | -# sort_keys=True), |
675 | | -# }) |
676 | | -# |
677 | | -# self.template_vars.update({'fit_bounds': fit_bounds_str}) |
678 | | -# |
| 619 | + def fit_bounds(self, bounds, padding_top_left=None, |
| 620 | + padding_bottom_right=None, padding=None, max_zoom=None): |
| 621 | + """Fit the map to contain a bounding box with the maximum zoom level possible. |
| 622 | +
|
| 623 | + Parameters |
| 624 | + ---------- |
| 625 | + bounds: list of (latitude, longitude) points |
| 626 | + Bounding box specified as two points [southwest, northeast] |
| 627 | + padding_top_left: (x, y) point, default None |
| 628 | + Padding in the top left corner. Useful if some elements in |
| 629 | + the corner, such as controls, might obscure objects you're zooming |
| 630 | + to. |
| 631 | + padding_bottom_right: (x, y) point, default None |
| 632 | + Padding in the bottom right corner. |
| 633 | + padding: (x, y) point, default None |
| 634 | + Equivalent to setting both top left and bottom right padding to |
| 635 | + the same value. |
| 636 | + max_zoom: int, default None |
| 637 | + Maximum zoom to be used. |
| 638 | +
|
| 639 | + Example |
| 640 | + ------- |
| 641 | + >>> map.fit_bounds([[52.193636, -2.221575], [52.636878, -1.139759]]) |
| 642 | +
|
| 643 | + """ |
| 644 | + self.add_children(FitBounds(bounds, |
| 645 | + padding_top_left=padding_top_left, |
| 646 | + padding_bottom_right=padding_bottom_right, |
| 647 | + padding=padding, |
| 648 | + max_zoom=max_zoom, |
| 649 | + ) |
| 650 | + ) |
| 651 | + |
679 | 652 | def add_plugin(self, plugin): |
680 | 653 | """Adds a plugin to the map. |
681 | 654 |
|
|
0 commit comments