npm package: @feendy/localization-address
Description: Package allowing to obtain a search field by address working with adresse.data.gouv.fr.
Author: Thibeault Chenu
Latest version: 0.0.2



[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com) [![forthebadge](https://forthebadge.com/images/badges/made-with-javascript.svg)](https://forthebadge.com)

  

## Introduction 

 Ce paquet contient un composant VueJS permettant d'afficher un champs, de saisir une adresse et d'autocompléter cette recherche.

Celui-ci utilise l'API adresse.data.gouv.fr permettant de récupérer des résultats uniquement en France de manière illimitée. *(no rate limit)*

![](doc/demo.gif)

Vous pourrez ainsi récupérer de nombreuses informations comme : 

```javascript
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      2.372796,
      48.899609
    ]
  },
  "properties": {
    "label": "73 Rue Emile Bollaert 75019 Paris",
    "score": 0.8860401669600837,
    "housenumber": "73",
    "id": "75119_3212_00073",
    "type": "housenumber",
    "name": "73 Rue Emile Bollaert",
    "postcode": "75019",
    "citycode": "75119",
    "x": 654018.19,
    "y": 6866805.43,
    "city": "Paris",
    "district": "Paris 19e Arrondissement",
    "context": "75, Paris, Île-de-France",
    "importance": 0.7464418365609212,
    "street": "Rue Emile Bollaert"
  }
}
```

## Installation

Actuellement le paquet n'est pas disponible sur NPM publiquement, il faudra modifier manuellement votre *package.json* afin de rajouter la dépendance de cette manière :
  
```javascript
  "dependencies": {
    "@feendy/localization-address": "git+ssh://git@bitbucket.rib-server.fr:7999/feendy/localization-address.git"
  }
```
  
**Veuillez disposer des accès nécessaires pour cloner le dépôt.**
 
## Utilisation

Vous pouvez utiliser ce composant de deux manières différentes.

**Global**

```javascript
import LocalizationAddress from "@feendy/localization-address";
Vue.use(LocalizationAddress);
```

**Locale (dans un composant)**

```javascript
import LocalizationAddress from "@feendy/localization-address";
```
```javascript
components: {
	LocalizationAddress
},
```
---
```html
<Address></Address>
```

**Options**

| name | type | description | required | default
|--|--|--|--|--|--|--|
| wait | String | Millisecondes avant que l'évènement *submit* se déclenche | false | 500 | 
| attributes | Object | Attributs à insérer pour le champs de recherche | false | {} | 
| minLength | Number | Longueur minimum de caractères avant de déclencher une recherche | false | 5 | 
| type | Boolean ou String | Type de résultats souhaités (voir [https://adresse.data.gouv.fr/api](https://adresse.data.gouv.fr/api)) : *street*, *housenumber*, *locality*, *municipality* | false | housenumber | 
| limit | Number ou String | Limite de résultats | false | 5 | 

**Récupérer l'adresse sélectionnée (exemple de composant)**
```javascript
<template>
  <div>
    <label>Saisissez votre adresse : </label>
    <localization-address>
      :submit="submit" 
      :attributes="{autofocus: true}" 
      :wait="0"
      :min-length="3">
    </localization-address>
    <div v-if="suggestion">
      <label>Adresse</label> : {{ suggestion.properties.label }} <br>
      <a :href="'https://www.google.com/maps/place/' + suggestion.geometry.coordinates[1] + ',' + suggestion.geometry.coordinates[0]">Google Maps</a> <br>
      <label>Latitude</label> : {{ suggestion.geometry.coordinates[1] }} <br>
      <label>Longitude</label> : {{ suggestion.geometry.coordinates[0] }}
    </div>
  </div>
</template>

<script>
import LocalizationAddress from "@feendy/localization-address";

    export default {
        name: "Test",
        components: {
          LocalizationAddress
        },
        data () {
          return {
            suggestion: null,
          }
        },
        methods : {
          submit (suggestion) {
            this.suggestion = suggestion
          }
        }
    }
</script>

```

## Développement

Un composant de test est disponible en utilisant la commande ci-dessous.
```bash
npm run test
```

Vous pouvez compiler le paquet avec la commande suivante.
```bash
npm run build
```

## License

The MIT License (MIT)
Copyright (c) 2019 Thibeault Chenu

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.