diff --git a/.DS_Store b/.DS_Store index 1fd6ba5dc70e4..e5fc085b6ec67 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/_pages/.DS_Store b/_pages/.DS_Store index 5c3e0ec3702a2..50df098058040 100644 Binary files a/_pages/.DS_Store and b/_pages/.DS_Store differ diff --git a/_pages/sitemap.md b/_pages/sitemap.md deleted file mode 100644 index 0525daf0f6c97..0000000000000 --- a/_pages/sitemap.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -layout: archive -title: "Sitemap" -permalink: /sitemap/ -author_profile: true ---- - -{% include base_path %} - -A list of all the posts and pages found on the site. For you robots out there is an [XML version]({{ base_path }}/sitemap.xml) available for digesting as well. - -

Pages

-{% for post in site.pages %} - {% include archive-single.html %} -{% endfor %} - -

Posts

-{% for post in site.posts %} - {% include archive-single.html %} -{% endfor %} - -{% capture written_label %}'None'{% endcapture %} - -{% for collection in site.collections %} -{% unless collection.output == false or collection.label == "posts" %} - {% capture label %}{{ collection.label }}{% endcapture %} - {% if label != written_label %} -

{{ label }}

- {% capture written_label %}{{ label }}{% endcapture %} - {% endif %} -{% endunless %} -{% for post in collection.docs %} - {% unless collection.output == false or collection.label == "posts" %} - {% include archive-single.html %} - {% endunless %} -{% endfor %} -{% endfor %} diff --git a/_pages/talkmap.html b/_pages/talkmap.html deleted file mode 100644 index c4ca03ea55424..0000000000000 --- a/_pages/talkmap.html +++ /dev/null @@ -1,9 +0,0 @@ ---- -layout: archive -title: "Talk map" -permalink: /talkmap.html -author_profile: true ---- - -

This map is generated from a Jupyter Notebook file in /_talks/talkmap.ipynb, which mines the location fields in the .md files in _talks/.

- diff --git a/markdown_generator/PubsFromBib.ipynb b/markdown_generator/PubsFromBib.ipynb deleted file mode 100644 index df898a7128007..0000000000000 --- a/markdown_generator/PubsFromBib.ipynb +++ /dev/null @@ -1,223 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Publications markdown generator for academicpages\n", - "\n", - "Takes a set of bibtex of publications and converts them for use with [academicpages.github.io](academicpages.github.io). This is an interactive Jupyter notebook ([see more info here](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html)). \n", - "\n", - "The core python code is also in `pubsFromBibs.py`. \n", - "Run either from the `markdown_generator` folder after replacing updating the publist dictionary with:\n", - "* bib file names\n", - "* specific venue keys based on your bib file preferences\n", - "* any specific pre-text for specific files\n", - "* Collection Name (future feature)\n", - "\n", - "TODO: Make this work with other databases of citations, \n", - "TODO: Merge this with the existing TSV parsing solution" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pybtex.database.input import bibtex\n", - "import pybtex.database.input.bibtex \n", - "from time import strptime\n", - "import string\n", - "import html\n", - "import os\n", - "import re" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#todo: incorporate different collection types rather than a catch all publications, requires other changes to template\n", - "publist = {\n", - " \"proceeding\": {\n", - " \"file\" : \"proceedings.bib\",\n", - " \"venuekey\": \"booktitle\",\n", - " \"venue-pretext\": \"In the proceedings of \",\n", - " \"collection\" : {\"name\":\"publications\",\n", - " \"permalink\":\"/publication/\"}\n", - " \n", - " },\n", - " \"journal\":{\n", - " \"file\": \"pubs.bib\",\n", - " \"venuekey\" : \"journal\",\n", - " \"venue-pretext\" : \"\",\n", - " \"collection\" : {\"name\":\"publications\",\n", - " \"permalink\":\"/publication/\"}\n", - " } \n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "html_escape_table = {\n", - " \"&\": \"&\",\n", - " '\"': \""\",\n", - " \"'\": \"'\"\n", - " }\n", - "\n", - "def html_escape(text):\n", - " \"\"\"Produce entities within text.\"\"\"\n", - " return \"\".join(html_escape_table.get(c,c) for c in text)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "for pubsource in publist:\n", - " parser = bibtex.Parser()\n", - " bibdata = parser.parse_file(publist[pubsource][\"file\"])\n", - "\n", - " #loop through the individual references in a given bibtex file\n", - " for bib_id in bibdata.entries:\n", - " #reset default date\n", - " pub_year = \"1900\"\n", - " pub_month = \"01\"\n", - " pub_day = \"01\"\n", - " \n", - " b = bibdata.entries[bib_id].fields\n", - " \n", - " try:\n", - " pub_year = f'{b[\"year\"]}'\n", - "\n", - " #todo: this hack for month and day needs some cleanup\n", - " if \"month\" in b.keys(): \n", - " if(len(b[\"month\"])<3):\n", - " pub_month = \"0\"+b[\"month\"]\n", - " pub_month = pub_month[-2:]\n", - " elif(b[\"month\"] not in range(12)):\n", - " tmnth = strptime(b[\"month\"][:3],'%b').tm_mon \n", - " pub_month = \"{:02d}\".format(tmnth) \n", - " else:\n", - " pub_month = str(b[\"month\"])\n", - " if \"day\" in b.keys(): \n", - " pub_day = str(b[\"day\"])\n", - "\n", - " \n", - " pub_date = pub_year+\"-\"+pub_month+\"-\"+pub_day\n", - " \n", - " #strip out {} as needed (some bibtex entries that maintain formatting)\n", - " clean_title = b[\"title\"].replace(\"{\", \"\").replace(\"}\",\"\").replace(\"\\\\\",\"\").replace(\" \",\"-\") \n", - "\n", - " url_slug = re.sub(\"\\\\[.*\\\\]|[^a-zA-Z0-9_-]\", \"\", clean_title)\n", - " url_slug = url_slug.replace(\"--\",\"-\")\n", - "\n", - " md_filename = (str(pub_date) + \"-\" + url_slug + \".md\").replace(\"--\",\"-\")\n", - " html_filename = (str(pub_date) + \"-\" + url_slug).replace(\"--\",\"-\")\n", - "\n", - " #Build Citation from text\n", - " citation = \"\"\n", - "\n", - " #citation authors - todo - add highlighting for primary author?\n", - " for author in bibdata.entries[bib_id].persons[\"author\"]:\n", - " citation = citation+\" \"+author.first_names[0]+\" \"+author.last_names[0]+\", \"\n", - "\n", - " #citation title\n", - " citation = citation + \"\\\"\" + html_escape(b[\"title\"].replace(\"{\", \"\").replace(\"}\",\"\").replace(\"\\\\\",\"\")) + \".\\\"\"\n", - "\n", - " #add venue logic depending on citation type\n", - " venue = publist[pubsource][\"venue-pretext\"]+b[publist[pubsource][\"venuekey\"]].replace(\"{\", \"\").replace(\"}\",\"\").replace(\"\\\\\",\"\")\n", - "\n", - " citation = citation + \" \" + html_escape(venue)\n", - " citation = citation + \", \" + pub_year + \".\"\n", - "\n", - " \n", - " ## YAML variables\n", - " md = \"---\\ntitle: \\\"\" + html_escape(b[\"title\"].replace(\"{\", \"\").replace(\"}\",\"\").replace(\"\\\\\",\"\")) + '\"\\n'\n", - " \n", - " md += \"\"\"collection: \"\"\" + publist[pubsource][\"collection\"][\"name\"]\n", - "\n", - " md += \"\"\"\\npermalink: \"\"\" + publist[pubsource][\"collection\"][\"permalink\"] + html_filename\n", - " \n", - " note = False\n", - " if \"note\" in b.keys():\n", - " if len(str(b[\"note\"])) > 5:\n", - " md += \"\\nexcerpt: '\" + html_escape(b[\"note\"]) + \"'\"\n", - " note = True\n", - "\n", - " md += \"\\ndate: \" + str(pub_date) \n", - "\n", - " md += \"\\nvenue: '\" + html_escape(venue) + \"'\"\n", - " \n", - " url = False\n", - " if \"url\" in b.keys():\n", - " if len(str(b[\"url\"])) > 5:\n", - " md += \"\\npaperurl: '\" + b[\"url\"] + \"'\"\n", - " url = True\n", - "\n", - " md += \"\\ncitation: '\" + html_escape(citation) + \"'\"\n", - "\n", - " md += \"\\n---\"\n", - "\n", - " \n", - " ## Markdown description for individual page\n", - " if note:\n", - " md += \"\\n\" + html_escape(b[\"note\"]) + \"\\n\"\n", - "\n", - " if url:\n", - " md += \"\\n[Access paper here](\" + b[\"url\"] + \"){:target=\\\"_blank\\\"}\\n\" \n", - " else:\n", - " md += \"\\nUse [Google Scholar](https://scholar.google.com/scholar?q=\"+html.escape(clean_title.replace(\"-\",\"+\"))+\"){:target=\\\"_blank\\\"} for full citation\"\n", - "\n", - " md_filename = os.path.basename(md_filename)\n", - "\n", - " with open(\"../_publications/\" + md_filename, 'w') as f:\n", - " f.write(md)\n", - " print(f'SUCESSFULLY PARSED {bib_id}: \\\"', b[\"title\"][:60],\"...\"*(len(b['title'])>60),\"\\\"\")\n", - " # field may not exist for a reference\n", - " except KeyError as e:\n", - " print(f'WARNING Missing Expected Field {e} from entry {bib_id}: \\\"', b[\"title\"][:30],\"...\"*(len(b['title'])>30),\"\\\"\")\n", - " continue\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/markdown_generator/publications.ipynb b/markdown_generator/publications.ipynb deleted file mode 100644 index 8657e1009b7b6..0000000000000 --- a/markdown_generator/publications.ipynb +++ /dev/null @@ -1,371 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "deletable": true, - "editable": true - }, - "source": [ - "# Publications markdown generator for academicpages\n", - "\n", - "Takes a TSV of publications with metadata and converts them for use with [academicpages.github.io](academicpages.github.io). This is an interactive Jupyter notebook ([see more info here](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html)). The core python code is also in `publications.py`. Run either from the `markdown_generator` folder after replacing `publications.tsv` with one containing your data.\n", - "\n", - "TODO: Make this work with BibTex and other databases of citations, rather than Stuart's non-standard TSV format and citation style.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Data format\n", - "\n", - "The TSV needs to have the following columns: pub_date, title, venue, excerpt, citation, site_url, and paper_url, with a header at the top. \n", - "\n", - "- `excerpt` and `paper_url` can be blank, but the others must have values. \n", - "- `pub_date` must be formatted as YYYY-MM-DD.\n", - "- `url_slug` will be the descriptive part of the .md file and the permalink URL for the page about the paper. The .md file will be `YYYY-MM-DD-[url_slug].md` and the permalink will be `https://[yourdomain]/publications/YYYY-MM-DD-[url_slug]`\n", - "\n", - "This is how the raw file looks (it doesn't look pretty, use a spreadsheet or other program to edit and create)." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "pub_date\ttitle\tvenue\texcerpt\tcitation\turl_slug\tpaper_url\r\n", - "2009-10-01\tPaper Title Number 1\tJournal 1\tThis paper is about the number 1. The number 2 is left for future work.\tYour Name, You. (2009). \"Paper Title Number 1.\" Journal 1. 1(1).\tpaper-title-number-1\thttp://academicpages.github.io/files/paper1.pdf\r\n", - "2010-10-01\tPaper Title Number 2\tJournal 1\tThis paper is about the number 2. The number 3 is left for future work.\tYour Name, You. (2010). \"Paper Title Number 2.\" Journal 1. 1(2).\tpaper-title-number-2\thttp://academicpages.github.io/files/paper2.pdf\r\n", - "2015-10-01\tPaper Title Number 3\tJournal 1\tThis paper is about the number 3. The number 4 is left for future work.\tYour Name, You. (2015). \"Paper Title Number 3.\" Journal 1. 1(3).\tpaper-title-number-3\thttp://academicpages.github.io/files/paper3.pdf" - ] - } - ], - "source": [ - "!cat publications.tsv" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Import pandas\n", - "\n", - "We are using the very handy pandas library for dataframes." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": true, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Import TSV\n", - "\n", - "Pandas makes this easy with the read_csv function. We are using a TSV, so we specify the separator as a tab, or `\\t`.\n", - "\n", - "I found it important to put this data in a tab-separated values format, because there are a lot of commas in this kind of data and comma-separated values can get messed up. However, you can modify the import statement, as pandas also has read_excel(), read_json(), and others." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
pub_datetitlevenueexcerptcitationurl_slugpaper_url
02009-10-01Paper Title Number 1Journal 1This paper is about the number 1. The number 2...Your Name, You. (2009). \"Paper Title Number 1....paper-title-number-1http://academicpages.github.io/files/paper1.pdf
12010-10-01Paper Title Number 2Journal 1This paper is about the number 2. The number 3...Your Name, You. (2010). \"Paper Title Number 2....paper-title-number-2http://academicpages.github.io/files/paper2.pdf
22015-10-01Paper Title Number 3Journal 1This paper is about the number 3. The number 4...Your Name, You. (2015). \"Paper Title Number 3....paper-title-number-3http://academicpages.github.io/files/paper3.pdf
\n", - "
" - ], - "text/plain": [ - " pub_date title venue \\\n", - "0 2009-10-01 Paper Title Number 1 Journal 1 \n", - "1 2010-10-01 Paper Title Number 2 Journal 1 \n", - "2 2015-10-01 Paper Title Number 3 Journal 1 \n", - "\n", - " excerpt \\\n", - "0 This paper is about the number 1. The number 2... \n", - "1 This paper is about the number 2. The number 3... \n", - "2 This paper is about the number 3. The number 4... \n", - "\n", - " citation url_slug \\\n", - "0 Your Name, You. (2009). \"Paper Title Number 1.... paper-title-number-1 \n", - "1 Your Name, You. (2010). \"Paper Title Number 2.... paper-title-number-2 \n", - "2 Your Name, You. (2015). \"Paper Title Number 3.... paper-title-number-3 \n", - "\n", - " paper_url \n", - "0 http://academicpages.github.io/files/paper1.pdf \n", - "1 http://academicpages.github.io/files/paper2.pdf \n", - "2 http://academicpages.github.io/files/paper3.pdf " - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "publications = pd.read_csv(\"publications.tsv\", sep=\"\\t\", header=0)\n", - "publications\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Escape special characters\n", - "\n", - "YAML is very picky about how it takes a valid string, so we are replacing single and double quotes (and ampersands) with their HTML encoded equivilents. This makes them look not so readable in raw format, but they are parsed and rendered nicely." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": true, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [ - "html_escape_table = {\n", - " \"&\": \"&\",\n", - " '\"': \""\",\n", - " \"'\": \"'\"\n", - " }\n", - "\n", - "def html_escape(text):\n", - " \"\"\"Produce entities within text.\"\"\"\n", - " return \"\".join(html_escape_table.get(c,c) for c in text)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Creating the markdown files\n", - "\n", - "This is where the heavy lifting is done. This loops through all the rows in the TSV dataframe, then starts to concatentate a big string (```md```) that contains the markdown for each type. It does the YAML metadata first, then does the description for the individual page." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [ - "import os\n", - "for row, item in publications.iterrows():\n", - " \n", - " md_filename = str(item.pub_date) + \"-\" + item.url_slug + \".md\"\n", - " html_filename = str(item.pub_date) + \"-\" + item.url_slug\n", - " year = item.pub_date[:4]\n", - " \n", - " ## YAML variables\n", - " \n", - " md = \"---\\ntitle: \\\"\" + item.title + '\"\\n'\n", - " \n", - " md += \"\"\"collection: publications\"\"\"\n", - " \n", - " md += \"\"\"\\npermalink: /publication/\"\"\" + html_filename\n", - " \n", - " if len(str(item.excerpt)) > 5:\n", - " md += \"\\nexcerpt: '\" + html_escape(item.excerpt) + \"'\"\n", - " \n", - " md += \"\\ndate: \" + str(item.pub_date) \n", - " \n", - " md += \"\\nvenue: '\" + html_escape(item.venue) + \"'\"\n", - " \n", - " if len(str(item.paper_url)) > 5:\n", - " md += \"\\npaperurl: '\" + item.paper_url + \"'\"\n", - " \n", - " md += \"\\ncitation: '\" + html_escape(item.citation) + \"'\"\n", - " \n", - " md += \"\\n---\"\n", - " \n", - " ## Markdown description for individual page\n", - " \n", - " if len(str(item.excerpt)) > 5:\n", - " md += \"\\n\" + html_escape(item.excerpt) + \"\\n\"\n", - " \n", - " if len(str(item.paper_url)) > 5:\n", - " md += \"\\n[Download paper here](\" + item.paper_url + \")\\n\" \n", - " \n", - " md += \"\\nRecommended citation: \" + item.citation\n", - " \n", - " md_filename = os.path.basename(md_filename)\n", - " \n", - " with open(\"../_publications/\" + md_filename, 'w') as f:\n", - " f.write(md)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "These files are in the publications directory, one directory below where we're working from." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2009-10-01-paper-title-number-1.md 2015-10-01-paper-title-number-3.md\r\n", - "2010-10-01-paper-title-number-2.md\r\n" - ] - } - ], - "source": [ - "!ls ../_publications/" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "---\r\n", - "title: \"Paper Title Number 1\"\r\n", - "collection: publications\r\n", - "permalink: /publication/2009-10-01-paper-title-number-1\r\n", - "excerpt: 'This paper is about the number 1. The number 2 is left for future work.'\r\n", - "date: 2009-10-01\r\n", - "venue: 'Journal 1'\r\n", - "paperurl: 'http://academicpages.github.io/files/paper1.pdf'\r\n", - "citation: 'Your Name, You. (2009). "Paper Title Number 1." Journal 1. 1(1).'\r\n", - "---\r\n", - "This paper is about the number 1. The number 2 is left for future work.\r\n", - "\r\n", - "[Download paper here](http://academicpages.github.io/files/paper1.pdf)\r\n", - "\r\n", - "Recommended citation: Your Name, You. (2009). \"Paper Title Number 1.\" Journal 1. 1(1)." - ] - } - ], - "source": [ - "!cat ../_publications/2009-10-01-paper-title-number-1.md" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.1" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/markdown_generator/publications.py b/markdown_generator/publications.py deleted file mode 100644 index 2d0b1026b8c9b..0000000000000 --- a/markdown_generator/publications.py +++ /dev/null @@ -1,108 +0,0 @@ - -# coding: utf-8 - -# # Publications markdown generator for academicpages -# -# Takes a TSV of publications with metadata and converts them for use with [academicpages.github.io](academicpages.github.io). This is an interactive Jupyter notebook, with the core python code in publications.py. Run either from the `markdown_generator` folder after replacing `publications.tsv` with one that fits your format. -# -# TODO: Make this work with BibTex and other databases of citations, rather than Stuart's non-standard TSV format and citation style. -# - -# ## Data format -# -# The TSV needs to have the following columns: pub_date, title, venue, excerpt, citation, site_url, and paper_url, with a header at the top. -# -# - `excerpt` and `paper_url` can be blank, but the others must have values. -# - `pub_date` must be formatted as YYYY-MM-DD. -# - `url_slug` will be the descriptive part of the .md file and the permalink URL for the page about the paper. The .md file will be `YYYY-MM-DD-[url_slug].md` and the permalink will be `https://[yourdomain]/publications/YYYY-MM-DD-[url_slug]` - - -# ## Import pandas -# -# We are using the very handy pandas library for dataframes. - -# In[2]: - -import pandas as pd - - -# ## Import TSV -# -# Pandas makes this easy with the read_csv function. We are using a TSV, so we specify the separator as a tab, or `\t`. -# -# I found it important to put this data in a tab-separated values format, because there are a lot of commas in this kind of data and comma-separated values can get messed up. However, you can modify the import statement, as pandas also has read_excel(), read_json(), and others. - -# In[3]: - -publications = pd.read_csv("publications.tsv", sep="\t", header=0) -publications - - -# ## Escape special characters -# -# YAML is very picky about how it takes a valid string, so we are replacing single and double quotes (and ampersands) with their HTML encoded equivilents. This makes them look not so readable in raw format, but they are parsed and rendered nicely. - -# In[4]: - -html_escape_table = { - "&": "&", - '"': """, - "'": "'" - } - -def html_escape(text): - """Produce entities within text.""" - return "".join(html_escape_table.get(c,c) for c in text) - - -# ## Creating the markdown files -# -# This is where the heavy lifting is done. This loops through all the rows in the TSV dataframe, then starts to concatentate a big string (```md```) that contains the markdown for each type. It does the YAML metadata first, then does the description for the individual page. If you don't want something to appear (like the "Recommended citation") - -# In[5]: - -import os -for row, item in publications.iterrows(): - - md_filename = str(item.pub_date) + "-" + item.url_slug + ".md" - html_filename = str(item.pub_date) + "-" + item.url_slug - year = item.pub_date[:4] - - ## YAML variables - - md = "---\ntitle: \"" + item.title + '"\n' - - md += """collection: publications""" - - md += """\npermalink: /publication/""" + html_filename - - if len(str(item.excerpt)) > 5: - md += "\nexcerpt: '" + html_escape(item.excerpt) + "'" - - md += "\ndate: " + str(item.pub_date) - - md += "\nvenue: '" + html_escape(item.venue) + "'" - - if len(str(item.paper_url)) > 5: - md += "\npaperurl: '" + item.paper_url + "'" - - md += "\ncitation: '" + html_escape(item.citation) + "'" - - md += "\n---" - - ## Markdown description for individual page - - if len(str(item.paper_url)) > 5: - md += "\n\nDownload paper here\n" - - if len(str(item.excerpt)) > 5: - md += "\n" + html_escape(item.excerpt) + "\n" - - md += "\nRecommended citation: " + item.citation - - md_filename = os.path.basename(md_filename) - - with open("../_publications/" + md_filename, 'w') as f: - f.write(md) - - diff --git a/markdown_generator/publications.tsv b/markdown_generator/publications.tsv deleted file mode 100644 index 49e79632b0b24..0000000000000 --- a/markdown_generator/publications.tsv +++ /dev/null @@ -1,4 +0,0 @@ -pub_date title venue excerpt citation url_slug paper_url -2009-10-01 Paper Title Number 1 Journal 1 This paper is about the number 1. The number 2 is left for future work. Your Name, You. (2009). "Paper Title Number 1." Journal 1. 1(1). paper-title-number-1 http://academicpages.github.io/files/paper1.pdf -2010-10-01 Paper Title Number 2 Journal 1 This paper is about the number 2. The number 3 is left for future work. Your Name, You. (2010). "Paper Title Number 2." Journal 1. 1(2). paper-title-number-2 http://academicpages.github.io/files/paper2.pdf -2015-10-01 Paper Title Number 3 Journal 1 This paper is about the number 3. The number 4 is left for future work. Your Name, You. (2015). "Paper Title Number 3." Journal 1. 1(3). paper-title-number-3 http://academicpages.github.io/files/paper3.pdf \ No newline at end of file diff --git a/markdown_generator/pubsFromBib.py b/markdown_generator/pubsFromBib.py deleted file mode 100644 index 92b4d02f942f3..0000000000000 --- a/markdown_generator/pubsFromBib.py +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # Publications markdown generator for academicpages -# -# Takes a set of bibtex of publications and converts them for use with [academicpages.github.io](academicpages.github.io). This is an interactive Jupyter notebook ([see more info here](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html)). -# -# The core python code is also in `pubsFromBibs.py`. -# Run either from the `markdown_generator` folder after replacing updating the publist dictionary with: -# * bib file names -# * specific venue keys based on your bib file preferences -# * any specific pre-text for specific files -# * Collection Name (future feature) -# -# TODO: Make this work with other databases of citations, -# TODO: Merge this with the existing TSV parsing solution - - -from pybtex.database.input import bibtex -import pybtex.database.input.bibtex -from time import strptime -import string -import html -import os -import re - -#todo: incorporate different collection types rather than a catch all publications, requires other changes to template -publist = { - "proceeding": { - "file" : "proceedings.bib", - "venuekey": "booktitle", - "venue-pretext": "In the proceedings of ", - "collection" : {"name":"publications", - "permalink":"/publication/"} - - }, - "journal":{ - "file": "pubs.bib", - "venuekey" : "journal", - "venue-pretext" : "", - "collection" : {"name":"publications", - "permalink":"/publication/"} - } -} - -html_escape_table = { - "&": "&", - '"': """, - "'": "'" - } - -def html_escape(text): - """Produce entities within text.""" - return "".join(html_escape_table.get(c,c) for c in text) - - -for pubsource in publist: - parser = bibtex.Parser() - bibdata = parser.parse_file(publist[pubsource]["file"]) - - #loop through the individual references in a given bibtex file - for bib_id in bibdata.entries: - #reset default date - pub_year = "1900" - pub_month = "01" - pub_day = "01" - - b = bibdata.entries[bib_id].fields - - try: - pub_year = f'{b["year"]}' - - #todo: this hack for month and day needs some cleanup - if "month" in b.keys(): - if(len(b["month"])<3): - pub_month = "0"+b["month"] - pub_month = pub_month[-2:] - elif(b["month"] not in range(12)): - tmnth = strptime(b["month"][:3],'%b').tm_mon - pub_month = "{:02d}".format(tmnth) - else: - pub_month = str(b["month"]) - if "day" in b.keys(): - pub_day = str(b["day"]) - - - pub_date = pub_year+"-"+pub_month+"-"+pub_day - - #strip out {} as needed (some bibtex entries that maintain formatting) - clean_title = b["title"].replace("{", "").replace("}","").replace("\\","").replace(" ","-") - - url_slug = re.sub("\\[.*\\]|[^a-zA-Z0-9_-]", "", clean_title) - url_slug = url_slug.replace("--","-") - - md_filename = (str(pub_date) + "-" + url_slug + ".md").replace("--","-") - html_filename = (str(pub_date) + "-" + url_slug).replace("--","-") - - #Build Citation from text - citation = "" - - #citation authors - todo - add highlighting for primary author? - for author in bibdata.entries[bib_id].persons["author"]: - citation = citation+" "+author.first_names[0]+" "+author.last_names[0]+", " - - #citation title - citation = citation + "\"" + html_escape(b["title"].replace("{", "").replace("}","").replace("\\","")) + ".\"" - - #add venue logic depending on citation type - venue = publist[pubsource]["venue-pretext"]+b[publist[pubsource]["venuekey"]].replace("{", "").replace("}","").replace("\\","") - - citation = citation + " " + html_escape(venue) - citation = citation + ", " + pub_year + "." - - - ## YAML variables - md = "---\ntitle: \"" + html_escape(b["title"].replace("{", "").replace("}","").replace("\\","")) + '"\n' - - md += """collection: """ + publist[pubsource]["collection"]["name"] - - md += """\npermalink: """ + publist[pubsource]["collection"]["permalink"] + html_filename - - note = False - if "note" in b.keys(): - if len(str(b["note"])) > 5: - md += "\nexcerpt: '" + html_escape(b["note"]) + "'" - note = True - - md += "\ndate: " + str(pub_date) - - md += "\nvenue: '" + html_escape(venue) + "'" - - url = False - if "url" in b.keys(): - if len(str(b["url"])) > 5: - md += "\npaperurl: '" + b["url"] + "'" - url = True - - md += "\ncitation: '" + html_escape(citation) + "'" - - md += "\n---" - - - ## Markdown description for individual page - if note: - md += "\n" + html_escape(b["note"]) + "\n" - - if url: - md += "\n[Access paper here](" + b["url"] + "){:target=\"_blank\"}\n" - else: - md += "\nUse [Google Scholar](https://scholar.google.com/scholar?q="+html.escape(clean_title.replace("-","+"))+"){:target=\"_blank\"} for full citation" - - md_filename = os.path.basename(md_filename) - - with open("../_publications/" + md_filename, 'w') as f: - f.write(md) - print(f'SUCESSFULLY PARSED {bib_id}: \"', b["title"][:60],"..."*(len(b['title'])>60),"\"") - # field may not exist for a reference - except KeyError as e: - print(f'WARNING Missing Expected Field {e} from entry {bib_id}: \"', b["title"][:30],"..."*(len(b['title'])>30),"\"") - continue diff --git a/markdown_generator/readme.md b/markdown_generator/readme.md deleted file mode 100644 index 013aa7324d595..0000000000000 --- a/markdown_generator/readme.md +++ /dev/null @@ -1,7 +0,0 @@ -# Jupyter notebook markdown generator - -These .ipynb files are Jupyter notebook files that convert a TSV containing structured data about talks (`talks.tsv`) or presentations (`presentations.tsv`) into individual markdown files that will be properly formatted for the academicpages template. The notebooks contain a lot of documentation about the process. The .py files are pure python that do the same things if they are executed in a terminal, they just don't have pretty documentation. - - - - diff --git a/markdown_generator/talks.ipynb b/markdown_generator/talks.ipynb deleted file mode 100644 index f7e2347d34f2f..0000000000000 --- a/markdown_generator/talks.ipynb +++ /dev/null @@ -1,380 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "deletable": true, - "editable": true - }, - "source": [ - "# Talks markdown generator for academicpages\n", - "\n", - "Takes a TSV of talks with metadata and converts them for use with [academicpages.github.io](academicpages.github.io). This is an interactive Jupyter notebook ([see more info here](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html)). The core python code is also in `talks.py`. Run either from the `markdown_generator` folder after replacing `talks.tsv` with one containing your data.\n", - "\n", - "TODO: Make this work with BibTex and other databases, rather than Stuart's non-standard TSV format and citation style." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import os" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Data format\n", - "\n", - "The TSV needs to have the following columns: title, type, url_slug, venue, date, location, talk_url, description, with a header at the top. Many of these fields can be blank, but the columns must be in the TSV.\n", - "\n", - "- Fields that cannot be blank: `title`, `url_slug`, `date`. All else can be blank. `type` defaults to \"Talk\" \n", - "- `date` must be formatted as YYYY-MM-DD.\n", - "- `url_slug` will be the descriptive part of the .md file and the permalink URL for the page about the paper. \n", - " - The .md file will be `YYYY-MM-DD-[url_slug].md` and the permalink will be `https://[yourdomain]/talks/YYYY-MM-DD-[url_slug]`\n", - " - The combination of `url_slug` and `date` must be unique, as it will be the basis for your filenames\n", - "\n", - "This is how the raw file looks (it doesn't look pretty, use a spreadsheet or other program to edit and create)." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "title\ttype\turl_slug\tvenue\tdate\tlocation\ttalk_url\tdescription\r\n", - "Talk 1 on Relevant Topic in Your Field\tTalk\ttalk-1\tUC San Francisco, Department of Testing\t2012-03-01\tSan Francisco, California\t\tThis is a description of your talk, which is a markdown files that can be all markdown-ified like any other post. Yay markdown!\r\n", - "Tutorial 1 on Relevant Topic in Your Field\tTutorial\ttutorial-1\tUC-Berkeley Institute for Testing Science\t2013-03-01\tBerkeley CA, USA\thttp://exampleurl.com\tThis is a description of your tutorial, note the different field in type. This is a markdown files that can be all markdown-ified like any other post. Yay markdown!\r\n", - "Talk 2 on Relevant Topic in Your Field\tTalk\ttalk-2\tLondon School of Testing\t2014-02-01\tLondon, UK\thttp://example2.com\tThis is a description of your talk, which is a markdown files that can be all markdown-ified like any other post. Yay markdown!\r\n", - "Conference Proceeding talk 3 on Relevant Topic in Your Field\tConference proceedings talk\ttalk-3\tTesting Institute of America 2014 Annual Conference\t2014-03-01\tLos Angeles, CA\t\tThis is a description of your conference proceedings talk, note the different field in type. You can put anything in this field." - ] - } - ], - "source": [ - "!cat talks.tsv" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Import TSV\n", - "\n", - "Pandas makes this easy with the read_csv function. We are using a TSV, so we specify the separator as a tab, or `\\t`.\n", - "\n", - "I found it important to put this data in a tab-separated values format, because there are a lot of commas in this kind of data and comma-separated values can get messed up. However, you can modify the import statement, as pandas also has read_excel(), read_json(), and others." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
titletypeurl_slugvenuedatelocationtalk_urldescription
0Talk 1 on Relevant Topic in Your FieldTalktalk-1UC San Francisco, Department of Testing2012-03-01San Francisco, CaliforniaNaNThis is a description of your talk, which is a...
1Tutorial 1 on Relevant Topic in Your FieldTutorialtutorial-1UC-Berkeley Institute for Testing Science2013-03-01Berkeley CA, USAhttp://exampleurl.comThis is a description of your tutorial, note t...
2Talk 2 on Relevant Topic in Your FieldTalktalk-2London School of Testing2014-02-01London, UKhttp://example2.comThis is a description of your talk, which is a...
3Conference Proceeding talk 3 on Relevant Topic...Conference proceedings talktalk-3Testing Institute of America 2014 Annual Confe...2014-03-01Los Angeles, CANaNThis is a description of your conference proce...
\n", - "
" - ], - "text/plain": [ - " title \\\n", - "0 Talk 1 on Relevant Topic in Your Field \n", - "1 Tutorial 1 on Relevant Topic in Your Field \n", - "2 Talk 2 on Relevant Topic in Your Field \n", - "3 Conference Proceeding talk 3 on Relevant Topic... \n", - "\n", - " type url_slug \\\n", - "0 Talk talk-1 \n", - "1 Tutorial tutorial-1 \n", - "2 Talk talk-2 \n", - "3 Conference proceedings talk talk-3 \n", - "\n", - " venue date \\\n", - "0 UC San Francisco, Department of Testing 2012-03-01 \n", - "1 UC-Berkeley Institute for Testing Science 2013-03-01 \n", - "2 London School of Testing 2014-02-01 \n", - "3 Testing Institute of America 2014 Annual Confe... 2014-03-01 \n", - "\n", - " location talk_url \\\n", - "0 San Francisco, California NaN \n", - "1 Berkeley CA, USA http://exampleurl.com \n", - "2 London, UK http://example2.com \n", - "3 Los Angeles, CA NaN \n", - "\n", - " description \n", - "0 This is a description of your talk, which is a... \n", - "1 This is a description of your tutorial, note t... \n", - "2 This is a description of your talk, which is a... \n", - "3 This is a description of your conference proce... " - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "talks = pd.read_csv(\"talks.tsv\", sep=\"\\t\", header=0)\n", - "talks" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Escape special characters\n", - "\n", - "YAML is very picky about how it takes a valid string, so we are replacing single and double quotes (and ampersands) with their HTML encoded equivilents. This makes them look not so readable in raw format, but they are parsed and rendered nicely." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [ - "html_escape_table = {\n", - " \"&\": \"&\",\n", - " '\"': \""\",\n", - " \"'\": \"'\"\n", - " }\n", - "\n", - "def html_escape(text):\n", - " if type(text) is str:\n", - " return \"\".join(html_escape_table.get(c,c) for c in text)\n", - " else:\n", - " return \"False\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Creating the markdown files\n", - "\n", - "This is where the heavy lifting is done. This loops through all the rows in the TSV dataframe, then starts to concatentate a big string (```md```) that contains the markdown for each type. It does the YAML metadata first, then does the description for the individual page." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [], - "source": [ - "loc_dict = {}\n", - "\n", - "for row, item in talks.iterrows():\n", - " \n", - " md_filename = str(item.date) + \"-\" + item.url_slug + \".md\"\n", - " html_filename = str(item.date) + \"-\" + item.url_slug \n", - " year = item.date[:4]\n", - " \n", - " md = \"---\\ntitle: \\\"\" + item.title + '\"\\n'\n", - " md += \"collection: talks\" + \"\\n\"\n", - " \n", - " if len(str(item.type)) > 3:\n", - " md += 'type: \"' + item.type + '\"\\n'\n", - " else:\n", - " md += 'type: \"Talk\"\\n'\n", - " \n", - " md += \"permalink: /talks/\" + html_filename + \"\\n\"\n", - " \n", - " if len(str(item.venue)) > 3:\n", - " md += 'venue: \"' + item.venue + '\"\\n'\n", - " \n", - " if len(str(item.location)) > 3:\n", - " md += \"date: \" + str(item.date) + \"\\n\"\n", - " \n", - " if len(str(item.location)) > 3:\n", - " md += 'location: \"' + str(item.location) + '\"\\n'\n", - " \n", - " md += \"---\\n\"\n", - " \n", - " \n", - " if len(str(item.talk_url)) > 3:\n", - " md += \"\\n[More information here](\" + item.talk_url + \")\\n\" \n", - " \n", - " \n", - " if len(str(item.description)) > 3:\n", - " md += \"\\n\" + html_escape(item.description) + \"\\n\"\n", - " \n", - " \n", - " md_filename = os.path.basename(md_filename)\n", - " #print(md)\n", - " \n", - " with open(\"../_talks/\" + md_filename, 'w') as f:\n", - " f.write(md)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "These files are in the talks directory, one directory below where we're working from." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2012-03-01-talk-1.md\t 2014-02-01-talk-2.md\r\n", - "2013-03-01-tutorial-1.md 2014-03-01-talk-3.md\r\n" - ] - } - ], - "source": [ - "!ls ../_talks" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "---\r\n", - "title: \"Tutorial 1 on Relevant Topic in Your Field\"\r\n", - "collection: talks\r\n", - "type: \"Tutorial\"\r\n", - "permalink: /talks/2013-03-01-tutorial-1\r\n", - "venue: \"UC-Berkeley Institute for Testing Science\"\r\n", - "date: 2013-03-01\r\n", - "location: \"Berkeley CA, USA\"\r\n", - "---\r\n", - "\r\n", - "[More information here](http://exampleurl.com)\r\n", - "\r\n", - "This is a description of your tutorial, note the different field in type. This is a markdown files that can be all markdown-ified like any other post. Yay markdown!\r\n" - ] - } - ], - "source": [ - "!cat ../_talks/2013-03-01-tutorial-1.md" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.1" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/markdown_generator/talks.py b/markdown_generator/talks.py deleted file mode 100644 index 818fd28dae125..0000000000000 --- a/markdown_generator/talks.py +++ /dev/null @@ -1,111 +0,0 @@ - -# coding: utf-8 - -# # Talks markdown generator for academicpages -# -# Takes a TSV of talks with metadata and converts them for use with [academicpages.github.io](academicpages.github.io). This is an interactive Jupyter notebook ([see more info here](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html)). The core python code is also in `talks.py`. Run either from the `markdown_generator` folder after replacing `talks.tsv` with one containing your data. -# -# TODO: Make this work with BibTex and other databases, rather than Stuart's non-standard TSV format and citation style. - -# In[1]: - -import pandas as pd -import os - - -# ## Data format -# -# The TSV needs to have the following columns: title, type, url_slug, venue, date, location, talk_url, description, with a header at the top. Many of these fields can be blank, but the columns must be in the TSV. -# -# - Fields that cannot be blank: `title`, `url_slug`, `date`. All else can be blank. `type` defaults to "Talk" -# - `date` must be formatted as YYYY-MM-DD. -# - `url_slug` will be the descriptive part of the .md file and the permalink URL for the page about the paper. -# - The .md file will be `YYYY-MM-DD-[url_slug].md` and the permalink will be `https://[yourdomain]/talks/YYYY-MM-DD-[url_slug]` -# - The combination of `url_slug` and `date` must be unique, as it will be the basis for your filenames -# - - -# ## Import TSV -# -# Pandas makes this easy with the read_csv function. We are using a TSV, so we specify the separator as a tab, or `\t`. -# -# I found it important to put this data in a tab-separated values format, because there are a lot of commas in this kind of data and comma-separated values can get messed up. However, you can modify the import statement, as pandas also has read_excel(), read_json(), and others. - -# In[3]: - -talks = pd.read_csv("talks.tsv", sep="\t", header=0) -talks - - -# ## Escape special characters -# -# YAML is very picky about how it takes a valid string, so we are replacing single and double quotes (and ampersands) with their HTML encoded equivilents. This makes them look not so readable in raw format, but they are parsed and rendered nicely. - -# In[4]: - -html_escape_table = { - "&": "&", - '"': """, - "'": "'" - } - -def html_escape(text): - if type(text) is str: - return "".join(html_escape_table.get(c,c) for c in text) - else: - return "False" - - -# ## Creating the markdown files -# -# This is where the heavy lifting is done. This loops through all the rows in the TSV dataframe, then starts to concatentate a big string (```md```) that contains the markdown for each type. It does the YAML metadata first, then does the description for the individual page. - -# In[5]: - -loc_dict = {} - -for row, item in talks.iterrows(): - - md_filename = str(item.date) + "-" + item.url_slug + ".md" - html_filename = str(item.date) + "-" + item.url_slug - year = item.date[:4] - - md = "---\ntitle: \"" + item.title + '"\n' - md += "collection: talks" + "\n" - - if len(str(item.type)) > 3: - md += 'type: "' + item.type + '"\n' - else: - md += 'type: "Talk"\n' - - md += "permalink: /talks/" + html_filename + "\n" - - if len(str(item.venue)) > 3: - md += 'venue: "' + item.venue + '"\n' - - if len(str(item.location)) > 3: - md += "date: " + str(item.date) + "\n" - - if len(str(item.location)) > 3: - md += 'location: "' + str(item.location) + '"\n' - - md += "---\n" - - - if len(str(item.talk_url)) > 3: - md += "\n[More information here](" + item.talk_url + ")\n" - - - if len(str(item.description)) > 3: - md += "\n" + html_escape(item.description) + "\n" - - - md_filename = os.path.basename(md_filename) - #print(md) - - with open("../_talks/" + md_filename, 'w') as f: - f.write(md) - - -# These files are in the talks directory, one directory below where we're working from. - diff --git a/markdown_generator/talks.tsv b/markdown_generator/talks.tsv deleted file mode 100644 index 4e4b0d22ded66..0000000000000 --- a/markdown_generator/talks.tsv +++ /dev/null @@ -1,5 +0,0 @@ -title type url_slug venue date location talk_url description -Talk 1 on Relevant Topic in Your Field Talk talk-1 UC San Francisco, Department of Testing 2012-03-01 San Francisco, California This is a description of your talk, which is a markdown files that can be all markdown-ified like any other post. Yay markdown! -Tutorial 1 on Relevant Topic in Your Field Tutorial tutorial-1 UC-Berkeley Institute for Testing Science 2013-03-01 Berkeley CA, USA http://exampleurl.com This is a description of your tutorial, note the different field in type. This is a markdown files that can be all markdown-ified like any other post. Yay markdown! -Talk 2 on Relevant Topic in Your Field Talk talk-2 London School of Testing 2014-02-01 London, UK http://example2.com This is a description of your talk, which is a markdown files that can be all markdown-ified like any other post. Yay markdown! -Conference Proceeding talk 3 on Relevant Topic in Your Field Conference proceedings talk talk-3 Testing Institute of America 2014 Annual Conference 2014-03-01 Los Angeles, CA This is a description of your conference proceedings talk, note the different field in type. You can put anything in this field. \ No newline at end of file diff --git a/talkmap.ipynb b/talkmap.ipynb deleted file mode 100644 index f3aa57cd3b133..0000000000000 --- a/talkmap.ipynb +++ /dev/null @@ -1,158 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Leaflet cluster map of talk locations\n", - "\n", - "Run this from the _talks/ directory, which contains .md files of all your talks. This scrapes the location YAML field from each .md file, geolocates it with geopy/Nominatim, and uses the getorg library to output data, HTML, and Javascript for a standalone cluster map." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already up-to-date: getorg in /home/vm/anaconda3/lib/python3.5/site-packages\n", - "Requirement already up-to-date: geopy in /home/vm/.local/lib/python3.5/site-packages (from getorg)\n", - "Requirement already up-to-date: retrying in /home/vm/.local/lib/python3.5/site-packages (from getorg)\n", - "Requirement already up-to-date: pygithub in /home/vm/anaconda3/lib/python3.5/site-packages (from getorg)\n", - "Requirement already up-to-date: six>=1.7.0 in /home/vm/.local/lib/python3.5/site-packages (from retrying->getorg)\n", - "IPywidgets and ipyleaflet support enabled.\n" - ] - } - ], - "source": [ - "!pip install getorg --upgrade\n", - "import glob\n", - "import getorg\n", - "from geopy import Nominatim" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "g = glob.glob(\"*.md\")" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "geocoder = Nominatim()\n", - "location_dict = {}\n", - "location = \"\"\n", - "permalink = \"\"\n", - "title = \"\"" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Berkeley CA, USA \n", - " Berkeley, Alameda County, California, United States of America\n", - "Los Angeles, CA \n", - " LA, Los Angeles County, California, United States of America\n", - "London, UK \n", - " London, Greater London, England, UK\n", - "San Francisco, California \n", - " SF, California, United States of America\n" - ] - } - ], - "source": [ - "\n", - "for file in g:\n", - " with open(file, 'r') as f:\n", - " lines = f.read()\n", - " if lines.find('location: \"') > 1:\n", - " loc_start = lines.find('location: \"') + 11\n", - " lines_trim = lines[loc_start:]\n", - " loc_end = lines_trim.find('\"')\n", - " location = lines_trim[:loc_end]\n", - " \n", - " \n", - " location_dict[location] = geocoder.geocode(location)\n", - " print(location, \"\\n\", location_dict[location])\n" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'Written map to ../talkmap/'" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "m = getorg.orgmap.create_map_obj()\n", - "getorg.orgmap.output_html_cluster_map(location_dict, folder_name=\"../talkmap\", hashed_usernames=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "kernelspec": { - "display_name": "Python [Root]", - "language": "python", - "name": "Python [Root]" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/talkmap.py b/talkmap.py deleted file mode 100644 index 803c5f45d4084..0000000000000 --- a/talkmap.py +++ /dev/null @@ -1,47 +0,0 @@ - - -# # Leaflet cluster map of talk locations -# -# (c) 2016-2017 R. Stuart Geiger, released under the MIT license -# -# Run this from the _talks/ directory, which contains .md files of all your talks. -# This scrapes the location YAML field from each .md file, geolocates it with -# geopy/Nominatim, and uses the getorg library to output data, HTML, -# and Javascript for a standalone cluster map. -# -# Requires: glob, getorg, geopy - -import glob -import getorg -from geopy import Nominatim - -g = glob.glob("*.md") - - -geocoder = Nominatim() -location_dict = {} -location = "" -permalink = "" -title = "" - - -for file in g: - with open(file, 'r') as f: - lines = f.read() - if lines.find('location: "') > 1: - loc_start = lines.find('location: "') + 11 - lines_trim = lines[loc_start:] - loc_end = lines_trim.find('"') - location = lines_trim[:loc_end] - - - location_dict[location] = geocoder.geocode(location) - print(location, "\n", location_dict[location]) - - -m = getorg.orgmap.create_map_obj() -getorg.orgmap.output_html_cluster_map(location_dict, folder_name="../talkmap", hashed_usernames=False) - - - - diff --git a/talkmap/leaflet_dist/MarkerCluster.Default.css b/talkmap/leaflet_dist/MarkerCluster.Default.css deleted file mode 100644 index 47d5954b8ef05..0000000000000 --- a/talkmap/leaflet_dist/MarkerCluster.Default.css +++ /dev/null @@ -1,62 +0,0 @@ - - .marker-cluster-small { - background-color: rgba(181, 226, 140, 0.6); - } - .marker-cluster-small div { - background-color: rgba(110, 204, 57, 0.6); - } - - .marker-cluster-medium { - background-color: rgba(241, 211, 87, 0.6); - } - .marker-cluster-medium div { - background-color: rgba(240, 194, 12, 0.6); - } - - .marker-cluster-large { - background-color: rgba(253, 156, 115, 0.6); - } - .marker-cluster-large div { - background-color: rgba(241, 128, 23, 0.6); - } - - /* IE 6-8 fallback colors */ - .leaflet-oldie .marker-cluster-small { - background-color: rgb(181, 226, 140); - } - .leaflet-oldie .marker-cluster-small div { - background-color: rgb(110, 204, 57); - } - - .leaflet-oldie .marker-cluster-medium { - background-color: rgb(241, 211, 87); - } - .leaflet-oldie .marker-cluster-medium div { - background-color: rgb(240, 194, 12); - } - - .leaflet-oldie .marker-cluster-large { - background-color: rgb(253, 156, 115); - } - .leaflet-oldie .marker-cluster-large div { - background-color: rgb(241, 128, 23); - } - - .marker-cluster { - background-clip: padding-box; - border-radius: 20px; - } - .marker-cluster div { - width: 30px; - height: 30px; - margin-left: 5px; - margin-top: 5px; - - text-align: center; - border-radius: 15px; - font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif; - } - .marker-cluster span { - line-height: 30px; - } - \ No newline at end of file diff --git a/talkmap/leaflet_dist/MarkerCluster.css b/talkmap/leaflet_dist/MarkerCluster.css deleted file mode 100644 index dac8d4158ba51..0000000000000 --- a/talkmap/leaflet_dist/MarkerCluster.css +++ /dev/null @@ -1,16 +0,0 @@ - - .leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow { - -webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in; - -moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in; - -o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in; - transition: transform 0.3s ease-out, opacity 0.3s ease-in; - } - - .leaflet-cluster-spider-leg { - /* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */ - -webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in; - -moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in; - -o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in; - transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in; - } - \ No newline at end of file diff --git a/talkmap/leaflet_dist/leaflet.markercluster-src.js b/talkmap/leaflet_dist/leaflet.markercluster-src.js deleted file mode 100644 index 5b477c0124eaf..0000000000000 --- a/talkmap/leaflet_dist/leaflet.markercluster-src.js +++ /dev/null @@ -1,2627 +0,0 @@ - - /* - Leaflet.markercluster, Provides Beautiful Animated Marker Clustering functionality for Leaflet, a JS library for interactive maps. - https://github.com/Leaflet/Leaflet.markercluster - (c) 2012-2013, Dave Leaver, smartrak - */ - (function (window, document, undefined) {/* - * L.MarkerClusterGroup extends L.FeatureGroup by clustering the markers contained within - */ - - L.MarkerClusterGroup = L.FeatureGroup.extend({ - - options: { - maxClusterRadius: 80, //A cluster will cover at most this many pixels from its center - iconCreateFunction: null, - - spiderfyOnMaxZoom: true, - showCoverageOnHover: true, - zoomToBoundsOnClick: true, - singleMarkerMode: false, - - disableClusteringAtZoom: null, - - // Setting this to false prevents the removal of any clusters outside of the viewpoint, which - // is the default behaviour for performance reasons. - removeOutsideVisibleBounds: true, - - // Set to false to disable all animations (zoom and spiderfy). - // If false, option animateAddingMarkers below has no effect. - // If L.DomUtil.TRANSITION is falsy, this option has no effect. - animate: true, - - //Whether to animate adding markers after adding the MarkerClusterGroup to the map - // If you are adding individual markers set to true, if adding bulk markers leave false for massive performance gains. - animateAddingMarkers: false, - - //Increase to increase the distance away that spiderfied markers appear from the center - spiderfyDistanceMultiplier: 1, - - // Make it possible to specify a polyline options on a spider leg - spiderLegPolylineOptions: { weight: 1.5, color: '#222', opacity: 0.5 }, - - // When bulk adding layers, adds markers in chunks. Means addLayers may not add all the layers in the call, others will be loaded during setTimeouts - chunkedLoading: false, - chunkInterval: 200, // process markers for a maximum of ~ n milliseconds (then trigger the chunkProgress callback) - chunkDelay: 50, // at the end of each interval, give n milliseconds back to system/browser - chunkProgress: null, // progress callback: function(processed, total, elapsed) (e.g. for a progress indicator) - - //Options to pass to the L.Polygon constructor - polygonOptions: {} - }, - - initialize: function (options) { - L.Util.setOptions(this, options); - if (!this.options.iconCreateFunction) { - this.options.iconCreateFunction = this._defaultIconCreateFunction; - } - - this._featureGroup = L.featureGroup(); - this._featureGroup.addEventParent(this); - - this._nonPointGroup = L.featureGroup(); - this._nonPointGroup.addEventParent(this); - - this._inZoomAnimation = 0; - this._needsClustering = []; - this._needsRemoving = []; //Markers removed while we aren't on the map need to be kept track of - //The bounds of the currently shown area (from _getExpandedVisibleBounds) Updated on zoom/move - this._currentShownBounds = null; - - this._queue = []; - - // Hook the appropriate animation methods. - var animate = L.DomUtil.TRANSITION && this.options.animate; - L.extend(this, animate ? this._withAnimation : this._noAnimation); - // Remember which MarkerCluster class to instantiate (animated or not). - this._markerCluster = animate ? L.MarkerCluster : L.MarkerClusterNonAnimated; - }, - - addLayer: function (layer) { - - if (layer instanceof L.LayerGroup) { - return this.addLayers([layer]); - } - - //Don't cluster non point data - if (!layer.getLatLng) { - this._nonPointGroup.addLayer(layer); - return this; - } - - if (!this._map) { - this._needsClustering.push(layer); - return this; - } - - if (this.hasLayer(layer)) { - return this; - } - - - //If we have already clustered we'll need to add this one to a cluster - - if (this._unspiderfy) { - this._unspiderfy(); - } - - this._addLayer(layer, this._maxZoom); - - // Refresh bounds and weighted positions. - this._topClusterLevel._recalculateBounds(); - - this._refreshClustersIcons(); - - //Work out what is visible - var visibleLayer = layer, - currentZoom = this._map.getZoom(); - if (layer.__parent) { - while (visibleLayer.__parent._zoom >= currentZoom) { - visibleLayer = visibleLayer.__parent; - } - } - - if (this._currentShownBounds.contains(visibleLayer.getLatLng())) { - if (this.options.animateAddingMarkers) { - this._animationAddLayer(layer, visibleLayer); - } else { - this._animationAddLayerNonAnimated(layer, visibleLayer); - } - } - return this; - }, - - removeLayer: function (layer) { - - if (layer instanceof L.LayerGroup) { - return this.removeLayers([layer]); - } - - //Non point layers - if (!layer.getLatLng) { - this._nonPointGroup.removeLayer(layer); - return this; - } - - if (!this._map) { - if (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) { - this._needsRemoving.push(layer); - } - return this; - } - - if (!layer.__parent) { - return this; - } - - if (this._unspiderfy) { - this._unspiderfy(); - this._unspiderfyLayer(layer); - } - - //Remove the marker from clusters - this._removeLayer(layer, true); - - // Refresh bounds and weighted positions. - this._topClusterLevel._recalculateBounds(); - - this._refreshClustersIcons(); - - layer.off('move', this._childMarkerMoved, this); - - if (this._featureGroup.hasLayer(layer)) { - this._featureGroup.removeLayer(layer); - if (layer.clusterShow) { - layer.clusterShow(); - } - } - - return this; - }, - - //Takes an array of markers and adds them in bulk - addLayers: function (layersArray) { - if (!L.Util.isArray(layersArray)) { - return this.addLayer(layersArray); - } - - var fg = this._featureGroup, - npg = this._nonPointGroup, - chunked = this.options.chunkedLoading, - chunkInterval = this.options.chunkInterval, - chunkProgress = this.options.chunkProgress, - l = layersArray.length, - offset = 0, - originalArray = true, - m; - - if (this._map) { - var started = (new Date()).getTime(); - var process = L.bind(function () { - var start = (new Date()).getTime(); - for (; offset < l; offset++) { - if (chunked && offset % 200 === 0) { - // every couple hundred markers, instrument the time elapsed since processing started: - var elapsed = (new Date()).getTime() - start; - if (elapsed > chunkInterval) { - break; // been working too hard, time to take a break :-) - } - } - - m = layersArray[offset]; - - // Group of layers, append children to layersArray and skip. - // Side effects: - // - Total increases, so chunkProgress ratio jumps backward. - // - Groups are not included in this group, only their non-group child layers (hasLayer). - // Changing array length while looping does not affect performance in current browsers: - // http://jsperf.com/for-loop-changing-length/6 - if (m instanceof L.LayerGroup) { - if (originalArray) { - layersArray = layersArray.slice(); - originalArray = false; - } - this._extractNonGroupLayers(m, layersArray); - l = layersArray.length; - continue; - } - - //Not point data, can't be clustered - if (!m.getLatLng) { - npg.addLayer(m); - continue; - } - - if (this.hasLayer(m)) { - continue; - } - - this._addLayer(m, this._maxZoom); - - //If we just made a cluster of size 2 then we need to remove the other marker from the map (if it is) or we never will - if (m.__parent) { - if (m.__parent.getChildCount() === 2) { - var markers = m.__parent.getAllChildMarkers(), - otherMarker = markers[0] === m ? markers[1] : markers[0]; - fg.removeLayer(otherMarker); - } - } - } - - if (chunkProgress) { - // report progress and time elapsed: - chunkProgress(offset, l, (new Date()).getTime() - started); - } - - // Completed processing all markers. - if (offset === l) { - - // Refresh bounds and weighted positions. - this._topClusterLevel._recalculateBounds(); - - this._refreshClustersIcons(); - - this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds); - } else { - setTimeout(process, this.options.chunkDelay); - } - }, this); - - process(); - } else { - var needsClustering = this._needsClustering; - - for (; offset < l; offset++) { - m = layersArray[offset]; - - // Group of layers, append children to layersArray and skip. - if (m instanceof L.LayerGroup) { - if (originalArray) { - layersArray = layersArray.slice(); - originalArray = false; - } - this._extractNonGroupLayers(m, layersArray); - l = layersArray.length; - continue; - } - - //Not point data, can't be clustered - if (!m.getLatLng) { - npg.addLayer(m); - continue; - } - - if (this.hasLayer(m)) { - continue; - } - - needsClustering.push(m); - } - } - return this; - }, - - //Takes an array of markers and removes them in bulk - removeLayers: function (layersArray) { - var i, m, - l = layersArray.length, - fg = this._featureGroup, - npg = this._nonPointGroup, - originalArray = true; - - if (!this._map) { - for (i = 0; i < l; i++) { - m = layersArray[i]; - - // Group of layers, append children to layersArray and skip. - if (m instanceof L.LayerGroup) { - if (originalArray) { - layersArray = layersArray.slice(); - originalArray = false; - } - this._extractNonGroupLayers(m, layersArray); - l = layersArray.length; - continue; - } - - this._arraySplice(this._needsClustering, m); - npg.removeLayer(m); - if (this.hasLayer(m)) { - this._needsRemoving.push(m); - } - } - return this; - } - - if (this._unspiderfy) { - this._unspiderfy(); - - // Work on a copy of the array, so that next loop is not affected. - var layersArray2 = layersArray.slice(), - l2 = l; - for (i = 0; i < l2; i++) { - m = layersArray2[i]; - - // Group of layers, append children to layersArray and skip. - if (m instanceof L.LayerGroup) { - this._extractNonGroupLayers(m, layersArray2); - l2 = layersArray2.length; - continue; - } - - this._unspiderfyLayer(m); - } - } - - for (i = 0; i < l; i++) { - m = layersArray[i]; - - // Group of layers, append children to layersArray and skip. - if (m instanceof L.LayerGroup) { - if (originalArray) { - layersArray = layersArray.slice(); - originalArray = false; - } - this._extractNonGroupLayers(m, layersArray); - l = layersArray.length; - continue; - } - - if (!m.__parent) { - npg.removeLayer(m); - continue; - } - - this._removeLayer(m, true, true); - - if (fg.hasLayer(m)) { - fg.removeLayer(m); - if (m.clusterShow) { - m.clusterShow(); - } - } - } - - // Refresh bounds and weighted positions. - this._topClusterLevel._recalculateBounds(); - - this._refreshClustersIcons(); - - //Fix up the clusters and markers on the map - this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds); - - return this; - }, - - //Removes all layers from the MarkerClusterGroup - clearLayers: function () { - //Need our own special implementation as the LayerGroup one doesn't work for us - - //If we aren't on the map (yet), blow away the markers we know of - if (!this._map) { - this._needsClustering = []; - delete this._gridClusters; - delete this._gridUnclustered; - } - - if (this._noanimationUnspiderfy) { - this._noanimationUnspiderfy(); - } - - //Remove all the visible layers - this._featureGroup.clearLayers(); - this._nonPointGroup.clearLayers(); - - this.eachLayer(function (marker) { - marker.off('move', this._childMarkerMoved, this); - delete marker.__parent; - }); - - if (this._map) { - //Reset _topClusterLevel and the DistanceGrids - this._generateInitialClusters(); - } - - return this; - }, - - //Override FeatureGroup.getBounds as it doesn't work - getBounds: function () { - var bounds = new L.LatLngBounds(); - - if (this._topClusterLevel) { - bounds.extend(this._topClusterLevel._bounds); - } - - for (var i = this._needsClustering.length - 1; i >= 0; i--) { - bounds.extend(this._needsClustering[i].getLatLng()); - } - - bounds.extend(this._nonPointGroup.getBounds()); - - return bounds; - }, - - //Overrides LayerGroup.eachLayer - eachLayer: function (method, context) { - var markers = this._needsClustering.slice(), - needsRemoving = this._needsRemoving, - i; - - if (this._topClusterLevel) { - this._topClusterLevel.getAllChildMarkers(markers); - } - - for (i = markers.length - 1; i >= 0; i--) { - if (needsRemoving.indexOf(markers[i]) === -1) { - method.call(context, markers[i]); - } - } - - this._nonPointGroup.eachLayer(method, context); - }, - - //Overrides LayerGroup.getLayers - getLayers: function () { - var layers = []; - this.eachLayer(function (l) { - layers.push(l); - }); - return layers; - }, - - //Overrides LayerGroup.getLayer, WARNING: Really bad performance - getLayer: function (id) { - var result = null; - - id = parseInt(id, 10); - - this.eachLayer(function (l) { - if (L.stamp(l) === id) { - result = l; - } - }); - - return result; - }, - - //Returns true if the given layer is in this MarkerClusterGroup - hasLayer: function (layer) { - if (!layer) { - return false; - } - - var i, anArray = this._needsClustering; - - for (i = anArray.length - 1; i >= 0; i--) { - if (anArray[i] === layer) { - return true; - } - } - - anArray = this._needsRemoving; - for (i = anArray.length - 1; i >= 0; i--) { - if (anArray[i] === layer) { - return false; - } - } - - return !!(layer.__parent && layer.__parent._group === this) || this._nonPointGroup.hasLayer(layer); - }, - - //Zoom down to show the given layer (spiderfying if necessary) then calls the callback - zoomToShowLayer: function (layer, callback) { - - if (typeof callback !== 'function') { - callback = function () {}; - } - - var showMarker = function () { - if ((layer._icon || layer.__parent._icon) && !this._inZoomAnimation) { - this._map.off('moveend', showMarker, this); - this.off('animationend', showMarker, this); - - if (layer._icon) { - callback(); - } else if (layer.__parent._icon) { - this.once('spiderfied', callback, this); - layer.__parent.spiderfy(); - } - } - }; - - if (layer._icon && this._map.getBounds().contains(layer.getLatLng())) { - //Layer is visible ond on screen, immediate return - callback(); - } else if (layer.__parent._zoom < this._map.getZoom()) { - //Layer should be visible at this zoom level. It must not be on screen so just pan over to it - this._map.on('moveend', showMarker, this); - this._map.panTo(layer.getLatLng()); - } else { - var moveStart = function () { - this._map.off('movestart', moveStart, this); - moveStart = null; - }; - - this._map.on('movestart', moveStart, this); - this._map.on('moveend', showMarker, this); - this.on('animationend', showMarker, this); - layer.__parent.zoomToBounds(); - - if (moveStart) { - //Never started moving, must already be there, probably need clustering however - showMarker.call(this); - } - } - }, - - //Overrides FeatureGroup.onAdd - onAdd: function (map) { - this._map = map; - var i, l, layer; - - if (!isFinite(this._map.getMaxZoom())) { - throw "Map has no maxZoom specified"; - } - - this._featureGroup.addTo(map); - this._nonPointGroup.addTo(map); - - if (!this._gridClusters) { - this._generateInitialClusters(); - } - - this._maxLat = map.options.crs.projection.MAX_LATITUDE; - - for (i = 0, l = this._needsRemoving.length; i < l; i++) { - layer = this._needsRemoving[i]; - this._removeLayer(layer, true); - } - this._needsRemoving = []; - - //Remember the current zoom level and bounds - this._zoom = this._map.getZoom(); - this._currentShownBounds = this._getExpandedVisibleBounds(); - - this._map.on('zoomend', this._zoomEnd, this); - this._map.on('moveend', this._moveEnd, this); - - if (this._spiderfierOnAdd) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely - this._spiderfierOnAdd(); - } - - this._bindEvents(); - - //Actually add our markers to the map: - l = this._needsClustering; - this._needsClustering = []; - this.addLayers(l); - }, - - //Overrides FeatureGroup.onRemove - onRemove: function (map) { - map.off('zoomend', this._zoomEnd, this); - map.off('moveend', this._moveEnd, this); - - this._unbindEvents(); - - //In case we are in a cluster animation - this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', ''); - - if (this._spiderfierOnRemove) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely - this._spiderfierOnRemove(); - } - - delete this._maxLat; - - //Clean up all the layers we added to the map - this._hideCoverage(); - this._featureGroup.remove(); - this._nonPointGroup.remove(); - - this._featureGroup.clearLayers(); - - this._map = null; - }, - - getVisibleParent: function (marker) { - var vMarker = marker; - while (vMarker && !vMarker._icon) { - vMarker = vMarker.__parent; - } - return vMarker || null; - }, - - //Remove the given object from the given array - _arraySplice: function (anArray, obj) { - for (var i = anArray.length - 1; i >= 0; i--) { - if (anArray[i] === obj) { - anArray.splice(i, 1); - return true; - } - } - }, - - /** - * Removes a marker from all _gridUnclustered zoom levels, starting at the supplied zoom. - * @param marker to be removed from _gridUnclustered. - * @param z integer bottom start zoom level (included) - * @private - */ - _removeFromGridUnclustered: function (marker, z) { - var map = this._map, - gridUnclustered = this._gridUnclustered; - - for (; z >= 0; z--) { - if (!gridUnclustered[z].removeObject(marker, map.project(marker.getLatLng(), z))) { - break; - } - } - }, - - _childMarkerMoved: function (e) { - if (!this._ignoreMove) { - e.target._latlng = e.oldLatLng; - this.removeLayer(e.target); - - e.target._latlng = e.latlng; - this.addLayer(e.target); - } - }, - - //Internal function for removing a marker from everything. - //dontUpdateMap: set to true if you will handle updating the map manually (for bulk functions) - _removeLayer: function (marker, removeFromDistanceGrid, dontUpdateMap) { - var gridClusters = this._gridClusters, - gridUnclustered = this._gridUnclustered, - fg = this._featureGroup, - map = this._map; - - //Remove the marker from distance clusters it might be in - if (removeFromDistanceGrid) { - this._removeFromGridUnclustered(marker, this._maxZoom); - } - - //Work our way up the clusters removing them as we go if required - var cluster = marker.__parent, - markers = cluster._markers, - otherMarker; - - //Remove the marker from the immediate parents marker list - this._arraySplice(markers, marker); - - while (cluster) { - cluster._childCount--; - cluster._boundsNeedUpdate = true; - - if (cluster._zoom < 0) { - //Top level, do nothing - break; - } else if (removeFromDistanceGrid && cluster._childCount <= 1) { //Cluster no longer required - //We need to push the other marker up to the parent - otherMarker = cluster._markers[0] === marker ? cluster._markers[1] : cluster._markers[0]; - - //Update distance grid - gridClusters[cluster._zoom].removeObject(cluster, map.project(cluster._cLatLng, cluster._zoom)); - gridUnclustered[cluster._zoom].addObject(otherMarker, map.project(otherMarker.getLatLng(), cluster._zoom)); - - //Move otherMarker up to parent - this._arraySplice(cluster.__parent._childClusters, cluster); - cluster.__parent._markers.push(otherMarker); - otherMarker.__parent = cluster.__parent; - - if (cluster._icon) { - //Cluster is currently on the map, need to put the marker on the map instead - fg.removeLayer(cluster); - if (!dontUpdateMap) { - fg.addLayer(otherMarker); - } - } - } else { - cluster._iconNeedsUpdate = true; - } - - cluster = cluster.__parent; - } - - delete marker.__parent; - }, - - _isOrIsParent: function (el, oel) { - while (oel) { - if (el === oel) { - return true; - } - oel = oel.parentNode; - } - return false; - }, - - //Override L.Evented.fire - fire: function (type, data, propagate) { - if (data && data.layer instanceof L.MarkerCluster) { - //Prevent multiple clustermouseover/off events if the icon is made up of stacked divs (Doesn't work in ie <= 8, no relatedTarget) - if (data.originalEvent && this._isOrIsParent(data.layer._icon, data.originalEvent.relatedTarget)) { - return; - } - type = 'cluster' + type; - } - - L.FeatureGroup.prototype.fire.call(this, type, data, propagate); - }, - - //Override L.Evented.listens - listens: function (type, propagate) { - return L.FeatureGroup.prototype.listens.call(this, type, propagate) || L.FeatureGroup.prototype.listens.call(this, 'cluster' + type, propagate); - }, - - //Default functionality - _defaultIconCreateFunction: function (cluster) { - var childCount = cluster.getChildCount(); - - var c = ' marker-cluster-'; - if (childCount < 10) { - c += 'small'; - } else if (childCount < 100) { - c += 'medium'; - } else { - c += 'large'; - } - - return new L.DivIcon({ html: '
' + childCount + '
', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) }); - }, - - _bindEvents: function () { - var map = this._map, - spiderfyOnMaxZoom = this.options.spiderfyOnMaxZoom, - showCoverageOnHover = this.options.showCoverageOnHover, - zoomToBoundsOnClick = this.options.zoomToBoundsOnClick; - - //Zoom on cluster click or spiderfy if we are at the lowest level - if (spiderfyOnMaxZoom || zoomToBoundsOnClick) { - this.on('clusterclick', this._zoomOrSpiderfy, this); - } - - //Show convex hull (boundary) polygon on mouse over - if (showCoverageOnHover) { - this.on('clustermouseover', this._showCoverage, this); - this.on('clustermouseout', this._hideCoverage, this); - map.on('zoomend', this._hideCoverage, this); - } - }, - - _zoomOrSpiderfy: function (e) { - var cluster = e.layer, - bottomCluster = cluster; - - while (bottomCluster._childClusters.length === 1) { - bottomCluster = bottomCluster._childClusters[0]; - } - - if (bottomCluster._zoom === this._maxZoom && - bottomCluster._childCount === cluster._childCount && - this.options.spiderfyOnMaxZoom) { - - // All child markers are contained in a single cluster from this._maxZoom to this cluster. - cluster.spiderfy(); - } else if (this.options.zoomToBoundsOnClick) { - cluster.zoomToBounds(); - } - - // Focus the map again for keyboard users. - if (e.originalEvent && e.originalEvent.keyCode === 13) { - this._map._container.focus(); - } - }, - - _showCoverage: function (e) { - var map = this._map; - if (this._inZoomAnimation) { - return; - } - if (this._shownPolygon) { - map.removeLayer(this._shownPolygon); - } - if (e.layer.getChildCount() > 2 && e.layer !== this._spiderfied) { - this._shownPolygon = new L.Polygon(e.layer.getConvexHull(), this.options.polygonOptions); - map.addLayer(this._shownPolygon); - } - }, - - _hideCoverage: function () { - if (this._shownPolygon) { - this._map.removeLayer(this._shownPolygon); - this._shownPolygon = null; - } - }, - - _unbindEvents: function () { - var spiderfyOnMaxZoom = this.options.spiderfyOnMaxZoom, - showCoverageOnHover = this.options.showCoverageOnHover, - zoomToBoundsOnClick = this.options.zoomToBoundsOnClick, - map = this._map; - - if (spiderfyOnMaxZoom || zoomToBoundsOnClick) { - this.off('clusterclick', this._zoomOrSpiderfy, this); - } - if (showCoverageOnHover) { - this.off('clustermouseover', this._showCoverage, this); - this.off('clustermouseout', this._hideCoverage, this); - map.off('zoomend', this._hideCoverage, this); - } - }, - - _zoomEnd: function () { - if (!this._map) { //May have been removed from the map by a zoomEnd handler - return; - } - this._mergeSplitClusters(); - - this._zoom = Math.round(this._map._zoom); - this._currentShownBounds = this._getExpandedVisibleBounds(); - }, - - _moveEnd: function () { - if (this._inZoomAnimation) { - return; - } - - var newBounds = this._getExpandedVisibleBounds(); - - this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, this._zoom, newBounds); - this._topClusterLevel._recursivelyAddChildrenToMap(null, Math.round(this._map._zoom), newBounds); - - this._currentShownBounds = newBounds; - return; - }, - - _generateInitialClusters: function () { - var maxZoom = this._map.getMaxZoom(), - radius = this.options.maxClusterRadius, - radiusFn = radius; - - //If we just set maxClusterRadius to a single number, we need to create - //a simple function to return that number. Otherwise, we just have to - //use the function we've passed in. - if (typeof radius !== "function") { - radiusFn = function () { return radius; }; - } - - if (this.options.disableClusteringAtZoom) { - maxZoom = this.options.disableClusteringAtZoom - 1; - } - this._maxZoom = maxZoom; - this._gridClusters = {}; - this._gridUnclustered = {}; - - //Set up DistanceGrids for each zoom - for (var zoom = maxZoom; zoom >= 0; zoom--) { - this._gridClusters[zoom] = new L.DistanceGrid(radiusFn(zoom)); - this._gridUnclustered[zoom] = new L.DistanceGrid(radiusFn(zoom)); - } - - // Instantiate the appropriate L.MarkerCluster class (animated or not). - this._topClusterLevel = new this._markerCluster(this, -1); - }, - - //Zoom: Zoom to start adding at (Pass this._maxZoom to start at the bottom) - _addLayer: function (layer, zoom) { - var gridClusters = this._gridClusters, - gridUnclustered = this._gridUnclustered, - markerPoint, z; - - if (this.options.singleMarkerMode) { - this._overrideMarkerIcon(layer); - } - - layer.on('move', this._childMarkerMoved, this); - - //Find the lowest zoom level to slot this one in - for (; zoom >= 0; zoom--) { - markerPoint = this._map.project(layer.getLatLng(), zoom); // calculate pixel position - - //Try find a cluster close by - var closest = gridClusters[zoom].getNearObject(markerPoint); - if (closest) { - closest._addChild(layer); - layer.__parent = closest; - return; - } - - //Try find a marker close by to form a new cluster with - closest = gridUnclustered[zoom].getNearObject(markerPoint); - if (closest) { - var parent = closest.__parent; - if (parent) { - this._removeLayer(closest, false); - } - - //Create new cluster with these 2 in it - - var newCluster = new this._markerCluster(this, zoom, closest, layer); - gridClusters[zoom].addObject(newCluster, this._map.project(newCluster._cLatLng, zoom)); - closest.__parent = newCluster; - layer.__parent = newCluster; - - //First create any new intermediate parent clusters that don't exist - var lastParent = newCluster; - for (z = zoom - 1; z > parent._zoom; z--) { - lastParent = new this._markerCluster(this, z, lastParent); - gridClusters[z].addObject(lastParent, this._map.project(closest.getLatLng(), z)); - } - parent._addChild(lastParent); - - //Remove closest from this zoom level and any above that it is in, replace with newCluster - this._removeFromGridUnclustered(closest, zoom); - - return; - } - - //Didn't manage to cluster in at this zoom, record us as a marker here and continue upwards - gridUnclustered[zoom].addObject(layer, markerPoint); - } - - //Didn't get in anything, add us to the top - this._topClusterLevel._addChild(layer); - layer.__parent = this._topClusterLevel; - return; - }, - - /** - * Refreshes the icon of all "dirty" visible clusters. - * Non-visible "dirty" clusters will be updated when they are added to the map. - * @private - */ - _refreshClustersIcons: function () { - this._featureGroup.eachLayer(function (c) { - if (c instanceof L.MarkerCluster && c._iconNeedsUpdate) { - c._updateIcon(); - } - }); - }, - - //Enqueue code to fire after the marker expand/contract has happened - _enqueue: function (fn) { - this._queue.push(fn); - if (!this._queueTimeout) { - this._queueTimeout = setTimeout(L.bind(this._processQueue, this), 300); - } - }, - _processQueue: function () { - for (var i = 0; i < this._queue.length; i++) { - this._queue[i].call(this); - } - this._queue.length = 0; - clearTimeout(this._queueTimeout); - this._queueTimeout = null; - }, - - //Merge and split any existing clusters that are too big or small - _mergeSplitClusters: function () { - var mapZoom = Math.round(this._map._zoom); - - //In case we are starting to split before the animation finished - this._processQueue(); - - if (this._zoom < mapZoom && this._currentShownBounds.intersects(this._getExpandedVisibleBounds())) { //Zoom in, split - this._animationStart(); - //Remove clusters now off screen - this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, this._zoom, this._getExpandedVisibleBounds()); - - this._animationZoomIn(this._zoom, mapZoom); - - } else if (this._zoom > mapZoom) { //Zoom out, merge - this._animationStart(); - - this._animationZoomOut(this._zoom, mapZoom); - } else { - this._moveEnd(); - } - }, - - //Gets the maps visible bounds expanded in each direction by the size of the screen (so the user cannot see an area we do not cover in one pan) - _getExpandedVisibleBounds: function () { - if (!this.options.removeOutsideVisibleBounds) { - return this._mapBoundsInfinite; - } else if (L.Browser.mobile) { - return this._checkBoundsMaxLat(this._map.getBounds()); - } - - return this._checkBoundsMaxLat(this._map.getBounds().pad(1)); // Padding expands the bounds by its own dimensions but scaled with the given factor. - }, - - /** - * Expands the latitude to Infinity (or -Infinity) if the input bounds reach the map projection maximum defined latitude - * (in the case of Web/Spherical Mercator, it is 85.0511287798 / see https://en.wikipedia.org/wiki/Web_Mercator#Formulas). - * Otherwise, the removeOutsideVisibleBounds option will remove markers beyond that limit, whereas the same markers without - * this option (or outside MCG) will have their position floored (ceiled) by the projection and rendered at that limit, - * making the user think that MCG "eats" them and never displays them again. - * @param bounds L.LatLngBounds - * @returns {L.LatLngBounds} - * @private - */ - _checkBoundsMaxLat: function (bounds) { - var maxLat = this._maxLat; - - if (maxLat !== undefined) { - if (bounds.getNorth() >= maxLat) { - bounds._northEast.lat = Infinity; - } - if (bounds.getSouth() <= -maxLat) { - bounds._southWest.lat = -Infinity; - } - } - - return bounds; - }, - - //Shared animation code - _animationAddLayerNonAnimated: function (layer, newCluster) { - if (newCluster === layer) { - this._featureGroup.addLayer(layer); - } else if (newCluster._childCount === 2) { - newCluster._addToMap(); - - var markers = newCluster.getAllChildMarkers(); - this._featureGroup.removeLayer(markers[0]); - this._featureGroup.removeLayer(markers[1]); - } else { - newCluster._updateIcon(); - } - }, - - /** - * Extracts individual (i.e. non-group) layers from a Layer Group. - * @param group to extract layers from. - * @param output {Array} in which to store the extracted layers. - * @returns {*|Array} - * @private - */ - _extractNonGroupLayers: function (group, output) { - var layers = group.getLayers(), - i = 0, - layer; - - output = output || []; - - for (; i < layers.length; i++) { - layer = layers[i]; - - if (layer instanceof L.LayerGroup) { - this._extractNonGroupLayers(layer, output); - continue; - } - - output.push(layer); - } - - return output; - }, - - /** - * Implements the singleMarkerMode option. - * @param layer Marker to re-style using the Clusters iconCreateFunction. - * @returns {L.Icon} The newly created icon. - * @private - */ - _overrideMarkerIcon: function (layer) { - var icon = layer.options.icon = this.options.iconCreateFunction({ - getChildCount: function () { - return 1; - }, - getAllChildMarkers: function () { - return [layer]; - } - }); - - return icon; - } - }); - - // Constant bounds used in case option "removeOutsideVisibleBounds" is set to false. - L.MarkerClusterGroup.include({ - _mapBoundsInfinite: new L.LatLngBounds(new L.LatLng(-Infinity, -Infinity), new L.LatLng(Infinity, Infinity)) - }); - - L.MarkerClusterGroup.include({ - _noAnimation: { - //Non Animated versions of everything - _animationStart: function () { - //Do nothing... - }, - _animationZoomIn: function (previousZoomLevel, newZoomLevel) { - this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, previousZoomLevel); - this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); - - //We didn't actually animate, but we use this event to mean "clustering animations have finished" - this.fire('animationend'); - }, - _animationZoomOut: function (previousZoomLevel, newZoomLevel) { - this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, previousZoomLevel); - this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); - - //We didn't actually animate, but we use this event to mean "clustering animations have finished" - this.fire('animationend'); - }, - _animationAddLayer: function (layer, newCluster) { - this._animationAddLayerNonAnimated(layer, newCluster); - } - }, - - _withAnimation: { - //Animated versions here - _animationStart: function () { - this._map._mapPane.className += ' leaflet-cluster-anim'; - this._inZoomAnimation++; - }, - - _animationZoomIn: function (previousZoomLevel, newZoomLevel) { - var bounds = this._getExpandedVisibleBounds(), - fg = this._featureGroup, - i; - - this._ignoreMove = true; - - //Add all children of current clusters to map and remove those clusters from map - this._topClusterLevel._recursively(bounds, previousZoomLevel, 0, function (c) { - var startPos = c._latlng, - markers = c._markers, - m; - - if (!bounds.contains(startPos)) { - startPos = null; - } - - if (c._isSingleParent() && previousZoomLevel + 1 === newZoomLevel) { //Immediately add the new child and remove us - fg.removeLayer(c); - c._recursivelyAddChildrenToMap(null, newZoomLevel, bounds); - } else { - //Fade out old cluster - c.clusterHide(); - c._recursivelyAddChildrenToMap(startPos, newZoomLevel, bounds); - } - - //Remove all markers that aren't visible any more - //TODO: Do we actually need to do this on the higher levels too? - for (i = markers.length - 1; i >= 0; i--) { - m = markers[i]; - if (!bounds.contains(m._latlng)) { - fg.removeLayer(m); - } - } - - }); - - this._forceLayout(); - - //Update opacities - this._topClusterLevel._recursivelyBecomeVisible(bounds, newZoomLevel); - //TODO Maybe? Update markers in _recursivelyBecomeVisible - fg.eachLayer(function (n) { - if (!(n instanceof L.MarkerCluster) && n._icon) { - n.clusterShow(); - } - }); - - //update the positions of the just added clusters/markers - this._topClusterLevel._recursively(bounds, previousZoomLevel, newZoomLevel, function (c) { - c._recursivelyRestoreChildPositions(newZoomLevel); - }); - - this._ignoreMove = false; - - //Remove the old clusters and close the zoom animation - this._enqueue(function () { - //update the positions of the just added clusters/markers - this._topClusterLevel._recursively(bounds, previousZoomLevel, 0, function (c) { - fg.removeLayer(c); - c.clusterShow(); - }); - - this._animationEnd(); - }); - }, - - _animationZoomOut: function (previousZoomLevel, newZoomLevel) { - this._animationZoomOutSingle(this._topClusterLevel, previousZoomLevel - 1, newZoomLevel); - - //Need to add markers for those that weren't on the map before but are now - this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); - //Remove markers that were on the map before but won't be now - this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, previousZoomLevel, this._getExpandedVisibleBounds()); - }, - - _animationAddLayer: function (layer, newCluster) { - var me = this, - fg = this._featureGroup; - - fg.addLayer(layer); - if (newCluster !== layer) { - if (newCluster._childCount > 2) { //Was already a cluster - - newCluster._updateIcon(); - this._forceLayout(); - this._animationStart(); - - layer._setPos(this._map.latLngToLayerPoint(newCluster.getLatLng())); - layer.clusterHide(); - - this._enqueue(function () { - fg.removeLayer(layer); - layer.clusterShow(); - - me._animationEnd(); - }); - - } else { //Just became a cluster - this._forceLayout(); - - me._animationStart(); - me._animationZoomOutSingle(newCluster, this._map.getMaxZoom(), this._map.getZoom()); - } - } - } - }, - - // Private methods for animated versions. - _animationZoomOutSingle: function (cluster, previousZoomLevel, newZoomLevel) { - var bounds = this._getExpandedVisibleBounds(); - - //Animate all of the markers in the clusters to move to their cluster center point - cluster._recursivelyAnimateChildrenInAndAddSelfToMap(bounds, previousZoomLevel + 1, newZoomLevel); - - var me = this; - - //Update the opacity (If we immediately set it they won't animate) - this._forceLayout(); - cluster._recursivelyBecomeVisible(bounds, newZoomLevel); - - //TODO: Maybe use the transition timing stuff to make this more reliable - //When the animations are done, tidy up - this._enqueue(function () { - - //This cluster stopped being a cluster before the timeout fired - if (cluster._childCount === 1) { - var m = cluster._markers[0]; - //If we were in a cluster animation at the time then the opacity and position of our child could be wrong now, so fix it - this._ignoreMove = true; - m.setLatLng(m.getLatLng()); - this._ignoreMove = false; - if (m.clusterShow) { - m.clusterShow(); - } - } else { - cluster._recursively(bounds, newZoomLevel, 0, function (c) { - c._recursivelyRemoveChildrenFromMap(bounds, previousZoomLevel + 1); - }); - } - me._animationEnd(); - }); - }, - - _animationEnd: function () { - if (this._map) { - this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', ''); - } - this._inZoomAnimation--; - this.fire('animationend'); - }, - - //Force a browser layout of stuff in the map - // Should apply the current opacity and location to all elements so we can update them again for an animation - _forceLayout: function () { - //In my testing this works, infact offsetWidth of any element seems to work. - //Could loop all this._layers and do this for each _icon if it stops working - - L.Util.falseFn(document.body.offsetWidth); - } - }); - - L.markerClusterGroup = function (options) { - return new L.MarkerClusterGroup(options); - }; - - - L.MarkerCluster = L.Marker.extend({ - initialize: function (group, zoom, a, b) { - - L.Marker.prototype.initialize.call(this, a ? (a._cLatLng || a.getLatLng()) : new L.LatLng(0, 0), { icon: this }); - - - this._group = group; - this._zoom = zoom; - - this._markers = []; - this._childClusters = []; - this._childCount = 0; - this._iconNeedsUpdate = true; - this._boundsNeedUpdate = true; - - this._bounds = new L.LatLngBounds(); - - if (a) { - this._addChild(a); - } - if (b) { - this._addChild(b); - } - }, - - //Recursively retrieve all child markers of this cluster - getAllChildMarkers: function (storageArray) { - storageArray = storageArray || []; - - for (var i = this._childClusters.length - 1; i >= 0; i--) { - this._childClusters[i].getAllChildMarkers(storageArray); - } - - for (var j = this._markers.length - 1; j >= 0; j--) { - storageArray.push(this._markers[j]); - } - - return storageArray; - }, - - //Returns the count of how many child markers we have - getChildCount: function () { - return this._childCount; - }, - - //Zoom to the minimum of showing all of the child markers, or the extents of this cluster - zoomToBounds: function () { - var childClusters = this._childClusters.slice(), - map = this._group._map, - boundsZoom = map.getBoundsZoom(this._bounds), - zoom = this._zoom + 1, - mapZoom = map.getZoom(), - i; - - //calculate how far we need to zoom down to see all of the markers - while (childClusters.length > 0 && boundsZoom > zoom) { - zoom++; - var newClusters = []; - for (i = 0; i < childClusters.length; i++) { - newClusters = newClusters.concat(childClusters[i]._childClusters); - } - childClusters = newClusters; - } - - if (boundsZoom > zoom) { - this._group._map.setView(this._latlng, zoom); - } else if (boundsZoom <= mapZoom) { //If fitBounds wouldn't zoom us down, zoom us down instead - this._group._map.setView(this._latlng, mapZoom + 1); - } else { - this._group._map.fitBounds(this._bounds); - } - }, - - getBounds: function () { - var bounds = new L.LatLngBounds(); - bounds.extend(this._bounds); - return bounds; - }, - - _updateIcon: function () { - this._iconNeedsUpdate = true; - if (this._icon) { - this.setIcon(this); - } - }, - - //Cludge for Icon, we pretend to be an icon for performance - createIcon: function () { - if (this._iconNeedsUpdate) { - this._iconObj = this._group.options.iconCreateFunction(this); - this._iconNeedsUpdate = false; - } - return this._iconObj.createIcon(); - }, - createShadow: function () { - return this._iconObj.createShadow(); - }, - - - _addChild: function (new1, isNotificationFromChild) { - - this._iconNeedsUpdate = true; - - this._boundsNeedUpdate = true; - this._setClusterCenter(new1); - - if (new1 instanceof L.MarkerCluster) { - if (!isNotificationFromChild) { - this._childClusters.push(new1); - new1.__parent = this; - } - this._childCount += new1._childCount; - } else { - if (!isNotificationFromChild) { - this._markers.push(new1); - } - this._childCount++; - } - - if (this.__parent) { - this.__parent._addChild(new1, true); - } - }, - - /** - * Makes sure the cluster center is set. If not, uses the child center if it is a cluster, or the marker position. - * @param child L.MarkerCluster|L.Marker that will be used as cluster center if not defined yet. - * @private - */ - _setClusterCenter: function (child) { - if (!this._cLatLng) { - // when clustering, take position of the first point as the cluster center - this._cLatLng = child._cLatLng || child._latlng; - } - }, - - /** - * Assigns impossible bounding values so that the next extend entirely determines the new bounds. - * This method avoids having to trash the previous L.LatLngBounds object and to create a new one, which is much slower for this class. - * As long as the bounds are not extended, most other methods would probably fail, as they would with bounds initialized but not extended. - * @private - */ - _resetBounds: function () { - var bounds = this._bounds; - - if (bounds._southWest) { - bounds._southWest.lat = Infinity; - bounds._southWest.lng = Infinity; - } - if (bounds._northEast) { - bounds._northEast.lat = -Infinity; - bounds._northEast.lng = -Infinity; - } - }, - - _recalculateBounds: function () { - var markers = this._markers, - childClusters = this._childClusters, - latSum = 0, - lngSum = 0, - totalCount = this._childCount, - i, child, childLatLng, childCount; - - // Case where all markers are removed from the map and we are left with just an empty _topClusterLevel. - if (totalCount === 0) { - return; - } - - // Reset rather than creating a new object, for performance. - this._resetBounds(); - - // Child markers. - for (i = 0; i < markers.length; i++) { - childLatLng = markers[i]._latlng; - - this._bounds.extend(childLatLng); - - latSum += childLatLng.lat; - lngSum += childLatLng.lng; - } - - // Child clusters. - for (i = 0; i < childClusters.length; i++) { - child = childClusters[i]; - - // Re-compute child bounds and weighted position first if necessary. - if (child._boundsNeedUpdate) { - child._recalculateBounds(); - } - - this._bounds.extend(child._bounds); - - childLatLng = child._wLatLng; - childCount = child._childCount; - - latSum += childLatLng.lat * childCount; - lngSum += childLatLng.lng * childCount; - } - - this._latlng = this._wLatLng = new L.LatLng(latSum / totalCount, lngSum / totalCount); - - // Reset dirty flag. - this._boundsNeedUpdate = false; - }, - - //Set our markers position as given and add it to the map - _addToMap: function (startPos) { - if (startPos) { - this._backupLatlng = this._latlng; - this.setLatLng(startPos); - } - this._group._featureGroup.addLayer(this); - }, - - _recursivelyAnimateChildrenIn: function (bounds, center, maxZoom) { - this._recursively(bounds, 0, maxZoom - 1, - function (c) { - var markers = c._markers, - i, m; - for (i = markers.length - 1; i >= 0; i--) { - m = markers[i]; - - //Only do it if the icon is still on the map - if (m._icon) { - m._setPos(center); - m.clusterHide(); - } - } - }, - function (c) { - var childClusters = c._childClusters, - j, cm; - for (j = childClusters.length - 1; j >= 0; j--) { - cm = childClusters[j]; - if (cm._icon) { - cm._setPos(center); - cm.clusterHide(); - } - } - } - ); - }, - - _recursivelyAnimateChildrenInAndAddSelfToMap: function (bounds, previousZoomLevel, newZoomLevel) { - this._recursively(bounds, newZoomLevel, 0, - function (c) { - c._recursivelyAnimateChildrenIn(bounds, c._group._map.latLngToLayerPoint(c.getLatLng()).round(), previousZoomLevel); - - //TODO: depthToAnimateIn affects _isSingleParent, if there is a multizoom we may/may not be. - //As a hack we only do a animation free zoom on a single level zoom, if someone does multiple levels then we always animate - if (c._isSingleParent() && previousZoomLevel - 1 === newZoomLevel) { - c.clusterShow(); - c._recursivelyRemoveChildrenFromMap(bounds, previousZoomLevel); //Immediately remove our children as we are replacing them. TODO previousBounds not bounds - } else { - c.clusterHide(); - } - - c._addToMap(); - } - ); - }, - - _recursivelyBecomeVisible: function (bounds, zoomLevel) { - this._recursively(bounds, 0, zoomLevel, null, function (c) { - c.clusterShow(); - }); - }, - - _recursivelyAddChildrenToMap: function (startPos, zoomLevel, bounds) { - this._recursively(bounds, -1, zoomLevel, - function (c) { - if (zoomLevel === c._zoom) { - return; - } - - //Add our child markers at startPos (so they can be animated out) - for (var i = c._markers.length - 1; i >= 0; i--) { - var nm = c._markers[i]; - - if (!bounds.contains(nm._latlng)) { - continue; - } - - if (startPos) { - nm._backupLatlng = nm.getLatLng(); - - nm.setLatLng(startPos); - if (nm.clusterHide) { - nm.clusterHide(); - } - } - - c._group._featureGroup.addLayer(nm); - } - }, - function (c) { - c._addToMap(startPos); - } - ); - }, - - _recursivelyRestoreChildPositions: function (zoomLevel) { - //Fix positions of child markers - for (var i = this._markers.length - 1; i >= 0; i--) { - var nm = this._markers[i]; - if (nm._backupLatlng) { - nm.setLatLng(nm._backupLatlng); - delete nm._backupLatlng; - } - } - - if (zoomLevel - 1 === this._zoom) { - //Reposition child clusters - for (var j = this._childClusters.length - 1; j >= 0; j--) { - this._childClusters[j]._restorePosition(); - } - } else { - for (var k = this._childClusters.length - 1; k >= 0; k--) { - this._childClusters[k]._recursivelyRestoreChildPositions(zoomLevel); - } - } - }, - - _restorePosition: function () { - if (this._backupLatlng) { - this.setLatLng(this._backupLatlng); - delete this._backupLatlng; - } - }, - - //exceptBounds: If set, don't remove any markers/clusters in it - _recursivelyRemoveChildrenFromMap: function (previousBounds, zoomLevel, exceptBounds) { - var m, i; - this._recursively(previousBounds, -1, zoomLevel - 1, - function (c) { - //Remove markers at every level - for (i = c._markers.length - 1; i >= 0; i--) { - m = c._markers[i]; - if (!exceptBounds || !exceptBounds.contains(m._latlng)) { - c._group._featureGroup.removeLayer(m); - if (m.clusterShow) { - m.clusterShow(); - } - } - } - }, - function (c) { - //Remove child clusters at just the bottom level - for (i = c._childClusters.length - 1; i >= 0; i--) { - m = c._childClusters[i]; - if (!exceptBounds || !exceptBounds.contains(m._latlng)) { - c._group._featureGroup.removeLayer(m); - if (m.clusterShow) { - m.clusterShow(); - } - } - } - } - ); - }, - - //Run the given functions recursively to this and child clusters - // boundsToApplyTo: a L.LatLngBounds representing the bounds of what clusters to recurse in to - // zoomLevelToStart: zoom level to start running functions (inclusive) - // zoomLevelToStop: zoom level to stop running functions (inclusive) - // runAtEveryLevel: function that takes an L.MarkerCluster as an argument that should be applied on every level - // runAtBottomLevel: function that takes an L.MarkerCluster as an argument that should be applied at only the bottom level - _recursively: function (boundsToApplyTo, zoomLevelToStart, zoomLevelToStop, runAtEveryLevel, runAtBottomLevel) { - var childClusters = this._childClusters, - zoom = this._zoom, - i, c; - - if (zoomLevelToStart > zoom) { //Still going down to required depth, just recurse to child clusters - for (i = childClusters.length - 1; i >= 0; i--) { - c = childClusters[i]; - if (boundsToApplyTo.intersects(c._bounds)) { - c._recursively(boundsToApplyTo, zoomLevelToStart, zoomLevelToStop, runAtEveryLevel, runAtBottomLevel); - } - } - } else { //In required depth - - if (runAtEveryLevel) { - runAtEveryLevel(this); - } - if (runAtBottomLevel && this._zoom === zoomLevelToStop) { - runAtBottomLevel(this); - } - - //TODO: This loop is almost the same as above - if (zoomLevelToStop > zoom) { - for (i = childClusters.length - 1; i >= 0; i--) { - c = childClusters[i]; - if (boundsToApplyTo.intersects(c._bounds)) { - c._recursively(boundsToApplyTo, zoomLevelToStart, zoomLevelToStop, runAtEveryLevel, runAtBottomLevel); - } - } - } - } - }, - - //Returns true if we are the parent of only one cluster and that cluster is the same as us - _isSingleParent: function () { - //Don't need to check this._markers as the rest won't work if there are any - return this._childClusters.length > 0 && this._childClusters[0]._childCount === this._childCount; - } - }); - - - - /* - * Extends L.Marker to include two extra methods: clusterHide and clusterShow. - * - * They work as setOpacity(0) and setOpacity(1) respectively, but - * they will remember the marker's opacity when hiding and showing it again. - * - */ - - - L.Marker.include({ - - clusterHide: function () { - this.options.opacityWhenUnclustered = this.options.opacity || 1; - return this.setOpacity(0); - }, - - clusterShow: function () { - var ret = this.setOpacity(this.options.opacity || this.options.opacityWhenUnclustered); - delete this.options.opacityWhenUnclustered; - return ret; - } - - }); - - - - - - L.DistanceGrid = function (cellSize) { - this._cellSize = cellSize; - this._sqCellSize = cellSize * cellSize; - this._grid = {}; - this._objectPoint = { }; - }; - - L.DistanceGrid.prototype = { - - addObject: function (obj, point) { - var x = this._getCoord(point.x), - y = this._getCoord(point.y), - grid = this._grid, - row = grid[y] = grid[y] || {}, - cell = row[x] = row[x] || [], - stamp = L.Util.stamp(obj); - - this._objectPoint[stamp] = point; - - cell.push(obj); - }, - - updateObject: function (obj, point) { - this.removeObject(obj); - this.addObject(obj, point); - }, - - //Returns true if the object was found - removeObject: function (obj, point) { - var x = this._getCoord(point.x), - y = this._getCoord(point.y), - grid = this._grid, - row = grid[y] = grid[y] || {}, - cell = row[x] = row[x] || [], - i, len; - - delete this._objectPoint[L.Util.stamp(obj)]; - - for (i = 0, len = cell.length; i < len; i++) { - if (cell[i] === obj) { - - cell.splice(i, 1); - - if (len === 1) { - delete row[x]; - } - - return true; - } - } - - }, - - eachObject: function (fn, context) { - var i, j, k, len, row, cell, removed, - grid = this._grid; - - for (i in grid) { - row = grid[i]; - - for (j in row) { - cell = row[j]; - - for (k = 0, len = cell.length; k < len; k++) { - removed = fn.call(context, cell[k]); - if (removed) { - k--; - len--; - } - } - } - } - }, - - getNearObject: function (point) { - var x = this._getCoord(point.x), - y = this._getCoord(point.y), - i, j, k, row, cell, len, obj, dist, - objectPoint = this._objectPoint, - closestDistSq = this._sqCellSize, - closest = null; - - for (i = y - 1; i <= y + 1; i++) { - row = this._grid[i]; - if (row) { - - for (j = x - 1; j <= x + 1; j++) { - cell = row[j]; - if (cell) { - - for (k = 0, len = cell.length; k < len; k++) { - obj = cell[k]; - dist = this._sqDist(objectPoint[L.Util.stamp(obj)], point); - if (dist < closestDistSq) { - closestDistSq = dist; - closest = obj; - } - } - } - } - } - } - return closest; - }, - - _getCoord: function (x) { - return Math.floor(x / this._cellSize); - }, - - _sqDist: function (p, p2) { - var dx = p2.x - p.x, - dy = p2.y - p.y; - return dx * dx + dy * dy; - } - }; - - - /* Copyright (c) 2012 the authors listed at the following URL, and/or - the authors of referenced articles or incorporated external code: - http://en.literateprograms.org/Quickhull_(Javascript)?action=history&offset=20120410175256 - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Retrieved from: http://en.literateprograms.org/Quickhull_(Javascript)?oldid=18434 - */ - - (function () { - L.QuickHull = { - - /* - * @param {Object} cpt a point to be measured from the baseline - * @param {Array} bl the baseline, as represented by a two-element - * array of latlng objects. - * @returns {Number} an approximate distance measure - */ - getDistant: function (cpt, bl) { - var vY = bl[1].lat - bl[0].lat, - vX = bl[0].lng - bl[1].lng; - return (vX * (cpt.lat - bl[0].lat) + vY * (cpt.lng - bl[0].lng)); - }, - - /* - * @param {Array} baseLine a two-element array of latlng objects - * representing the baseline to project from - * @param {Array} latLngs an array of latlng objects - * @returns {Object} the maximum point and all new points to stay - * in consideration for the hull. - */ - findMostDistantPointFromBaseLine: function (baseLine, latLngs) { - var maxD = 0, - maxPt = null, - newPoints = [], - i, pt, d; - - for (i = latLngs.length - 1; i >= 0; i--) { - pt = latLngs[i]; - d = this.getDistant(pt, baseLine); - - if (d > 0) { - newPoints.push(pt); - } else { - continue; - } - - if (d > maxD) { - maxD = d; - maxPt = pt; - } - } - - return { maxPoint: maxPt, newPoints: newPoints }; - }, - - - /* - * Given a baseline, compute the convex hull of latLngs as an array - * of latLngs. - * - * @param {Array} latLngs - * @returns {Array} - */ - buildConvexHull: function (baseLine, latLngs) { - var convexHullBaseLines = [], - t = this.findMostDistantPointFromBaseLine(baseLine, latLngs); - - if (t.maxPoint) { // if there is still a point "outside" the base line - convexHullBaseLines = - convexHullBaseLines.concat( - this.buildConvexHull([baseLine[0], t.maxPoint], t.newPoints) - ); - convexHullBaseLines = - convexHullBaseLines.concat( - this.buildConvexHull([t.maxPoint, baseLine[1]], t.newPoints) - ); - return convexHullBaseLines; - } else { // if there is no more point "outside" the base line, the current base line is part of the convex hull - return [baseLine[0]]; - } - }, - - /* - * Given an array of latlngs, compute a convex hull as an array - * of latlngs - * - * @param {Array} latLngs - * @returns {Array} - */ - getConvexHull: function (latLngs) { - // find first baseline - var maxLat = false, minLat = false, - maxLng = false, minLng = false, - maxLatPt = null, minLatPt = null, - maxLngPt = null, minLngPt = null, - maxPt = null, minPt = null, - i; - - for (i = latLngs.length - 1; i >= 0; i--) { - var pt = latLngs[i]; - if (maxLat === false || pt.lat > maxLat) { - maxLatPt = pt; - maxLat = pt.lat; - } - if (minLat === false || pt.lat < minLat) { - minLatPt = pt; - minLat = pt.lat; - } - if (maxLng === false || pt.lng > maxLng) { - maxLngPt = pt; - maxLng = pt.lng; - } - if (minLng === false || pt.lng < minLng) { - minLngPt = pt; - minLng = pt.lng; - } - } - - if (minLat !== maxLat) { - minPt = minLatPt; - maxPt = maxLatPt; - } else { - minPt = minLngPt; - maxPt = maxLngPt; - } - - var ch = [].concat(this.buildConvexHull([minPt, maxPt], latLngs), - this.buildConvexHull([maxPt, minPt], latLngs)); - return ch; - } - }; - }()); - - L.MarkerCluster.include({ - getConvexHull: function () { - var childMarkers = this.getAllChildMarkers(), - points = [], - p, i; - - for (i = childMarkers.length - 1; i >= 0; i--) { - p = childMarkers[i].getLatLng(); - points.push(p); - } - - return L.QuickHull.getConvexHull(points); - } - }); - - - //This code is 100% based on https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet - //Huge thanks to jawj for implementing it first to make my job easy :-) - - L.MarkerCluster.include({ - - _2PI: Math.PI * 2, - _circleFootSeparation: 25, //related to circumference of circle - _circleStartAngle: Math.PI / 6, - - _spiralFootSeparation: 28, //related to size of spiral (experiment!) - _spiralLengthStart: 11, - _spiralLengthFactor: 5, - - _circleSpiralSwitchover: 9, //show spiral instead of circle from this marker count upwards. - // 0 -> always spiral; Infinity -> always circle - - spiderfy: function () { - if (this._group._spiderfied === this || this._group._inZoomAnimation) { - return; - } - - var childMarkers = this.getAllChildMarkers(), - group = this._group, - map = group._map, - center = map.latLngToLayerPoint(this._latlng), - positions; - - this._group._unspiderfy(); - this._group._spiderfied = this; - - //TODO Maybe: childMarkers order by distance to center - - if (childMarkers.length >= this._circleSpiralSwitchover) { - positions = this._generatePointsSpiral(childMarkers.length, center); - } else { - center.y += 10; // Otherwise circles look wrong => hack for standard blue icon, renders differently for other icons. - positions = this._generatePointsCircle(childMarkers.length, center); - } - - this._animationSpiderfy(childMarkers, positions); - }, - - unspiderfy: function (zoomDetails) { - /// Argument from zoomanim if being called in a zoom animation or null otherwise - if (this._group._inZoomAnimation) { - return; - } - this._animationUnspiderfy(zoomDetails); - - this._group._spiderfied = null; - }, - - _generatePointsCircle: function (count, centerPt) { - var circumference = this._group.options.spiderfyDistanceMultiplier * this._circleFootSeparation * (2 + count), - legLength = circumference / this._2PI, //radius from circumference - angleStep = this._2PI / count, - res = [], - i, angle; - - res.length = count; - - for (i = count - 1; i >= 0; i--) { - angle = this._circleStartAngle + i * angleStep; - res[i] = new L.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round(); - } - - return res; - }, - - _generatePointsSpiral: function (count, centerPt) { - var spiderfyDistanceMultiplier = this._group.options.spiderfyDistanceMultiplier, - legLength = spiderfyDistanceMultiplier * this._spiralLengthStart, - separation = spiderfyDistanceMultiplier * this._spiralFootSeparation, - lengthFactor = spiderfyDistanceMultiplier * this._spiralLengthFactor * this._2PI, - angle = 0, - res = [], - i; - - res.length = count; - - // Higher index, closer position to cluster center. - for (i = count - 1; i >= 0; i--) { - angle += separation / legLength + i * 0.0005; - res[i] = new L.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round(); - legLength += lengthFactor / angle; - } - return res; - }, - - _noanimationUnspiderfy: function () { - var group = this._group, - map = group._map, - fg = group._featureGroup, - childMarkers = this.getAllChildMarkers(), - m, i; - - group._ignoreMove = true; - - this.setOpacity(1); - for (i = childMarkers.length - 1; i >= 0; i--) { - m = childMarkers[i]; - - fg.removeLayer(m); - - if (m._preSpiderfyLatlng) { - m.setLatLng(m._preSpiderfyLatlng); - delete m._preSpiderfyLatlng; - } - if (m.setZIndexOffset) { - m.setZIndexOffset(0); - } - - if (m._spiderLeg) { - map.removeLayer(m._spiderLeg); - delete m._spiderLeg; - } - } - - group.fire('unspiderfied', { - cluster: this, - markers: childMarkers - }); - group._ignoreMove = false; - group._spiderfied = null; - } - }); - - //Non Animated versions of everything - L.MarkerClusterNonAnimated = L.MarkerCluster.extend({ - _animationSpiderfy: function (childMarkers, positions) { - var group = this._group, - map = group._map, - fg = group._featureGroup, - legOptions = this._group.options.spiderLegPolylineOptions, - i, m, leg, newPos; - - group._ignoreMove = true; - - // Traverse in ascending order to make sure that inner circleMarkers are on top of further legs. Normal markers are re-ordered by newPosition. - // The reverse order trick no longer improves performance on modern browsers. - for (i = 0; i < childMarkers.length; i++) { - newPos = map.layerPointToLatLng(positions[i]); - m = childMarkers[i]; - - // Add the leg before the marker, so that in case the latter is a circleMarker, the leg is behind it. - leg = new L.Polyline([this._latlng, newPos], legOptions); - map.addLayer(leg); - m._spiderLeg = leg; - - // Now add the marker. - m._preSpiderfyLatlng = m._latlng; - m.setLatLng(newPos); - if (m.setZIndexOffset) { - m.setZIndexOffset(1000000); //Make these appear on top of EVERYTHING - } - - fg.addLayer(m); - } - this.setOpacity(0.3); - - group._ignoreMove = false; - group.fire('spiderfied', { - cluster: this, - markers: childMarkers - }); - }, - - _animationUnspiderfy: function () { - this._noanimationUnspiderfy(); - } - }); - - //Animated versions here - L.MarkerCluster.include({ - - _animationSpiderfy: function (childMarkers, positions) { - var me = this, - group = this._group, - map = group._map, - fg = group._featureGroup, - thisLayerLatLng = this._latlng, - thisLayerPos = map.latLngToLayerPoint(thisLayerLatLng), - svg = L.Path.SVG, - legOptions = L.extend({}, this._group.options.spiderLegPolylineOptions), // Copy the options so that we can modify them for animation. - finalLegOpacity = legOptions.opacity, - i, m, leg, legPath, legLength, newPos; - - if (finalLegOpacity === undefined) { - finalLegOpacity = L.MarkerClusterGroup.prototype.options.spiderLegPolylineOptions.opacity; - } - - if (svg) { - // If the initial opacity of the spider leg is not 0 then it appears before the animation starts. - legOptions.opacity = 0; - - // Add the class for CSS transitions. - legOptions.className = (legOptions.className || '') + ' leaflet-cluster-spider-leg'; - } else { - // Make sure we have a defined opacity. - legOptions.opacity = finalLegOpacity; - } - - group._ignoreMove = true; - - // Add markers and spider legs to map, hidden at our center point. - // Traverse in ascending order to make sure that inner circleMarkers are on top of further legs. Normal markers are re-ordered by newPosition. - // The reverse order trick no longer improves performance on modern browsers. - for (i = 0; i < childMarkers.length; i++) { - m = childMarkers[i]; - - newPos = map.layerPointToLatLng(positions[i]); - - // Add the leg before the marker, so that in case the latter is a circleMarker, the leg is behind it. - leg = new L.Polyline([thisLayerLatLng, newPos], legOptions); - map.addLayer(leg); - m._spiderLeg = leg; - - // Explanations: https://jakearchibald.com/2013/animated-line-drawing-svg/ - // In our case the transition property is declared in the CSS file. - if (svg) { - legPath = leg._path; - legLength = legPath.getTotalLength() + 0.1; // Need a small extra length to avoid remaining dot in Firefox. - legPath.style.strokeDasharray = legLength; // Just 1 length is enough, it will be duplicated. - legPath.style.strokeDashoffset = legLength; - } - - // If it is a marker, add it now and we'll animate it out - if (m.setZIndexOffset) { - m.setZIndexOffset(1000000); // Make normal markers appear on top of EVERYTHING - } - if (m.clusterHide) { - m.clusterHide(); - } - - // Vectors just get immediately added - fg.addLayer(m); - - if (m._setPos) { - m._setPos(thisLayerPos); - } - } - - group._forceLayout(); - group._animationStart(); - - // Reveal markers and spider legs. - for (i = childMarkers.length - 1; i >= 0; i--) { - newPos = map.layerPointToLatLng(positions[i]); - m = childMarkers[i]; - - //Move marker to new position - m._preSpiderfyLatlng = m._latlng; - m.setLatLng(newPos); - - if (m.clusterShow) { - m.clusterShow(); - } - - // Animate leg (animation is actually delegated to CSS transition). - if (svg) { - leg = m._spiderLeg; - legPath = leg._path; - legPath.style.strokeDashoffset = 0; - //legPath.style.strokeOpacity = finalLegOpacity; - leg.setStyle({opacity: finalLegOpacity}); - } - } - this.setOpacity(0.3); - - group._ignoreMove = false; - - setTimeout(function () { - group._animationEnd(); - group.fire('spiderfied', { - cluster: me, - markers: childMarkers - }); - }, 200); - }, - - _animationUnspiderfy: function (zoomDetails) { - var me = this, - group = this._group, - map = group._map, - fg = group._featureGroup, - thisLayerPos = zoomDetails ? map._latLngToNewLayerPoint(this._latlng, zoomDetails.zoom, zoomDetails.center) : map.latLngToLayerPoint(this._latlng), - childMarkers = this.getAllChildMarkers(), - svg = L.Path.SVG, - m, i, leg, legPath, legLength, nonAnimatable; - - group._ignoreMove = true; - group._animationStart(); - - //Make us visible and bring the child markers back in - this.setOpacity(1); - for (i = childMarkers.length - 1; i >= 0; i--) { - m = childMarkers[i]; - - //Marker was added to us after we were spiderfied - if (!m._preSpiderfyLatlng) { - continue; - } - - //Fix up the location to the real one - m.setLatLng(m._preSpiderfyLatlng); - delete m._preSpiderfyLatlng; - - //Hack override the location to be our center - nonAnimatable = true; - if (m._setPos) { - m._setPos(thisLayerPos); - nonAnimatable = false; - } - if (m.clusterHide) { - m.clusterHide(); - nonAnimatable = false; - } - if (nonAnimatable) { - fg.removeLayer(m); - } - - // Animate the spider leg back in (animation is actually delegated to CSS transition). - if (svg) { - leg = m._spiderLeg; - legPath = leg._path; - legLength = legPath.getTotalLength() + 0.1; - legPath.style.strokeDashoffset = legLength; - leg.setStyle({opacity: 0}); - } - } - - group._ignoreMove = false; - - setTimeout(function () { - //If we have only <= one child left then that marker will be shown on the map so don't remove it! - var stillThereChildCount = 0; - for (i = childMarkers.length - 1; i >= 0; i--) { - m = childMarkers[i]; - if (m._spiderLeg) { - stillThereChildCount++; - } - } - - - for (i = childMarkers.length - 1; i >= 0; i--) { - m = childMarkers[i]; - - if (!m._spiderLeg) { //Has already been unspiderfied - continue; - } - - if (m.clusterShow) { - m.clusterShow(); - } - if (m.setZIndexOffset) { - m.setZIndexOffset(0); - } - - if (stillThereChildCount > 1) { - fg.removeLayer(m); - } - - map.removeLayer(m._spiderLeg); - delete m._spiderLeg; - } - group._animationEnd(); - group.fire('unspiderfied', { - cluster: me, - markers: childMarkers - }); - }, 200); - } - }); - - - L.MarkerClusterGroup.include({ - //The MarkerCluster currently spiderfied (if any) - _spiderfied: null, - - unspiderfy: function () { - this._unspiderfy.apply(this, arguments); - }, - - _spiderfierOnAdd: function () { - this._map.on('click', this._unspiderfyWrapper, this); - - if (this._map.options.zoomAnimation) { - this._map.on('zoomstart', this._unspiderfyZoomStart, this); - } - //Browsers without zoomAnimation or a big zoom don't fire zoomstart - this._map.on('zoomend', this._noanimationUnspiderfy, this); - - if (!L.Browser.touch) { - this._map.getRenderer(this); - //Needs to happen in the pageload, not after, or animations don't work in webkit - // http://stackoverflow.com/questions/8455200/svg-animate-with-dynamically-added-elements - //Disable on touch browsers as the animation messes up on a touch zoom and isn't very noticable - } - }, - - _spiderfierOnRemove: function () { - this._map.off('click', this._unspiderfyWrapper, this); - this._map.off('zoomstart', this._unspiderfyZoomStart, this); - this._map.off('zoomanim', this._unspiderfyZoomAnim, this); - this._map.off('zoomend', this._noanimationUnspiderfy, this); - - //Ensure that markers are back where they should be - // Use no animation to avoid a sticky leaflet-cluster-anim class on mapPane - this._noanimationUnspiderfy(); - }, - - //On zoom start we add a zoomanim handler so that we are guaranteed to be last (after markers are animated) - //This means we can define the animation they do rather than Markers doing an animation to their actual location - _unspiderfyZoomStart: function () { - if (!this._map) { //May have been removed from the map by a zoomEnd handler - return; - } - - this._map.on('zoomanim', this._unspiderfyZoomAnim, this); - }, - - _unspiderfyZoomAnim: function (zoomDetails) { - //Wait until the first zoomanim after the user has finished touch-zooming before running the animation - if (L.DomUtil.hasClass(this._map._mapPane, 'leaflet-touching')) { - return; - } - - this._map.off('zoomanim', this._unspiderfyZoomAnim, this); - this._unspiderfy(zoomDetails); - }, - - _unspiderfyWrapper: function () { - /// _unspiderfy but passes no arguments - this._unspiderfy(); - }, - - _unspiderfy: function (zoomDetails) { - if (this._spiderfied) { - this._spiderfied.unspiderfy(zoomDetails); - } - }, - - _noanimationUnspiderfy: function () { - if (this._spiderfied) { - this._spiderfied._noanimationUnspiderfy(); - } - }, - - //If the given layer is currently being spiderfied then we unspiderfy it so it isn't on the map anymore etc - _unspiderfyLayer: function (layer) { - if (layer._spiderLeg) { - this._featureGroup.removeLayer(layer); - - if (layer.clusterShow) { - layer.clusterShow(); - } - //Position will be fixed up immediately in _animationUnspiderfy - if (layer.setZIndexOffset) { - layer.setZIndexOffset(0); - } - - this._map.removeLayer(layer._spiderLeg); - delete layer._spiderLeg; - } - } - }); - - - /** - * Adds 1 public method to MCG and 1 to L.Marker to facilitate changing - * markers' icon options and refreshing their icon and their parent clusters - * accordingly (case where their iconCreateFunction uses data of childMarkers - * to make up the cluster icon). - */ - - - L.MarkerClusterGroup.include({ - /** - * Updates the icon of all clusters which are parents of the given marker(s). - * In singleMarkerMode, also updates the given marker(s) icon. - * @param layers L.MarkerClusterGroup|L.LayerGroup|Array(L.Marker)|Map(L.Marker)| - * L.MarkerCluster|L.Marker (optional) list of markers (or single marker) whose parent - * clusters need to be updated. If not provided, retrieves all child markers of this. - * @returns {L.MarkerClusterGroup} - */ - refreshClusters: function (layers) { - if (!layers) { - layers = this._topClusterLevel.getAllChildMarkers(); - } else if (layers instanceof L.MarkerClusterGroup) { - layers = layers._topClusterLevel.getAllChildMarkers(); - } else if (layers instanceof L.LayerGroup) { - layers = layers._layers; - } else if (layers instanceof L.MarkerCluster) { - layers = layers.getAllChildMarkers(); - } else if (layers instanceof L.Marker) { - layers = [layers]; - } // else: must be an Array(L.Marker)|Map(L.Marker) - this._flagParentsIconsNeedUpdate(layers); - this._refreshClustersIcons(); - - // In case of singleMarkerMode, also re-draw the markers. - if (this.options.singleMarkerMode) { - this._refreshSingleMarkerModeMarkers(layers); - } - - return this; - }, - - /** - * Simply flags all parent clusters of the given markers as having a "dirty" icon. - * @param layers Array(L.Marker)|Map(L.Marker) list of markers. - * @private - */ - _flagParentsIconsNeedUpdate: function (layers) { - var id, parent; - - // Assumes layers is an Array or an Object whose prototype is non-enumerable. - for (id in layers) { - // Flag parent clusters' icon as "dirty", all the way up. - // Dumb process that flags multiple times upper parents, but still - // much more efficient than trying to be smart and make short lists, - // at least in the case of a hierarchy following a power law: - // http://jsperf.com/flag-nodes-in-power-hierarchy/2 - parent = layers[id].__parent; - while (parent) { - parent._iconNeedsUpdate = true; - parent = parent.__parent; - } - } - }, - - /** - * Re-draws the icon of the supplied markers. - * To be used in singleMarkerMode only. - * @param layers Array(L.Marker)|Map(L.Marker) list of markers. - * @private - */ - _refreshSingleMarkerModeMarkers: function (layers) { - var id, layer; - - for (id in layers) { - layer = layers[id]; - - // Make sure we do not override markers that do not belong to THIS group. - if (this.hasLayer(layer)) { - // Need to re-create the icon first, then re-draw the marker. - layer.setIcon(this._overrideMarkerIcon(layer)); - } - } - } - }); - - L.Marker.include({ - /** - * Updates the given options in the marker's icon and refreshes the marker. - * @param options map object of icon options. - * @param directlyRefreshClusters boolean (optional) true to trigger - * MCG.refreshClustersOf() right away with this single marker. - * @returns {L.Marker} - */ - refreshIconOptions: function (options, directlyRefreshClusters) { - var icon = this.options.icon; - - L.setOptions(icon, options); - - this.setIcon(icon); - - // Shortcut to refresh the associated MCG clusters right away. - // To be used when refreshing a single marker. - // Otherwise, better use MCG.refreshClusters() once at the end with - // the list of modified markers. - if (directlyRefreshClusters && this.__parent) { - this.__parent._group.refreshClusters(this); - } - - return this; - } - }); - - - }(window, document)); - \ No newline at end of file diff --git a/talkmap/leaflet_dist/leaflet.markercluster.js b/talkmap/leaflet_dist/leaflet.markercluster.js deleted file mode 100644 index 452d04ac6ebad..0000000000000 --- a/talkmap/leaflet_dist/leaflet.markercluster.js +++ /dev/null @@ -1,8 +0,0 @@ - - /* - Leaflet.markercluster, Provides Beautiful Animated Marker Clustering functionality for Leaflet, a JS library for interactive maps. - https://github.com/Leaflet/Leaflet.markercluster - (c) 2012-2013, Dave Leaver, smartrak - */ - !function(e,t,i){L.MarkerClusterGroup=L.FeatureGroup.extend({options:{maxClusterRadius:80,iconCreateFunction:null,spiderfyOnMaxZoom:!0,showCoverageOnHover:!0,zoomToBoundsOnClick:!0,singleMarkerMode:!1,disableClusteringAtZoom:null,removeOutsideVisibleBounds:!0,animate:!0,animateAddingMarkers:!1,spiderfyDistanceMultiplier:1,spiderLegPolylineOptions:{weight:1.5,color:"#222",opacity:.5},chunkedLoading:!1,chunkInterval:200,chunkDelay:50,chunkProgress:null,polygonOptions:{}},initialize:function(e){L.Util.setOptions(this,e),this.options.iconCreateFunction||(this.options.iconCreateFunction=this._defaultIconCreateFunction),this._featureGroup=L.featureGroup(),this._featureGroup.addEventParent(this),this._nonPointGroup=L.featureGroup(),this._nonPointGroup.addEventParent(this),this._inZoomAnimation=0,this._needsClustering=[],this._needsRemoving=[],this._currentShownBounds=null,this._queue=[];var t=L.DomUtil.TRANSITION&&this.options.animate;L.extend(this,t?this._withAnimation:this._noAnimation),this._markerCluster=t?L.MarkerCluster:L.MarkerClusterNonAnimated},addLayer:function(e){if(e instanceof L.LayerGroup)return this.addLayers([e]);if(!e.getLatLng)return this._nonPointGroup.addLayer(e),this;if(!this._map)return this._needsClustering.push(e),this;if(this.hasLayer(e))return this;this._unspiderfy&&this._unspiderfy(),this._addLayer(e,this._maxZoom),this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons();var t=e,i=this._map.getZoom();if(e.__parent)for(;t.__parent._zoom>=i;)t=t.__parent;return this._currentShownBounds.contains(t.getLatLng())&&(this.options.animateAddingMarkers?this._animationAddLayer(e,t):this._animationAddLayerNonAnimated(e,t)),this},removeLayer:function(e){return e instanceof L.LayerGroup?this.removeLayers([e]):e.getLatLng?this._map?e.__parent?(this._unspiderfy&&(this._unspiderfy(),this._unspiderfyLayer(e)),this._removeLayer(e,!0),this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons(),e.off("move",this._childMarkerMoved,this),this._featureGroup.hasLayer(e)&&(this._featureGroup.removeLayer(e),e.clusterShow&&e.clusterShow()),this):this:(!this._arraySplice(this._needsClustering,e)&&this.hasLayer(e)&&this._needsRemoving.push(e),this):(this._nonPointGroup.removeLayer(e),this)},addLayers:function(e){if(!L.Util.isArray(e))return this.addLayer(e);var t,i=this._featureGroup,n=this._nonPointGroup,s=this.options.chunkedLoading,r=this.options.chunkInterval,o=this.options.chunkProgress,a=e.length,h=0,u=!0;if(this._map){var l=(new Date).getTime(),_=L.bind(function(){for(var d=(new Date).getTime();a>h;h++){if(s&&0===h%200){var c=(new Date).getTime()-d;if(c>r)break}if(t=e[h],t instanceof L.LayerGroup)u&&(e=e.slice(),u=!1),this._extractNonGroupLayers(t,e),a=e.length;else if(t.getLatLng){if(!this.hasLayer(t)&&(this._addLayer(t,this._maxZoom),t.__parent&&2===t.__parent.getChildCount())){var p=t.__parent.getAllChildMarkers(),f=p[0]===t?p[1]:p[0];i.removeLayer(f)}}else n.addLayer(t)}o&&o(h,a,(new Date).getTime()-l),h===a?(this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons(),this._topClusterLevel._recursivelyAddChildrenToMap(null,this._zoom,this._currentShownBounds)):setTimeout(_,this.options.chunkDelay)},this);_()}else for(var d=this._needsClustering;a>h;h++)t=e[h],t instanceof L.LayerGroup?(u&&(e=e.slice(),u=!1),this._extractNonGroupLayers(t,e),a=e.length):t.getLatLng?this.hasLayer(t)||d.push(t):n.addLayer(t);return this},removeLayers:function(e){var t,i,n=e.length,s=this._featureGroup,r=this._nonPointGroup,o=!0;if(!this._map){for(t=0;n>t;t++)i=e[t],i instanceof L.LayerGroup?(o&&(e=e.slice(),o=!1),this._extractNonGroupLayers(i,e),n=e.length):(this._arraySplice(this._needsClustering,i),r.removeLayer(i),this.hasLayer(i)&&this._needsRemoving.push(i));return this}if(this._unspiderfy){this._unspiderfy();var a=e.slice(),h=n;for(t=0;h>t;t++)i=a[t],i instanceof L.LayerGroup?(this._extractNonGroupLayers(i,a),h=a.length):this._unspiderfyLayer(i)}for(t=0;n>t;t++)i=e[t],i instanceof L.LayerGroup?(o&&(e=e.slice(),o=!1),this._extractNonGroupLayers(i,e),n=e.length):i.__parent?(this._removeLayer(i,!0,!0),s.hasLayer(i)&&(s.removeLayer(i),i.clusterShow&&i.clusterShow())):r.removeLayer(i);return this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons(),this._topClusterLevel._recursivelyAddChildrenToMap(null,this._zoom,this._currentShownBounds),this},clearLayers:function(){return this._map||(this._needsClustering=[],delete this._gridClusters,delete this._gridUnclustered),this._noanimationUnspiderfy&&this._noanimationUnspiderfy(),this._featureGroup.clearLayers(),this._nonPointGroup.clearLayers(),this.eachLayer(function(e){e.off("move",this._childMarkerMoved,this),delete e.__parent}),this._map&&this._generateInitialClusters(),this},getBounds:function(){var e=new L.LatLngBounds;this._topClusterLevel&&e.extend(this._topClusterLevel._bounds);for(var t=this._needsClustering.length-1;t>=0;t--)e.extend(this._needsClustering[t].getLatLng());return e.extend(this._nonPointGroup.getBounds()),e},eachLayer:function(e,t){var i,n=this._needsClustering.slice(),s=this._needsRemoving;for(this._topClusterLevel&&this._topClusterLevel.getAllChildMarkers(n),i=n.length-1;i>=0;i--)-1===s.indexOf(n[i])&&e.call(t,n[i]);this._nonPointGroup.eachLayer(e,t)},getLayers:function(){var e=[];return this.eachLayer(function(t){e.push(t)}),e},getLayer:function(e){var t=null;return e=parseInt(e,10),this.eachLayer(function(i){L.stamp(i)===e&&(t=i)}),t},hasLayer:function(e){if(!e)return!1;var t,i=this._needsClustering;for(t=i.length-1;t>=0;t--)if(i[t]===e)return!0;for(i=this._needsRemoving,t=i.length-1;t>=0;t--)if(i[t]===e)return!1;return!(!e.__parent||e.__parent._group!==this)||this._nonPointGroup.hasLayer(e)},zoomToShowLayer:function(e,t){"function"!=typeof t&&(t=function(){});var i=function(){!e._icon&&!e.__parent._icon||this._inZoomAnimation||(this._map.off("moveend",i,this),this.off("animationend",i,this),e._icon?t():e.__parent._icon&&(this.once("spiderfied",t,this),e.__parent.spiderfy()))};if(e._icon&&this._map.getBounds().contains(e.getLatLng()))t();else if(e.__parent._zoomt;t++)n=this._needsRemoving[t],this._removeLayer(n,!0);this._needsRemoving=[],this._zoom=this._map.getZoom(),this._currentShownBounds=this._getExpandedVisibleBounds(),this._map.on("zoomend",this._zoomEnd,this),this._map.on("moveend",this._moveEnd,this),this._spiderfierOnAdd&&this._spiderfierOnAdd(),this._bindEvents(),i=this._needsClustering,this._needsClustering=[],this.addLayers(i)},onRemove:function(e){e.off("zoomend",this._zoomEnd,this),e.off("moveend",this._moveEnd,this),this._unbindEvents(),this._map._mapPane.className=this._map._mapPane.className.replace(" leaflet-cluster-anim",""),this._spiderfierOnRemove&&this._spiderfierOnRemove(),delete this._maxLat,this._hideCoverage(),this._featureGroup.remove(),this._nonPointGroup.remove(),this._featureGroup.clearLayers(),this._map=null},getVisibleParent:function(e){for(var t=e;t&&!t._icon;)t=t.__parent;return t||null},_arraySplice:function(e,t){for(var i=e.length-1;i>=0;i--)if(e[i]===t)return e.splice(i,1),!0},_removeFromGridUnclustered:function(e,t){for(var i=this._map,n=this._gridUnclustered;t>=0&&n[t].removeObject(e,i.project(e.getLatLng(),t));t--);},_childMarkerMoved:function(e){this._ignoreMove||(e.target._latlng=e.oldLatLng,this.removeLayer(e.target),e.target._latlng=e.latlng,this.addLayer(e.target))},_removeLayer:function(e,t,i){var n=this._gridClusters,s=this._gridUnclustered,r=this._featureGroup,o=this._map;t&&this._removeFromGridUnclustered(e,this._maxZoom);var a,h=e.__parent,u=h._markers;for(this._arraySplice(u,e);h&&(h._childCount--,h._boundsNeedUpdate=!0,!(h._zoom<0));)t&&h._childCount<=1?(a=h._markers[0]===e?h._markers[1]:h._markers[0],n[h._zoom].removeObject(h,o.project(h._cLatLng,h._zoom)),s[h._zoom].addObject(a,o.project(a.getLatLng(),h._zoom)),this._arraySplice(h.__parent._childClusters,h),h.__parent._markers.push(a),a.__parent=h.__parent,h._icon&&(r.removeLayer(h),i||r.addLayer(a))):h._iconNeedsUpdate=!0,h=h.__parent;delete e.__parent},_isOrIsParent:function(e,t){for(;t;){if(e===t)return!0;t=t.parentNode}return!1},fire:function(e,t,i){if(t&&t.layer instanceof L.MarkerCluster){if(t.originalEvent&&this._isOrIsParent(t.layer._icon,t.originalEvent.relatedTarget))return;e="cluster"+e}L.FeatureGroup.prototype.fire.call(this,e,t,i)},listens:function(e,t){return L.FeatureGroup.prototype.listens.call(this,e,t)||L.FeatureGroup.prototype.listens.call(this,"cluster"+e,t)},_defaultIconCreateFunction:function(e){var t=e.getChildCount(),i=" marker-cluster-";return i+=10>t?"small":100>t?"medium":"large",new L.DivIcon({html:"
"+t+"
",className:"marker-cluster"+i,iconSize:new L.Point(40,40)})},_bindEvents:function(){var e=this._map,t=this.options.spiderfyOnMaxZoom,i=this.options.showCoverageOnHover,n=this.options.zoomToBoundsOnClick;(t||n)&&this.on("clusterclick",this._zoomOrSpiderfy,this),i&&(this.on("clustermouseover",this._showCoverage,this),this.on("clustermouseout",this._hideCoverage,this),e.on("zoomend",this._hideCoverage,this))},_zoomOrSpiderfy:function(e){for(var t=e.layer,i=t;1===i._childClusters.length;)i=i._childClusters[0];i._zoom===this._maxZoom&&i._childCount===t._childCount&&this.options.spiderfyOnMaxZoom?t.spiderfy():this.options.zoomToBoundsOnClick&&t.zoomToBounds(),e.originalEvent&&13===e.originalEvent.keyCode&&this._map._container.focus()},_showCoverage:function(e){var t=this._map;this._inZoomAnimation||(this._shownPolygon&&t.removeLayer(this._shownPolygon),e.layer.getChildCount()>2&&e.layer!==this._spiderfied&&(this._shownPolygon=new L.Polygon(e.layer.getConvexHull(),this.options.polygonOptions),t.addLayer(this._shownPolygon)))},_hideCoverage:function(){this._shownPolygon&&(this._map.removeLayer(this._shownPolygon),this._shownPolygon=null)},_unbindEvents:function(){var e=this.options.spiderfyOnMaxZoom,t=this.options.showCoverageOnHover,i=this.options.zoomToBoundsOnClick,n=this._map;(e||i)&&this.off("clusterclick",this._zoomOrSpiderfy,this),t&&(this.off("clustermouseover",this._showCoverage,this),this.off("clustermouseout",this._hideCoverage,this),n.off("zoomend",this._hideCoverage,this))},_zoomEnd:function(){this._map&&(this._mergeSplitClusters(),this._zoom=Math.round(this._map._zoom),this._currentShownBounds=this._getExpandedVisibleBounds())},_moveEnd:function(){if(!this._inZoomAnimation){var e=this._getExpandedVisibleBounds();this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,this._zoom,e),this._topClusterLevel._recursivelyAddChildrenToMap(null,Math.round(this._map._zoom),e),this._currentShownBounds=e}},_generateInitialClusters:function(){var e=this._map.getMaxZoom(),t=this.options.maxClusterRadius,i=t;"function"!=typeof t&&(i=function(){return t}),this.options.disableClusteringAtZoom&&(e=this.options.disableClusteringAtZoom-1),this._maxZoom=e,this._gridClusters={},this._gridUnclustered={};for(var n=e;n>=0;n--)this._gridClusters[n]=new L.DistanceGrid(i(n)),this._gridUnclustered[n]=new L.DistanceGrid(i(n));this._topClusterLevel=new this._markerCluster(this,-1)},_addLayer:function(e,t){var i,n,s=this._gridClusters,r=this._gridUnclustered;for(this.options.singleMarkerMode&&this._overrideMarkerIcon(e),e.on("move",this._childMarkerMoved,this);t>=0;t--){i=this._map.project(e.getLatLng(),t);var o=s[t].getNearObject(i);if(o)return o._addChild(e),e.__parent=o,void 0;if(o=r[t].getNearObject(i)){var a=o.__parent;a&&this._removeLayer(o,!1);var h=new this._markerCluster(this,t,o,e);s[t].addObject(h,this._map.project(h._cLatLng,t)),o.__parent=h,e.__parent=h;var u=h;for(n=t-1;n>a._zoom;n--)u=new this._markerCluster(this,n,u),s[n].addObject(u,this._map.project(o.getLatLng(),n));return a._addChild(u),this._removeFromGridUnclustered(o,t),void 0}r[t].addObject(e,i)}this._topClusterLevel._addChild(e),e.__parent=this._topClusterLevel},_refreshClustersIcons:function(){this._featureGroup.eachLayer(function(e){e instanceof L.MarkerCluster&&e._iconNeedsUpdate&&e._updateIcon()})},_enqueue:function(e){this._queue.push(e),this._queueTimeout||(this._queueTimeout=setTimeout(L.bind(this._processQueue,this),300))},_processQueue:function(){for(var e=0;ee?(this._animationStart(),this._animationZoomOut(this._zoom,e)):this._moveEnd()},_getExpandedVisibleBounds:function(){return this.options.removeOutsideVisibleBounds?L.Browser.mobile?this._checkBoundsMaxLat(this._map.getBounds()):this._checkBoundsMaxLat(this._map.getBounds().pad(1)):this._mapBoundsInfinite},_checkBoundsMaxLat:function(e){var t=this._maxLat;return t!==i&&(e.getNorth()>=t&&(e._northEast.lat=1/0),e.getSouth()<=-t&&(e._southWest.lat=-1/0)),e},_animationAddLayerNonAnimated:function(e,t){if(t===e)this._featureGroup.addLayer(e);else if(2===t._childCount){t._addToMap();var i=t.getAllChildMarkers();this._featureGroup.removeLayer(i[0]),this._featureGroup.removeLayer(i[1])}else t._updateIcon()},_extractNonGroupLayers:function(e,t){var i,n=e.getLayers(),s=0;for(t=t||[];s=0;i--)o=h[i],n.contains(o._latlng)||s.removeLayer(o)}),this._forceLayout(),this._topClusterLevel._recursivelyBecomeVisible(n,t),s.eachLayer(function(e){e instanceof L.MarkerCluster||!e._icon||e.clusterShow()}),this._topClusterLevel._recursively(n,e,t,function(e){e._recursivelyRestoreChildPositions(t)}),this._ignoreMove=!1,this._enqueue(function(){this._topClusterLevel._recursively(n,e,0,function(e){s.removeLayer(e),e.clusterShow()}),this._animationEnd()})},_animationZoomOut:function(e,t){this._animationZoomOutSingle(this._topClusterLevel,e-1,t),this._topClusterLevel._recursivelyAddChildrenToMap(null,t,this._getExpandedVisibleBounds()),this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,e,this._getExpandedVisibleBounds())},_animationAddLayer:function(e,t){var i=this,n=this._featureGroup;n.addLayer(e),t!==e&&(t._childCount>2?(t._updateIcon(),this._forceLayout(),this._animationStart(),e._setPos(this._map.latLngToLayerPoint(t.getLatLng())),e.clusterHide(),this._enqueue(function(){n.removeLayer(e),e.clusterShow(),i._animationEnd()})):(this._forceLayout(),i._animationStart(),i._animationZoomOutSingle(t,this._map.getMaxZoom(),this._map.getZoom())))}},_animationZoomOutSingle:function(e,t,i){var n=this._getExpandedVisibleBounds();e._recursivelyAnimateChildrenInAndAddSelfToMap(n,t+1,i);var s=this;this._forceLayout(),e._recursivelyBecomeVisible(n,i),this._enqueue(function(){if(1===e._childCount){var r=e._markers[0];this._ignoreMove=!0,r.setLatLng(r.getLatLng()),this._ignoreMove=!1,r.clusterShow&&r.clusterShow()}else e._recursively(n,i,0,function(e){e._recursivelyRemoveChildrenFromMap(n,t+1)});s._animationEnd()})},_animationEnd:function(){this._map&&(this._map._mapPane.className=this._map._mapPane.className.replace(" leaflet-cluster-anim","")),this._inZoomAnimation--,this.fire("animationend")},_forceLayout:function(){L.Util.falseFn(t.body.offsetWidth)}}),L.markerClusterGroup=function(e){return new L.MarkerClusterGroup(e)},L.MarkerCluster=L.Marker.extend({initialize:function(e,t,i,n){L.Marker.prototype.initialize.call(this,i?i._cLatLng||i.getLatLng():new L.LatLng(0,0),{icon:this}),this._group=e,this._zoom=t,this._markers=[],this._childClusters=[],this._childCount=0,this._iconNeedsUpdate=!0,this._boundsNeedUpdate=!0,this._bounds=new L.LatLngBounds,i&&this._addChild(i),n&&this._addChild(n)},getAllChildMarkers:function(e){e=e||[];for(var t=this._childClusters.length-1;t>=0;t--)this._childClusters[t].getAllChildMarkers(e);for(var i=this._markers.length-1;i>=0;i--)e.push(this._markers[i]);return e},getChildCount:function(){return this._childCount},zoomToBounds:function(){for(var e,t=this._childClusters.slice(),i=this._group._map,n=i.getBoundsZoom(this._bounds),s=this._zoom+1,r=i.getZoom();t.length>0&&n>s;){s++;var o=[];for(e=0;es?this._group._map.setView(this._latlng,s):r>=n?this._group._map.setView(this._latlng,r+1):this._group._map.fitBounds(this._bounds)},getBounds:function(){var e=new L.LatLngBounds;return e.extend(this._bounds),e},_updateIcon:function(){this._iconNeedsUpdate=!0,this._icon&&this.setIcon(this)},createIcon:function(){return this._iconNeedsUpdate&&(this._iconObj=this._group.options.iconCreateFunction(this),this._iconNeedsUpdate=!1),this._iconObj.createIcon()},createShadow:function(){return this._iconObj.createShadow()},_addChild:function(e,t){this._iconNeedsUpdate=!0,this._boundsNeedUpdate=!0,this._setClusterCenter(e),e instanceof L.MarkerCluster?(t||(this._childClusters.push(e),e.__parent=this),this._childCount+=e._childCount):(t||this._markers.push(e),this._childCount++),this.__parent&&this.__parent._addChild(e,!0)},_setClusterCenter:function(e){this._cLatLng||(this._cLatLng=e._cLatLng||e._latlng)},_resetBounds:function(){var e=this._bounds;e._southWest&&(e._southWest.lat=1/0,e._southWest.lng=1/0),e._northEast&&(e._northEast.lat=-1/0,e._northEast.lng=-1/0)},_recalculateBounds:function(){var e,t,i,n,s=this._markers,r=this._childClusters,o=0,a=0,h=this._childCount;if(0!==h){for(this._resetBounds(),e=0;e=0;i--)n=s[i],n._icon&&(n._setPos(t),n.clusterHide())},function(e){var i,n,s=e._childClusters;for(i=s.length-1;i>=0;i--)n=s[i],n._icon&&(n._setPos(t),n.clusterHide())})},_recursivelyAnimateChildrenInAndAddSelfToMap:function(e,t,i){this._recursively(e,i,0,function(n){n._recursivelyAnimateChildrenIn(e,n._group._map.latLngToLayerPoint(n.getLatLng()).round(),t),n._isSingleParent()&&t-1===i?(n.clusterShow(),n._recursivelyRemoveChildrenFromMap(e,t)):n.clusterHide(),n._addToMap()})},_recursivelyBecomeVisible:function(e,t){this._recursively(e,0,t,null,function(e){e.clusterShow()})},_recursivelyAddChildrenToMap:function(e,t,i){this._recursively(i,-1,t,function(n){if(t!==n._zoom)for(var s=n._markers.length-1;s>=0;s--){var r=n._markers[s];i.contains(r._latlng)&&(e&&(r._backupLatlng=r.getLatLng(),r.setLatLng(e),r.clusterHide&&r.clusterHide()),n._group._featureGroup.addLayer(r))}},function(t){t._addToMap(e)})},_recursivelyRestoreChildPositions:function(e){for(var t=this._markers.length-1;t>=0;t--){var i=this._markers[t];i._backupLatlng&&(i.setLatLng(i._backupLatlng),delete i._backupLatlng)}if(e-1===this._zoom)for(var n=this._childClusters.length-1;n>=0;n--)this._childClusters[n]._restorePosition();else for(var s=this._childClusters.length-1;s>=0;s--)this._childClusters[s]._recursivelyRestoreChildPositions(e)},_restorePosition:function(){this._backupLatlng&&(this.setLatLng(this._backupLatlng),delete this._backupLatlng)},_recursivelyRemoveChildrenFromMap:function(e,t,i){var n,s;this._recursively(e,-1,t-1,function(e){for(s=e._markers.length-1;s>=0;s--)n=e._markers[s],i&&i.contains(n._latlng)||(e._group._featureGroup.removeLayer(n),n.clusterShow&&n.clusterShow())},function(e){for(s=e._childClusters.length-1;s>=0;s--)n=e._childClusters[s],i&&i.contains(n._latlng)||(e._group._featureGroup.removeLayer(n),n.clusterShow&&n.clusterShow())})},_recursively:function(e,t,i,n,s){var r,o,a=this._childClusters,h=this._zoom;if(t>h)for(r=a.length-1;r>=0;r--)o=a[r],e.intersects(o._bounds)&&o._recursively(e,t,i,n,s);else if(n&&n(this),s&&this._zoom===i&&s(this),i>h)for(r=a.length-1;r>=0;r--)o=a[r],e.intersects(o._bounds)&&o._recursively(e,t,i,n,s)},_isSingleParent:function(){return this._childClusters.length>0&&this._childClusters[0]._childCount===this._childCount}}),L.Marker.include({clusterHide:function(){return this.options.opacityWhenUnclustered=this.options.opacity||1,this.setOpacity(0)},clusterShow:function(){var e=this.setOpacity(this.options.opacity||this.options.opacityWhenUnclustered);return delete this.options.opacityWhenUnclustered,e}}),L.DistanceGrid=function(e){this._cellSize=e,this._sqCellSize=e*e,this._grid={},this._objectPoint={}},L.DistanceGrid.prototype={addObject:function(e,t){var i=this._getCoord(t.x),n=this._getCoord(t.y),s=this._grid,r=s[n]=s[n]||{},o=r[i]=r[i]||[],a=L.Util.stamp(e);this._objectPoint[a]=t,o.push(e)},updateObject:function(e,t){this.removeObject(e),this.addObject(e,t)},removeObject:function(e,t){var i,n,s=this._getCoord(t.x),r=this._getCoord(t.y),o=this._grid,a=o[r]=o[r]||{},h=a[s]=a[s]||[];for(delete this._objectPoint[L.Util.stamp(e)],i=0,n=h.length;n>i;i++)if(h[i]===e)return h.splice(i,1),1===n&&delete a[s],!0},eachObject:function(e,t){var i,n,s,r,o,a,h,u=this._grid;for(i in u){o=u[i];for(n in o)for(a=o[n],s=0,r=a.length;r>s;s++)h=e.call(t,a[s]),h&&(s--,r--)}},getNearObject:function(e){var t,i,n,s,r,o,a,h,u=this._getCoord(e.x),l=this._getCoord(e.y),_=this._objectPoint,d=this._sqCellSize,c=null;for(t=l-1;l+1>=t;t++)if(s=this._grid[t])for(i=u-1;u+1>=i;i++)if(r=s[i])for(n=0,o=r.length;o>n;n++)a=r[n],h=this._sqDist(_[L.Util.stamp(a)],e),d>h&&(d=h,c=a);return c},_getCoord:function(e){return Math.floor(e/this._cellSize)},_sqDist:function(e,t){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n}},function(){L.QuickHull={getDistant:function(e,t){var i=t[1].lat-t[0].lat,n=t[0].lng-t[1].lng;return n*(e.lat-t[0].lat)+i*(e.lng-t[0].lng)},findMostDistantPointFromBaseLine:function(e,t){var i,n,s,r=0,o=null,a=[];for(i=t.length-1;i>=0;i--)n=t[i],s=this.getDistant(n,e),s>0&&(a.push(n),s>r&&(r=s,o=n));return{maxPoint:o,newPoints:a}},buildConvexHull:function(e,t){var i=[],n=this.findMostDistantPointFromBaseLine(e,t);return n.maxPoint?(i=i.concat(this.buildConvexHull([e[0],n.maxPoint],n.newPoints)),i=i.concat(this.buildConvexHull([n.maxPoint,e[1]],n.newPoints))):[e[0]]},getConvexHull:function(e){var t,i=!1,n=!1,s=!1,r=!1,o=null,a=null,h=null,u=null,l=null,_=null;for(t=e.length-1;t>=0;t--){var d=e[t];(i===!1||d.lat>i)&&(o=d,i=d.lat),(n===!1||d.lats)&&(h=d,s=d.lng),(r===!1||d.lng=0;t--)e=i[t].getLatLng(),n.push(e);return L.QuickHull.getConvexHull(n)}}),L.MarkerCluster.include({_2PI:2*Math.PI,_circleFootSeparation:25,_circleStartAngle:Math.PI/6,_spiralFootSeparation:28,_spiralLengthStart:11,_spiralLengthFactor:5,_circleSpiralSwitchover:9,spiderfy:function(){if(this._group._spiderfied!==this&&!this._group._inZoomAnimation){var e,t=this.getAllChildMarkers(),i=this._group,n=i._map,s=n.latLngToLayerPoint(this._latlng);this._group._unspiderfy(),this._group._spiderfied=this,t.length>=this._circleSpiralSwitchover?e=this._generatePointsSpiral(t.length,s):(s.y+=10,e=this._generatePointsCircle(t.length,s)),this._animationSpiderfy(t,e)}},unspiderfy:function(e){this._group._inZoomAnimation||(this._animationUnspiderfy(e),this._group._spiderfied=null)},_generatePointsCircle:function(e,t){var i,n,s=this._group.options.spiderfyDistanceMultiplier*this._circleFootSeparation*(2+e),r=s/this._2PI,o=this._2PI/e,a=[];for(a.length=e,i=e-1;i>=0;i--)n=this._circleStartAngle+i*o,a[i]=new L.Point(t.x+r*Math.cos(n),t.y+r*Math.sin(n))._round();return a},_generatePointsSpiral:function(e,t){var i,n=this._group.options.spiderfyDistanceMultiplier,s=n*this._spiralLengthStart,r=n*this._spiralFootSeparation,o=n*this._spiralLengthFactor*this._2PI,a=0,h=[];for(h.length=e,i=e-1;i>=0;i--)a+=r/s+5e-4*i,h[i]=new L.Point(t.x+s*Math.cos(a),t.y+s*Math.sin(a))._round(),s+=o/a;return h},_noanimationUnspiderfy:function(){var e,t,i=this._group,n=i._map,s=i._featureGroup,r=this.getAllChildMarkers();for(i._ignoreMove=!0,this.setOpacity(1),t=r.length-1;t>=0;t--)e=r[t],s.removeLayer(e),e._preSpiderfyLatlng&&(e.setLatLng(e._preSpiderfyLatlng),delete e._preSpiderfyLatlng),e.setZIndexOffset&&e.setZIndexOffset(0),e._spiderLeg&&(n.removeLayer(e._spiderLeg),delete e._spiderLeg);i.fire("unspiderfied",{cluster:this,markers:r}),i._ignoreMove=!1,i._spiderfied=null}}),L.MarkerClusterNonAnimated=L.MarkerCluster.extend({_animationSpiderfy:function(e,t){var i,n,s,r,o=this._group,a=o._map,h=o._featureGroup,u=this._group.options.spiderLegPolylineOptions;for(o._ignoreMove=!0,i=0;i=0;n--)h=_.layerPointToLatLng(t[n]),s=e[n],s._preSpiderfyLatlng=s._latlng,s.setLatLng(h),s.clusterShow&&s.clusterShow(),f&&(r=s._spiderLeg,o=r._path,o.style.strokeDashoffset=0,r.setStyle({opacity:g}));this.setOpacity(.3),l._ignoreMove=!1,setTimeout(function(){l._animationEnd(),l.fire("spiderfied",{cluster:u,markers:e})},200)},_animationUnspiderfy:function(e){var t,i,n,s,r,o,a=this,h=this._group,u=h._map,l=h._featureGroup,_=e?u._latLngToNewLayerPoint(this._latlng,e.zoom,e.center):u.latLngToLayerPoint(this._latlng),d=this.getAllChildMarkers(),c=L.Path.SVG;for(h._ignoreMove=!0,h._animationStart(),this.setOpacity(1),i=d.length-1;i>=0;i--)t=d[i],t._preSpiderfyLatlng&&(t.setLatLng(t._preSpiderfyLatlng),delete t._preSpiderfyLatlng,o=!0,t._setPos&&(t._setPos(_),o=!1),t.clusterHide&&(t.clusterHide(),o=!1),o&&l.removeLayer(t),c&&(n=t._spiderLeg,s=n._path,r=s.getTotalLength()+.1,s.style.strokeDashoffset=r,n.setStyle({opacity:0})));h._ignoreMove=!1,setTimeout(function(){var e=0;for(i=d.length-1;i>=0;i--)t=d[i],t._spiderLeg&&e++;for(i=d.length-1;i>=0;i--)t=d[i],t._spiderLeg&&(t.clusterShow&&t.clusterShow(),t.setZIndexOffset&&t.setZIndexOffset(0),e>1&&l.removeLayer(t),u.removeLayer(t._spiderLeg),delete t._spiderLeg);h._animationEnd(),h.fire("unspiderfied",{cluster:a,markers:d})},200)}}),L.MarkerClusterGroup.include({_spiderfied:null,unspiderfy:function(){this._unspiderfy.apply(this,arguments)},_spiderfierOnAdd:function(){this._map.on("click",this._unspiderfyWrapper,this),this._map.options.zoomAnimation&&this._map.on("zoomstart",this._unspiderfyZoomStart,this),this._map.on("zoomend",this._noanimationUnspiderfy,this),L.Browser.touch||this._map.getRenderer(this)},_spiderfierOnRemove:function(){this._map.off("click",this._unspiderfyWrapper,this),this._map.off("zoomstart",this._unspiderfyZoomStart,this),this._map.off("zoomanim",this._unspiderfyZoomAnim,this),this._map.off("zoomend",this._noanimationUnspiderfy,this),this._noanimationUnspiderfy()},_unspiderfyZoomStart:function(){this._map&&this._map.on("zoomanim",this._unspiderfyZoomAnim,this)},_unspiderfyZoomAnim:function(e){L.DomUtil.hasClass(this._map._mapPane,"leaflet-touching")||(this._map.off("zoomanim",this._unspiderfyZoomAnim,this),this._unspiderfy(e))},_unspiderfyWrapper:function(){this._unspiderfy()},_unspiderfy:function(e){this._spiderfied&&this._spiderfied.unspiderfy(e)},_noanimationUnspiderfy:function(){this._spiderfied&&this._spiderfied._noanimationUnspiderfy()},_unspiderfyLayer:function(e){e._spiderLeg&&(this._featureGroup.removeLayer(e),e.clusterShow&&e.clusterShow(),e.setZIndexOffset&&e.setZIndexOffset(0),this._map.removeLayer(e._spiderLeg),delete e._spiderLeg)}}),L.MarkerClusterGroup.include({refreshClusters:function(e){return e?e instanceof L.MarkerClusterGroup?e=e._topClusterLevel.getAllChildMarkers():e instanceof L.LayerGroup?e=e._layers:e instanceof L.MarkerCluster?e=e.getAllChildMarkers():e instanceof L.Marker&&(e=[e]):e=this._topClusterLevel.getAllChildMarkers(),this._flagParentsIconsNeedUpdate(e),this._refreshClustersIcons(),this.options.singleMarkerMode&&this._refreshSingleMarkerModeMarkers(e),this},_flagParentsIconsNeedUpdate:function(e){var t,i;for(t in e)for(i=e[t].__parent;i;)i._iconNeedsUpdate=!0,i=i.__parent},_refreshSingleMarkerModeMarkers:function(e){var t,i;for(t in e)i=e[t],this.hasLayer(i)&&i.setIcon(this._overrideMarkerIcon(i))}}),L.Marker.include({refreshIconOptions:function(e,t){var i=this.options.icon;return L.setOptions(i,e),this.setIcon(i),t&&this.__parent&&this.__parent._group.refreshClusters(this),this}})}(window,document); - \ No newline at end of file diff --git a/talkmap/leaflet_dist/screen.css b/talkmap/leaflet_dist/screen.css deleted file mode 100644 index 5fa679424041a..0000000000000 --- a/talkmap/leaflet_dist/screen.css +++ /dev/null @@ -1,30 +0,0 @@ - - #map { - width: 800px; - height: 600px; - border: 1px solid #ccc; - } - - #progress { - display: none; - position: absolute; - z-index: 1000; - left: 400px; - top: 300px; - width: 200px; - height: 20px; - margin-top: -20px; - margin-left: -100px; - background-color: #fff; - background-color: rgba(255, 255, 255, 0.7); - border-radius: 4px; - padding: 2px; - } - - #progress-bar { - width: 0; - height: 100%; - background-color: #76A6FC; - border-radius: 4px; - } - \ No newline at end of file diff --git a/talkmap/map.html b/talkmap/map.html deleted file mode 100644 index 6a81aab23177d..0000000000000 --- a/talkmap/map.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - Leaflet debug page - - - - - - - - - - - - - - -
- Mouse over a cluster to see the bounds of its children and click a cluster to zoom to those bounds - - - - \ No newline at end of file diff --git a/talkmap/org-locations.js b/talkmap/org-locations.js deleted file mode 100644 index 8662d8bbd81c3..0000000000000 --- a/talkmap/org-locations.js +++ /dev/null @@ -1,22 +0,0 @@ -var addressPoints = [ - [ - "Berkeley CA, USA", - 37.8708393, - -122.2728638 - ], - [ - "London, UK", - 51.5073219, - -0.1276473 - ], - [ - "San Francisco, California", - 37.7792808, - -122.4192362 - ], - [ - "Los Angeles, CA", - 34.0543942, - -118.2439408 - ] -]; \ No newline at end of file