kematjaya / leaflet-bundle
provide map for get latitude and longitude base on leaflet.js
Installs: 761
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- symfony/form: ^5.0
- symfony/framework-bundle: ^5.0
- symfony/twig-bundle: ^5.0
- symfony/yaml: ^5.0
README
symfony bundle base on leaflet js for selecting location using map
- Installation
composer kematjaya/leaflet-bundle
- add to config/bundles.php
// add to config/bundles.php
...
Kematjaya\LeafletBundle\LeafletBundle::class => ['all' => true]
...
- add to form
// src/Form/AddressType.php
...
use Kematjaya\LeafletBundle\Type\LeafletMapType
...
$builder
->add('location', LeafletMapType::class, [
'label' => 'location',
"map_height" => "350px", // default 250px
"map_width" => "100%", // default 100%
]);
...
- create configuration file config/packages/leaflet.yaml
leaflet:
map_box:
api_token: '%env(resolve:LEAFLET_MAPBOX_TOKEN)%'
map:
lock_map: true # lock map at center point, default true
lock_coordinates:
southwest: "-7.777488, 114.776975" # point lock
northeast: "-7.403438, 110.834149" # point lock
min_zoom: 8 # minimal zoom available, default 8
max_zoom: 20 # maximal zoom available, default 20
zoom_value: 11 # default zoom when map loaded
on_click_zoom: 14 # zoom when map clicked, default 14
center_point: '%env(resolve:LEAFLET_MAP_CENTER_POINT)%'
zoom_point: '%env(resolve:LEAFLET_MAP_CENTER_POINT)%'
and add value to .env
LEAFLET_MAPBOX_TOKEN=your.mapbox.token
LEAFLET_MAP_CENTER_POINT=longlat point ## example: '-7.293421341699741, 112.73709354459358'
- use distance calculator
...
use Kematjaya\LeafletBundle\Calculator\Point;
use Kematjaya\LeafletBundle\Calculator\DistanceCalculatorInterface;
...
public function test(DistanceCalculatorInterface $distanceCalculator)
{
$from = new Point(-7.345728218434821, 112.76383132697055);
$to = new Point(-7.2491223553386375, 112.79650342712807);
$distance = $distanceCalculator->getDistance($from, $to); // in KM
}