-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b21360c
commit 5a102f2
Showing
2 changed files
with
43 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from wagtail.embeds.finders.base import EmbedFinder | ||
|
||
|
||
class OSMFinder(EmbedFinder): | ||
"""OpenStreetMap.org embed""" | ||
def __init__(self, **options): | ||
pass | ||
|
||
def accept(self, url): | ||
""" | ||
Returns True if this finder knows how to fetch an embed for the URL. | ||
This should not have any side effects (no requests to external servers) | ||
""" | ||
|
||
if not url.startswith('https://www.openstreetmap.org/export/embed.html'): | ||
return False | ||
return True | ||
|
||
|
||
def find_embed(self, url, max_width=None): | ||
""" | ||
Takes a URL and max width and returns a dictionary of information about the | ||
content to be used for embedding it on the site. | ||
This is the part that may make requests to external APIs. | ||
""" | ||
|
||
return { | ||
# 'title': "", | ||
'author_name': "OpenStreetMap contributors", | ||
'provider_name': "OpenStreetMap.org", | ||
'type': "rich", | ||
# 'thumbnail_url': "URL to thumbnail image", | ||
'width': 425, | ||
'height': 350, | ||
'html': f"""<div class='osm-embed'><iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="{url}" style="border: 1px solid black"></iframe><br/><small><a href="https://www.openstreetmap.org/#map=14/54.7747/-1.5886">View Larger Map</a></small></div>""", | ||
} |