Advertisement
Guest User

Untitled

a guest
Oct 7th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. @model IEnumerable<MapPractise.Models.GeoCodeLocation>
  2.  
  3. @{
  4. ViewBag.Title = "Index";
  5. Layout = "~/Views/Shared/_Layout.cshtml";
  6. }
  7. <style>
  8. #map {
  9. height: 500px;
  10. width: 800px;
  11. }
  12. </style>
  13. <h2>Index</h2>
  14.  
  15. @*<input id="pac-input" class="controls" type="text" placeholder="Search Box">*@
  16.  
  17. <div id="map"></div>
  18. <br />
  19. <p>
  20. @Html.ActionLink("Create New", "Create", "Locations", new { @class = "btn btn-primary" })
  21. </p>
  22.  
  23. <table class="table">
  24. <tr>
  25. <th>
  26. @Html.DisplayNameFor(model => model.Name)
  27. </th>
  28. <th>
  29. @Html.DisplayNameFor(model => model.Description)
  30. </th>
  31. <th>
  32. @Html.DisplayNameFor(model => model.Address)
  33. </th>
  34. <th></th>
  35. </tr>
  36.  
  37. @foreach (var item in Model)
  38. {
  39. <tr class="coordinates">
  40. <td>
  41. @Html.DisplayFor(modelItem => item.Name)
  42. </td>
  43. <td class="description">
  44. @Html.DisplayFor(modelItem => item.Description)
  45. </td>
  46. <td id="addressLoc" class="address">
  47. @Html.DisplayFor(modelItem => item.Address)
  48. </td>
  49. <td>
  50. @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
  51. @Html.ActionLink("Details", "Details", new { id = item.Id }) |
  52. @Html.ActionLink("Delete", "Delete", new { id = item.Id })
  53. </td>
  54. </tr>
  55. }
  56.  
  57. </table>
  58.  
  59. @section Scripts {
  60. @Scripts.Render("~/bundles/SidzMapbox")
  61. }
  62. <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_API&libraries=places&callback=initAutocomplete" async defer></script>
  63.  
  64. function initAutocomplete()
  65. {
  66. var map = new google.maps.Map(document.getElementById('map'), {
  67. center: {
  68. lat: 52.728616,
  69. lng: 6.4901
  70. },
  71. zoom: 13,
  72. mapTypeId: 'roadmap'
  73. });
  74. var markers = [];
  75.  
  76. // Create the search boxs and link them to the UI elements.
  77. var searchBoxes = $(".address");
  78. for (var i = 0; i < searchBoxes.length; i++) {
  79. var searchBox = new google.maps.places.SearchBox(searchBoxes[i]);
  80. map.controls[google.maps.ControlPosition.TOP_LEFT].push(searchBoxes[i]);
  81. map.addListener('bounds_changed', function() {
  82. searchBox.setBounds(map.getBounds());
  83. });
  84. markers.push([]);
  85. searchBox.addListener('places_changed', (function(i) {
  86. return function() {
  87. processSearch(i, this)
  88. }
  89. }(i)));
  90. }
  91.  
  92. function processSearch(uniqueId, searchBox)
  93. {
  94. var places = searchBox.getPlaces();
  95.  
  96. if (places.length == 0) {
  97. return ;
  98. }
  99.  
  100. // Clear out the old markers.
  101. markers[uniqueId].forEach(function(marker) {
  102. marker.setMap(null);
  103. });
  104. markers[uniqueId] = [];
  105.  
  106. // For each place, get the icon, name and location.
  107. var bounds = new google.maps.LatLngBounds();
  108. places.forEach(function(place) {
  109. if (!place.geometry) {
  110. console.log("Returned place contains no geometry");
  111. return;
  112. }
  113. var icon = {
  114. url: place.icon,
  115. size: new google.maps.Size(71, 71),
  116. origin: new google.maps.Point(0, 0),
  117. anchor: new google.maps.Point(17, 34),
  118. scaledSize: new google.maps.Size(25, 25)
  119. };
  120.  
  121. // Create a marker for each place.
  122. if (!markers[uniqueId]) markers.push([]);
  123. markers[uniqueId].push(new google.maps.Marker({
  124. map: map,
  125. icon: icon,
  126. title: place.name,
  127. position: place.geometry.location
  128. }));
  129.  
  130. if (place.geometry.viewport) {
  131. // Only geocodes have viewport.
  132. bounds.union(place.geometry.viewport);
  133. } else {
  134. bounds.extend(place.geometry.location);
  135. }
  136. });
  137. map.fitBounds(bounds);
  138. }
  139. }
  140.  
  141. <!DOCTYPE html>
  142. <html>
  143. <head>
  144. <meta charset="utf-8" />
  145. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  146. <title>@ViewBag.Title - My ASP.NET Application</title>
  147. @Styles.Render("~/Content/css")
  148. @Scripts.Render("~/bundles/modernizr")
  149.  
  150.  
  151. @* This is for the mapbox map. *@
  152. <script src='https://api.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.js'></script>
  153. <link href='https://api.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.css' rel='stylesheet' />
  154. @*This is used for the Geocoding Mapbox API*@
  155. <script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.2.0/mapbox-gl-geocoder.min.js'>
  156. </script>
  157. <link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.2.0/mapbox-gl-geocoder.css' type='text/css' />
  158.  
  159. </head>
  160. <body>
  161. <div class="navbar navbar-inverse navbar-fixed-top">
  162. <div class="container">
  163. <div class="navbar-header">
  164. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  165. <span class="icon-bar"></span>
  166. <span class="icon-bar"></span>
  167. <span class="icon-bar"></span>
  168. </button>
  169. @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
  170. </div>
  171. <div class="navbar-collapse collapse">
  172. <ul class="nav navbar-nav">
  173. <li>@Html.ActionLink("Home", "Index", "Home")</li>
  174. <li>@Html.ActionLink("About", "About", "Home")</li>
  175. <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
  176. <li>@Html.ActionLink("MapBoxGeoCoder", "MapBoxGeoCoder", "Home")</li>
  177. <li>@Html.ActionLink("Location", "Index", "Locations")</li>
  178. <li>@Html.ActionLink("ViewGeo Code","Index","GeoCodeLocations")</li>
  179. </ul>
  180. @Html.Partial("_LoginPartial")
  181. </div>
  182. </div>
  183. </div>
  184. <div class="container body-content">
  185. @RenderBody()
  186. <hr />
  187. <footer>
  188. <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
  189. </footer>
  190. </div>
  191.  
  192. @Scripts.Render("~/bundles/jquery")
  193. @Scripts.Render("~/bundles/bootstrap")
  194. @RenderSection("scripts", required: false)
  195. </body>
  196. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement