RouteMAP IMS 3.0 .NET API

Finding What's Nearby

In addition to the Find location, there is another similar feature that allows you to find nearby places. There are several options:
1) Find locations within a circle of a specified radius;
2) Find locations within a polygon;
3) Find locations within a rectangle;
4) Find locations within a specified distance along a line;
5) Find locations within a specified distance along a route.

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");
    }
}

VBScript version

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 = "&nbsp;";

            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;
}

VBScript version

Output:

NameHub SizeStateShape
Flabob CAshape
Redlands Muni CAshape
Rialto Muni /Miro Fld/ CAshape
San Bernardino International CAshape
March Air Force BaseGCAshape
Riverside MuniGCAshape
Banning Muni CAshape


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);

3) To find locations within a rectangle:
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);

4) To find locations along a line:
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);

5) To find locations along a route;
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);

VBScript version