kematjaya/leaflet-bundle

provide map for get latitude and longitude base on leaflet.js

Installs: 752

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0

Language:JavaScript

1.0.4 2022-12-20 04:22 UTC

This package is auto-updated.

Last update: 2024-04-20 07:04:22 UTC


README

symfony bundle base on leaflet js for selecting location using map

  1. Installation
composer kematjaya/leaflet-bundle
  1. add to config/bundles.php
// add to config/bundles.php
...
Kematjaya\LeafletBundle\LeafletBundle::class => ['all' => true]
...
  1. 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%
      ]);
...
  1. 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'
  1. 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
}