技术开发 频道

详解在ASP.NET Web应用中使用VEMap控件

  (3)保存 Default.aspx。

  (4)在调试菜单上,单击开始执行(不调试)。

  (5)当 Internet Explorer 打开时,单击 Show All Stores,并验证商店在地图上显示为图钉。

  (6)关闭 Internet Explorer。

  3.添加代码以显示指定位置附近的商店

  (1)在 Default.aspx 中的 ShowNearbyStores 函数中,在注释 Use the VEMap.Find method to find the location entered by the user and call the onFind function to process the results下,添加以下代码。

results  = map.Find(    null,
            document.getElementById(
"SearchLocation").value,
            
null, null,null, 1, false, false, false, true,
            onFind);

 

  注意:此代码使用 Virtual Earth 根据用户输入的文本查找位置。当找到一个或多个位置时,此代码会指定应调用 OnFind 函数。

  (2)在 onFind 函数中,在注释 define the search point as the latitude and longitude of the first place in the results下,添加以下代码。

var SearchFromPoint = places[0].LatLong;

 

  注意:此代码取用在结果中找到的第一个位置,并以逗号分隔的字符串的形式提取纬度和经度。

  (3)在 onFind 函数中,在注释 Import GeoRSS feed of stores near the search point, and call onNearbyStoresLoad function when the data is loaded下,添加以下代码。

var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS,
                                
"./Stores.georss?SearchFrom=" + SearchFromPoint);
map.ImportShapeLayerData(veLayerSpec, onNearbyStoresLoad,
true);

 

  注意:此代码向网站发送针对 Stores.georss 页的请求,该请求使用一个包含搜索位置的纬度和经度的 SearchFrom 参数。此请求将由您在上一练习中实现的 HTTP 处理程序处理,并返回包含搜索区域和其中的所有商店的 GeoRSS 订阅源。接着,此代码将 GeoRSS 数据作为新层加载到地图控件中,并指定在将此数据加载到地图中后调用 onNearbyStoresLoad 函数。

  (4)在 onNearbyStoresLoad 函数中,在注释 Don't count or show the first shape (the search location)下,添加以下代码。

var storecount = feed.GetShapeCount()-1;
feed.GetShapeByIndex(
0).HideIcon();
document.getElementById(
"Info").innerHTML =
    
'There are ' + storecount + ' stores.';

 

  (5)在 onNearbyStoresLoad 函数中,在注释 Show the info for the search area when the results first load下,添加以下代码。

map.ShowInfoBox(feed.GetShapeByIndex(0));

 

  注意:此代码将显示搜索区域的信息气球。

  (6)保存 Default.aspx。

  (7)在调试菜单上,单击开始执行(不调试)。

  (8)当 Internet Explorer 打开时,输入文本 Seattle 并单击 Show Stores Near,然后验证这些商店在地图中显示为图钉并用一个圆圈显示搜索区域。

  (9)使用位置 San Francisco 和90210 重复此搜索。

  (10)关闭 Internet Explorer。

  (11)关闭 Visual Studio。

  (12)关闭 Hyper-V,放弃更改。

0