Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Add documentation, tile layer provider customization, search provider…
Browse files Browse the repository at this point in the history
… customization
  • Loading branch information
mikebronner committed Jun 23, 2019
1 parent 4e1748a commit 93a209c
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 8 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]

## [0.1.1] - 2019-06-23
### Added
- option to customize tile provider.
- option to customize search provider.
- documentation.

## [0.1.0] - 2019-06-22
### Added
- initial functionality.
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# How to contribute
We welcome everyone to submit pull requests with:
- issue fixes
- change suggestions
- documentation updates

However, not every pull request will automatically be accepted. I will review each carefully to make sure it is in line with
the direction I want the package to continue in. This might mean that some pull requests are not accepted, or might stay
unmerged until a place for them can be determined.

## Testing
- [ ] After making your changes, make sure the tests still pass.
- [ ] When adding new functionality, also add new tests.
- [ ] When fixing errors write and satisfy new unit tests that replicate the issue.
- [ ] Make sure there are no build errors.
- [ ] All code must past PHPCS and PHPMD PSR2 validation.

## Submitting changes
When submitting a pull request, it is important to make sure to complete the following:
- [ ] Add a descriptive header that explains in a single sentence what problem the PR solves.
- [ ] Add a detailed description with animated screen-grab GIFs visualizing how it works.
- [ ] Explain why you think it should be implemented one way vs. another, highlight performance improvements, etc.

## Coding conventions
Start reading our code and you'll get the hang of it. We optimize for readability:
- indent using four spaces (soft tabs)
- use Blade for all views
- avoid logic in views, put it in controllers or service classes
- ALWAYS put spaces after list items and method parameters (`[1, 2, 3]`, not `[1,2,3]`), around operators (`x += 1`, not `x+=1`), and around hash arrows.
- this is open source software. Consider the people who will read your code, and make it look nice for them. It's sort of like driving a car: Perhaps you love doing donuts when you're alone, but with passengers the goal is to make the ride as smooth as possible.
- emphasis readability of code over patterns to reduce mental debt
- always add an empty line around structures (if statements, loops, etc.)

