Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add plugins control with standard controls ? #321

Open
mohamed-shaheen opened this issue Apr 15, 2021 · 0 comments
Open

how to add plugins control with standard controls ? #321

mohamed-shaheen opened this issue Apr 15, 2021 · 0 comments

Comments

@mohamed-shaheen
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant