zoomTo: function (gId) { array.forEach(this.map.resultsLayer.graphics, function (graphic) { if (graphic.gId === gId) { if (graphic.geometry.type === 'point') { this.map.centerAndZoom(graphic.geometry, 18); } else { this.map.setExtent(graphic.geometry.getExtent(), true); } return; } }); }
function calcGraphicsExtent(graphicsArray) { var g = graphicsArray[0].geometry, fullExt = g.getExtent(), ext, i, il = graphicsArray.length; if (fullExt === null) { fullExt = new Extent(g.x, g.y, g.x, g.y, g.spatialReference); } for (i=1; i<il; i++) { ext = (g = graphicsArray.geometry).getExtent(); if (ext === null) { ext = new Extent(g.x, g.y, g.x, g.y, g.spatialReference); } fullExt = fullExt.union(ext); } return fullExt; }
function showResults(featureSet) { //remove all graphics on the maps graphics layer map.graphics.clear(); var extent = esri.graphicsExtent(featureSet.features); map.setExtent(extent.expand(1), true); //Performance enhancer - assign featureSet array to a single variable. var resultFeatures = featureSet.features; var railLocationTemplate = new InfoTemplate("Shop Location", "<b>Shop Name: </b>${NAME}<br/>"); for (var i=0, il=resultFeatures.length; i<il; i++) { //Get the current feature from the featureSet. //Feature is a graphic var graphic = resultFeatures; // graphic.setSymbol(symbol); //Set the infoTemplate. graphic.setInfoTemplate(railLocationTemplate); console.log("BUTTON CLICKED"); //Add graphic to the map graphics layer. map.graphics.add(graphic); } }
function showResults(featureSet) { map.graphics.clear(); var graphicsArray = []; var resultFeatures = featureSet.features; var railLocationTemplate = new InfoTemplate("Shop Location", "<b>Shop Name: </b>${NAME}<br/>"); for (var i=0, il=resultFeatures.length; i<il; i++) { var graphic = resultFeatures; graphic.setInfoTemplate(railLocationTemplate); graphicsArray.push(graphic); } var extent = calcGraphicsExtent(graphicsArray); map.setExtent(extent, true).then(function(){ for(var i=0; i<graphicsArray.length; i++) { map.graphics.add(graphicsArray); } }); } function calcGraphicsExtent(graphicsArray) { var g = graphicsArray[0].geometry, fullExt = g.getExtent(), ext, i, il = graphicsArray.length; if (fullExt === null) { fullExt = new Extent(g.x, g.y, g.x, g.y, g.spatialReference); } for (i=1; i<il; i++) { ext = (g = graphicsArray.geometry).getExtent(); if (ext === null) { ext = new Extent(g.x, g.y, g.x, g.y, g.spatialReference); } fullExt = fullExt.union(ext); } return fullExt; }
if (graphic.geometry.type === 'point') { var maxZoom = map.getMaxZoom(); map.centerAndZoom(graphic.geometry, maxZoom - 1); } else { map.setExtent(graphicsUtils.graphicsExtent([graphic])); }
if (this.graphics.length === 1 && this.graphics[0].geometry.type === 'point')for a generic check. I actually ran into an issue with a dataset in which the queries being made by the user regularly return multiple records at the same point. graphicsExtent also returns null in this situation but not as easy to check. I think they are considering graphicsExtent returning an extent with the point(s) at the center in these situations.
require(["dojo/ready", "dojo/on", "esri/map", "esri/InfoTemplate", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/tasks/IdentifyTask", "esri/tasks/IdentifyParameters", "esri/dijit/Popup", "dojo/_base/array", "esri/Color", "dojo/dom-construct", "esri/tasks/QueryTask", "esri/tasks/query", "esri/urlUtils", "esri/dijit/BasemapToggle", "esri/symbols/SimpleMarkerSymbol", "dojo/domReady!", "esri/Credential", "esri/config" ], function(ready, on, Map, InfoTemplate, ArcGISDynamicMapServiceLayer, SimpleFillSymbol, SimpleLineSymbol, IdentifyTask, IdentifyParameters, Popup, arrayUtils, Color, domConstruct, QueryTask, Query, urlUtils, BasemapToggle, SimpleMarkerSymbol)