powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 413 forks source link

Geolocation/Geocoordinates Map plugin? #409

Closed rjcorwin closed 8 years ago

rjcorwin commented 10 years ago

Has anyone heard of a plugin for Backbone-Forms that allows would render a field as a map that you can select geocoordinates on? In particular I have a need to allow folks to select areas on a map (fields on farms).

exussum12 commented 10 years ago

The way I do this is have a long, lat and zoom set up as hidden fields.

Then using googles api

https://developers.google.com/maps/documentation/javascript/examples/event-simple

schema extract

longitude : {
  type: 'Hidden'
},
latitude : {
  type: 'Hidden'
},
zoom : {
  type: 'Hidden'
 }

and processing code

      form.getEditor("latitude").setValue(myMarker.getPosition().lat());
      form.getEditor("longitude").setValue(myMarker.getPosition().lng());
      form.getEditor("zoom").setValue(map.getZoom());

      form.trigger("lnglat:change") 

This seems to work pretty well for me. You could extend this to allow an array and set the value to be an array of ordered coorniate pairs for area shapes too

bielfrontera commented 9 years ago

@rjsteinert I have developed a custom editor to manage a bounding box field. It uses leafletjs with two plugins (Draw and Pan). I have taken the date field editor as a example.

Here you have a gist with the code: https://gist.github.com/bielfrontera/de36b1f510000ccbaf48

image

rjcorwin commented 9 years ago

@bielfrontera Cool :). That would be cool to see as a bower package.

glenpike commented 8 years ago

Looks like question was answered. Will close this now.