Skip to content

how to add plugins control with standard controls ? #321

@mohamed-shaheen

Description

@mohamed-shaheen

I need to add Leaflet.Control.GPS ( https://github.com/stefanocudini/leaflet-gps ) with location picker from forms .
I need to create simple map to get point and save it to PointField() .
My knowledge about leaflet java script is not well but, but I try to follow the documentation but nothing went well :)
........
My sittings config :

LEAFLET_CONFIG = {
          # conf here
          'DEFAULT_CENTER': (30.033333, 31.233334),
          'DEFAULT_ZOOM': 16,
          'MIN_ZOOM': 3,
          'MAX_ZOOM': 18,
          'DEFAULT_PRECISION': 6,
          #'TILES': [],
          'PLUGINS': {
                  'forms': {
                      'css': [ '/static/leaflet-gps-master/src/leaflet-gps.css'],
                      'js': [ '/static/leaflet-gps-master/src/leaflet-gps.js'],
                      'auto-include': True,
                   },
         }
}

And my forms.py :

 class MapWidget(LeafletWidget):
           geometry_field_class = 'address.GeometryField'

class NewShopForm(forms.ModelForm):
           class Meta:
                model = Shop    
                fields = ["SHname", "SHlocation"]
                widgets = {'SHlocation': MapWidget()} 

and in html inject script in form element :

address.GeometryField = L.GeometryField.extend({
    addTo: function (map) {

         var GpsControl = this._GpsControl = new L.Control.Gps();
         map.on('gps:located', function(e) {

            console.log(e.latlng, map.getCenter())
         map.on('gps:disabled', function(e) {
            e.marker.closePopup()
         });   
        })
     },
 }); 

any help please :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions