arcgisjsapi根据屏幕输入的经纬度坐标定位从而获取地图中心点坐标。
1.ArcGIS产品线为用户提供一个可伸缩的,全面的GIS平台。ArcObjects包含了大量的可编程组件,从细粒度的对象(例如,单个的几何对象)到粗粒度的对象(例如与现有ArcMap文档交互的地图对象)涉及面极广,这些对象为开发者集成了全面的GIS功能。
2.每一个使用ArcObjects建成的ArcGIS产品都为开发者提供了一个应用开发的容器,包括桌面GIS(ArcGISDesktop),嵌入式GIS(ArcGISEngine)以及服务端GIS(ArcGISServer)。
定位蓝点不显示有很多种原因,我这里记录一种我遇到过的,就是我添加了定位信息之后,定位蓝点会消失,把定位信息去掉,蓝点就出现了,这是我在初始化定位的时候添加了这行代码aMap.setLocationSource(this)//设置了定位的监听,这里要实现LocationSource接口
去掉就可以了
思路:把ajax获取的数据,替换mapPoints
<script type="text/javascript">var mapPoints = []
var map = new BMap.Map("container")
$(function () {
$.ajax({
url: "/BaiduMap/GetPoints",
type: 'get',
success: function (data) {
mapPoints = data//替换数据
if (mapPoints != null)
{
InitMap()
for (var i=0 i < mapPoints.length i++) {
var points = new BMap.Point(mapPoints[i].y, mapPoints[i].x)//创建坐标点
var opts = {
width: 250,
height: 100,
title: mapPoints[i].title
}
var label = new BMap.Label(mapPoints[i].branch, {
offset: new BMap.Size(25, 5)
})
var infoWindows = new BMap.InfoWindow(mapPoints[i].con, opts)
markerFun(points, label, infoWindows)
}
}
}
})
})
function InitMap() {
var point = new BMap.Point(120.382029, 30.312903)
map.centerAndZoom(point, 9)
var marker = new BMap.Marker(point)
//var mapPoints = [//这里读到数据就是没显示定位,看了下,显示出来的是字符串,mapPoints 内加载的内容都是对象
//{ x: 30.312903, y: 120.382029, title: "A", con: "我是A", branch: "老大" },
//{ x: 30.215855, y: 120.024568, title: "B", con: "我是B", branch: "老二" },
//{ x: 30.18015, y: 120.174968, title: "C", con: "我是C", branch: "老三" },
//{ x: 30.324994, y: 120.164399, title: "D", con: "我是D", branch: "老四" },
//{ x: 30.24884, y: 120.305074, title: "E", con: "我是E", branch: "老五" }
//]
var i = 0
map.addOverlay(marker)
map.enableScrollWheelZoom(true)
}
// 函数 创建多个标注
function markerFun(points, label, infoWindows) {
var markers = new BMap.Marker(points)
map.addOverlay(markers)
markers.setLabel(label)
markers.addEventListener("click", function (event) {
console.log("0001")
map.openInfoWindow(infoWindows, points)//参数:窗口、点 根据点击的点出现对应的窗口
})
}
</script>
后台:
public JsonResult GetPoints(){
List<PointView> lstPoint = new List<PointView>{
new PointView{x=30.312903M,y=120.382029M,title="A",con="我是A",branch="老大"},
new PointView{x=30.215855M,y=120.024568M,title="B",con="我是B",branch="老二"},
new PointView{x=30.18015M,y=120.174968M,title="C",con="我是C",branch="老三"},
new PointView{x=30.324994M,y=120.164399M,title="D",con="我是D",branch="老四"},
new PointView{x=30.24884M,y=120.305074M,title="E",con="我是E",branch="老五"}
}
JsonResult jsonResult = new JsonResult()
jsonResult.Data = lstPoint
jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet
return jsonResult
}
public class PointView
{
public decimal x { get set }
public decimal y { get set }
public string title { get set }
public string con { get set }
public string branch { get set }
}
效果: