0

I am thinking of caching the returned routing object in leaflet routing machine. But I cannot serialize the object using JSON.stringify() as it throws up an error stating it's a circular object. I tried to use some java script libraries that can overcome this, but de-serializing it is destroying the object.

var control = L.Routing.control({
    waypoints: [
        L.latLng(57.74, 11.94),
        L.latLng(57.6792, 11.949)
    ],
    geocoder: L.Control.Geocoder.nominatim(),
    routeWhileDragging: true,
    reverseWaypoints: true,
    showAlternatives: true,
    altLineOptions: {
        styles: [
            {color: 'black', opacity: 0.15, weight: 9},
            {color: 'white', opacity: 0.8, weight: 6},
            {color: 'blue', opacity: 0.5, weight: 2}
        ]
    }
});

Help me in storing the control object locally and retrieve it again to add it to the map.

raven
  • 23
  • 3
  • Im not sure what do you mean by "but de-serializing it is destroying the object" what libraries have you used? – Ahmad Sanie May 01 '16 at 21:03
  • dojox json ref library. Thing is we can just use control.addto(map) to render the map. but the de-serialized control object throws an error which is "addto is not specified". – raven May 01 '16 at 21:27

1 Answers1

0

I cannot serialize the object using JSON.stringify() as it throws up an error stating it's a circular object

It seems that you have an object with circular references, I would suggest using the second parameter of stringify as mentioned here, but this may cause problems as it removes anything that appears more than once not just cyclic references.

checkout this plugin hope it will work for you.

Community
  • 1
  • 1
Ahmad Sanie
  • 3,678
  • 2
  • 21
  • 56