trantuanvn / jquery-ui-map

Automatically exported from code.google.com/p/jquery-ui-map
0 stars 0 forks source link

load from json and clustring #82

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
hi.

im using jquery-ui-map-3.0-rc .

i can load marker from json  , but i can not clustering them.
According to Examples i use this way :

<script type="text/javascript">
$(function() { 
    demo.add(function() {
        $('#map_canvas').gmap({'disableDefaultUI':true, 'callback': function() {

            var self = this;
            $.getJSON( 'json/demo.json', function(data) { 
                $.each( data.markers, function(i, marker) {

                    self.addMarker({ 'position': new google.maps.LatLng(marker.latitude, marker.longitude), 'bounds':true } ).click(function() {
                        self.openInfoWindow({ 'content': marker.content }, this);
                    });
                });
                $(this).gmap('set', 'MarkerClusterer', new MarkerClusterer(map, $(this).gmap('get', 'markers')));
            });
            $(this).gmap('set', 'MarkerClusterer', new MarkerClusterer(map, $(this).gmap('get', 'markers')));
        }}); 
    }).load();
});
</script>

what's problem?
thank you.

Original issue reported on code.google.com by virus30y...@gmail.com on 18 Jan 2014 at 2:43

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
create the marker cluster after the markers have been added to the map, not 
before. try this :

$(function() { 
        $('#map_canvas').gmap({'center': '37.4419, -122.1419','zoom': 5, 'disableDefaultUI':true}).bind('init', function(evt, map) { 
            $.getJSON('json/demo.json', function(data){
                $.each(data.markers, function(i, marker){
                    $('#map_canvas').gmap('addMarker', {
                        'position': new google.maps.LatLng(marker.latitude, marker.longitude)
                    }).click(function(){
                        $('#map_canvas').gmap('openInfoWindow', {
                            'content': marker.content
                        },this);
                    });
                });
               $('#map_canvas').gmap('set', 'MarkerClusterer', new MarkerClusterer($('#map_canvas').gmap('get', 'map'), $('#map_canvas').gmap('get', 'markers'))); 
            });
        });     
});

Original comment by alankila...@gmail.com on 22 May 2014 at 6:21