我正在使用ArcGIS地图显示位置,并允许用户缩放并拖动到目的地。当他们单击“保存”按钮时,我想保存坐标,在我的回发中,我想向他们显示相同的缩放位置。我能够保存范围值,不知道如何在鼠标点击时将其恢复。 setExtent对我不起作用。请参阅以下内容。
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.locator");
var map, locator;
function init() {
var initExtent = new esri.geometry.Extent({ xmin: -20098296, ymin: -2804413, xmax: 5920428, ymax: 15813776, spatialReference: { wkid: 54032} });
map = new esri.Map("map", { extent: initExtent });
var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://maps.dcgis.dc.gov/DCGIS/rest/services/DCGIS_DATA/DC_Basemap_WebMercator/MapServer");
map.addLayer(tiledMapServiceLayer);
locator = new esri.tasks.Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer");
dojo.connect(locator, "onAddressToLocationsComplete", showResults);
dojo.connect(map, "onExtentChange", showExtent);
dojo.connect(map, "onMouseMove", showCoordinates);
dojo.connect(map, "onMouseDrag", showCoordinates);
// setExtent(map, document.getElementById('extent').value);
}
function showCoordinates(evt) {
//get mapPoint from event
var mp = evt.mapPoint;
//display mouse coordinatesLabel1
dojo.byId("Label1").innerHTML = mp.x + ", " + mp.y;
}
function refreshMap() {
setExtent(map, document.getElementById('extent').value);
}
function setExtent(map,ext) {
// var startExtent = new esri.geometry.Extent(ext,
// new esri.SpatialReference({ wkid: 54032 }));
debugger
var coordinate = ext.split(" ");
var xmin=coordinate[1];
var ymin=coordinate[3];
var xmax=coordinate[5];
var ymax = coordinate[7];
var newExtent = new esri.geometry.Extent();
newExtent.xmin = xmin;
newExtent.ymin = ymin;
newExtent.xmax = xmax;
newExtent.ymax = ymax;
newExtent.spatialReference = new esri.SpatialReference({ wkid: 31466 });
map.setExtent(newExtent);
dojo.connect(locator, "onAddressToLocationsComplete", showResults);
}
function showExtent(ext) {
var s = "";
s = "XMin: " + ext.xmin +
" YMin: " + ext.ymin +
" XMax: " + ext.xmax +
" YMax: " + ext.ymax;
var spatialref = ext.spatialReference.wkid;
dojo.byId("onExtentChangeInfo").innerHTML = s;
document.getElementById('extent').value = s;
}
function locate() {
map.graphics.clear();
var add = dojo.byId("address").value.split(",");
var address = {
Address : add[0],
City: add[1],
State: add[2],
Zip: add[3]
};
locator.addressToLocations(address,["Loc_name"]);
}
function showResults(candidates) {
var candidate;
var symbol = new esri.symbol.SimpleMarkerSymbol();
var infoTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />Score: ${score}<br />Source locator: ${locatorName}");
symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);
symbol.setColor(new dojo.Color([255,0,0,0.75]));
var points = new esri.geometry.Multipoint(map.spatialReference);
for (var i=0, il=candidates.length; i<il; i++) {
candidate = candidates[i];
if (candidate.score > 70) {
var attributes = { address: candidate.address, score:candidate.score, locatorName:candidate.attributes.Loc_name };
var geom = esri.geometry.geographicToWebMercator(candidate.location);
var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate);
map.graphics.add(graphic);
map.graphics.add(new esri.Graphic(geom, new esri.symbol.TextSymbol(attributes.address).setOffset(0, 8)));
points.addPoint(geom);
}
}
// map.centerAndZoom(points, 6);
map.setExtent(points.getExtent().expand(1));
}
dojo.addOnLoad(init);
</script>
答案 0 :(得分:0)
在我的应用程序中,我也在计算和设置地图中的范围。它有效,但在我的情况下,我不是在arcgis地图上工作,而是在C#编码的ArcMap上,因为在我的示例代码中,方法/类看起来有点不同(例如我使用ESRI.ArcGIS.Carto。来自IMxDocument的IActiveView而不是esri.map类来获取/发送范围)但它看起来像一个类似的过程,所以也许这对你也有用。
我认为你唯一缺少的是刷新视图/地图?代码的相关部分在我的代码中看起来像这样:
// zoom
activeView.Extent = envelope.Envelope; // activeView.Extent is of class IEnvelope
activeView.Refresh();
所以也许你可以使用map.refresh()或类似的东西?