Copied to clipboard

Flag this post as spam?

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


  • Connor Forsyth 7 posts 88 karma points
    Jan 23, 2019 @ 09:12
    Connor Forsyth
    0

    Uncaught reference error: terratype is not defined

    Hi,

    I've recently started using your package and was wanting to play about with the clusterer settings using terratype.onRender. However when I load the page with the map, I receive the Uncaught ReferenceError: terratype is not defined.

    The website currently uses Umbraco v7.12.4

    Thank you for your time,

    Connor Forsyth

  • Jonathan Richards 288 posts 1742 karma points MVP
    Jan 23, 2019 @ 12:22
    Jonathan Richards
    1

    Hi Connor,

    I suspect you are trying to access the js object terratype before it has been defined. It gets loaded, the first time you call the @Html.Terratype in your razor page.

    To give an Razor example to make it clear

            @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
            @using Terratype
            @{
                Layout = null;
            }
    
            <html>
                <head>
    
                    //  mymapcode.js can't contain any references to terratype object, as its not defined yet
                    <script src="mymapcode.js"></script>
    
    
                    <script>
                        //  The line below will fail because terratype still doesn't exist yet
                        terratype.onRender(function (p, m) {
                            alert('terratype doesn't exist');
                        });
                    </script>
    
                </head>
    
                <body>
    
                    <script>
                        //  The line below will fail because terratype still doesn't exist yet
                        terratype.onRender(function (p, m) {
                            alert('terratype doesn't exist');
                        });
                    </script>
    
    
                    @* This is the line of code that will define the terratype object *@
    
                    @Html.Terratype(Model.Content.MyMap)
    
                    @* From this point on, the js object called terratype exists *@
    
    
    
                    <script>
                        //  This line will succeed because it is after the Html.Terratype command which defined terratype
                        terratype.onRender(function (p, m) {
                            alert('Woohoo we will work');
                        });
                    </script>
    
                    @*  mymapcode2.js can contain references to terratype object, as it does now exist *@
                    <script src="mymapcode2.js"></script>
    
    
                </body>
            </html>
    

    Hope this helps

    Jonathan

  • Connor Forsyth 7 posts 88 karma points
    Jan 24, 2019 @ 09:45
    Connor Forsyth
    1

    Hi Jonathan,

    Sorry for the slow reply,

    I called the terratype.onRender after I defined the terratype but couldn't get it working.

                    var map2 = mapContent.GetPropertyValue<Terratype.Models.Model>("mapMarker");
                    map2.Icon.Url = new Uri("https://mt.google.com/vt/icon/name=icons/spotlight/spotlight-poi.png?type=" + testType + "&town=" + townName);
    
                    if( (map2 != null) && (map2.Position.ToString().Length > 0 ) ){
    
                         @Html.Terratype(new Options{MapSetId=9},@map2,@<text>
                                [{"link":"@venLink.Link",
                                "title":"@locationName",
                                "img":"@popupImage",
                                "icon":"@tileIcon",
                                "time":"@tileTime"}]
                                </text>);
                    } 
    
         @*This is called at the end of the razor page*@
         <script>
            terratype.onRender(function (provider, map) {
                  map._markerclusterer.setMaxZoom(1);
                  map._markerclusterer.setGridSize(1);
                  map._markerclusterer.redraw();
            })
          </script>
    

    This probably looks like a mess, as the terratype along with various other properties are nested content, so I used IPublishedContent to loop through each instance.

    Thank you for your time,

    Connor Forsyth

  • Jonathan Richards 288 posts 1742 karma points MVP
    Jan 24, 2019 @ 10:24
    Jonathan Richards
    1

    Hi Connor,

    I've just tested your code and other than your three lines of js (map._markerclusterer) seems to stop the Clustering from doing its job, I get no errors with it. eg. Setting the Icon Url yourself works for me, using Json in the Label works for me, The javascript you have works for me.

    What version of Terratype you using, as the js library was released in version 1.0.15

    Otherwise maybe check that terratype.renderer.min.js is loading and running correctly - no errors.

    Check using Chrome debugger if there is a window.terratype object created after the above script file runs.

    Without something more to go on, I'm at a bit of a loss.

    Sorry

    Jonathan

  • Connor Forsyth 7 posts 88 karma points
    Jan 24, 2019 @ 10:49
    Connor Forsyth
    0

    Hi Jonathan,

    I apologize, I really haven't given you much useful information, I'm using the version of Terratype that is included with Umbraco (v7.12.4).

    I encased the terratype.onRender inside the if statement and it returned the with the console log.

     <script>
           if(window.terratype != null){
                terratype.onRender(function (provider, map) {
                      map._markerclusterer.setMaxZoom(1);
                      map._markerclusterer.setGridSize(1);
                      map._markerclusterer.redraw();
                })
            }else{console.log("No window.terratype");}
      </script>
    

    Again, thank you for your time,

    Connor Forsyth

  • Jonathan Richards 288 posts 1742 karma points MVP
    Jan 24, 2019 @ 10:55
    Jonathan Richards
    100

    Hi Connor,

    As you don't seem to know what version you are using, I'm gonna guess that this is our issue. Can you update to the latest version please.

    On a side note, Terratype doesn't come with any version of Umbraco, you might have installed it when you installed a starter kit, without knowing which starter kit you installed it would be tough for me to guess.

    Cheers

    Jonathan

  • Connor Forsyth 7 posts 88 karma points
    Jan 24, 2019 @ 10:58
    Connor Forsyth
    0

    Hi Jonathan,

    Perfect, that's what I'll do. I just had a look and it seems we installed the Umbraco starter kit here: https://github.com/umbraco/The-Starter-Kit. Apologies for wasting your time.

    Thank you for your help,

    Connor Forsyth

Please Sign in or register to post replies

Write your reply to:

Draft