dojo.connect(map, 'onLoad', function (theMap) { //resize the map when the browser resizes dojo.connect(dijit.byId('mapDiv'), 'resize', map, map.resize); var maxOffset = function maxOffset(map, pixelTolerance) { return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance; }; });
function zoomToEFH_Feature(name) { //set up maxOffset for performance var maxOffset = function maxOffset(map, pixelTolerance) { return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance; }; //create feature layer var efhLayer = new esri.layers.FeatureLayer("http://<internal server>/ArcGIS/rest/services/NMFS/EFH_MapperData/MapServer/6", { maxAllowableOffset: maxOffset(map, 1), outFields: ["*"], opacity: 0.75, id: "efhL" }); efhLayer.setDefinitionExpression("TYPE='EFH'"); //initialize query EFH_Fquery = new esri.tasks.Query(); EFH_Fquery.where = "DDBOX = '" + name + "' AND FMC = '" + regionName + "'"; //console.log(EFH_Fquery.where); //execute query efhLayer.queryFeatures(EFH_Fquery, function showResults(featureSet) { //console.log('inside show Results for EFH query'); map.graphics.clear(); var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID).setColor(new dojo.Color([255, 255, 0, 0.5])); //console.log(featureSet.features.length); var legendcode = '<table border=0 cellspacing="5" cellpadding="5"><caption>Lifestages</caption>'; //Loop through features in the featureSet and add them to the map. for (var i = 0, il = featureSet.features.length; i < il; i++) { //Get the current feature from the featureSet. //Feature is a graphic var graphic = featureSet.features; graphic.setSymbol(symbol); var featureextent = graphic.geometry.getExtent(); map.setExtent(featureextent, true); //Add graphic to the map graphics layer. map.graphics.add(graphic); }) }
var maxOffset = function maxOffset(map, pixelTolerance) { return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance; };
dojo.connect(efhLayer, "onLoad", function() { dojo.connect(map, "onZoomEnd", function() { efhLayer.setMaxAllowableOffset(maxOffset(map,1)); }); });
dojo.connect(globals.map, 'onZoomEnd', function() { globals.maxOffset = calcOffset(); dojo.forEach(globals.featureLayers, function(fl) { fl.setMaxAllowableOffset(globals.maxOffset); }); });
I'm having a hard time understanding how to solve this. Although I'm sure the answer is right in front of me. 🙂
Yep . You need to set up an event listener for onZoomEnd. When that event fires, calculate a value for maxAllowableOffset and then pass it to your feature layer's setMaxAllowableOffset method. The feature layer will then update with new geometries that are appropriate for the map's new scale.
if the feature is large it won't draw at all and I get a script errorError: timeout exceededhttp://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.6Line 14plus a "script too large" error.
Post your code? Is your server endpoint public?
Do you see this in all browsers?
var maxOffset = function maxOffset(map, pixelTolerance) { return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance; }; var highlightCountyLayer = new esri.layers.FeatureLayer("countyURL", { mode: esri.layers.FeatureLayer.MODE_SNAPSHOT, maxAllowableOffset: maxOffset(map,1) }); dojo.connect(highlightCountyLayer, "onLoad", function() { dojo.connect(map, "onZoomEnd", function() { console.log('onZoomEnd highlightCountyLayer') highlightCountyLayer.setMaxAllowableOffset(maxOffset(map,1)); }); }); map.addLayer(highlightCountyLayer);
Hi Don,At 2.7, we do this by default for feature layers in ONDEMAND mode so you no longer listen for onZoomEnd and update your features. Can you move to 2.7?
Thanks Derek! I was using version 2.6. Using 2.7 solves the issue i was having.
If i were to use SNAPSHOT mode, would I need to use the onZoomEnd method for recalculating?
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.