mirror of
https://github.com/netzmacht/contao-leaflet-geocode-widget.git
synced 2025-11-29 20:23:39 +01:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b31c6ebad | ||
|
|
bad7175bab | ||
|
|
268372c12a | ||
|
|
accedc63e4 | ||
|
|
37f94737c5 | ||
|
|
03668e5852 | ||
|
|
c7e65d2db5 | ||
|
|
08acfbc473 | ||
|
|
99f080473b | ||
|
|
e7115cd227 | ||
|
|
1f556ba752 | ||
|
|
178520dd6f | ||
|
|
572b58edeb | ||
|
|
940b9b07f7 | ||
|
|
e47d2b0a9d | ||
|
|
229ff66f98 | ||
|
|
b6418dd2de | ||
|
|
617a996e0e | ||
|
|
be820179de | ||
|
|
a4c24a80c2 | ||
|
|
e7b930f4a1 | ||
|
|
76a0793efa | ||
|
|
67d39cc8c0 | ||
|
|
656ddc3089 | ||
|
|
c0ce2f4c5c | ||
|
|
e505651cd9 | ||
|
|
c3e034f161 | ||
|
|
047cc7b7cf | ||
|
|
c4517b2dec | ||
|
|
b7192d0972 | ||
|
|
5a56204a22 | ||
|
|
32e2c7578d | ||
|
|
e933eb0126 | ||
|
|
f4fc8c9fe5 | ||
|
|
1964dab9e8 |
11
.composer-require-checker.json
Normal file
11
.composer-require-checker.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"symbol-whitelist": [
|
||||||
|
"null", "true", "false",
|
||||||
|
"static", "self", "parent",
|
||||||
|
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
|
||||||
|
"Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface",
|
||||||
|
"Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig",
|
||||||
|
"Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface",
|
||||||
|
"Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig"
|
||||||
|
]
|
||||||
|
}
|
||||||
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.php]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.js]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[{*.vue,*.json,*.html5,*.xlf,*.twig}]
|
||||||
|
indent_size = 2
|
||||||
15
.gitattributes
vendored
Normal file
15
.gitattributes
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
.check-author.yml export-ignore
|
||||||
|
.gitattributes export-ignore
|
||||||
|
.github export-ignore
|
||||||
|
.gitignore export-ignore
|
||||||
|
.travis.yml export-ignore
|
||||||
|
build.default.properties export-ignore
|
||||||
|
build.xml export-ignore
|
||||||
|
phpunit.xml.dist export-ignore
|
||||||
|
/tests export-ignore
|
||||||
|
/specs export-ignore
|
||||||
|
.phpcq.lock export-ignore
|
||||||
|
.phpcq.yaml.dis export-ignore
|
||||||
|
psalm.xml export-ignore
|
||||||
|
phpcs.xml.dis export-ignore
|
||||||
|
composer.lock export-ignore
|
||||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
github: [dmolineus]
|
||||||
27
.github/dependabot.yaml
vendored
Normal file
27
.github/dependabot.yaml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- commit-message:
|
||||||
|
include: "scope"
|
||||||
|
prefix: "composer"
|
||||||
|
directory: "/"
|
||||||
|
labels:
|
||||||
|
- "dependency"
|
||||||
|
open-pull-requests-limit: 0
|
||||||
|
package-ecosystem: "composer"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
versioning-strategy: "increase"
|
||||||
|
|
||||||
|
- commit-message:
|
||||||
|
include: "scope"
|
||||||
|
prefix: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
labels:
|
||||||
|
- "dependency"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
package-ecosystem: "github-actions"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
75
.github/workflows/diagnostics.yml
vendored
Normal file
75
.github/workflows/diagnostics.yml
vendored
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
name: Code Quality Diagnostics
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- develop
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
name: PHP ${{ matrix.php }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: '7.4'
|
||||||
|
phpcq_install: 'install'
|
||||||
|
phpcq_flags: ''
|
||||||
|
- php: '8.0'
|
||||||
|
phpcq_install: 'update'
|
||||||
|
phpcq_flags: ''
|
||||||
|
- php: '8.1'
|
||||||
|
phpcq_install: 'update'
|
||||||
|
phpcq_flags: ''
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Pull source
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup PHP with PECL extension
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
coverage: xdebug2
|
||||||
|
|
||||||
|
- name: Cache composer cache directory
|
||||||
|
uses: actions/cache@v1
|
||||||
|
env:
|
||||||
|
cache-name: composer-cache-dir-${{ matrix.php }}
|
||||||
|
with:
|
||||||
|
path: ~/.cache/composer
|
||||||
|
key: ${{ runner.os }}-build-${{ env.cache-name }}
|
||||||
|
|
||||||
|
- name: Install composer dependencies
|
||||||
|
run: composer install
|
||||||
|
|
||||||
|
- name: Cache vendor directory of phpcq tool runner
|
||||||
|
uses: actions/cache@v1
|
||||||
|
env:
|
||||||
|
cache-name: vendor-${{ matrix.php }}
|
||||||
|
with:
|
||||||
|
path: $GITHUB_WORKSPACE/vendor
|
||||||
|
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
|
|
||||||
|
- name: Update phpcq
|
||||||
|
run: $GITHUB_WORKSPACE/vendor/bin/phpcq self-update --unsigned
|
||||||
|
|
||||||
|
- name: Install phpcq toolchain
|
||||||
|
run: $GITHUB_WORKSPACE/vendor/bin/phpcq ${{ matrix.phpcq_install }} -v
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: $GITHUB_WORKSPACE/vendor/bin/phpcq run -o github-action -o default ${{ matrix.phpcq_flags }} -v
|
||||||
|
|
||||||
|
- name: Upload build directory to artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
if: ${{ success() }} || ${{ failure() }}
|
||||||
|
with:
|
||||||
|
name: phpcq-builds-php-${{ matrix.php }}
|
||||||
|
path: .phpcq/build/
|
||||||
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,10 +1,10 @@
|
|||||||
/vendor/
|
# composer related
|
||||||
/bin/
|
vendor/
|
||||||
/demo/
|
|
||||||
/assets/js/*.js
|
|
||||||
/node_modules/
|
|
||||||
/.tx/
|
|
||||||
|
|
||||||
coverage.xml
|
|
||||||
composer.lock
|
composer.lock
|
||||||
npm-debug.log
|
|
||||||
|
# Translations
|
||||||
|
.tx
|
||||||
|
|
||||||
|
# phpcq
|
||||||
|
/.phpcq/
|
||||||
|
.phpcs-cache
|
||||||
|
|||||||
1
.phpcq.lock
Normal file
1
.phpcq.lock
Normal file
File diff suppressed because one or more lines are too long
96
.phpcq.yaml.dist
Normal file
96
.phpcq.yaml.dist
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
phpcq:
|
||||||
|
repositories:
|
||||||
|
- https://phpcq.github.io/repository/repository.json
|
||||||
|
directories:
|
||||||
|
- src
|
||||||
|
artifact: .phpcq/build
|
||||||
|
|
||||||
|
plugins:
|
||||||
|
composer-require-checker:
|
||||||
|
version: ^1.0
|
||||||
|
signed: false
|
||||||
|
phpmd:
|
||||||
|
version: ^1.0
|
||||||
|
signed: false
|
||||||
|
requirements:
|
||||||
|
phpmd:
|
||||||
|
signed: false
|
||||||
|
phpcpd:
|
||||||
|
version: ^1.1
|
||||||
|
signed: false
|
||||||
|
phploc:
|
||||||
|
version: ^1.0
|
||||||
|
signed: false
|
||||||
|
phpcs:
|
||||||
|
version: ^1.0
|
||||||
|
signed: false
|
||||||
|
composer-normalize:
|
||||||
|
version: ^1.0
|
||||||
|
signed: false
|
||||||
|
trusted-keys:
|
||||||
|
# composer-require-checker
|
||||||
|
- 033E5F8D801A2F8D
|
||||||
|
# sb@sebastian-bergmann.de
|
||||||
|
- 4AA394086372C20A
|
||||||
|
# psalm
|
||||||
|
- 8A03EA3B385DBAA1
|
||||||
|
- 12CE0F1D262429A5
|
||||||
|
# magl@magll.net
|
||||||
|
- D2CCAC42F6295E7D
|
||||||
|
# PHP_CodeSniffer
|
||||||
|
- 31C7E470E2138192
|
||||||
|
# Composer normalize
|
||||||
|
- C00543248C87FB13
|
||||||
|
# phpmd
|
||||||
|
- 0F9684B8B16B7AB0
|
||||||
|
- A4E55EA12C7C085C
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
fix:
|
||||||
|
- composer-normalize-fix
|
||||||
|
- phpcbf
|
||||||
|
|
||||||
|
verify:
|
||||||
|
- composer-require-checker
|
||||||
|
- composer-normalize
|
||||||
|
|
||||||
|
analyze:
|
||||||
|
- phploc
|
||||||
|
- phpcpd
|
||||||
|
- phpmd
|
||||||
|
- phpcs
|
||||||
|
# - psalm
|
||||||
|
|
||||||
|
default:
|
||||||
|
- verify
|
||||||
|
- analyze
|
||||||
|
|
||||||
|
composer-require-checker:
|
||||||
|
config:
|
||||||
|
config_file: '.composer-require-checker.json'
|
||||||
|
|
||||||
|
phpcs:
|
||||||
|
plugin: phpcs
|
||||||
|
config: &phpcs-config
|
||||||
|
standard: ~
|
||||||
|
standard_paths:
|
||||||
|
- ./vendor/slevomat/coding-standard
|
||||||
|
- ./vendor/doctrine/coding-standard/lib
|
||||||
|
excluded:
|
||||||
|
- src/Resources/contao/languages
|
||||||
|
|
||||||
|
phpcbf:
|
||||||
|
plugin: phpcs
|
||||||
|
config:
|
||||||
|
<<: *phpcs-config
|
||||||
|
fix: true
|
||||||
|
|
||||||
|
composer-normalize:
|
||||||
|
config:
|
||||||
|
ignore_output:
|
||||||
|
- '#Root package is not of type "project", we will not installing Contao extensions\.#'
|
||||||
|
|
||||||
|
composer-normalize-fix:
|
||||||
|
plugin: composer-normalize
|
||||||
|
config:
|
||||||
|
dry_run: false
|
||||||
37
CHANGELOG.md
Normal file
37
CHANGELOG.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
Changelog
|
||||||
|
=========
|
||||||
|
|
||||||
|
Version 1.4.0 (2022-11-29)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/netzmacht/contao-leaflet-geocode-widget/compare/1.3.0...1.4.0)
|
||||||
|
|
||||||
|
- Support PHP 8 and Contao 5
|
||||||
|
- Update coding standard
|
||||||
|
|
||||||
|
Version 1.3.0 (2018-02-13)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/netzmacht/contao-leaflet-geocode-widget/compare/1.2.1...1.3.0)
|
||||||
|
|
||||||
|
- Move apply button to the modal footer.
|
||||||
|
- Deprecate `Netzmacht\Contao\Leaflet\GeocodeWidget`. Use `Netzmacht\Contao\Leaflet\Widget\GeocodeWidget` instead.
|
||||||
|
- Add feature to adjust a radius.
|
||||||
|
- Allow Contao 4.5.0.
|
||||||
|
|
||||||
|
Version 1.2.0 (2017-11-13)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/netzmacht/contao-leaflet-geocode-widget/compare/1.1.0...1.2.0)
|
||||||
|
|
||||||
|
- Allow multiple elements
|
||||||
|
|
||||||
|
Version 1.1.0
|
||||||
|
-------------
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/netzmacht/contao-leaflet-geocode-widget/compare/1.0.0...1.1.0)
|
||||||
|
|
||||||
|
- Add wizard class using an extra div wrapper
|
||||||
|
- Require Contao 4.4.2 (BC break in Contao see #1)
|
||||||
|
- Apply coding standards
|
||||||
165
LICENSE
Normal file
165
LICENSE
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
69
README.md
69
README.md
@@ -1,13 +1,23 @@
|
|||||||
Leaflet geocode widget
|
Leaflet geocode widget
|
||||||
======================
|
======================
|
||||||
|
|
||||||
This extension provides an widget to pick coordinates from a map. It uses the leaflet framework.
|
[](https://github.com/netzmacht/contao-leaflet-geocode-widget/actions)
|
||||||
|
[](http://packagist.org/packages/netzmacht/contao-leaflet-geocode-widget)
|
||||||
|
[](http://packagist.org/packages/netzmacht/contao-leaflet-geocode-widget)
|
||||||
|
[](http://packagist.org/packages/netzmacht/contao-leaflet-geocode-widget)
|
||||||
|
|
||||||
|
This extension provides a widget to pick coordinates from a map. It uses the leaflet framework.
|
||||||
|
|
||||||
|
Changlog
|
||||||
|
--------
|
||||||
|
|
||||||
|
See [CHANGELOG](CHANGELOG.md).
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Contao 4.3
|
- Contao ^4.13||^5.0
|
||||||
|
- PHP ^7.4||^8.0
|
||||||
|
|
||||||
|
|
||||||
Install
|
Install
|
||||||
@@ -28,7 +38,7 @@ If you use the managed edition of Contao you can skip this step.
|
|||||||
|
|
||||||
// Dependency is automatically installed and has to be registered
|
// Dependency is automatically installed and has to be registered
|
||||||
new Contao\CoreBundle\HttpKernel\Bundle\ContaoModuleBundle('leaflet-libs', $this->getRootDir()),
|
new Contao\CoreBundle\HttpKernel\Bundle\ContaoModuleBundle('leaflet-libs', $this->getRootDir()),
|
||||||
|
|
||||||
// Register the bundle
|
// Register the bundle
|
||||||
new Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle(),
|
new Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle(),
|
||||||
```
|
```
|
||||||
@@ -41,12 +51,63 @@ bin/console assets:install --symlink
|
|||||||
|
|
||||||
### 4. Use the widget
|
### 4. Use the widget
|
||||||
|
|
||||||
|
#### Coordinates only
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$GLOBALS['TL_DCA']['tl_example']['fields']['coordinates'] = [
|
$GLOBALS['TL_DCA']['tl_example']['fields']['coordinates'] = [
|
||||||
'label' => ['Koordinaten', 'Geben Sie die Koordinaten ein'],
|
'label' => ['Koordinaten', 'Geben Sie die Koordinaten ein'],
|
||||||
'inputType' => 'leaflet_geocode',
|
'inputType' => 'leaflet_geocode',
|
||||||
'eval' => [
|
'eval' => [
|
||||||
'tl_class' => 'w50 wizard',
|
'tl_class' => 'w50',
|
||||||
|
],
|
||||||
|
'sql' => 'varchar(255) NOT NULL default \'\''
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Coordinates and radius
|
||||||
|
|
||||||
|
To pick the radius in meters as well, you have to configure the `eval.radius` option for the related radius field.
|
||||||
|
The radius field should be a simle text input. The `default`, `minval` and `maxval` flags are passed to the geocode
|
||||||
|
widget so that only radius in that boundary can be chosen.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$GLOBALS['TL_DCA']['tl_page']['fields']['coordinates'] = [
|
||||||
|
'label' => ['Koordinaten', 'Geben Sie die Koordinaten ein'],
|
||||||
|
'inputType' => 'leaflet_geocode',
|
||||||
|
'eval' => [
|
||||||
|
'tl_class' => 'w50',
|
||||||
|
'radius' => 'radius'
|
||||||
|
],
|
||||||
|
'sql' => 'varchar(255) NOT NULL default \'\''
|
||||||
|
];
|
||||||
|
|
||||||
|
$GLOBALS['TL_DCA']['tl_page']['fields']['radius'] = [
|
||||||
|
'label' => ['Radius', 'Angabe des Radius in Metern'],
|
||||||
|
'inputType' => 'leaflet_radius', // Optional, you can use a text widget as well
|
||||||
|
'eval' => [
|
||||||
|
'default' => 500,
|
||||||
|
'minval' => 100,
|
||||||
|
'maxval' => 5000,
|
||||||
|
'steps' => 100, // Round value to the closest 100m.
|
||||||
|
'tl_class' => 'w50',
|
||||||
|
],
|
||||||
|
'sql' => 'varchar(255) NOT NULL default \'\''
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to add an wizard icon to the radius field as well, you only have to reference the coordinates field.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$GLOBALS['TL_DCA']['tl_page']['fields']['radius'] = [
|
||||||
|
'label' => ['Radius', 'Angabe des Radius in Metern'],
|
||||||
|
'inputType' => 'leaflet_radius',
|
||||||
|
'eval' => [
|
||||||
|
'rgxp' => 'natural',
|
||||||
|
'default' => 500,
|
||||||
|
'minval' => 100,
|
||||||
|
'maxval' => 5000,
|
||||||
|
'tl_class' => 'w50 wizard',
|
||||||
|
'coordinates' => 'coordinates'
|
||||||
],
|
],
|
||||||
'sql' => 'varchar(255) NOT NULL default \'\''
|
'sql' => 'varchar(255) NOT NULL default \'\''
|
||||||
];
|
];
|
||||||
|
|||||||
111
composer.json
111
composer.json
@@ -1,56 +1,63 @@
|
|||||||
{
|
{
|
||||||
"name": "netzmacht/contao-leaflet-geocode-widget",
|
"name": "netzmacht/contao-leaflet-geocode-widget",
|
||||||
"description": "Geocode widget based on Leaflet",
|
"description": "Geocode widget based on Leaflet",
|
||||||
"keywords": [
|
"license": "LGPL-3.0-or-later",
|
||||||
"geocode",
|
"type": "contao-bundle",
|
||||||
"contao",
|
"keywords": [
|
||||||
"widget",
|
"geocode",
|
||||||
"leaflet"
|
"contao",
|
||||||
],
|
"widget",
|
||||||
"type": "contao-bundle",
|
"leaflet"
|
||||||
"license": "LGPL-3.0+",
|
],
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "David Molineus",
|
"name": "David Molineus",
|
||||||
"email": "mail@netzmacht.de",
|
"email": "mail@netzmacht.de",
|
||||||
"homepage": "http://www.netzmacht.de",
|
"homepage": "https://netzmacht.de",
|
||||||
"role": "Project leader"
|
"role": "Developer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"email": "mail@netzmacht.de",
|
"email": "mail@netzmacht.de",
|
||||||
"issues": "https://github.com/contao-bootstrap/core/issues",
|
"issues": "https://github.com/netzmacht/contao-leaflet-geocode-widget/issues",
|
||||||
"wiki": "http://contao-bootstrap.netzmacht.de",
|
"source": "https://github.com/netzmacht/contao-leaflet-geocode-widget"
|
||||||
"source": "https://github.com/contao-bootstrap/core"
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.4 || ^8.0",
|
||||||
|
"contao/core-bundle": "^4.13 || ^5.0",
|
||||||
|
"netzmacht/contao-leaflet-libraries": "~1.3",
|
||||||
|
"symfony/config": "^5.4 || ^6.0",
|
||||||
|
"symfony/dependency-injection": "^5.4 || ^6.0",
|
||||||
|
"symfony/http-kernel": "^5.4 || ^6.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"contao/manager-plugin": "^2.0",
|
||||||
|
"doctrine/coding-standard": "^9.0",
|
||||||
|
"phpcq/runner-bootstrap": "1.x-dev",
|
||||||
|
"phpspec/phpspec": "^6.3.0 || ^7.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"netzmacht/contao-leaflet-maps": "Leaflet Maps for Contao"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"contao-components/installer": true,
|
||||||
|
"contao/manager-plugin": true,
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||||
|
"contao-community-alliance/composer-plugin": true
|
||||||
},
|
},
|
||||||
"require": {
|
"sort-packages": true
|
||||||
"php": ">=5.5.0",
|
},
|
||||||
"contao/core-bundle": "~4.3",
|
"extra": {
|
||||||
"contao-community-alliance/composer-plugin": "~2.4 || ~3.0",
|
"branch-alias": {
|
||||||
"netzmacht/contao-leaflet-libraries": "~1.0"
|
"dev-develop": "1.5.x-dev",
|
||||||
|
"dev-master": "1.4.x-dev"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin"
|
||||||
"netzmacht/contao-build-tools": "~1.1",
|
}
|
||||||
"contao/manager-plugin": "^2.0"
|
|
||||||
},
|
|
||||||
"conflict": {
|
|
||||||
"contao/manager-plugin": "<2.0 || >=3.0"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"netzmacht/contao-leaflet-maps": "Leaflet Maps for Contao"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "1.0.x-dev",
|
|
||||||
"dev-develop": "1.1.x-dev"
|
|
||||||
},
|
|
||||||
"contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin"
|
|
||||||
},
|
|
||||||
"minimum-stability": "dev",
|
|
||||||
"prefer-stable": true
|
|
||||||
}
|
}
|
||||||
|
|||||||
102
phpcs.xml.dist
Normal file
102
phpcs.xml.dist
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset>
|
||||||
|
<arg name="basepath" value="."/>
|
||||||
|
<arg name="extensions" value="php"/>
|
||||||
|
<arg name="parallel" value="80"/>
|
||||||
|
<arg name="cache" value=".phpcs-cache"/>
|
||||||
|
<arg name="colors"/>
|
||||||
|
|
||||||
|
<!-- Required for the SlevomatCodingStandard which utilizes composer dependencies -->
|
||||||
|
<autoload>vendor/autoload.php</autoload>
|
||||||
|
|
||||||
|
<!-- Ignore warnings, show progress of the run and show sniff names -->
|
||||||
|
<arg value="nps"/>
|
||||||
|
|
||||||
|
<!-- Directories to be checked -->
|
||||||
|
<file>src</file>
|
||||||
|
|
||||||
|
<!-- Include full Doctrine Coding Standard -->
|
||||||
|
<rule ref="Doctrine">
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="Generic.Files.LineLength">
|
||||||
|
<properties>
|
||||||
|
<property name="lineLimit" value="120"/>
|
||||||
|
<property name="absoluteLineLimit" value="120"/>
|
||||||
|
</properties>
|
||||||
|
<exclude-pattern>src/Resources/contao/languages/*</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
|
||||||
|
<properties>
|
||||||
|
<property name="enableObjectTypeHint" value="false" />
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
|
||||||
|
<properties>
|
||||||
|
<property name="enableMixedTypeHint" value="false" />
|
||||||
|
<property name="enableUnionTypeHint" value="false" />
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
|
||||||
|
<properties>
|
||||||
|
<property name="enableStaticTypeHint" value="false" />
|
||||||
|
<property name="enableMixedTypeHint" value="false" />
|
||||||
|
<property name="enableUnionTypeHint" value="false" />
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
|
||||||
|
<exclude-pattern>spec/.*\.php</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->
|
||||||
|
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
|
||||||
|
<properties>
|
||||||
|
<property name="linesCountBeforeFirstContent" value="0"/>
|
||||||
|
<property name="linesCountAfterLastContent" value="0"/>
|
||||||
|
<property name="linesCountBetweenDescriptionAndAnnotations" value="1"/>
|
||||||
|
<property name="linesCountBetweenAnnotationsGroups" value="1"/>
|
||||||
|
<property name="annotationsGroups" type="array">
|
||||||
|
<element value="
|
||||||
|
@internal,
|
||||||
|
@deprecated,
|
||||||
|
"/>
|
||||||
|
<element value="
|
||||||
|
@template,
|
||||||
|
@psalm-template,
|
||||||
|
@template-implements,
|
||||||
|
@template-extends,
|
||||||
|
@implements,
|
||||||
|
@extends
|
||||||
|
"/>
|
||||||
|
<element value="
|
||||||
|
@link,
|
||||||
|
@see,
|
||||||
|
@uses,
|
||||||
|
"/>
|
||||||
|
<element value="
|
||||||
|
@ORM\,
|
||||||
|
@ODM\,
|
||||||
|
@PHPCR\,
|
||||||
|
"/>
|
||||||
|
<element value="
|
||||||
|
@param,
|
||||||
|
@psalm-param,
|
||||||
|
@phpstan-param,
|
||||||
|
"/>
|
||||||
|
<element value="
|
||||||
|
@return,
|
||||||
|
@psalm-return,
|
||||||
|
@phpstan-return,
|
||||||
|
"/>
|
||||||
|
<element value="@throws"/>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
</ruleset>
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
declare(strict_types=1);
|
||||||
* @package netzmacht
|
|
||||||
* @author David Molineus <david.molineus@netzmacht.de>
|
|
||||||
* @copyright 2017 netzmacht David Molineus. All rights reserved.
|
|
||||||
* @filesource
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager;
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager;
|
||||||
|
|
||||||
@@ -16,17 +10,12 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
|
|||||||
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
|
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
|
||||||
use Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle;
|
use Netzmacht\Contao\Leaflet\GeocodeWidget\LeafletGeocodeWidgetBundle;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Plugin
|
|
||||||
*
|
|
||||||
* @package Netzmacht\Contao\Leaflet\GeocodeWidget\ContaoManager
|
|
||||||
*/
|
|
||||||
class Plugin implements BundlePluginInterface
|
class Plugin implements BundlePluginInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getBundles(ParserInterface $parser)
|
public function getBundles(ParserInterface $parser): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
BundleConfig::create(LeafletGeocodeWidgetBundle::class)
|
BundleConfig::create(LeafletGeocodeWidgetBundle::class)
|
||||||
|
|||||||
28
src/DependencyInjection/LeafletGeocodeWidgetExtension.php
Normal file
28
src/DependencyInjection/LeafletGeocodeWidgetExtension.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\FileLocator;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||||
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
|
|
||||||
|
use function dirname;
|
||||||
|
|
||||||
|
class LeafletGeocodeWidgetExtension extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function load(array $configs, ContainerBuilder $container): void
|
||||||
|
{
|
||||||
|
$loader = new YamlFileLoader(
|
||||||
|
$container,
|
||||||
|
new FileLocator(dirname(__DIR__) . '/Resources/config')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loader->load('listeners.yml');
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/EventListener/RadiusWizardCallbackListener.php
Normal file
34
src/EventListener/RadiusWizardCallbackListener.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener;
|
||||||
|
|
||||||
|
use Contao\DataContainer;
|
||||||
|
|
||||||
|
use function sprintf;
|
||||||
|
|
||||||
|
class RadiusWizardCallbackListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generate the wizard for the radius widget.
|
||||||
|
*
|
||||||
|
* @param DataContainer $dataContainer Data container driver.
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.Superglobals)
|
||||||
|
*/
|
||||||
|
public function generateWizard(DataContainer $dataContainer): string
|
||||||
|
{
|
||||||
|
$fields = $GLOBALS['TL_DCA'][$dataContainer->table]['fields'];
|
||||||
|
|
||||||
|
if (! isset($fields[$dataContainer->field]['eval']['coordinates'])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'<a href="#" onclick="$(\'ctrl_%s_toggle\').click();return false;"><img src="%s"></a>',
|
||||||
|
$GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'],
|
||||||
|
'bundles/leafletgeocodewidget/img/map.png'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,104 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
declare(strict_types=1);
|
||||||
* @package netzmacht
|
|
||||||
* @author David Molineus <david.molineus@netzmacht.de>
|
|
||||||
* @copyright 2017 netzmacht David Molineus. All rights reserved.
|
|
||||||
* @filesource
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
|
||||||
|
|
||||||
/**
|
use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget as BaseWidget;
|
||||||
* Class GeocodeWidget
|
|
||||||
*
|
class GeocodeWidget extends BaseWidget
|
||||||
* @package Netzmacht\Contao\Leaflet\GeocodeWidget
|
|
||||||
*/
|
|
||||||
class GeocodeWidget extends \Widget
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Submit user input.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
*/
|
||||||
protected $blnSubmitInput = true;
|
public function __construct(?array $arrAttributes = null)
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a for attribute.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
protected $blnForAttribute = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $strTemplate = 'be_widget';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template name.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $widgetTemplate = 'be_widget_leaflet_geocode';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the input.
|
|
||||||
*
|
|
||||||
* @param mixed $value Given value.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function validator($value)
|
|
||||||
{
|
{
|
||||||
$value = parent::validator($value);
|
parent::__construct($arrAttributes);
|
||||||
|
|
||||||
if (!$value) {
|
// @codingStandardsIgnoreStart
|
||||||
return $value;
|
@trigger_error(
|
||||||
}
|
sprintf(
|
||||||
|
'"%s" is deprecated and will be removed in version 2.0.0. Use "%s" instead.',
|
||||||
if (
|
GeocodeWidget::class,
|
||||||
// See: http://stackoverflow.com/a/18690202
|
BaseWidget::class
|
||||||
!preg_match(
|
),
|
||||||
'#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#',
|
E_USER_DEPRECATED
|
||||||
$value
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
$this->addError(
|
|
||||||
sprintf(
|
|
||||||
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'],
|
|
||||||
$value
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the widget.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function generate()
|
|
||||||
{
|
|
||||||
$template = new \BackendTemplate($this->widgetTemplate);
|
|
||||||
$template->setData(
|
|
||||||
[
|
|
||||||
'widget' => $this,
|
|
||||||
'value' => specialchars($this->value),
|
|
||||||
'class' => $this->strClass ? ' ' . $this->strClass : '',
|
|
||||||
'id' => $this->strId,
|
|
||||||
'name' => $this->strName,
|
|
||||||
'attributes' => $this->getAttributes(),
|
|
||||||
'wizard' => $this->wizard,
|
|
||||||
'label' => $this->strLabel
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
return $template->parse();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
declare(strict_types=1);
|
||||||
* @package netzmacht
|
|
||||||
* @author David Molineus <david.molineus@netzmacht.de>
|
|
||||||
* @copyright 2017 netzmacht David Molineus. All rights reserved.
|
|
||||||
* @filesource
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class LeafletGeocodeWidgetBundle
|
|
||||||
*
|
|
||||||
* @package Netzmacht\Contao\Leaflet\GeocodeWidget
|
|
||||||
*/
|
|
||||||
class LeafletGeocodeWidgetBundle extends Bundle
|
class LeafletGeocodeWidgetBundle extends Bundle
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/Resources/config/listeners.yml
Normal file
4
src/Resources/config/listeners.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
services:
|
||||||
|
netzmacht.contao_leaflet_geocode.listeners.radius_wizard:
|
||||||
|
class: Netzmacht\Contao\Leaflet\GeocodeWidget\EventListener\RadiusWizardCallbackListener
|
||||||
|
public: true
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
declare(strict_types=1);
|
||||||
* @package netzmacht
|
|
||||||
* @author David Molineus <david.molineus@netzmacht.de>
|
|
||||||
* @copyright 2017 netzmacht David Molineus. All rights reserved.
|
|
||||||
* @filesource
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$GLOBALS['BE_FFL']['leaflet_geocode'] = 'Netzmacht\Contao\Leaflet\GeocodeWidget\GeocodeWidget';
|
use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\GeocodeWidget;
|
||||||
|
use Netzmacht\Contao\Leaflet\GeocodeWidget\Widget\RadiusWidget;
|
||||||
|
|
||||||
|
$GLOBALS['BE_FFL']['leaflet_geocode'] = GeocodeWidget::class;
|
||||||
|
$GLOBALS['BE_FFL']['leaflet_radius'] = RadiusWidget::class;
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Geocode backend widget based on Leaflet.
|
||||||
|
*
|
||||||
* @package netzmacht
|
* @package netzmacht
|
||||||
* @author David Molineus <david.molineus@netzmacht.de>
|
* @author David Molineus <david.molineus@netzmacht.de>
|
||||||
* @copyright 2017 netzmacht David Molineus. All rights reserved.
|
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
|
||||||
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE
|
||||||
* @filesource
|
* @filesource
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'] = 'Die angegebenen Koordinaten sind ungültig.';
|
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'] = 'Die angegebenen Koordinaten sind ungültig.';
|
||||||
$GLOBALS['TL_LANG']['MSC']['leafletSearchPositionLabel'] = 'Suchen';
|
$GLOBALS['TL_LANG']['MSC']['leafletSearchPositionLabel'] = 'Suchen';
|
||||||
$GLOBALS['TL_LANG']['MSC']['leafletApplyPositionLabel'] = 'Übernehmen';
|
$GLOBALS['TL_LANG']['MSC']['leafletApplyPositionLabel'] = 'Übernehmen';
|
||||||
|
$GLOBALS['TL_LANG']['MSC']['leafletConfirmPositionLabel'] = 'Als neue Position übernehmen?';
|
||||||
|
$GLOBALS['TL_LANG']['MSC']['leafletOkLabel'] = 'Ja';
|
||||||
|
$GLOBALS['TL_LANG']['MSC']['leafletCancelLabel'] = 'Nein';
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Geocode backend widget based on Leaflet.
|
||||||
|
*
|
||||||
* @package netzmacht
|
* @package netzmacht
|
||||||
* @author David Molineus <david.molineus@netzmacht.de>
|
* @author David Molineus <david.molineus@netzmacht.de>
|
||||||
* @copyright 2017 netzmacht David Molineus. All rights reserved.
|
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
|
||||||
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE
|
||||||
* @filesource
|
* @filesource
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'] = 'Invalid coordinates given.';
|
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'] = 'Invalid coordinates given.';
|
||||||
$GLOBALS['TL_LANG']['MSC']['leafletSearchPositionLabel'] = 'Search';
|
$GLOBALS['TL_LANG']['MSC']['leafletSearchPositionLabel'] = 'Search';
|
||||||
$GLOBALS['TL_LANG']['MSC']['leafletApplyPositionLabel'] = 'Apply';
|
$GLOBALS['TL_LANG']['MSC']['leafletApplyPositionLabel'] = 'Apply';
|
||||||
|
$GLOBALS['TL_LANG']['MSC']['leafletConfirmPositionLabel'] = 'Set as new position';
|
||||||
|
$GLOBALS['TL_LANG']['MSC']['leafletOkLabel'] = 'Ok';
|
||||||
|
$GLOBALS['TL_LANG']['MSC']['leafletCancelLabel'] = 'Cancel';
|
||||||
|
|||||||
@@ -1,30 +1,50 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.css';
|
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.css';
|
||||||
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.css';
|
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.css';
|
||||||
|
$GLOBALS['TL_CSS'][] = 'bundles/leafletgeocodewidget/css/backend.css';
|
||||||
|
|
||||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet/leaflet.js';
|
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet/leaflet.js';
|
||||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.js';
|
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.js';
|
||||||
|
|
||||||
|
if ($this->radius) {
|
||||||
|
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet-pm/leaflet.pm.css';
|
||||||
|
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet-pm/leaflet.pm.min.js';
|
||||||
|
}
|
||||||
|
|
||||||
$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/leafletgeocodewidget/js/geocode.widget.js';
|
$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/leafletgeocodewidget/js/geocode.widget.js';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<input type="text"
|
<div class="<?= $this->wrapperClass ?>">
|
||||||
name="<?= $this->name ?>"
|
<input type="text"
|
||||||
id="ctrl_<?= $this->id ?>"
|
name="<?= $this->name ?>"
|
||||||
class="tl_text tl_leaflet_geocode<?= $this->class ?>"
|
id="ctrl_<?= $this->id ?>"
|
||||||
value="<?= $this->value ?>"<?= $this->attributes ?>
|
class="tl_text tl_leaflet_geocode<?= $this->class ?>"
|
||||||
onfocus="Backend.getScrollOffset()"
|
value="<?= $this->value ?>"<?= $this->attributes ?>
|
||||||
>
|
onfocus="Backend.getScrollOffset()"
|
||||||
|
>
|
||||||
|
|
||||||
<img src="bundles/leafletgeocodewidget/img/map.png" id="ctrl_<?= $this->id ?>_toggle">
|
<a href="#"><img src="bundles/leafletgeocodewidget/img/map.png" id="ctrl_<?= $this->id ?>_toggle"></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?= $this->wizard ?>
|
<?= $this->wizard ?>
|
||||||
<script>
|
<script>
|
||||||
new LeafletGeocodeWidget({
|
window.addEvent(
|
||||||
id: 'ctrl_<?= $this->id ?>',
|
'domready',
|
||||||
searchPositionLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletSearchPositionLabel'] ?>',
|
function () {
|
||||||
applyPositionLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletApplyPositionLabel'] ?>',
|
new LeafletGeocodeWidget({
|
||||||
modalTitle: '<?= $this->label ?>'
|
id: 'ctrl_<?= $this->id ?>',
|
||||||
})
|
searchPositionLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletSearchPositionLabel'] ?>',
|
||||||
|
applyPositionLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletApplyPositionLabel'] ?>',
|
||||||
|
confirmPositionLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletConfirmPositionLabel'] ?>',
|
||||||
|
okLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletOkLabel'] ?>',
|
||||||
|
cancelLabel: '<?= $GLOBALS['TL_LANG']['MSC']['leafletCancelLabel'] ?>',
|
||||||
|
modalTitle: '<?= $this->label ?>'<?php if ($this->radius): ?>,
|
||||||
|
radius: <?= json_encode($this->radius) ?>,
|
||||||
|
picker: LeafletGeocodeCirclePicker
|
||||||
|
<?php endif ?>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<div class="<?= $this->wrapperClass ?>">
|
||||||
|
<input type="text"
|
||||||
|
name="<?= $this->name ?>"
|
||||||
|
id="ctrl_<?= $this->id ?>"
|
||||||
|
class="tl_text tl_leaflet_geocode<?= $this->class ?>"
|
||||||
|
value="<?= $this->value ?>"<?= $this->attributes ?>
|
||||||
|
onfocus="Backend.getScrollOffset()"
|
||||||
|
>
|
||||||
|
|
||||||
|
<?php if ($this->coordinates): ?>
|
||||||
|
<a href="#" onclick="$('ctrl_<?= $this->coordinates ?>_toggle').click();return false;"><img src="bundles/leafletgeocodewidget/img/map.png"></a>,
|
||||||
|
<?php endif ?>
|
||||||
|
</div>
|
||||||
26
src/Resources/public/css/backend.css
Normal file
26
src/Resources/public/css/backend.css
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
.wizard_2 {
|
||||||
|
width: 325px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-geocode-map {
|
||||||
|
width: 100%;
|
||||||
|
height: 50vh;
|
||||||
|
min-height: 400px
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-geocode-btn {
|
||||||
|
margin-top: 10px;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 7px 12px;
|
||||||
|
border: 1px solid #aaa;
|
||||||
|
border-radius: 2px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #eee;
|
||||||
|
transition: background .2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-geocode-btn + .leaflet-geocode-btn {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
@@ -1,10 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* Geocode backend widget based on Leaflet.
|
||||||
|
*
|
||||||
|
* @package netzmacht
|
||||||
|
* @author David Molineus <david.molineus@netzmacht.de>
|
||||||
|
* @copyright 2016-2018 netzmacht David Molineus. All rights reserved.
|
||||||
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/master/LICENSE
|
||||||
|
* @filesource
|
||||||
|
*/
|
||||||
|
|
||||||
|
var LeafletGeocodeAbstractPicker = L.Class.extend({
|
||||||
|
initialize: function (map, options) {
|
||||||
|
L.Util.setOptions(this, options);
|
||||||
|
this.map = map;
|
||||||
|
},
|
||||||
|
show: function (position, radius) {
|
||||||
|
if (!this.marker) {
|
||||||
|
this._createMarker(position, radius);
|
||||||
|
} else {
|
||||||
|
this._updateCoordinates(position, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._panTo(position);
|
||||||
|
},
|
||||||
|
_updateCoordinates: function (position) {
|
||||||
|
this.marker.setLatLng(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var LeafletGeocodeMarkerPicker = LeafletGeocodeAbstractPicker.extend({
|
||||||
|
apply: function (coordinatesInput) {
|
||||||
|
var coordinates = this.marker
|
||||||
|
? ( this.marker.getLatLng().lat + ',' + this.marker.getLatLng().lng)
|
||||||
|
: '';
|
||||||
|
|
||||||
|
coordinatesInput.set('value', coordinates);
|
||||||
|
},
|
||||||
|
_panTo: function (position) {
|
||||||
|
this.map.setZoom(this.map.getMaxZoom());
|
||||||
|
this.map.panTo(position);
|
||||||
|
},
|
||||||
|
_createMarker: function (position) {
|
||||||
|
this.marker = L.marker(position, {draggable: true}).addTo(this.map);
|
||||||
|
this.marker.on('dragend', function () {
|
||||||
|
this.map.panTo(this.marker.getLatLng());
|
||||||
|
}.bind(this));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var LeafletGeocodeCirclePicker = LeafletGeocodeAbstractPicker.extend({
|
||||||
|
apply: function (coordinatesInput, radiusInput) {
|
||||||
|
var radius = '';
|
||||||
|
var coordinates = this.marker
|
||||||
|
? ( this.marker.getLatLng().lat + ',' + this.marker.getLatLng().lng)
|
||||||
|
: '';
|
||||||
|
|
||||||
|
coordinatesInput.set('value', coordinates);
|
||||||
|
|
||||||
|
if (this.marker) {
|
||||||
|
radius = Math.round(this.marker.getRadius());
|
||||||
|
|
||||||
|
if (this.options.radius.steps > 0) {
|
||||||
|
radius = (this.options.radius.steps * Math.round(radius / this.options.radius.steps));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
radiusInput.set('value', radius);
|
||||||
|
},
|
||||||
|
_panTo: function () {
|
||||||
|
this.map.fitBounds(this.marker.getBounds());
|
||||||
|
},
|
||||||
|
_createMarker: function (position, radius) {
|
||||||
|
this.marker = L.circle(position, { radius: radius || this.options.radius.default });
|
||||||
|
this.marker.addTo(this.map);
|
||||||
|
|
||||||
|
this.marker.on('pm:markerdragend', function () {
|
||||||
|
var radius = this.marker.getRadius();
|
||||||
|
|
||||||
|
if (this.options.radius.steps > 0) {
|
||||||
|
radius = (this.options.radius.steps * Math.round(radius / this.options.radius.steps));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.radius.min > 0 && this.options.radius.min > radius) {
|
||||||
|
radius = this.options.radius.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.radius.max > 0 && this.options.radius.max < radius) {
|
||||||
|
radius = this.options.radius.max;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radius != this.marker.getRadius()) {
|
||||||
|
this.marker.pm.disable();
|
||||||
|
this.marker.setRadius(radius);
|
||||||
|
this._enableEditMode();
|
||||||
|
} else {
|
||||||
|
this.marker.pm._outerMarker.setTooltipContent(this._formatRadius(radius));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.map.fitBounds(this.marker.getBounds());
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
this._enableEditMode();
|
||||||
|
},
|
||||||
|
_updateCoordinates: function (position,radius) {
|
||||||
|
this.marker.pm.disable();
|
||||||
|
this.marker.setLatLng(position);
|
||||||
|
|
||||||
|
if (radius !== undefined) {
|
||||||
|
this.marker.setRadius(radius);
|
||||||
|
}
|
||||||
|
this.marker.pm.enable();
|
||||||
|
},
|
||||||
|
_enableEditMode: function () {
|
||||||
|
this.marker.pm.enable();
|
||||||
|
this.marker.pm._outerMarker.bindTooltip(
|
||||||
|
this._formatRadius(this.marker.getRadius()),
|
||||||
|
{permanent: true, direction: 'right', offset: [10, 0] }
|
||||||
|
);
|
||||||
|
},
|
||||||
|
_formatRadius: function (radius) {
|
||||||
|
var unit = 'm';
|
||||||
|
|
||||||
|
radius = Math.floor(radius);
|
||||||
|
|
||||||
|
if (radius > 1000) {
|
||||||
|
unit = 'km';
|
||||||
|
radius = (radius / 1000).toFixed(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return radius.toString() + ' ' + unit;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var LeafletGeocodeWidget = L.Class.extend({
|
var LeafletGeocodeWidget = L.Class.extend({
|
||||||
options: {
|
options: {
|
||||||
mapTemplate: '<div id="leaflet_geocode_widget_map_{id}" class="" style="width 100%; height: 50vh; min-height: 400px"></div>',
|
mapTemplate: '<div id="leaflet_geocode_widget_map_{id}" class="leaflet-geocode-map"></div>',
|
||||||
modalWidth: 800,
|
modalWidth: 800,
|
||||||
modalTitle: 'Choose coordinates',
|
modalTitle: 'Choose coordinates',
|
||||||
searchPositionLabel: 'Search',
|
searchPositionLabel: 'Search',
|
||||||
applyPositionLabel: 'Apply'
|
applyPositionLabel: 'Apply',
|
||||||
|
confirmPositionLabel: 'Set as new position',
|
||||||
|
okLabel: 'Ok',
|
||||||
|
cancelLabel: 'Cancel',
|
||||||
|
radius: null,
|
||||||
|
picker: LeafletGeocodeMarkerPicker,
|
||||||
|
map: {
|
||||||
|
maxZoom: 15,
|
||||||
|
minZoom: 2
|
||||||
|
},
|
||||||
|
bboxPadding: [0, 70]
|
||||||
},
|
},
|
||||||
initialize: function (options) {
|
initialize: function (options) {
|
||||||
L.Util.setOptions(this, options);
|
L.Util.setOptions(this, options);
|
||||||
@@ -12,36 +155,94 @@ var LeafletGeocodeWidget = L.Class.extend({
|
|||||||
this.element = $(this.options.id);
|
this.element = $(this.options.id);
|
||||||
this.toggle = $(this.options.id + '_toggle');
|
this.toggle = $(this.options.id + '_toggle');
|
||||||
this.toggle.addEvent('click', this._showMap.bind(this));
|
this.toggle.addEvent('click', this._showMap.bind(this));
|
||||||
|
|
||||||
|
if (this.options.radius) {
|
||||||
|
this.radius = $(this.options.radius.element);
|
||||||
|
|
||||||
|
if (this.radius.get('value').length > 0) {
|
||||||
|
this.options.radius.default = parseInt(this.radius.get('value'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.radius.default === undefined) {
|
||||||
|
this.options.radius.default = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_showMap: function () {
|
_showMap: function (e) {
|
||||||
var content, modal;
|
e.stop();
|
||||||
|
|
||||||
// Create modal window.
|
// Create modal window.
|
||||||
content = L.Util.template(this.options.mapTemplate, this.options);
|
var content = L.Util.template(this.options.mapTemplate, this.options);
|
||||||
modal = this._createModal();
|
this.modal = this._createModal();
|
||||||
|
|
||||||
modal.show({'title': this.options.modalTitle, 'contents': content});
|
this.modal.show({title: this.options.modalTitle, contents: content});
|
||||||
|
|
||||||
// Initialize map after showing modal so element exists.
|
// Initialize map after showing modal so element exists.
|
||||||
this._createMap(modal);
|
this._createMap();
|
||||||
},
|
},
|
||||||
_createModal: function () {
|
_createModal: function () {
|
||||||
return new SimpleModal({
|
var modal = new SimpleModal({
|
||||||
'width': this.options.modalWidth,
|
width: this.options.modalWidth,
|
||||||
'hideFooter': true,
|
hideFooter: false,
|
||||||
'draggable': false,
|
draggable: false,
|
||||||
'overlayOpacity': .5,
|
overlayOpacity: .5,
|
||||||
'onShow': function() { document.body.setStyle('overflow', 'hidden'); },
|
btn_ok: Contao.lang.close,
|
||||||
'onHide': function() { document.body.setStyle('overflow', 'auto'); }
|
onShow: function () {
|
||||||
|
document.body.setStyle('overflow', 'hidden');
|
||||||
|
},
|
||||||
|
onHide: function () {
|
||||||
|
document.body.setStyle('overflow', 'auto');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modal.addButton(Contao.lang.apply, 'btn', function () {
|
||||||
|
this.picker.apply(this.element, this.radius);
|
||||||
|
modal.hide();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
return modal;
|
||||||
},
|
},
|
||||||
_createMap: function (modal) {
|
_createMap: function () {
|
||||||
var map = L.map('leaflet_geocode_widget_map_' + this.options.id).setView([0, 0], 2);
|
var map = L.map('leaflet_geocode_widget_map_' + this.options.id, this.options.map).setView([0, 0], 2);
|
||||||
|
var radius = 0;
|
||||||
|
this.picker = new this.options.picker(map, this.options);
|
||||||
|
|
||||||
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
|
map.on('click', function (event) {
|
||||||
|
var marker = new L.marker(event.latlng).addTo(map);
|
||||||
|
var container = document.createElement('div');
|
||||||
|
var okButton = document.createElement('button');
|
||||||
|
var cancelButton = document.createElement('button');
|
||||||
|
|
||||||
|
okButton.set('class', 'leaflet-geocode-btn').appendHTML(this.options.okLabel);
|
||||||
|
okButton.addEvent('click', function (event) {
|
||||||
|
event.stop();
|
||||||
|
|
||||||
|
this.picker.show(marker.getLatLng());
|
||||||
|
map.removeLayer(marker);
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
cancelButton.set('class', 'leaflet-geocode-btn').appendHTML(this.options.cancelLabel);
|
||||||
|
cancelButton.addEvent('click', function (event) {
|
||||||
|
map.removeLayer(marker);
|
||||||
|
});
|
||||||
|
|
||||||
|
container.appendHTML('<h2>' + this.options.confirmPositionLabel + '</h2>');
|
||||||
|
container.appendChild(okButton);
|
||||||
|
container.appendChild(cancelButton);
|
||||||
|
|
||||||
|
marker.bindPopup(container, {
|
||||||
|
keepInView: true,
|
||||||
|
autoPanPaddingTopLeft: this.options.bboxPadding,
|
||||||
|
autoClose: false,
|
||||||
|
closeOnClick: false,
|
||||||
|
closeButton: false
|
||||||
|
}).openPopup();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
var geoCoder = L.Control.geocoder({
|
var geoCoder = L.Control.geocoder({
|
||||||
defaultMarkGeocode: false,
|
defaultMarkGeocode: false,
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
@@ -49,53 +250,15 @@ var LeafletGeocodeWidget = L.Class.extend({
|
|||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
geoCoder.on('markgeocode', function (event) {
|
geoCoder.on('markgeocode', function (event) {
|
||||||
this._handleGeoCode.call(this, modal, map, event);
|
this.picker.show(event.geocode.center);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
if (this.element.value) {
|
if (this.element.value) {
|
||||||
var value = this.element.value.split(/,/);
|
if (this.radius && this.radius.get('value').length > 0) {
|
||||||
this._createMarker(value, map);
|
radius = parseInt(this.radius.get('value'));
|
||||||
|
}
|
||||||
|
|
||||||
map.setZoom(16);
|
this.picker.show(L.latLng(this.element.value.split(/,/)), radius);
|
||||||
map.panTo(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
|
||||||
},
|
|
||||||
_handleGeoCode: function (modal, map, event) {
|
|
||||||
var container = document.createElement('div');
|
|
||||||
var link = document.createElement('button');
|
|
||||||
var result = event.geocode;
|
|
||||||
|
|
||||||
link.set('style', 'margin-left: 10px;');
|
|
||||||
link.appendText(this.options.applyPositionLabel);
|
|
||||||
link.addEvent('click', function(e) {
|
|
||||||
e.stop();
|
|
||||||
|
|
||||||
this.element.set('value', result.center.lat + ',' + result.center.lng);
|
|
||||||
modal.hide();
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
container.appendHTML(result.html || result.name);
|
|
||||||
container.appendChild(link);
|
|
||||||
|
|
||||||
if (this._geocodeMarker) {
|
|
||||||
map.removeLayer(this._geocodeMarker);
|
|
||||||
}
|
|
||||||
|
|
||||||
map.fitBounds(result.bbox, { padding: [0, 70]});
|
|
||||||
map.panTo(result.center);
|
|
||||||
|
|
||||||
this._createMarker(result.center, map);
|
|
||||||
this._geocodeMarker.bindPopup(container, {
|
|
||||||
keepInView: true,
|
|
||||||
autoPanPaddingTopLeft: [0, 70]
|
|
||||||
}).openPopup();
|
|
||||||
},
|
|
||||||
_createMarker: function (position, map) {
|
|
||||||
this._geocodeMarker = L.marker(position, {draggable: true}).addTo(map);
|
|
||||||
this._geocodeMarker.on('dragend', function (event) {
|
|
||||||
this.element.set('value', event.target._latlng.lat + ',' + event.target._latlng.lng);
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
163
src/Widget/GeocodeWidget.php
Normal file
163
src/Widget/GeocodeWidget.php
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget;
|
||||||
|
|
||||||
|
use Contao\BackendTemplate;
|
||||||
|
use Contao\StringUtil;
|
||||||
|
use Contao\Widget;
|
||||||
|
|
||||||
|
use function is_array;
|
||||||
|
use function preg_match;
|
||||||
|
use function sprintf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int size
|
||||||
|
* @property bool multiple
|
||||||
|
*/
|
||||||
|
class GeocodeWidget extends Widget
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Submit user input.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $blnSubmitInput = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a for attribute.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $blnForAttribute = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $strTemplate = 'be_widget';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $widgetTemplate = 'be_widget_leaflet_geocode';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the input.
|
||||||
|
*
|
||||||
|
* @param mixed $value Given value.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.Superglobals)
|
||||||
|
*/
|
||||||
|
protected function validator($value)
|
||||||
|
{
|
||||||
|
$value = parent::validator($value);
|
||||||
|
|
||||||
|
if (! $value) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($value)) {
|
||||||
|
foreach ($value as $key => $val) {
|
||||||
|
$value[$key] = $this->validator($val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See: http://stackoverflow.com/a/18690202
|
||||||
|
$pattern = '#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|'
|
||||||
|
. '((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#';
|
||||||
|
|
||||||
|
if (! preg_match($pattern, $value)) {
|
||||||
|
$this->addError(
|
||||||
|
sprintf(
|
||||||
|
$GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'],
|
||||||
|
$value
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the widget.
|
||||||
|
*/
|
||||||
|
public function generate(): string
|
||||||
|
{
|
||||||
|
$wrapperClass = 'wizard';
|
||||||
|
|
||||||
|
if (! $this->multiple || ! $this->size) {
|
||||||
|
$this->size = 1;
|
||||||
|
} else {
|
||||||
|
$wrapperClass .= ' wizard_' . $this->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! is_array($this->value)) {
|
||||||
|
$this->value = [$this->value];
|
||||||
|
}
|
||||||
|
|
||||||
|
$buffer = '';
|
||||||
|
|
||||||
|
for ($index = 0; $index < $this->size; $index++) {
|
||||||
|
$template = new BackendTemplate($this->widgetTemplate);
|
||||||
|
$template->setData(
|
||||||
|
[
|
||||||
|
'wrapperClass' => $wrapperClass,
|
||||||
|
'widget' => $this,
|
||||||
|
'value' => StringUtil::specialchars($this->value[$index]),
|
||||||
|
'class' => $this->strClass ? ' ' . $this->strClass : '',
|
||||||
|
'id' => $this->strId . ($this->size > 1 ? '_' . $index : ''),
|
||||||
|
'name' => $this->strName . ($this->size > 1 ? '[]' : ''),
|
||||||
|
'attributes' => $this->getAttributes(),
|
||||||
|
'wizard' => $this->wizard,
|
||||||
|
'label' => $this->strLabel,
|
||||||
|
'radius' => $this->buildRadiusOptions(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$buffer .= $template->parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the radius options.
|
||||||
|
*
|
||||||
|
* @return array<string,mixed>|null
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.Superglobals)
|
||||||
|
*/
|
||||||
|
private function buildRadiusOptions(): ?array
|
||||||
|
{
|
||||||
|
if (! $this->radius || ! isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'element' => 'ctrl_' . $this->radius,
|
||||||
|
'min' => 0,
|
||||||
|
'max' => 0,
|
||||||
|
'defaultValue' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'])) {
|
||||||
|
$config = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'];
|
||||||
|
|
||||||
|
$options['min'] = isset($config['minval']) ? (int) $config['minval'] : 0;
|
||||||
|
$options['max'] = isset($config['maxval']) ? (int) $config['maxval'] : 0;
|
||||||
|
$options['defaultValue'] = isset($config['default']) ? (int) $config['default'] : 0;
|
||||||
|
$options['steps'] = isset($config['steps']) ? (int) $config['steps'] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
}
|
||||||
92
src/Widget/RadiusWidget.php
Normal file
92
src/Widget/RadiusWidget.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Netzmacht\Contao\Leaflet\GeocodeWidget\Widget;
|
||||||
|
|
||||||
|
use Contao\BackendTemplate;
|
||||||
|
use Contao\StringUtil;
|
||||||
|
use Contao\TextField;
|
||||||
|
|
||||||
|
use function is_array;
|
||||||
|
use function is_numeric;
|
||||||
|
use function round;
|
||||||
|
use function trim;
|
||||||
|
|
||||||
|
class RadiusWidget extends TextField
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Template name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $widgetTemplate = 'be_widget_leaflet_radius';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function __get($strKey)
|
||||||
|
{
|
||||||
|
if ($strKey === 'rgxp') {
|
||||||
|
return 'natural';
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::__get($strKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the widget.
|
||||||
|
*/
|
||||||
|
public function generate(): string
|
||||||
|
{
|
||||||
|
$wrapperClass = $this->coordinates ? 'wizard' : '';
|
||||||
|
|
||||||
|
if (! $this->multiple || ! $this->size) {
|
||||||
|
$this->size = 1;
|
||||||
|
} else {
|
||||||
|
$wrapperClass .= ' wizard_' . $this->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! is_array($this->value)) {
|
||||||
|
$this->value = [$this->value];
|
||||||
|
}
|
||||||
|
|
||||||
|
$buffer = '';
|
||||||
|
|
||||||
|
for ($index = 0; $index < $this->size; $index++) {
|
||||||
|
$template = new BackendTemplate($this->widgetTemplate);
|
||||||
|
$template->setData(
|
||||||
|
[
|
||||||
|
'wrapperClass' => trim($wrapperClass),
|
||||||
|
'widget' => $this,
|
||||||
|
'value' => StringUtil::specialchars($this->value[$index]),
|
||||||
|
'class' => $this->strClass ? ' ' . $this->strClass : '',
|
||||||
|
'id' => $this->strId . ($this->size > 1 ? '_' . $index : ''),
|
||||||
|
'name' => $this->strName . ($this->size > 1 ? '[]' : ''),
|
||||||
|
'attributes' => $this->getAttributes(),
|
||||||
|
'wizard' => $this->wizard,
|
||||||
|
'label' => $this->strLabel,
|
||||||
|
'coordinates' => $this->coordinates,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$buffer .= $template->parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function validator($varInput)
|
||||||
|
{
|
||||||
|
if (is_numeric($varInput) && $this->steps > 0) {
|
||||||
|
$steps = (int) $this->steps;
|
||||||
|
$varInput = (int) $varInput;
|
||||||
|
$varInput = $steps * round($varInput / $steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::validator($varInput);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user