Copied to clipboard

Flag this post as spam?

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


  • Sam 79 posts 426 karma points
    May 31, 2018 @ 18:01
    Sam
    0

    Terratype display a map for each location in the content tree

    Hello,

    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*@
    @CurrentPage.GetGridHtml("content")
    @Html.Partial("TerraMaps")
    break;
    

    Partial View:

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

    Thanks in advance.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jun 01, 2018 @ 07:33
    Dave Woestenborghs
    2

    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

    Dave

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

    Hi Sam,

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

    @Html.Terratype(location.GetProperty("locationMap"))
    

    to

    @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.

    Cheers

    Jonathan.

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

  • Sam 79 posts 426 karma points
    Jun 01, 2018 @ 18:34
    Sam
    0

    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)
    {
    
        @Html.Terratype((Terratype.Models.Model)location.GetProperty("locationMap").Value)
    
    }
    
  • Sam 79 posts 426 karma points
    Jun 01, 2018 @ 20:32
    Sam
    1

    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:

Draft