0

I created a view block for displaying geocodeed nodes on a View Leaflet map. Everything working, the map displays the markers as I want. Now, I would like to load this map throught drupal ajax

I attached the leaflet libraries to the page. Then I load the view with:

$view = Views::getView('map');

$view->setArguments($args);
$view->setDisplay('block');
$view->preExecute();
$view->execute();
$content = $this->renderer->render($view->render());

$response->addCommand(
    new HtmlCommand('.result__map', $content)
 ));

The $content contain only an empty div generatated from the view and when the response is instered in the Dom nothing happen. I suspesct that the map is missing some JS trigger to instanciante the map and maybe some JS settings.

Could someone send me an example or point me in the right direction.

1 Answer 1

1

You must use the ViewExecutable::buildRenderable function.

Instead of:

$content = $this->renderer->render($view->render()); 

You must do like this:

$content = $view->buildRenderable('block', $args);
7
  • hi @Jdrupal Thank you for your answer .. now the map is lading the Json object is sent but the Key "feature:[]" is empty.
    – Eacute
    Commented Nov 22, 2019 at 14:48
  • I'm sorry, I'm not sure I understand your question. Is the view not being sent with ajax or is it not rendered properly?
    – user72672
    Commented Nov 22, 2019 at 14:51
  • hi @Jdrupal Thank you for your answer .. now the map is lading the Json object is sent but the Key "feature:[]" is empty. With View preview : features […] 0 {…} type point lat 48.862725 lon 2.287592 entity_id 4675 The coordinate are here.
    – Eacute
    Commented Nov 22, 2019 at 14:55
  • yes now with $view->buildRenderable('block', $args) the map is rendered .. but there no markers on the map . after looking the Json i am seeing that is missing the key feature
    – Eacute
    Commented Nov 22, 2019 at 14:57
  • OK, are the markers sent as contextual filters, if so, have you then remembered to add them to $args when rendering your view?
    – user72672
    Commented Nov 22, 2019 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.