Skip to content

Commit

Permalink
Merge pull request #45 from mostafaznv/dev
Browse files Browse the repository at this point in the history
feat: capture a screenshot
  • Loading branch information
mostafaznv authored Nov 11, 2023
2 parents e5a87c8 + b319b81 commit 084caa5
Show file tree
Hide file tree
Showing 25 changed files with 990 additions and 201 deletions.
128 changes: 92 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,43 +123,42 @@ Therefore, if you decide to use my packages, please kindly consider making a don
5. ##### Done
----
## Map Field Methods
| method | Arguments | description |
|-----------------------------|------------------------------------------|--------------------------------------------------------------------------------|
| templateUrl | url <br> `string` | Specifies template of map |
| projection | projection <br> `string` | Specifies projection of map |
| srid | srid <br> `integer` `default: 0` | Specifies SRID of map |
| defaultLatitude | latitude <br> `float` | Specifies latitude of map on page load |
| defaultLongitude | longitude <br> `float` | Specifies longitude of map on page load |
| zoom | zoom <br> `integer` | Specifies default map zoom |
| withoutZoomControl | status <br> `bool` `default: true` | Specifies whether zoom in/out button should display on map or not |
| withoutZoomSlider | status <br> `bool` `default: true` | Specifies whether zoom slider should display on map or not |
| withFullScreenControl | status <br> `bool` `default: true` | Specifies whether full screen button should display on map or not |
| mapHeight | height <br> `integer` `default: 400` | Map's height |
| hideDetailButton | status <br> `bool` `default: true` | Specifies whether **Show Details** button should appear on detail pages or not |
| markerIcon | icon <br> `integer` `available: 1, 2, 3` | Marker icon |
| withSearchBox | `boolean` | Specifies whether map has search box or not |
| searchProvider | provider `MapSearchProvider` | |
| searchProviderApiKey | apiKey `string` | Specifies api key for search provider, if needed |
| withAutocompleteSearch | status `bool` `default: true` | Specifies whether search results should load immediately or not |
| searchAutocompleteMinLength | minLength `int` | Specifies the minimum number of characters to trigger search action |
| searchAutocompleteTimeout | timeout `int` | Specifies the minimum number of ms to wait before triggering search action |
| searchLanguage | language `string` | Specifies preferable language |
| searchPlaceholder | placeholder `string` | |
| searchBoxType | type `MapSearchBoxType` | Using this item, you can specify type of search box (button, or text-field |
| searchResultLimit | limit `int` | Specifies limit of results |
| searchResultKeepOpen | status `boolean` | Specifies whether the results keep opened |
| withTransformation | status `boolean` | Specifies whether transport feature should be enable on polygons |
| transformScale | status `boolean` | Using this method, you can enable/disable scaling features |
| transformRotate | status `boolean` | Using this method, you can enable/disable rotating features |
| transformStretch | status `boolean` | Using this method, you can enable/disable stretch option |
| requiredOnCreate | status <br> `bool` `default: true` | Makes field required on creation |
| requiredOnUpdate | status <br> `bool` `default: true` | Makes field required on update |
| default | $callback <br> `PointValue` | Set default value for map field. <br>**Note:** Only works in `MapPointField` |
| method | Arguments | description |
|-----------------------------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| templateUrl | url <br> `string` | Specifies template of map |
| projection | projection <br> `string` | Specifies projection of map |
| srid | srid <br> `integer` `default: 0` | Specifies SRID of map |
| defaultLatitude | latitude <br> `float` | Specifies latitude of map on page load |
| defaultLongitude | longitude <br> `float` | Specifies longitude of map on page load |
| zoom | zoom <br> `integer` | Specifies default map zoom |
| withoutZoomControl | status <br> `bool` `default: true` | Specifies whether zoom in/out button should display on map or not |
| withoutZoomSlider | status <br> `bool` `default: true` | Specifies whether zoom slider should display on map or not |
| withFullScreenControl | status <br> `bool` `default: true` | Specifies whether full screen button should display on map or not |
| mapHeight | height <br> `integer` `default: 400` | Map's height |
| hideDetailButton | status <br> `bool` `default: true` | Specifies whether **Show Details** button should appear on detail pages or not |
| markerIcon | icon <br> `integer` `available: 1, 2, 3` | Marker icon |
| withSearchBox | `boolean` | Specifies whether map has search box or not |
| searchProvider | provider `MapSearchProvider` | |
| searchProviderApiKey | apiKey `string` | Specifies api key for search provider, if needed |
| withAutocompleteSearch | status `bool` `default: true` | Specifies whether search results should load immediately or not |
| searchAutocompleteMinLength | minLength `int` | Specifies the minimum number of characters to trigger search action |
| searchAutocompleteTimeout | timeout `int` | Specifies the minimum number of ms to wait before triggering search action |
| searchLanguage | language `string` | Specifies preferable language |
| searchPlaceholder | placeholder `string` | |
| searchBoxType | type `MapSearchBoxType` | Using this item, you can specify type of search box (button, or text-field |
| searchResultLimit | limit `int` | Specifies limit of results |
| searchResultKeepOpen | status `boolean` | Specifies whether the results keep opened |
| withTransformation | status `boolean` | Specifies whether transport feature should be enable on polygons |
| transformScale | status `boolean` | Using this method, you can enable/disable scaling features |
| transformRotate | status `boolean` | Using this method, you can enable/disable rotating features |
| transformStretch | status `boolean` | Using this method, you can enable/disable stretch option |
| requiredOnCreate | status <br> `bool` `default: true` | Makes field required on creation |
| requiredOnUpdate | status <br> `bool` `default: true` | Makes field required on update |
| default | $callback <br> `PointValue` | Set default value for map field. <br>**Note:** Only works in `MapPointField` |
| capture | capture <br> `Capture` `experimental` | By employing this method, you can capture a screenshot reflecting the current state of the map field and save it to the filesystem |
## Config Properties
Expand Down Expand Up @@ -198,13 +197,60 @@ Therefore, if you decide to use my packages, please kindly consider making a don
| transform.scale | bool | true | Using this property, you can toggle rotating features |
| transform.stretch | bool | true | Using this property, you can enable/disable stretch option |
----
## Capture Screenshot
Utilizing this method enables the capture of a screenshot that mirrors the current state of the map field, subsequently saving it to the filesystem. It is important to note that this feature is `experimental` and its performance may vary. The underlying mechanism operates by generating an image on the client's machine each time the client/admin modifies the map field state. Subsequently, this image is transmitted to the server, where it is then stored in the filesystem.
To enable this feature, you must first add the `capture` method to your map field. This method accepts a single argument, which is an instance of the `Capture` class.
```php
<?php
namespace App\Nova\Resources;
use App\Nova\Resource;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use App\Models\Location as Model;
use Mostafaznv\NovaMapField\DTOs\Capture;
use Mostafaznv\NovaMapField\Fields\MapPointField;
class Location extends Resource
{
public static string $model = Model::class;
public function fields(Request $request): array
{
return [
ID::make()->sortable(),
MapPointField::make(trans('Location'), 'location')
->capture(
Capture::make('location_screenshot', 600, 600)
->disk('location')
->maxZoom(9)
->padding([10, 10, 10, 10])
->nearest(true)
->prunable(true)
),
Image::make(trans('Location Screenshot'), 'location_screenshot')
->disk('location')
->prunable()
->exceptOnForms(),
];
}
}
```
> [!NOTE]
> Activating this feature is as straightforward as calling the static `make` function of `Capture`. Nevertheless, for those seeking to tailor the behavior of this functionality, alternative methods are available for customization.
## Using Spatial Columns over Application
This package uses [Laravel Eloquent Spatial](https://github.com/MatanYadaev/laravel-eloquent-spatial/) under the hood. to use columns and querying them over the application, please read **Laravel Eloquent Spatial** documentation
----
## Tricks
Expand All @@ -230,6 +276,7 @@ use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use App\Models\Location as Model;
use Mostafaznv\NovaMapField\DTOs\Capture;
use Mostafaznv\NovaMapField\DTOs\MapSearchBoxType;
use Mostafaznv\NovaMapField\DTOs\MapSearchProvider;
use Mostafaznv\NovaMapField\DTOs\PointValue;
Expand Down Expand Up @@ -280,6 +327,15 @@ class Location extends Resource
->requiredOnCreate()
->requiredOnUpdate()
->stacked()
->capture(
Capture::make('location_screenshot', 600, 600)
->disk('location')
->maxZoom(9)
->padding([10, 10, 10, 10])
->nearest(true)
->prunable(true)
)
->default(
PointValue::make(51.5887845, 4.7760237)
),
Expand Down
2 changes: 1 addition & 1 deletion dist/field.js

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions dist/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ PERFORMANCE OF THIS SOFTWARE.

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/**
* @license
Copyright (c) 2008, Adobe Systems Incorporated
Expand Down Expand Up @@ -215,15 +217,6 @@ PERFORMANCE OF THIS SOFTWARE.
* http://opensource.org/licenses/mit-license
*/

/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/

/**
* @license
* Unicode Bidi Engine based on the work of Alex Shensis (@asthensis)
Expand Down
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/field.css": "/field.css?id=0b29f4e7358b74e4b94d6e9a649b58e6",
"/field.js": "/field.js?id=6bbf46af552c44e8c0d6f02e89f152a7",
"/field.js": "/field.js?id=f64606caf6305ae78dc87eab0dcfa0a9",
"/vendor/nova-map-field/dist/images/ic-pin-1.png": "/vendor/nova-map-field/dist/images/ic-pin-1.png?id=400bb8273d9fe0a31d86e144ef534856",
"/vendor/nova-map-field/dist/images/ic-pin-2.png": "/vendor/nova-map-field/dist/images/ic-pin-2.png?id=e084fdbb00a78f7e6d53819e518e64ec",
"/vendor/nova-map-field/dist/images/ic-pin-3.png": "/vendor/nova-map-field/dist/images/ic-pin-3.png?id=19780e69e0b6125989e3209759e51997"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"vue": "^3.2.37",
"vue-loader": "^16.8.3",
"vue-template-compiler": "^2.6.14",
"vue3-openlayers": "^3.0.0"
"vue3-openlayers": "^3.1.0"
}
}
Loading

0 comments on commit 084caa5

Please sign in to comment.