关键技术:SuperMap GIS、JavaScript 、Jquery
发布人:李嘉乐
撰写时间 : 2019/01/18
一、先用SuperMap iDesktop 9D 制作一张地图,然后通过SuperMap iServer 发布地图。再在Visual Studio 通过视图层实例化需要的控件和图层并展示地图。
代码如下:
var map, layer,polygonLayer,vector ,markerLayer ,markerLayer2,drawPoint,infowin = null
url = 'http://localhost:8097/iserver/services/map-ZengChengQu/rest/maps/区县界_region_1@ZengChengregion1';//地图路径
function init() {
polygonLayer = new SuperMap.Layer.Vector("Vector Layer");//矢量图层
markerLayer = new SuperMap.Layer.Markers("Markers");//点坐标标志图层
markerLayer2 = new SuperMap.Layer.Markers("Markers");//点坐标标志图层
vector = new SuperMap.Layer.Vector("vector");//绘圆图层
drawPoint = new SuperMap.Control.DrawFeature(polygonLayer, SuperMap.Handler.Point);//绘点控件声明
drawPoint.events.on({
"featureadded": drawCompletedCenter});
map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.Zoom(),//缩放控件
new SuperMap.Control.LayerSwitcher(),///图层管理器
new SuperMap.Control.Navigation({
//地图浏览控件
dragPanOptions: {
enableKinetic: true
}
}), drawPoint]
});//添加控件
layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {
maxResolution: "auto" }); //向服务请求地图,声明图层
layer.events.on({
"layerInitialized": addLayer });//layer监听事件
//SuperMap.Layer.Vector 该图层用于渲染矢量要素。
}
function addLayer() {
map.addLayers([layer, vector, markerLayer2, polygonLayer, markerLayer]);//添加图层
map.setCenter(new SuperMap.LonLat(113.822210532997, 23.290412124899), 3);//地图中心坐标
}
二、要执行周边查询,那么就要先明确一个周边查询的中心点。代码如下:
function drawCompletedCenter(drawGeometryArgs) {
drawPoint.deactivate();//选择中心点禁用
markerLayer.clearMarkers();//清除标签图层
polygonLayer.removeAllFeatures();//清除矢量图层
var x = drawGeometryArgs.feature.geometry.x;//获取中心的x坐标
var y = drawGeometryArgs.feature.geometry.y//获取中心的y坐标
$("#X").html(x);
$("#Y").html(y);//给两个分别元素赋上x,y坐标值,显示为none. 方便随时利用。