Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Structure Coordinate
- Public Property Latitude As Double
- Public Property Longitude As Double
- End Structure
- Public Function SchoolDistrictVertices() As List(Of List(Of Coordinate))
- If SchoolDistrict Is Nothing OrElse SchoolDistrict.DistrictLocation Is Nothing Then
- Return Nothing
- Else
- 'get the points that define the shape by parsing the shape's WKT
- Dim result = New List(Of List(Of Coordinate))
- Dim wkt = SchoolDistrict.DistrictLocation.Location.WellKnownValue().WellKnownText
- Dim startPos = wkt.IndexOf("((")
- Do Until startPos = -1
- Dim list = New List(Of Coordinate)
- Dim endPos = wkt.IndexOf(")", startPos)
- Dim piece = wkt.Substring(startPos + 1, endPos - (startPos + 1))
- Dim coords = piece.Split(","c)
- For Each item In coords
- item = item.Trim().Replace("(", "")
- Dim parts = item.Split(" "c)
- Dim lng = parts(0)
- Dim lat = parts(1)
- Dim coord = New Coordinate()
- coord.Latitude = Convert.ToDouble(lat)
- coord.Longitude = Convert.ToDouble(lng)
- list.Add(coord)
- Next
- result.Add(list)
- startPos = wkt.IndexOf("(", endPos)
- Loop
- Return result
- End If
- End Function
- @<div style="margin-top: 5px; height: 500px" id="map-canvas">
- </div>
- @Section Scripts
- <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false"></script>
- <script>
- $(function () {
- google.maps.event.addDomListener(window, 'load', InitializeMap());
- });
- function InitializeMap()
- {
- var mapOptions = {
- zoom: 12
- };
- var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
- @code
- Dim count = 0
- Dim shapeList = ""
- End Code
- @If Model.SchoolDistrict IsNot Nothing Then
- @For Each shape In Model.SchoolDistrictVertices()
- @:var coordList@(count) = [
- @For Each coordinate In shape
- @:new google.maps.LatLng(@coordinate.Latitude, @coordinate.Longitude),
- Next
- If shapeList <> "" Then
- shapeList += ", "
- End If
- shapeList += "coordList" + count.ToString()
- count += 1
- @:];
- Next
- @:districtShape = new google.maps.Polygon({paths: [@shapeList], strokeColor: '#A366E0', strokeOpacity: 0.8, strokeWeight: 1, fillColor: '#A366E0', fillOpacity: 0.35});
- @:districtShape.setMap(map);
- End If
- }
- </script>
- End Section
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement