diff --git a/ecoscope/mapping/map.py b/ecoscope/mapping/map.py index 6975d9fe..533c4bf9 100644 --- a/ecoscope/mapping/map.py +++ b/ecoscope/mapping/map.py @@ -107,12 +107,16 @@ def add_legend(self, *args, **kwargs): return super().add_legend(*args, **kwargs) - def add_north_arrow(self, position="topright", scale=1.0): + def add_north_arrow(self,imagePath='',position="topright",angle=0,scale=1.0): """ Parameters ---------- + imagePath : str + Path to the image file for the north arrow. If not provided, default SVG image is uploaded. position : str Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'. + angle : int + Angle for the north arrow to be rotated. scale : float Scale dimensions of north arrow. @@ -124,7 +128,10 @@ def add_north_arrow(self, position="topright", scale=1.0): """, # noqa + imagePath=imagePath, position=position, + angle=angle, + scale=scale ) ) @@ -372,9 +379,21 @@ class ControlElement(MacroElement): {% macro script(this, kwargs) %} var {{ this.get_name() }} = L.Control.extend({ onAdd: function(map) { - var template = document.createElement('template'); - template.innerHTML = `{{ this.html }}`.trim(); - return template.content.firstChild; + var control; + if (this.options.imagePath){ + var img = document.createElement('img'); + img.src=this.options.imagePath; + img.style.width = (this.options.scale * 100) + 'px'; + img.style.height = (this.options.scale * 100) + 'px'; + control=img; + } else { + var template = document.createElement('template'); + template.innerHTML = `{{ this.html }}`.trim(); + control = template.content.firstChild + } + + control.style.transform = 'rotate({{ this.angle }}deg)'; + return control; } }); (new {{ this.get_name() }}({{ this.options|tojson }})).addTo({{this._parent.get_name()}}); @@ -383,11 +402,14 @@ class ControlElement(MacroElement): """ ) - def __init__(self, html, position="bottomright"): + def __init__(self, html,imagePath='',position="bottomright",angle="",scale=""): super().__init__() self.html = html + self.angle=angle self.options = folium.utilities.parse_options( position=position, + imagePath=imagePath, + scale=scale ) diff --git a/notebooks/04. EcoMap & EcoPlot/EcoMap.ipynb b/notebooks/04. EcoMap & EcoPlot/EcoMap.ipynb index b4b17232..9ade9bf2 100644 --- a/notebooks/04. EcoMap & EcoPlot/EcoMap.ipynb +++ b/notebooks/04. EcoMap & EcoPlot/EcoMap.ipynb @@ -299,7 +299,7 @@ "\n", "# Add north-arrow\n", "m.add_north_arrow(\n", - " position=\"top-left\",\n", + " position=\"topleft\",\n", ")\n", "\n", "# Add legend\n", diff --git a/tests/test_ng.py b/tests/test_ng.py new file mode 100644 index 00000000..d887a1bc --- /dev/null +++ b/tests/test_ng.py @@ -0,0 +1,7 @@ +import sys +sys.path.append('../ecoscope') +from ecoscope.mapping.map import EcoMap + +m=EcoMap(draw_control=False) +m.add_north_arrow(position="topleft",angle=0,scale=1.0) +m.to_html(r'C:\Users\DELL\Documents\EcoMap\new.html') \ No newline at end of file