Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Sam 75 posts 391 karma points
    May 31, 2018 @ 18:01

    Terratype display a map for each location in the content tree


    I am sure I am just missing something simple, because of my lack of knowledge of razor. I am unable to render a map for each location using the terratype package.

    I am trying to render the maps in a partial view, but i get the following error enter image description here

    Template Page:

    case "Locations": @*Multi Location*@

    Partial View:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Terratype;
    @{ var locations = CurrentPage.AncestorOrSelf(1).Descendants("locationInfo");}
    @foreach (var location in locations){

    Thanks in advance.

  • Dave Woestenborghs 3227 posts 10922 karma points MVP 5x admin c-trib
    Jun 01, 2018 @ 07:33
    Dave Woestenborghs

    Hi Sam,

    You are using dynamics to get your content. Can you try to use strongly typed variant

    var locations = Model.Content.AncestorOrSelf(1).Descendants("locationInfo");

    Also try to avoid using descendants because this can be come a performance bottle neck on large sites


  • Jonathan Richards 288 posts 1734 karma points MVP
    Jun 01, 2018 @ 09:16
    Jonathan Richards

    Hi Sam,

    In the specific case that is throwing your YSOD, could you change



    @Html.Terratype((Terratype.Models.Model) location.GetProperty("locationMap").Value)

    I can only apologise, but the code posted in the documentation doesn't work for all Umbraco versions. I will raise this as a bug and fix this in due course.

    BTW: As you aren't using Terratype Options each map with render separately, I suspect you want to use

    @Html.Terratype(new Options { MapSetId = 1 }, (Terratype.Models.Model) location.GetProperty("locationMap").Value)

    This will combine all the maps into one map with multiple markers on it.



    ps. Yes the performance of your Linq code is terrible as Dave points out, but I've left that issue alone.

  • Sam 75 posts 391 karma points
    Jun 01, 2018 @ 18:34

    Thank you both for Responding, I have adjusted the query, and changed the code for the values, but I get the error below.

    I do Actually want to render separate maps. There are only a few locations, and they are wide spread across the map. Client has requested a map for each. Is this going to be an issue?

    enter image description here

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Terratype;
        var locations = Model.Content.Site().FirstChild("locationFolder").Children("locationInfo");
    @foreach (var location in locations)
  • Sam 75 posts 391 karma points
    Jun 01, 2018 @ 20:32

    Ok, so this error is not really related to the rendering of the map... for some reason the data type forgot all the settings and the API key while i was working on it. I stopped debug and rebuilt and it seems to be ok now.

    I am working locally, do you think it is going to be an issue on a live site?

Please Sign in or register to post replies

Write your reply to: