-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Kakao] Move permalink function out of class
- Loading branch information
Showing
4 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .kakao import * | ||
from .util import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import math | ||
|
||
|
||
def build_permalink(id: int = None, wcongx: float = None, wcongy: float = None, | ||
heading: float = 0.0, pitch: float = 0.0, radians: bool = False) -> str: | ||
""" | ||
Creates a permalink to a panorama. All parameters are optional, but | ||
either a location, or a pano ID, or both must be passed. | ||
When linking by ID, the link will only work as expected for the most recent coverage | ||
at a location -- it does not appear to be possible to directly link to older panoramas. | ||
:param id: The pano ID. | ||
:param wcongx: X coordinate of the panorama's location in the WCongnamul coordinate system. | ||
:param wcongy: Y coordinate of the panorama's location in the WCongnamul coordinate system. | ||
:param heading: *(optional)* Initial heading of the viewport. Defaults to 0°. | ||
:param pitch: *(optional)* Initial pitch of the viewport. Defaults to 0°. | ||
:param radians: *(optional)* Whether angles are in radians. Defaults to False. | ||
:return: A KakaoMap URL which will open the given panorama. | ||
""" | ||
if id is None and (wcongx is None or wcongy is None): | ||
raise ValueError("You must pass a location, or pano ID, or both.") | ||
elif id is None: | ||
id = 0 | ||
elif wcongx is None and wcongy is None: | ||
(wcongx, wcongy) = (0.0, 0.0) | ||
elif (wcongx is None and wcongy is not None) or (wcongx is not None and wcongy is None): | ||
raise ValueError("wcongx and wcongx must either both be set or both be null.") | ||
|
||
if radians: | ||
heading = math.degrees(heading) | ||
pitch = math.degrees(pitch) | ||
url = f"https://map.kakao.com/?map_type=TYPE_MAP&map_attribute=ROADVIEW&panoid={id}" \ | ||
f"&urlX={wcongx}&urlY={wcongy}&pan={heading}&tilt={pitch}&zoom=0&urlLevel=3" | ||
return url |