Skip to content

Commit

Permalink
🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Nov 2, 2021
0 parents commit 0a3a5bb
Show file tree
Hide file tree
Showing 25 changed files with 36,754 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
vendor
mix-manifest.json
150 changes: 150 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
## Installation

1. Install Statamic Address Field from the `Tools > Addons` section of your control panel, or via composer:

```shell
composer require rias/statamic-address-field
```

2. You can publish the configuration file using

```shell
php artisan vendor:publish --tag=statamic-address-field-config
```

## Configuration

### Geocoding

This addon uses [OpenStreetMaps Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim) as its geocoding service.

### Google Maps API

To enable static map rendering and custom marker placement, you need to provide a Google Maps API key.

1. Sign in to [Google's developers console](http://console.developers.google.com/)
2. Create a new project
3. Enable the `Google Static Maps API`
4. Set the API key in your `.env` file as `GOOGLE_MAPS_API_KEY`

#### Other configuration

The config file also allows you to set some extra defaults:

- Default map styling (options are silver, retro, dark, night or aubergine)
- Default marker color
- Default marker icon

## Usage

### Antlers tag

The addon provides an Antlers tag `{{ address }}` which allows you to access most of the functionality.

#### `{{ address:countries }}`

This tag allows you to loop over all available countries, which can be useful for displaying certain data.

```antlers
{{ address:countries }}
{{ name }} <!-- Belgium -->
{{ display }} <!-- "Belgium" when locale is set to "EN", "België" when locale is set to "NL" -->
{{ name }} <!-- BE -->
{{ alpha2 }} <!-- BEL -->
{{ numeric }} <!-- 056 -->
{{ currency }}
{{ value }} <!-- EUR, countries can have more than one currency -->
{{ /currency }}
{{ /address:countries }}
```

### Fieldtype

This addon comes with a fieldtype that allows users to enter a full address. The fieldtype itself is configurable in which fields are shown to the user:

![Fieldtype](docs/fieldtype-settings.png)

Available configuration:
- enabledFields:
- name
- street
- street2
- postCode
- city
- state
- country
- latitude
- longitude

- defaultCountry
- In `alpha2` notation

- geoCode
- Whether to geocode the address to lat/lng coordinates `true`/`false`
- showCoordinates
- Whether to show the latitude & longitude fields `true`/`false`

### Displaying a static map

You can display a static map using the `{{ address:staticMap }}` tag.

#### Parameters

| Parameter | Description | Default |
|-----------|--------------------------------------------------------------|-------------------|
| `address` | The address data from the fieldtype | `null` (required) |
| `zoom` | How zoomed in the map should be | `14` |
| `width` | The width of the image in px | `640` |
| `height` | The height of the image in px | `640` |
| `style` | A style key that is defined in the `map_styles` config value | `default` |
| `color` | The color of the marker that is shown on the map | `null` (optional) |
| `icon` | A URL to a custom marker icon | `null` (optional) |
| `scale` | The scale of the map | `1` |

#### Example

The following static map will be generated for the Spatie HQ address:
```antlers
{{ address:staticMap :address="address" width="250" height="250" }}
```

![Static map](docs/staticmap.png)

#### Just the URL

If you need just the URL to the map image, you can call `staticMapUrl` instead, which will output the url.

```antlers
{{ address:staticMapUrl :address="address" width="250" height="250" }}
```

### Dynamic map

You can also display a dynamic embedded map using the tag.

```antlers
{{ address:map :address="address" width="250" height="250" }}
```

#### Parameters

The `q`, `origin` & `destination` parameters will be set depending on the `type` of map, you can still override them manually as well.

| Parameter | Description | Default |
|-----------|------------------------------------------------------------------------------------------------|-------------------|
| address | The address data from the fieldtype | `null` (required) |
| type | The type of embedded map, can be one of `place`, `directions`, `view`, `streetview`, `search` | `place` |
| maptype | The tiles to load, can be one of `roadmap` or `satellite` | `roadmap` |
| zoom | The map zoom | `14` |

For more information, and all available parameters depending on `type` you can view [https://developers.google.com/maps/documentation/embed/embedding-map](https://developers.google.com/maps/documentation/embed/embedding-map)

### Directions url

You can generate a directions url that links to the address by calling:

```antlers
{{ address:directions :address="address" :currentLocation="true" }}
```

`currentLocation` is optional and defaults to `true`.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Statamic Address Field

This addon provides a full-featured address field for Statamic.

![Screenshot](docs/fieldtype.png)

- Each field can be turned on or off
- Geolocation of the address
- Users can drag the marker to the exact location of the address
- Render static maps
- Render embedded maps
- Get direction URLs

And more! Check out the [Documentation](https://statamic.com/addons/rias/address-field/docs)

## License

Redirect requires a license to be used while on a production site.
You can purchase one at https://statamic.com/marketplace/addons/rias/address-field.

You may use Address Field without a license while developing locally.

## Installation

Require it using Composer.

```
composer require rias/statamic-address-field
```

Publish the assets:

```
php artisan vendor:publish --provider="Rias\StatamicAddressField\ServiceProvider"
```

Brought to you by [Rias](https://rias.be)
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "rias/statamic-address-field",
"autoload": {
"psr-4": {
"Rias\\StatamicAddressField\\": "src"
}
},
"require": {
"league/iso3166": "^4.0",
"giggsey/locale": "^2.0"
},
"extra": {
"statamic": {
"name": "Statamic Address Field",
"description": "A feature complete address field"
},
"laravel": {
"providers": [
"Rias\\StatamicAddressField\\ServiceProvider"
]
}
}
}
38 changes: 38 additions & 0 deletions config/address-field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

return [
/**
* Your Google Maps api key, only needed when using the maps features
* of this addon. Make sure to enable the necessary services.
*/
'google_maps_api_key' => env('GOOGLE_MAPS_API_KEY'),

/**
* The default marker color for displaying map markers.
*/
'defaultMarkerColor' => '#E50000',

/**
* The default marker icon for displaying map markers. This should
* be a public URL to an image. Set `null` to keep Google Map's.
* Make sure it satisfies the requirements, see:
* https://developers.google.com/maps/documentation/maps-static/start#CustomIcons
*/
'defaultMarkerIcon' => null,

/**
* The default map style to use when generating a map.
*/
'default_map_style' => 'default',

/**
* The available map styles.
*/
'map_styles' => [
'silver' => 'element:geometry%7Ccolor:0xf5f5f5&style=element:labels.icon%7Cvisibility:off&style=element:labels.text.fill%7Ccolor:0x616161&style=element:labels.text.stroke%7Ccolor:0xf5f5f5&style=feature:administrative.land_parcel%7Celement:labels.text.fill%7Ccolor:0xbdbdbd&style=feature:poi%7Celement:geometry%7Ccolor:0xeeeeee&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0x757575&style=feature:poi.park%7Celement:geometry%7Ccolor:0xe5e5e5&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x9e9e9e&style=feature:road%7Celement:geometry%7Ccolor:0xffffff&style=feature:road.arterial%7Celement:labels.text.fill%7Ccolor:0x757575&style=feature:road.highway%7Celement:geometry%7Ccolor:0xdadada&style=feature:road.highway%7Celement:labels.text.fill%7Ccolor:0x616161&style=feature:road.local%7Celement:labels.text.fill%7Ccolor:0x9e9e9e&style=feature:transit.line%7Celement:geometry%7Ccolor:0xe5e5e5&style=feature:transit.station%7Celement:geometry%7Ccolor:0xeeeeee&style=feature:water%7Celement:geometry%7Ccolor:0xc9c9c9&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x9e9e9e',
'retro' => 'element:geometry%7Ccolor:0xebe3cd&style=element:labels.text.fill%7Ccolor:0x523735&style=element:labels.text.stroke%7Ccolor:0xf5f1e6&style=feature:administrative%7Celement:geometry.stroke%7Ccolor:0xc9b2a6&style=feature:administrative.land_parcel%7Celement:geometry.stroke%7Ccolor:0xdcd2be&style=feature:administrative.land_parcel%7Celement:labels.text.fill%7Ccolor:0xae9e90&style=feature:landscape.natural%7Celement:geometry%7Ccolor:0xdfd2ae&style=feature:poi%7Celement:geometry%7Ccolor:0xdfd2ae&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0x93817c&style=feature:poi.park%7Celement:geometry.fill%7Ccolor:0xa5b076&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x447530&style=feature:road%7Celement:geometry%7Ccolor:0xf5f1e6&style=feature:road.arterial%7Celement:geometry%7Ccolor:0xfdfcf8&style=feature:road.highway%7Celement:geometry%7Ccolor:0xf8c967&style=feature:road.highway%7Celement:geometry.stroke%7Ccolor:0xe9bc62&style=feature:road.highway.controlled_access%7Celement:geometry%7Ccolor:0xe98d58&style=feature:road.highway.controlled_access%7Celement:geometry.stroke%7Ccolor:0xdb8555&style=feature:road.local%7Celement:labels.text.fill%7Ccolor:0x806b63&style=feature:transit.line%7Celement:geometry%7Ccolor:0xdfd2ae&style=feature:transit.line%7Celement:labels.text.fill%7Ccolor:0x8f7d77&style=feature:transit.line%7Celement:labels.text.stroke%7Ccolor:0xebe3cd&style=feature:transit.station%7Celement:geometry%7Ccolor:0xdfd2ae&style=feature:water%7Celement:geometry.fill%7Ccolor:0xb9d3c2&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x92998d',
'dark' => 'element:geometry%7Ccolor:0x212121&style=element:labels.icon%7Cvisibility:off&style=element:labels.text.fill%7Ccolor:0x757575&style=element:labels.text.stroke%7Ccolor:0x212121&style=feature:administrative%7Celement:geometry%7Ccolor:0x757575&style=feature:administrative.country%7Celement:labels.text.fill%7Ccolor:0x9e9e9e&style=feature:administrative.land_parcel%7Cvisibility:off&style=feature:administrative.locality%7Celement:labels.text.fill%7Ccolor:0xbdbdbd&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0x757575&style=feature:poi.park%7Celement:geometry%7Ccolor:0x181818&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x616161&style=feature:poi.park%7Celement:labels.text.stroke%7Ccolor:0x1b1b1b&style=feature:road%7Celement:geometry.fill%7Ccolor:0x2c2c2c&style=feature:road%7Celement:labels.text.fill%7Ccolor:0x8a8a8a&style=feature:road.arterial%7Celement:geometry%7Ccolor:0x373737&style=feature:road.highway%7Celement:geometry%7Ccolor:0x3c3c3c&style=feature:road.highway.controlled_access%7Celement:geometry%7Ccolor:0x4e4e4e&style=feature:road.local%7Celement:labels.text.fill%7Ccolor:0x616161&style=feature:transit%7Celement:labels.text.fill%7Ccolor:0x757575&style=feature:water%7Celement:geometry%7Ccolor:0x000000&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x3d3d3d',
'night' => 'element:geometry%7Ccolor:0x242f3e&style=element:labels.text.fill%7Ccolor:0x746855&style=element:labels.text.stroke%7Ccolor:0x242f3e&style=feature:administrative.locality%7Celement:labels.text.fill%7Ccolor:0xd59563&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0xd59563&style=feature:poi.park%7Celement:geometry%7Ccolor:0x263c3f&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x6b9a76&style=feature:road%7Celement:geometry%7Ccolor:0x38414e&style=feature:road%7Celement:geometry.stroke%7Ccolor:0x212a37&style=feature:road%7Celement:labels.text.fill%7Ccolor:0x9ca5b3&style=feature:road.highway%7Celement:geometry%7Ccolor:0x746855&style=feature:road.highway%7Celement:geometry.stroke%7Ccolor:0x1f2835&style=feature:road.highway%7Celement:labels.text.fill%7Ccolor:0xf3d19c&style=feature:transit%7Celement:geometry%7Ccolor:0x2f3948&style=feature:transit.station%7Celement:labels.text.fill%7Ccolor:0xd59563&style=feature:water%7Celement:geometry%7Ccolor:0x17263c&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x515c6d&style=feature:water%7Celement:labels.text.stroke%7Ccolor:0x17263c',
'aubergine' => 'element:geometry%7Ccolor:0x1d2c4d&style=element:labels.text.fill%7Ccolor:0x8ec3b9&style=element:labels.text.stroke%7Ccolor:0x1a3646&style=feature:administrative.country%7Celement:geometry.stroke%7Ccolor:0x4b6878&style=feature:administrative.land_parcel%7Celement:labels.text.fill%7Ccolor:0x64779e&style=feature:administrative.province%7Celement:geometry.stroke%7Ccolor:0x4b6878&style=feature:landscape.man_made%7Celement:geometry.stroke%7Ccolor:0x334e87&style=feature:landscape.natural%7Celement:geometry%7Ccolor:0x023e58&style=feature:poi%7Celement:geometry%7Ccolor:0x283d6a&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0x6f9ba5&style=feature:poi%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:poi.park%7Celement:geometry.fill%7Ccolor:0x023e58&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x3C7680&style=feature:road%7Celement:geometry%7Ccolor:0x304a7d&style=feature:road%7Celement:labels.text.fill%7Ccolor:0x98a5be&style=feature:road%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:road.highway%7Celement:geometry%7Ccolor:0x2c6675&style=feature:road.highway%7Celement:geometry.stroke%7Ccolor:0x255763&style=feature:road.highway%7Celement:labels.text.fill%7Ccolor:0xb0d5ce&style=feature:road.highway%7Celement:labels.text.stroke%7Ccolor:0x023e58&style=feature:transit%7Celement:labels.text.fill%7Ccolor:0x98a5be&style=feature:transit%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:transit.line%7Celement:geometry.fill%7Ccolor:0x283d6a&style=feature:transit.station%7Celement:geometry%7Ccolor:0x3a4762&style=feature:water%7Celement:geometry%7Ccolor:0x0e1626&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x4e6d70',
],
];
Binary file added dist/images/layers-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/images/layers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/images/marker-icon-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/images/marker-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/images/marker-shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0a3a5bb

Please sign in to comment.