Despite all the options, the template that allows you to use any of these methods 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() { var LList = Map.getLayers(); var Layer; for( var i=0; i < LList.getCount(); i++) { Layer = LList.getLayer( i); Response.Write( i + ". <b>'" + Layer.getName() + "'</b> Visible: <b>" + Layer.isVisible() + "</b><br>\n"); } }
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;
// get the layer var Layer = Map.getLayers().getLayerByName("Airports"); // create the SearchDef object var searchDef = Server.CreateObject("RMIMS.SearchDef"); //************************************************************************** // convert current units (miles or kilometers) to map units var Radius = Map.convertDistance( 20, Map.getMeasureUnits(), rmMapUnits); var center = new GeoLocation ("Redlands, CA", 34.0528, -117.1531); searchDef.setSearchMethod( rmSortDistance); searchDef.addCircle( center.x, center.y, Radius, 0); //************************************************************************** var rs = Layer.search(searchDef); //returns Recordset object // prints all records from the recordset if( rs != null && rs.getRecordsCount() != 0) { var recCount = rs.getRecordsCount(); var fieldCount = rs.getFields().getFieldCount(); Response.Write( "<table border=1 cellspacing=0 cellpadding=2>\n"); Response.Write( "<tr bgcolor='#DDDDDD'>\n"); for (var i = 0; i < fieldCount; i++) Response.Write("<th>" + rs.getFields().getFieldName(i) + "</th>"); Response.Write("</tr>\n"); for (var i = 0; i < recCount; i++) { rs.move(i); Response.Write("<tr>"); for (var j = 0; j < fieldCount; j++) { value = rs.getAsString(j); if (value == "") value = " "; Response.Write("<td>" + value + "</td>"); } Response.Write("</tr>\n"); } Response.Write("</table>\n"); } function GeoLocation( label, lat, lon) { var pt = Map.getProjection().project( lat, lon); this.label = label; this.x = pt.x; this.y = pt.y; }
Output:
Name | Hub Size | State | Shape |
---|---|---|---|
Flabob | CA | shape | |
Redlands Muni | CA | shape | |
Rialto Muni /Miro Fld/ | CA | shape | |
San Bernardino International | CA | shape | |
March Air Force Base | G | CA | shape |
Riverside Muni | G | CA | shape |
Banning Muni | CA | shape |
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:
var locs = new Array(); locs[0] = new GeoLocation( "Redlands, CA", 34.0528, -117.1531); locs[1] = new GeoLocation( "Loma Linda, CA", 34.0484, -117.2629); locs[2] = new GeoLocation( "Bloomington, CA", 34.0704, -117.3976); locs[3] = new GeoLocation( "San Bernardino, CA", 34.1214, -117.3046); locs[4] = new GeoLocation( "Highland, CA", 34.1282, -117.2106); var gp = Server.CreateObject("RMIMS.GeoPointsImpl"); for(var i = 0; i < locs.length; i++) gp.addPoint( locs[i].x, locs[i].y); searchDef.addPolygon( gp, 0);
var locs = new Array(); locs[0] = new GeoLocation( "San Bernardino, CA", 34.1214, -117.3046); locs[1] = new GeoLocation( "Redlands, CA", 34.0528, -117.1531); var rc = Server.CreateObject("RMIMS.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);
var locs = new Array(); locs[0] = new GeoLocation( "Redlands, CA", 34.0528, -117.1531); locs[1] = new GeoLocation( "San Bernardino, CA", 34.1214, -117.3046); var gp = Server.CreateObject("RMIMS.GeoPoints"); for(var i = 0; i < locs.length; i++) gp.addPoint( locs[i].x, locs[i].y); searchDef.addLineBuffer( gp, Map.convertDistance( 10, Map.getMeasureUnits(), rmMapUnits), 0);
var locs = new Array(); locs[0] = new GeoLocation( "Redlands, CA", 34.0528, -117.1531); locs[1] = new GeoLocation( "San Bernardino, CA", 34.1214, -117.3046); // see the Routing section for details var RouteID = findRoute( locs, 50, rmShortest, false); searchDef.addRouteBuffer( RouteID, Map.convertDistance( 10, Map.getMeasureUnits(), rmMapUnits), 0);