ruby on rails - Mapbox fitBounds fits map to markers, but doesn't render tiles -


i building ruby on rails app creates unique map each product model in database , inserts slide of flexslider slideshow.

this working json requests contain 1 marker. however, when json requests made 2 markers, map's tiles not render (but both markers displayed , fit view).

the rendering issue solved moving "map.fitbounds(featurelayer.getbounds());" featurelayer.on('click') function. need functionality fitbounds after json loaded rather on click.

the error in browswer console is: "uncaught typeerror: cannot read property 'lat' of undefined" have searched dozens of threads this, cannot solve it. newbie of this, appreciated.

my javascript

function initproductmap(product) {  var map; map = l.mapbox.map(document.getelementbyid(product), 'jasonpearson.ha88l84b');      var featurelayer;     featurelayer = l.mapbox.featurelayer().loadurl('/products/' + product + '.json').addto(map);     map.scrollwheelzoom.disable();     map.zoomcontrol.setposition('bottomright');      featurelayer.on('ready', function() {         map.fitbounds(featurelayer.getbounds());          featurelayer.on('click', function(e) {         e.layer.unbindpopup();         window.open(e.layer.feature.properties.url, '_self');         });      });      $('ul.slides li').show();     map.invalidatesize(); }; 

my rails controller

  def show @product = product.find(params[:id]) @geojson = array.new  @product.producers.each |producer|   @geojson << {     type: 'featurecollection',     features: [               {         type: 'feature',         geometry: {           type: 'point',           coordinates: [producer.longitude, producer.latitude]         },         properties: {           name: producer.name,           'marker-color' => '#9f3335',           'marker-symbol' => 'circle',           'marker-size' => 'medium',           url: rails.application.routes.url_helpers.producer_path(producer)                   }       }     ]   }     end 


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -