require(["esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"dojo/domReady!"],
function (Map, ArcGISDynamicMapServiceLayer) {
map = new Map("map", { logo: false });
var layer = new ArcGISDynamicMapServiceLayer(“http://xxx/MapServer");
map.addLayer(layer);
});
我想在页面通过设置地图中心点(有设备点,点击设备后,地图以设备坐标为中心点)
function setCenter()
{
for (var i = 0; i < layer.graphics.length; i++) {
var item1 = layer.graphics[i];
if (item1.attributes.Id == mid) {
var initialExtent = new esri.geometry.Extent({ "xmin": item1._extent.xmin, "ymin": item1._extent.ymin, "xmax": item1._extent.xmax, "ymax": item1._extent.ymax, "spatialReference": { "wkid": 4326 } });
map.setExtent(initialExtent);
map.centerAt(item1.geometry);//试过了不行
map.centerAt(item1.geometry.x,item1.geometry.y);//也不行
return;
}
}
}
坐标系不同,spatialReference
centerAt()的参数是个Point类型的。
require(["esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/geometry/Point",
"dojo/domReady!"],
map.centerAt(new Point(item1.geometry.x, item1.geometry.y));
报错point
@apgk: 报错是因为 应该这样创建对象new esri.geometry.Point(...),请问你最后设置中心点成功了吗