Advertisement
Guest User

Untitled

a guest
May 6th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. Public Structure Coordinate
  2. Public Property Latitude As Double
  3. Public Property Longitude As Double
  4. End Structure
  5.  
  6. Public Function SchoolDistrictVertices() As List(Of List(Of Coordinate))
  7. If SchoolDistrict Is Nothing OrElse SchoolDistrict.DistrictLocation Is Nothing Then
  8. Return Nothing
  9. Else
  10. 'get the points that define the shape by parsing the shape's WKT
  11. Dim result = New List(Of List(Of Coordinate))
  12. Dim wkt = SchoolDistrict.DistrictLocation.Location.WellKnownValue().WellKnownText
  13. Dim startPos = wkt.IndexOf("((")
  14.  
  15. Do Until startPos = -1
  16. Dim list = New List(Of Coordinate)
  17. Dim endPos = wkt.IndexOf(")", startPos)
  18. Dim piece = wkt.Substring(startPos + 1, endPos - (startPos + 1))
  19. Dim coords = piece.Split(","c)
  20.  
  21. For Each item In coords
  22. item = item.Trim().Replace("(", "")
  23. Dim parts = item.Split(" "c)
  24. Dim lng = parts(0)
  25. Dim lat = parts(1)
  26. Dim coord = New Coordinate()
  27. coord.Latitude = Convert.ToDouble(lat)
  28. coord.Longitude = Convert.ToDouble(lng)
  29.  
  30. list.Add(coord)
  31. Next
  32. result.Add(list)
  33.  
  34. startPos = wkt.IndexOf("(", endPos)
  35. Loop
  36.  
  37. Return result
  38. End If
  39.  
  40. End Function
  41.  
  42. @<div style="margin-top: 5px; height: 500px" id="map-canvas">
  43. </div>
  44.  
  45. @Section Scripts
  46. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false"></script>
  47.  
  48. <script>
  49. $(function () {
  50. google.maps.event.addDomListener(window, 'load', InitializeMap());
  51. });
  52.  
  53. function InitializeMap()
  54. {
  55. var mapOptions = {
  56. zoom: 12
  57. };
  58. var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  59.  
  60.  
  61. @code
  62. Dim count = 0
  63. Dim shapeList = ""
  64. End Code
  65. @If Model.SchoolDistrict IsNot Nothing Then
  66. @For Each shape In Model.SchoolDistrictVertices()
  67. @:var coordList@(count) = [
  68. @For Each coordinate In shape
  69. @:new google.maps.LatLng(@coordinate.Latitude, @coordinate.Longitude),
  70. Next
  71.  
  72. If shapeList <> "" Then
  73. shapeList += ", "
  74. End If
  75. shapeList += "coordList" + count.ToString()
  76. count += 1
  77. @:];
  78. Next
  79.  
  80. @:districtShape = new google.maps.Polygon({paths: [@shapeList], strokeColor: '#A366E0', strokeOpacity: 0.8, strokeWeight: 1, fillColor: '#A366E0', fillOpacity: 0.35});
  81. @:districtShape.setMap(map);
  82. End If
  83. }
  84.  
  85. </script>
  86. End Section
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement