Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite in typescript with LitElement #95

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
22939de
rewrite in typescript with LitElement
bennypowers Jun 11, 2020
f92c756
fix: circle fit-to-bounds
bennypowers Jun 12, 2020
a74718a
0.0.7
bennypowers Jun 12, 2020
2887cf3
chore: add custom-elements.json to package
bennypowers Jun 12, 2020
fecbff8
0.0.8
bennypowers Jun 12, 2020
2323de1
feat: add `image-path` attr to map
bennypowers Jun 14, 2020
92bb8d2
0.0.9
bennypowers Jun 14, 2020
c04579c
fix: guessLeafletImagePath
bennypowers Jun 14, 2020
85ecc02
0.0.10
bennypowers Jun 14, 2020
1d255d1
fix: initialize slotted children
bennypowers Aug 4, 2020
ccbc228
0.0.11
bennypowers Aug 4, 2020
74235ab
fix: types for slotted children
bennypowers Aug 4, 2020
7c32cbe
docs: update docs
bennypowers Aug 4, 2020
297a9f6
0.0.12
bennypowers Aug 4, 2020
99a160e
fix: fit to markers
bennypowers Aug 4, 2020
2df7b0d
0.0.13
bennypowers Aug 4, 2020
b91b7bb
feat: init on intersection
bennypowers Aug 27, 2020
7f96721
0.0.14
bennypowers Aug 27, 2020
094d5d8
chore: fix files
bennypowers Aug 27, 2020
32a21fd
0.0.15
bennypowers Aug 27, 2020
459d13b
feat: use containerChanged method instead of setter
bennypowers Sep 4, 2020
053d08a
0.0.16
bennypowers Sep 4, 2020
6b0a8a0
perf: import tslib helpers
bennypowers Sep 10, 2020
cf1e8f7
fix: wait on feature elements to fit bounds
bennypowers Sep 10, 2020
d19dfe0
0.0.17
bennypowers Sep 10, 2020
cc2cb8e
fix: don't load undefined features
bennypowers Oct 12, 2020
20387a1
0.0.18
bennypowers Oct 12, 2020
813b1e0
fix: calculate marker bounds only if they exist
bennypowers Oct 14, 2020
1ed3e9a
0.0.19
bennypowers Oct 14, 2020
62b0408
fix: use tileset's max zoom by default
bennypowers Oct 14, 2020
98c3cfd
feat: react to marker position changes
bennypowers Oct 14, 2020
08cc1d7
fix: edge case when traversing for marker icon
bennypowers Oct 14, 2020
50e9176
fix: error when loading marker
bennypowers Oct 14, 2020
50b307c
0.0.20
bennypowers Oct 14, 2020
e763276
fix: bad import in base
bennypowers Oct 15, 2020
9aa7862
0.0.21
bennypowers Oct 15, 2020
7320f12
feat: leaflet-scale-control
bennypowers Dec 6, 2020
29b0bec
feat: leaflet-fullscreen-control
bennypowers Dec 6, 2020
4641774
feat: leaflet-zoom-control
bennypowers Dec 6, 2020
112cd90
feat: leaflet-legend
bennypowers Dec 6, 2020
30ef50a
0.0.22
bennypowers Dec 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@pwrs"
}
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
/bower_components
**/*~
coverage
node_modules

*.js
*.js.map
*.d.ts
*.tgz
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!*.js
!*.js.map
!*.d.ts
17 changes: 0 additions & 17 deletions .project

This file was deleted.

6 changes: 0 additions & 6 deletions .settings/.jsdtscope

This file was deleted.

1 change: 0 additions & 1 deletion .settings/org.eclipse.wst.jsdt.ui.superType.container

This file was deleted.

1 change: 0 additions & 1 deletion .settings/org.eclipse.wst.jsdt.ui.superType.name

This file was deleted.

7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.exclude": {
// "**/*.js": {"when": "$(basename).ts"},
// "**/*.d.ts": {"when": "$(basename).ts"},
// "**/*.js.map": true
},
}
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2020
Benny Powers

Copyright (c) 2014-2016
Hendrik Brummermann, Prateek Saxena

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File renamed without changes.
71 changes: 18 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
# leaflet-map

*leaflet-map* is a web-component which provides access to the [leaflet map](http://leafletjs.com)
*leaflet-map* is a web-component which provides access to the [leaflet map](http://leafletjs.com)
JavaScript library via html elements.

Please have a look at the [demo](https://leaflet-extras.github.io/leaflet-map/demo.html) or the [api documentation](https://leaflet-extras.github.io/leaflet-map/doc.html#leaflet-map).

Most of the options documented in the Leaflet reference are exported as html attributes.
Most of the options documented in the Leaflet reference are exported as html attributes.
All events are mapped into html events of the same name.</p>
For example use &lt;leaflet-map latitude="51.505" longitude="-0.09" zoom="13"&gt; &lt;/leaflet-map&gt;
For example use &lt;leaflet-map latitude="51.505" longitude="-0.09" zoom="13"&gt; &lt;/leaflet-map&gt;
to define the view and zoom level.


Web-components are an emerging standard which is based on Custom Elements, Shadow DOM, HTML Imports and Web Animations.
[Polymer](http://www.polymer-project.org/docs/start/tutorial/intro.html) is a library which simplifies working with web-components. It includes a compatibility layer for browsers which
do not yet support web-components natively, yet.


## Quickstart Guide

Make leaflet maps using declarative [Polymer](http://polymer-project.org) web components.
Make leaflet maps using declarative web components.
To get started read the [documentation](http://leaflet-extras.github.io/leaflet-map/doc.html)
or checkout the [demo](http://leaflet-extras.github.io/leaflet-map/).

Install this web component using [Bower](http://bower.io):
Install this web component using [npm](https://npm.im/leaflet-element):

```
bower install leaflet-map
npm i -S leaflet-element
```

Import the main component and start creating your map:

```js
import 'leaflet-element'
```
```html
<head>
<script type="text/javascript" src="../webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="leaflet-map.html">
<style>
html, body {
margin: 0;
Expand Down Expand Up @@ -61,7 +57,7 @@ Import the main component and start creating your map:

Although leaflet-map is still under heavy development, it is already fully usable.

List of demos:
List of demos:

* [leaflet-map](https://leaflet-extras.github.io/leaflet-map/demo.html#view) (L.map)
* [leaflet-marker](https://leaflet-extras.github.io/leaflet-map/demo.html#marker) (L.marker)
Expand All @@ -78,51 +74,20 @@ List of demos:

Please have a look at the [change log](https://github.com/nhnb/leaflet-map/blob/master/CHANGES.md), for recent developments.

## Dependencies

leaflet-map depends on webcomponentsjs in ../webcomponentsjs, Polymer in ../polymer and leaflet in ../leaflet. If you use bower, those will be installed automatically at the right locations.

Please note that the pages have to be accessed via a webserver. file://-urls are not supported.


## Notes for implementing child elements

Child elements like markers or layers will be initialized by the surrounding container (the map or a layer)
by setting a "container" javascript property.
Therefore the child element should define a _containerChanged method and use that as initializer.
Don't forget to define a detached method to support removal of elements. The leaflet-marker element is a good template.
Child elements like markers or layers will be initialized by the surrounding container
(the map or a layer) by setting a "container" javascript property.
Therefore the child element should define a `containerChanged` method and use that as initializer.
Don't forget to define a `disconnectedCallback` method that calls `super.disconnectedCallback`
to perform any necessary clean up. The leaflet-marker element is a good template.


## License

leaflet-map is based on polymer and leaflet. Small parts of leaflet,
See LICENSE file.

leaflet-map is based on leaflet. Small parts of leaflet,
especially the api documentation, have been copied into leaflet-map files.

* [Leaflet](https://github.com/Leaflet/Leaflet/blob/master/LICENSE)
* [Polymer](https://github.com/polymer/polymer/blob/master/LICENSE.txt)


Copyright (c) 2014-2016
Hendrik Brummermann, Prateek Saxena

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 changes: 48 additions & 0 deletions base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { FireMixin } from '@pwrs/mixins/fire';
import { LitElement } from 'lit-element';
import { bound } from './bound-decorator';
import type { LeafletMap } from './leaflet-map';
import * as L from 'leaflet';

type LeafletFeature =
| null
| L.Circle
| L.GeoJSON
| L.Marker
| L.LayerGroup
| L.Polyline
| L.Polygon
| L.Popup
| L.Point;

export class LeafletBase extends FireMixin(LitElement) {
declare static is: string;

declare feature: LeafletFeature;

declare protected mo?: MutationObserver;

declare private _container: L.Map | L.LayerGroup;

get container(): L.Map | L.LayerGroup {
return this._container;
}

set container(container: L.Map | L.LayerGroup) {
this._container = container;
this.containerChanged?.(container);
}

get mapElement(): LeafletMap {
return (
!(this.container instanceof L.Map) ? null
: (this.container.getContainer().getRootNode() as ShadowRoot).host as LeafletMap
);
}

@bound onLeafletEvent(e: L.LeafletEvent): void {
this.fire(e.type, e);
}

containerChanged?(container?: L.Map | L.LayerGroup): void
}
5 changes: 5 additions & 0 deletions boilerplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```html
<script src="https://unpkg.com/@webcomponentsjs/webcomponentsjs/webcomponents-loader.js"></script>
<script type="module" src="https://unpkg.com/leaflet-element?module"></script>
<leaflet-map></leaflet-map>
```
29 changes: 29 additions & 0 deletions bound-decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable @typescript-eslint/ban-types */
export function bound<T extends Function>(
target: object,
propertyKey: string,
descriptor: TypedPropertyDescriptor<T>
): TypedPropertyDescriptor<T> | void {
if (!descriptor || typeof descriptor.value !== 'function') {
throw new TypeError(
`Only methods can be decorated with @bound. <${propertyKey}> is not a method!`
);
}

return {
configurable: true,
get(this: T): T {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const f: T = descriptor.value!.bind(this);
// Credits to https://github.com/andreypopp/autobind-decorator for memoizing the result of bind against a symbol on the instance.
Object.defineProperty(this, propertyKey, {
value: f,
configurable: true,
writable: true,
});
return f;
},
};
}

export default bound;
31 changes: 0 additions & 31 deletions bower.json

This file was deleted.

Loading