Copied to clipboard

Flag this post as spam?

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


  • Chris 10 posts 40 karma points
    Apr 25, 2017 @ 17:38
    Chris
    0

    Locator Package for Umbraco 7

    Hi -

    I'm currently working to re-build an Umbraco 4 website on Umbraco Cloud. One problem: The old site uses the "Locator Razor Style" package to display a store locator, and this package doesn't work on Umbraco 7.

    Has anyone translated the contents of this older package to work on Umbraco 7?

    Or, would anyone take a shot at converting the below from a Razor Scripting File to a Partial View Scripting File? I believe I have everything else correctly converted - I'm just hung up on the syntax of the script itself...

    Thanks!

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using Locator
    @using Locator.GeoCoding
    @using Locator.GeoCoding.Services.Google
    @using umbraco.MacroEngines;
    
    @{
    
       @* Select the nodes you want to search through, defaults to children *@
       var nodesToSearchThrough = string.IsNullOrEmpty(Parameter.DocTypeAlias) ?
                Model.Children.Where("Visible"): Model.AncestorOrSelf(1).Descendants(Parameter.DocTypeAlias).Where("Visible");
    
       @* Alias of the property containing the long/lat, defaults to location *@
       string locationPropAlias = string.IsNullOrEmpty(Parameter.LocationPropAlias) ? "location" : Parameter.locationPropAlias;
    
       @* Number of results, defaults to 5 *@
       int numberOfSearchResults = string.IsNullOrEmpty(Parameter.NumberOfResults)|| Parameter.NumberOfResults == "0" ? 5 : int.Parse(Parameter.NumberOfResults);
    
       @* Distance unit, defaults to km *@
       DistanceUnits distanceunit = Parameter.UnitInMiles == "1" ? DistanceUnits.Miles : DistanceUnits.Kilometers;
    
    
       List<GeoItem> items = new List<GeoItem>();
       Location searchLocation = new Location();
    
       if(string.IsNullOrEmpty(Request["s"]))
       {
           @* Search term not provided HTML markup goes here... *@
           @*****************************************************@
    
       }
       else 
       {
          @* Lookup search location coordinates *@ 
          GeoResponse r = GoogleGeoCoder.CallGeoWS(Request["s"]);
    
          if(r.Results.Length == 0)
          {
            @* Location not found *@
            <div class="grid_12 rappel_2">
            <h2>@Request["s"] not found!</h2>
            <p>Try again.</p>
            </div>
          }
          else
          {
            @* build up list of results *@       
            searchLocation = new Location(r.Results[0].Geometry.Location.Lat, r.Results[0].Geometry.Location.Lng);
    
            foreach (var node in nodesToSearchThrough) {
    
                  Location itemLocation = new Location(
                        Convert.ToDouble(node.GetProperty(locationPropAlias).Value.Split(',')[0], Utility.NumberFormatInfo),
                        Convert.ToDouble(node.GetProperty(locationPropAlias).Value.Split(',')[1], Utility.NumberFormatInfo));  
    
                  items.Add(new GeoItem(node,itemLocation,searchLocation.DistanceBetween(itemLocation,distanceunit)));
    
            }
            @* sort based on distance *@
            items.Sort(new GeoItemComparer());
    
          }
       }
    }
    @if(items.Count > 0)
    {
    @* Output Results *@ 
    
    <h2 class="grid_12 rappel_2 blow_2">Closest dealers to @Request["s"]:</h2>
    
    <div class="grid_4" id="resultbox">
    
    @* Output list *@
    <ul class="notalist primary">
    @foreach (GeoItem geo in items.Take(numberOfSearchResults))
    {
        dynamic node = ((DynamicNode)geo.Node);
        if (node.locatorPriority == "Primary") { 
        <li class="findadealerresult">
            <h4>@node.Name</h4>
            <p>@node.Address1<br/>
               @node.City, @node.State, @node.Zip, @node.Country</p>
            <p><a target="_blank" href="http://maps.google.com/[email protected],@node.Address1,@node.City,@node.State,@node.Zip,@node.Country">Directions to Location</a></p>
            <p>Phone:&nbsp;@node.Phone<br/>
               Website:&nbsp;<a target="_blank" href="http://@node.Website">@node.Website</a><br/>
               Email:&nbsp;<a href="mailto:@node.Email">@node.Email</a>
        </li>
        }
    }
    </ul>
    
    <ul class="notalist secondary">
    @foreach (GeoItem geo in items.Take(numberOfSearchResults))
    {
        dynamic node = ((DynamicNode)geo.Node);
        if (node.locatorPriority == "Secondary") {
        <li class="findadealerresult">
            <h4>@node.Name</h4>
            <p>@node.Address1<br/>
               @node.City, @node.State, @node.Zip, @node.Country</p>
            <p><a target="_blank" href="http://maps.google.com/[email protected],@node.Address1,@node.City,@node.State,@node.Zip,@node.Country">Directions to Location</a></p>
            <p>Phone:&nbsp;@node.Phone<br/>
               Website:&nbsp;<a target="_blank" href="http://@node.Website">@node.Website</a><br/>
               Email:&nbsp;<a href="mailto:@node.Email">@node.Email</a>
        </li>
        }
    }
    </ul>
    
    <ul class="notalist tertiary">
    @foreach (GeoItem geo in items.Take(numberOfSearchResults))
    {
        dynamic node = ((DynamicNode)geo.Node);
        if (node.locatorPriority == "Tertiary") {
        <li class="findadealerresult">
            <h4>@node.Name</h4>
            <p>@node.Address1<br/>
               @node.City, @node.State, @node.Zip, @node.Country</p>
            <p><a target="_blank" href="http://maps.google.com/[email protected],@node.Address1,@node.City,@node.State,@node.Zip,@node.Country">Directions to Location</a></p>
            <p>Phone:&nbsp;@node.Phone<br/>
               Website:&nbsp;<a target="_blank" href="http://@node.Website">@node.Website</a><br/>
               Email:&nbsp;<a href="mailto:@node.Email">@node.Email</a>
        </li>
        }
    }
    </ul>
    
    <ul class="notalist unranked">
    @foreach (GeoItem geo in items.Take(numberOfSearchResults))
    {
        dynamic node = ((DynamicNode)geo.Node);
        if (node.locatorPriority == "") {
        <li class="findadealerresult">
            <h4>@node.Name</h4>
            <p>@node.Address1<br/>
               @node.City, @node.State, @node.Zip, @node.Country</p>
            <p><a target="_blank" href="http://maps.google.com/[email protected],@node.Address1,@node.City,@node.State,@node.Zip,@node.Country">Directions to Location</a></p>
            <p>Phone:&nbsp;@node.Phone<br/>
               Website:&nbsp;<a target="_blank" href="http://@node.Website">@node.Website</a><br/>
               Email:&nbsp;<a href="mailto:@node.Email">@node.Email</a>
        </li>
        }
    }
    </ul>
    
     </div> @* Grid_4 *@
    
    @* Output Map *@
    
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
    </script>
    
    <div id="map_canvas" class="grid_8" style="height:600px"></div>
    
    <script type="text/javascript">
      function initialize() {
        var latlng = new google.maps.LatLng(
                        @searchLocation.Latitude.ToString(Utility.NumberFormatInfo), 
                        @searchLocation.Longitude.ToString(Utility.NumberFormatInfo));
        var myOptions = {
          zoom: 10,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
        @{int c = 1;}                      
        @foreach (GeoItem geo in items.Take(numberOfSearchResults))
        {
            dynamic node = ((DynamicNode)geo.Node);    
    
            <text>
              var mLatlng@(c) = new google.maps.LatLng(
                                          @geo.Location.Latitude.ToString(Utility.NumberFormatInfo),
                                          @geo.Location.Longitude.ToString(Utility.NumberFormatInfo));
              var marker@(c) = new google.maps.Marker({
                  position: mLatlng@(c),
                  map: map,
                  title:"@node.Name"
              });                                                              
             </text>
            c++;
        }
      }
      initialize();
    
    </script>
    
    <div class="divide grid_12"></div>
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft