Skip to content

Commit

Permalink
Merge pull request #29 from HazemKhaled/Number-Array
Browse files Browse the repository at this point in the history
Support [Number] for GeoJSON
  • Loading branch information
mpowaga committed Jun 10, 2015
2 parents cdd0930 + ef28551 commit fe6bcba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ Schemas.Cities = new SimpleSchema
decimal: true
```

Or if you want to save lat and lng as a array, important for GEOJson:

```
Schemas.Cities = new SimpleSchema
location:
type: [Number]
decimal: true
autoform:
type: 'map'
afFieldInput:
# options
```

### Options ###

*mapType* type of google map. Possible values: `'roadmap' 'satellite' 'hybrid' 'terrain'`
Expand Down
4 changes: 3 additions & 1 deletion lib/client/autoform-map.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ AutoForm.addInputType 'map',
"#{value.lng},#{value.lat}"
else
"#{value.lat},#{value.lng}"
numberArray: (value) ->
[value.lng, value.lat]

Template.afMap.created = ->
GoogleMaps.load(libraries: 'places')
Expand Down Expand Up @@ -60,7 +62,7 @@ initTemplateAndGoogleMaps = ->
@data.map = new google.maps.Map @find('.js-map'), mapOptions

if @data.value
location = if typeof @data.value == 'string' then @data.value.split ',' else [@data.value.lat, @data.value.lng]
location = if typeof @data.value == 'string' then @data.value.split ',' else if @data.value.hasOwnProperty 'lat' then [@data.value.lat, @data.value.lng] else [@data.value[1],@data.value[0]]
location = new google.maps.LatLng parseFloat(location[0]), parseFloat(location[1])
@data.setMarker @data.map, location, @data.options.zoom
@data.map.setCenter location
Expand Down

0 comments on commit fe6bcba

Please sign in to comment.