0

I am creating layer definitions that I can add individually into into a collection where I will then render the view or to a L.LayerGroup from the leaflet api, but I am unsure how to map the properties or if there is a mapping function? I am relatively new to JavaScript.

I am creating a map and want to have an easy way to apply and load overlays through a json format.

J10598
  • 21
  • 5
  • 1
    Backbone isn't really that prescriptive about what format your data takes, as long as it's either a valid javascript object, in which case you just put it into a model or an array of javascript objects, in which case you put it into a collection. Beyond that, you would need to clarify what it is you're trying to do, or describe what your data is and where it's coming from. – kinakuta Nov 16 '12 at 20:58
  • ok I think I will use independent JavaScript functions to retrieve json attributes and set them in a constructor/initialize them to a backbone model. – J10598 Nov 16 '12 at 21:09

1 Answers1

0

Presuming you have data like this in your geojson:

{"type":"Feature","properties":{"name":"Ireland"},"geometry":
{"type":"Polygon","coordinates":[[[-6.197885,53.867565],[-6.032985,53.153164], 
[-6.788857,52.260118],[-8.561617,51.669301],[-9.977086,51.820455],
[-9.166283,52.864629], [-9.688525,53.881363],[-8.327987,54.664519], 
[-7.572168,55.131622],[-7.366031,54.595841],[-7.572168,54.059956],[-6.95373,54.073702],
[-6.197885,53.867565]]]},"id":"IRL"},

you would take the properties of the object and define parallel properties in your model definition.

Then you easily take your geosjsonobject in your model constructor:

var Ireland = new MyCountryModel(my_geojson_object);

To take care of parsing JSON you may be getting from the server, you define a method parse(response) in your model and/or collection definitions, which takes your server response object(string) as argument, and should return JSON object ready for use in initialization of collection/model

tonino.j
  • 3,837
  • 28
  • 27