markmarkoh / datamaps

Customizable SVG map visualizations for the web in a single Javascript file using D3.js
http://datamaps.github.io
MIT License
3.78k stars 1.01k forks source link

Easier way to AJAX bubbles? #87

Closed kengiher closed 10 years ago

kengiher commented 10 years ago

So I managed to hack 'n slash my way to update new bubbles upon an AJAX request. I didn't see or may have missed if there is a proper way already built in so this is what I did:

PHP: $json_arr = array();

//add an array for each bubble when possible array_push($json_arr, '{"name": "'.$name.'", "latitude": '.$lat.', "longitude": '.$long.', "radius": 10, "fillKey": "gt50"}');

//output array into text print implode(",",$json_arr);

jQuery/Ajax: .done(function( msg ) { //parse the result string into object(s) var obj = jQuery.parseJSON('['+msg+']'); //create new bubble(s) map.bubbles(obj);

Is there a more efficient way to achieve this?

alangularte commented 10 years ago

Hey, check if this solution helps you:

https://github.com/markmarkoh/datamaps/issues/99

kengiher commented 10 years ago

Perfect!