POST
|
"When is zoomToEFH_Feature called?" - it is called from a select box on a form. The user chooses an item and it calls this function. I do have maxOffset set as a global variable. I was looking at my code again after your last response and I noticed that I used this twice: var maxOffset = function maxOffset(map, pixelTolerance) {
return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance;
}; once in the init function and once in the zoomtoEFH_Feature function. Is that right? I also noticed that I am not using the setMaxAllowableOffset anywhere. Should I put that inside the zoomtoEFH_Feature function? dojo.connect(efhLayer, "onLoad", function() {
dojo.connect(map, "onZoomEnd", function() {
efhLayer.setMaxAllowableOffset(maxOffset(map,1));
});
});
... View more
01-13-2012
08:44 AM
|
0
|
0
|
1270
|
POST
|
[ATTACH=CONFIG]11168[/ATTACH][ATTACH=CONFIG]11169[/ATTACH] Thanks for your help. This is inside my init function: 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;
};
}); This is a function that I use to query my feature and then add the graphic(s) to the map: 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); })
}
... View more
01-13-2012
08:09 AM
|
0
|
0
|
1270
|
POST
|
Are the concepts that are presented in the generalize and performance samples under feature layers going to solve the problem of jagged edges at large scales? I have one featurelayer (150 mb featureclass) that displays 1-4 features at a time at most. At large scales I get really jagged edges. The source data, as viewed in ArcMap, is more detailed. I have included the maxAllowableOffset parameter as described in the generalize features sample. This does help with the speed of initially displaying some of the larger features based on what I am seeing in firebug. However, I'm struggling to make sense of the two samples and how I should implement the code in my own application. It seems that the code in the generalize sample might be all I need: var maxOffset = function maxOffset(map, pixelTolerance) { return Math.floor(map.extent.getWidth() / map.width) * pixelTolerance; }; but the performance sample uses a different calculation: function calcOffset() { return (globals.map.extent.getWidth() / globals.map.width); // console.log('extent changed...maxOffset: ', globals.maxOffset); } I'm not sure what to do or whether it will fix this problem.
... View more
01-13-2012
07:35 AM
|
0
|
17
|
3367
|
POST
|
The solution was to specify display levels on both of the layers I wanted to use (as the previous user suggested). I also made sure to not use the same level (10) in both layers.
basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer",{displayLevels:[10,11,12,13,14,15,16]});
map.addLayer(basemap); //added this layer so there would be a large number of zoom levels and for overview map
oceanBM = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer",{displayLevels:[0,1,2,3,4,5,6,7,8,9]});
map.addLayer(oceanBM);
... View more
12-20-2011
10:12 AM
|
0
|
0
|
305
|
POST
|
I want it the other way around. When the ocean basemap disappears I want the light canvas map to appear.
... View more
12-20-2011
09:08 AM
|
0
|
0
|
305
|
POST
|
I'm using two tiled services to display in my map. The ocean basemap and the world light gray canvas map. If I zoom past level 9 on the US Virgin Islands, the ocean basemap shows me "map data not yet available". I understand that part. What I don't understand is why the other basemap I've set up to display on the map does not appear until level 14. This happens regardless if I use the displayLevels parameter. Yet, if I look at that service through the services directory in the Javascript viewer I can see all of the levels including the ones between 9 and 14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> <title> Overview Map </title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.6/js/dojo/dijit/themes/claro/claro.css"> <style> html, body { height: 100%; width: 100%; margin: 0; padding: 0; } </style> <script type="text/javascript"> var djConfig = { parseOnLoad: true }; </script> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.6"> </script> <script type="text/javascript"> dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.dijit.OverviewMap"); var map; function init() { var initExtent = new esri.geometry.Extent({ "xmin":-7413378.648884336,"ymin":1898800.4677371255,"xmax":-7031499.25557178,"ymax":2094785.0082602233,"spatialReference":{"wkid":102100} }); map = new esri.Map("map", { extent: initExtent }); //resize the map when the browser resizes - view the 'Resizing and repositioning the map' section in //the following help topic for more details http://help.esri.com/EN/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/inside_guidelines.htm var resizeTimer; dojo.connect(map, 'onLoad', function(theMap) { //resize the map when the browser resizes dojo.connect(dijit.byId('map'), 'resize', map,map.resize); //add the overview map var overviewMapDijit = new esri.dijit.OverviewMap({ map: map }); overviewMapDijit.startup(); }); basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer",{displayLevels:[10,11,12,13,14,15,16]}); map.addLayer(basemap); oceanBM = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer"); map.addLayer(oceanBM); } dojo.addOnLoad(init); </script> </script> </head> <body class="claro"> <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin:0;"> <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="padding:0"> </div> </div> </body> </html>
... View more
12-16-2011
11:10 AM
|
0
|
3
|
598
|
POST
|
Thanks. The code you suggested provides the display I was looking for and helped me understand what I needed to do. After fiddling with it I realized I still had to add map.setExtent(taxLotExtent, true) with the boolean parameter as you suggested in an earlier post to make sure it fit within the window.
... View more
12-15-2011
08:54 AM
|
0
|
0
|
1120
|
POST
|
Thanks for both of those answers. Using expand with setExtent and the true option helps. But I have features that range in size from as big as the Gulf of Mexico to some dinky island in the middle of it. For the small area it would be helpful to see it within the context of nearby land or some other reference information from the Ocean basemap. That is why I was asking if there was a way to evaluate the size or shape of the area and then set a zoom level.
... View more
12-15-2011
06:56 AM
|
0
|
0
|
1120
|
POST
|
Okay, I should not have used esri.geometry.webMercatorToGeographic(geometry) in the example because that parcel layer is not in webMercator. I was thinking of my own layer which is in webMercator. That being said I would still like some thoughts on my original questions.
... View more
12-14-2011
11:28 AM
|
0
|
0
|
1120
|
POST
|
I want to display a feature on my map to provide better context within the surrounding area than usinng setExtent or setExtent().expand(). In this example, Display Find Task in Grid, the map displays each parcel at an extent that I think is too close for the viewer to see it within the context of the surrounding area. This is especially true for really small parcels. For larger parcels you get a slightly better view. Even so, in many cases, part of the boundary is blocked by the window. Would it be possible to evaluate the size/shape/area of each feature and then set a zoom level or extent that would provide a better view of the surrounding area? In other words, not be too close or too far away? I saw esri.geometry.geodesicAreas(polygons, areaUnit) and also saw I would probably need to use esri.geometry.webMercatorToGeographic(geometry) first. I tried adding a couple of lines in this function from the sample. I did not get any errors but I also did not see any numbers return in my console. Am I using this correctly? Overall, am I on the right track? function onRowClickHandler(evt){
var clickedTaxLotId = grid.getItem(evt.rowIndex).PARCELID;
var selectedTaxLot;
dojo.forEach(map.graphics.graphics,function(graphic){
if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId){
selectedTaxLot = graphic;
return;
}
});
var x = esri.geometry.webMercatorToGeographic(selectedTaxLot.graphic);
var areas = esri.geometry.geodesicAreas(x, esri.Units.ACRES);
console.log(areas);
var taxLotExtent = selectedTaxLot.geometry.getExtent();
map.setExtent(taxLotExtent);
}
... View more
12-14-2011
11:16 AM
|
0
|
6
|
1877
|
POST
|
I still don't understand how to zoom to the extent of a feature(graphic). The help/samples are not quite basic enough. I can see my graphic but I cannot zoom to it. I also want to use expand. function showResults(featureSet){
map.graphics.clear();
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID).setColor(new dojo.Color([255, 0, 0, 0.5]));
//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);
graphic.geometry.getExtent().expand(0.5); //my attempt
//Add graphic to the map graphics layer.
map.graphics.add(graphic);
}
}
... View more
12-13-2011
06:26 AM
|
0
|
2
|
4532
|
POST
|
Instead of two queries, why not add an onclick event to the item in the List that zooms to the geometry? (if you showed your populatelist /showresults functions, it would help) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>State Info</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript">var dojoConfig = { parseOnLoad:true };</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5"></script>
<script type="text/javascript">
dojo.require("esri.tasks.query");
dojo.require("dijit.form.Select");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.parser");
var query, queryTask, map, hapcLayer;
function init() {
//create map and add layer
map = new esri.Map("mapDiv");
var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer");
map.addLayer(layer);
hapcLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://egisws02.nos.noaa.gov/ArcGIS/rest/services/NMFS/HAPC/MapServer", {
"id": "HAPC"
});
map.addLayer(hapcLayer);
hapcLayer.hide();
}
//initialize query task
queryTask = new esri.tasks.QueryTask("http://egisws02.nos.noaa.gov/ArcGIS/rest/services/NMFS/HAPC/MapServer/0");
//initialize HAPC query
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["HAPC_Sitename","FisheryManagementCouncil"];
function executeQueryTask(fmc) {
//alert(fmc);
//set query based on what user selected in from list;
query.where = "FisheryManagementCouncil = '"+ fmc +"'";
//alert(query.where);
//execute query
queryTask.execute(query,populateList);
}
function populateList(results) {
//Populate the dropdown list box with unique values
var zone;
var values = []; //create array
var testValsEncountered={}; // create JSON object (dictionary) to hold multiple name:value pairs
//Add option to display all zoning types to the dropdown list
//values.push({name:"ALL"}); //All is not a value in the layer which is why it is being hard coded here.
var features = results.features; //features is a property of query task and has the type of 'graphic'. It is an array.
dojo.forEach (features, function(feature) { //optimized way of doing a for loop, specific to dojo, patterned after HTML5. Let's you apply a function to each element of an array. Feauture is each item in the array.
zone = feature.attributes.HAPC_Sitename; //feature in this context is a graphic and attribute is a property
if (!testValsEncountered[zone]) { //tests to see if the testval object containing the value of zone doesn't exist
testValsEncountered[zone] = true; //creates a "key" zone with a value of true
values.push({name:zone});//push the JSON pair into the values array
}
});
//sort function by Douglas Crockford, page 81, Javascript: The Good Parts
var by = function(name){
return function (o,p) {
var a,b;
if (typeof o === 'object' && typeof p === 'object' && o && p) {
a = o[name];
b = p[name];
if (a===b){
return o;
}
if (typeof a === typeof b){
return a < b ? -1 : 1;
}
return typeof a < typeof b ? -1 : 1;
}else {
throw {
name: 'Error',
message: 'Expected an object when sorting by ' + name
};
}
};
};
values.sort(by('name')); //sorts the array of unique values
values.unshift({name:"ALL"}); //ensures that an ALL option is not part of the sort and is listed first
//Create a ItemFileReadStore and use it for the ComboBox's data source
var dataItems = { //create JSON object to hold multiple name:value pairs
identifier: 'name', //optional
label: 'name', //optional
items: values
};
var store = new dojo.data.ItemFileReadStore({data:dataItems});
dijit.byId("mySelect").store = store;
}
function applyLayerDef(selItem){
map.graphics.clear();
//Filter the layer to display only the selected HAPC feature
if (selItem.value !== 'ALL') {
var layerDefs = [];
layerDefs[0] = "HAPC_Sitename = " + "'" + selItem.value + "'";
layerDefs.visibleLayers = [0];
map.getLayer("HAPC").setLayerDefinitions(layerDefs);
hapcLayer.show();
}
else {
map.getLayer("HAPC").setDefaultLayerDefinitions();
hapcLayer.show();
}
}
dojo.addOnLoad(init);
</script>
<body class="tundra">
<br/>
Select A Region :
<select name="fmc2" id="fmc2" onChange="executeQueryTask(dojo.byId('fmc2').value);">
<option value="" selected="selected">Select Region</option>
<option value="Mid-Atlantic Fishery Management Council">MAFMC</option>
<option value="Gulf of Mexico Fishery Management Council">GFMC</option>
</select>
<select id="mySelect"
dojotype="dijit.form.FilteringSelect"
style="width:300px;font-size:18px;"
autoComplete="true"
forceValidOption="false"
value="Select HAPC"
onChange="applyLayerDef(this)">
</select>
<div id="mapDiv" style="width:600px; height:600px; border:1px solid #000;"></div>
</body>
</html> Your comment reminded me that I had something similar working the other day in another file. I've included the full file here. Except I used onChange instead of onClick. My problem is really about how to zoom into a feature or graphic that the user chooses from a list. As a beginner I've been struggling to figure out how to do this. I think I have to use a graphic but I'm not sure because this applyLayerDef function seems to have no problem displaying the individual feature. I also want the map to zoom into a predefined area with the first drop down box but that list is not getting populated from a map service. I've thought about using a JSON file.
... View more
11-23-2011
10:32 AM
|
0
|
0
|
304
|
POST
|
I want to zoom to a feature (graphic) when a user selects it from a dojo filtering select list. This list is populated using a queryTask. Is it okay to execute a second queryTask that takes the same results and does something else with it? function HAPCexecuteQueryTask(fmc) {
HAPCquery.where = "FisheryManagementCouncil = '"+ fmc +"'";
HAPCqueryTask.execute(HAPCquery,populateList);
HAPCqueryTask.execute(HAPCquery,showResults);
} I have been looking at this example and it seems to be pretty close to what I want to do (see last entry for solution. http://forums.arcgis.com/threads/36317-Zoom-to-Graphic?highlight=graphics
... View more
11-23-2011
08:40 AM
|
0
|
2
|
1132
|
POST
|
I've seen some samples where only the basics of defining and adding a map are there. I've seen some samples where there are functions and/or functions that respond to events are in there. I've seen some samples where these functions are outside of the init function. What is the general idea or best practices of what should go inside your init function be? Is there another document or web page that explains this?
... View more
11-16-2011
07:38 AM
|
0
|
1
|
1119
|
Title | Kudos | Posted |
---|---|---|
1 | 02-01-2019 08:27 AM | |
2 | 04-23-2024 08:44 AM | |
1 | 11-07-2023 11:31 AM | |
1 | 11-21-2023 10:17 AM | |
1 | 03-19-2022 06:00 AM |
Online Status |
Offline
|
Date Last Visited |
05-22-2024
08:42 PM
|