Thanks!
Mike Bronner, GeneaLabs
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 GeneaLabs, LLC

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.
84 changes: 83 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,83 @@
# nova-map-marker-field
# Map Marker Field for Laravel Nova
[![GitHub (pre-)release](https://img.shields.io/github/release/GeneaLabs/nova-map-marker-field/all.svg)](https://github.com/GeneaLabs/nova-map-marker-field)
[![Packagist](https://img.shields.io/packagist/dt/GeneaLabs/nova-map-marker-field.svg)](https://packagist.org/packages/genealabs/nova-map-marker-field)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/GeneaLabs/nova-map-marker-field/master/LICENSE)

## Supporting This Package
This is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider [becoming a backer or sponsor on Patreon](https://www.patreon.com/mikebronner).

## Installation
1. Install the package:
```sh
composer require genealabs/nova-map-marker-field
```

2. Publish the marker icon assets (this is not necessary if you are specifying
your own):
```sh
php artisan vendor:publish --provider="GeneaLabs\NovaMapMarkerField\Providers\Service"
```

## Usage
To create the map marker field, all that is necessary is the form label, and the
remaining options will have defaults applied:
```php
MapMarker::make("Location"),
```

### Model Fields
By default the field will look for `latitude` and `longitude` fields on the
model. However, if your model uses different names, you may customize them with
the `->latitude('lat')` and `->longitude('long')` methods:
```php
MapMarker::make("Location")
->latitude('lat')
->longitude('long'),
```

### Search Provider
The underlying search capabilities are provided by
[leaflet-geosearch](https://github.com/smeijer/leaflet-geosearch). Please refer
to their documentation for provider configuration. By default we use the
ESRI search provider.
```php
MapMarker::make("Location")
->searchProvider('google')
->searchProviderKey('xxxxxxxxxxxxxxxxxxxxxxxxxxx'),
```

### Tile Layer
You are free to use any tile provider that is compatible with
[Leaflet](https://leafletjs.com/reference-1.5.0.html#tilelayer). Please refer to
their documentation on tile layer URLs. By default we use tiles provided by
OpenStreetMap:
```php
MapMarker::make("Location")
->tileProvider('http://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png'),
```

## Commitment to Quality
During package development I try as best as possible to embrace good design and development practices, to help ensure that this package is as good as it can
be. My checklist for package development includes:

- ✅ Achieve as close to 100% code coverage as possible using unit tests.
- ✅ Eliminate any issues identified by SensioLabs Insight and Scrutinizer.
- ✅ Be fully PSR1, PSR2, and PSR4 compliant.
- ✅ Include comprehensive documentation in README.md.
- ✅ Provide an up-to-date CHANGELOG.md which adheres to the format outlined
at <http://keepachangelog.com>.
- ✅ Have no PHPMD or PHPCS warnings throughout all code.

## Contributing
Please observe and respect all aspects of the included Code of Conduct <https://github.com/GeneaLabs/nova-map-marker-field/blob/master/CODE_OF_CONDUCT.md>.

### Reporting Issues
When reporting issues, please fill out the included template as completely as
possible. Incomplete issues may be ignored or closed if there is not enough
information included to be actionable.

### Submitting Pull Requests
Please review the Contribution Guidelines <https://github.com/GeneaLabs/nova-map-marker-field/blob/master/CONTRIBUTING.md>. Only PRs that meet all criterium will be accepted.

## If you ❤️ open-source software, give the repos you use a ⭐️.
We have included the awesome `symfony/thanks` composer package as a dev dependency. Let your OS package maintainers know you appreciate them by starring the packages you use. Simply run composer thanks after installing this package. (And not to worry, since it's a dev-dependency it won't be installed in your live environment.)
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"require": {
"laravel/nova": "2.*",
"php": ">=7.1.0"
"php": ">=7.1.0",
"symfony/thanks": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
data: function () {
return {
url: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
tileUrl: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
mapOptions: {
boxZoom: false,
doubleClickZoom: false,
Expand All @@ -35,6 +35,12 @@ export default {
};
},
created: function () {
if (this.field.tileProvider !== undefined) {
this.tileUrl = this.field.tileProvider;
}
},
computed: {
mapCenter: function () {
if (this.value.latitude === undefined) {
Expand Down Expand Up @@ -100,7 +106,7 @@ export default {
@move="mapMoved"
>
<l-tile-layer
:url="url"
:url="tileUrl"
></l-tile-layer>
<l-marker
:options="markerOptions"
Expand Down
30 changes: 27 additions & 3 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { FormField, HandlesValidationErrors } from 'laravel-nova';
import L from "leaflet";
import { LMap, LTileLayer, LMarker, LIcon } from 'vue2-leaflet';
import { EsriProvider } from 'leaflet-geosearch';
import { BingProvider, EsriProvider, GoogleProvider, LocationIQProvider, OpenCageProvider, OpenStreetMapProvider } from 'leaflet-geosearch';
import VGeosearch from 'vue2-leaflet-geosearch';
delete L.Icon.Default.prototype._getIconUrl;
Expand All @@ -26,7 +26,7 @@ export default {
data: function () {
return {
url: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
tileUrl: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
geosearchOptions: {
provider: new EsriProvider(),
showMarker: false,
Expand All @@ -38,6 +38,30 @@ export default {
};
},
created: function () {
switch (this.field.searchProvider) {
case "bing":
this.geosearchOptions.provider = new BingProvider();
break;
case "google":
this.geosearchOptions.provider = new GoogleProvider();
break;
case "locationiq":
this.geosearchOptions.provider = new LocationIQProvider();
break;
case "opencage":
this.geosearchOptions.provider = new OpenCageProvider();
break;
case "openstreetmap":
this.geosearchOptions.provider = new OpenStreetMapProvider();
break;
}
if (this.field.tileProvider !== undefined) {
this.tileUrl = this.field.tileProvider;
}
},
computed: {
mapCenter: function () {
if (this.value.latitude === undefined) {
Expand Down Expand Up @@ -107,7 +131,7 @@ export default {
@move="mapMoved"
>
<l-tile-layer
:url="url"
:url="tileUrl"
></l-tile-layer>
<l-marker
:options="markerOptions"
Expand Down
25 changes: 25 additions & 0 deletions src/MapMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ public function longitude($field)
return $this->withMeta([__FUNCTION__ => $field]);
}

// public function markerIcon(string $url)
// {
// return $this->withMeta([__FUNCTION__ => $url]);
// }

// public function markerIconShadow(string $url)
// {
// return $this->withMeta([__FUNCTION__ => $url]);
// }

public function searchProvider(string $provider)
{
return $this->withMeta([__FUNCTION__ => $provider]);
}

public function searchProviderKey(string $key)
{
return $this->withMeta([__FUNCTION__ => $key]);
}

public function tileProvider(string $url)
{
return $this->withMeta([__FUNCTION__ => $url]);
}

public function resolve($resource, $attribute = null)
{
$attribute = $attribute ?? $this->attribute;
Expand Down

0 comments on commit 93a209c

Please sign in to comment.