Using these methods with the template is quite simple:
1) Select a layer you want to search in;
2) Define a search method and search figure;
3) Perform search.
First, you may need to see all the attached layers:
Function printAllLayers( map) Dim Layer, LList, i LList = map.getLayers For i = 0 To LList.getCount - 1 Layer = LList.getLayer( i) Response.Write( i & ". <b>'" & Layer.getName & _ "'</b> Visible: <b>" & _ Layer.isVisible & "</b><br>" & vbCrLf) Next End Function
Output:
0. 'My Database' Visible: true
1. 'Cities' Visible: true
2. 'Business Listings' Visible: true
3. 'Exits' Visible: true
4. 'Airports' Visible: true
5. 'Landmarks' Visible: true
6. 'Arches, Craters, Geysers' Visible: true
7. 'Summits' Visible: true
8. 'Interstate Highways' Visible: true
9. 'Highways' Visible: true
10. 'Major Roads' Visible: true
11. 'Streets' Visible: true
12. 'Railroads' Visible: true
13. 'Minor Rivers, Creeks' Visible: true
14. 'State Borders' Visible: true
15. 'Lakes, Major Rivers' Visible: true
16. 'Parks, Forests' Visible: true
17. 'Landmark Boundaries' Visible: true
18. 'City Limits' Visible: true
19. 'Counties' Visible: true
20. 'States' Visible: true
Any one of the layers can be selected by either the layer name or the layer number.
Let's try to find, for example, all airports around Redlands, CA within specified radius.
There is a new feature in RouteMAP IMS version 3.0 that allows sorting the results
found within a circle by distance. This is one using the
SearchDef.setSearchMethod.
1) To find locations within a circle with a specified radius;
<script language="VBScript" runat=server> Class GeoLocation Public label Public x Public y Sub New( map, ilabel, ilat, ilon) Dim proj, pt proj = map.getProjection() pt = proj.project( ilat, ilon) label = ilabel x = pt.x y = pt.y End Sub End Class </script> <% Dim Layer, searchDef, Radius, center, rs, i, j, fieldCount, recCount, value ' get the layer Layer = map.getLayers().getLayerByName("Airports") ' create the SearchDef object searchDef = new SearchDef() '************************************************************************************ ' convert current units (miles or kilometers) to map units Radius = map.convertDistance( 20, map.getMeasureUnits(), MeasureUnit.rmMapUnits) center = new GeoLocation(map, "Redlands, CA", 34.0528, -117.1531) searchDef.setSearchMethod( SearchDef.rmSortDistance) searchDef.addCircle( center.x, center.y, Radius, 0) '************************************************************************************ rs = Layer.search((searchDef)) ' returns Recordset object ' prints all records from the recordset If Not rs Is Nothing Then recCount = rs.getRecordsCount() fieldCount = rs.getFields().getFieldCount() Response.Write( "<table border=1 cellspacing=0 cellpadding=2>" & vbCrLf) Response.Write( "<tr bgcolor='#DDDDDD'>" & vbCrLf) For i = 0 To fieldCount - 1 Response.Write("<th>" & rs.getFields().getFieldName(i) & "</th>") Next Response.Write("</tr>" & vbCrLf) For i = 0 To recCount - 1 rs.move( i) Response.Write("<tr>") For j = 0 To fieldCount - 1 value = rs.getAsString(j) If value = "" Then value = " " End If Response.Write("<td>" & value & "</td>") Next Response.Write("</tr>" & vbCrLf) Next Response.Write("</table>" & vbCrLf) End If %>
Output:
Name | Hub Size | State | Shape | #DISTANCE# |
---|---|---|---|---|
Redlands Muni | CA | shape | 2.246745296651 | |
San Bernardino International | CA | shape | 5.390558764235 | |
March Air Force Base | G | CA | shape | 13.239624913469 |
Rialto Muni /Miro Fld/ | CA | shape | 14.74300346114 | |
Flabob | CA | shape | 14.785189878143 | |
Riverside Muni | G | CA | shape | 17.410882909704 |
Banning Muni | CA | shape | 18.806164085232 |
You can easily modify this code to find locations by the other methods. Simply replace the
code outlined by asterisks above with the code below.
2) To find locations within a polygon:
Dim locs(5), gp locs(0) = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531) locs(1) = new GeoLocation( map, "Loma Linda, CA", 34.0484, -117.2629) locs(2) = new GeoLocation( map, "Bloomington, CA", 34.0704, -117.3976) locs(3) = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046) locs(4) = new GeoLocation( map, "Highland, CA", 34.1282, -117.2106) gp = new GeoPointsImpl() For i = 0 To UBound( locs) - 1 gp.addPoint( locs(i).x, locs(i).y) Next searchDef.addPolygon (gp, 0)
Dim locs(2), rc locs(0) = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046) locs(1) = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531) rc = new GeoRectangle() rc.left = locs(0).x rc.top = locs(0).y rc.right = locs(1).x rc.bottom = locs(1).y searchDef.addRectangle (rc, 0)
Dim locs(2), gp locs(0) = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531) locs(1) = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046) gp = new GeoPointsImpl() For i = 0 To UBound( locs) - 1 gp.addPoint( locs(i).x, locs(i).y) Next searchDef.addLineBuffer( gp, map.convertDistance( 10, map.getMeasureUnits(), MeasureUnit.rmMapUnits), 0)
Dim locs(2), RouteID locs(0) = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531) locs(1) = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046) ' see the Routing section for details RouteID = findRoute( locs) searchDef.addRouteBuffer( RouteID, map.convertDistance( 10, map.getMeasureUnits(), MeasureUnit.rmMapUnits), 0)