import com.esri.ags.FeatureSet; import com.esri.ags.utils.GraphicUtil; private function zoomToButton_clickHandler(event:MouseEvent):void { var graphic:Graphic = hostComponent.graphic; var map:Map = hostComponent.map; var geometry:Geometry = graphic.geometry; var extent:Extent = geometry.extent; // returns null for MapPoint or Multipoint's with only one point if (graphic.attributes.hasOwnProperty("Road_Id") && graphic.attributes.hasOwnProperty("Monument_Z")){ var featLay:FeatureLayer = new FeatureLayer("http://myserver/ArcGIS/rest/services/myservice/MapServer/5"); featLay.useAMF = true; var query:Query = new Query(); query.outSpatialReference = map.spatialReference; query.where = "ID = " + graphic.attributes.Road_Id; query.returnGeometry = true; featLay.queryFeatures(query, new AsyncResponder(qResult, qFault)); function qResult(featureSet:FeatureSet, token:XMLList = null):void { try{ extent = GraphicUtil.getGraphicsExtent(featureSet.features); if (extent) { map.extent = extent; // make sure the whole extent is visible if (!map.extent.contains(extent)) { map.level--; } } else { var mapPoint:MapPoint; if (geometry is MapPoint) { mapPoint = geometry as MapPoint; } else if (geometry is Multipoint) { var multipoint:Multipoint = geometry as Multipoint; if (multipoint.points && multipoint.points.length > 0) { mapPoint = multipoint.points[0]; } } if (mapPoint) { // Zoom to 1/16th the size of the current extent. // This is the same as calling map.zoomIn() four times. map.zoom(1 / 16, mapPoint); } } } catch (error:Error){ trace(error.message); } } //on fault function qFault(info:Object, token:Object = null):void { trace(info.toString()); } }else{ if (extent) { map.extent = extent; // make sure the whole extent is visible if (!map.extent.contains(extent)) { map.level--; } } else { var mapPoint2:MapPoint; if (geometry is MapPoint) { mapPoint2 = geometry as MapPoint; } else if (geometry is Multipoint) { var multipoint2:Multipoint = geometry as Multipoint; if (multipoint2.points && multipoint2.points.length > 0) { mapPoint2 = multipoint2.points[0]; } } if (mapPoint2) { // Zoom to 1/16th the size of the current extent. // This is the same as calling map.zoomIn() four times. map.zoom(1 / 16, mapPoint2); } } } }
import com.esri.ags.tasks.supportClasses.Query; import mx.rpc.AsyncResponder;
private function zoomToButton_clickHandler(event:MouseEvent):void { var graphic:Graphic = hostComponent.graphic; var map:Map = hostComponent.map; var geometry:Geometry = graphic.geometry; var extent:Extent = geometry.extent; // returns null for MapPoint or Multipoint's with only one point //This if is used to make sure you are only doing this if it is the right layer //that is why we check for the existance of two different fields if (graphic.attributes.hasOwnProperty("Rt_num") && graphic.attributes.hasOwnProperty("TARGET_FID")){ var featLay:FeatureLayer = new FeatureLayer("http://maps.co.stearns.mn.us/ArcGIS/rest/services/Construction/MapServer/0"); featLay.useAMF = true; var query:Query = new Query(); query.outSpatialReference = map.spatialReference; //Your attribute is a string where mine was a number query.where = "Rt_num = '" + graphic.attributes.Rt_num + "'"; query.returnGeometry = true; featLay.queryFeatures(query, new AsyncResponder(qResult, qFault)); function qResult(featureSet:FeatureSet, token:XMLList = null):void { try{ extent = GraphicUtil.getGraphicsExtent(featureSet.features); if (extent) { map.extent = extent; // make sure the whole extent is visible if (!map.extent.contains(extent)) { map.level--; } } else { var mapPoint:MapPoint; if (geometry is MapPoint) { mapPoint = geometry as MapPoint; } else if (geometry is Multipoint) { var multipoint:Multipoint = geometry as Multipoint; if (multipoint.points && multipoint.points.length > 0) { mapPoint = multipoint.points[0]; } } if (mapPoint) { // Zoom to 1/16th the size of the current extent. // This is the same as calling map.zoomIn() four times. map.zoom(1 / 16, mapPoint); } } } catch (error:Error){ trace(error.message); } } //on fault function qFault(info:Object, token:Object = null):void { trace(info.toString()); } }else{ if (extent) { map.extent = extent; // make sure the whole extent is visible if (!map.extent.contains(extent)) { map.level--; } } else { var mapPoint2:MapPoint; if (geometry is MapPoint) { mapPoint2 = geometry as MapPoint; } else if (geometry is Multipoint) { var multipoint2:Multipoint = geometry as Multipoint; if (multipoint2.points && multipoint2.points.length > 0) { mapPoint2 = multipoint2.points[0]; } } if (mapPoint2) { // Zoom to 1/16th the size of the current extent. // This is the same as calling map.zoomIn() four times. map.zoom(1 / 16, mapPoint2); } } } }
var featLay:FeatureLayer = new FeatureLayer("http://maps.co.stearns.mn.us/ArcGIS/rest/services/Construction/MapServer/0");
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.