|
POST
|
Hi Dan, You're right in that the API puts it on the developer to sort out values for a unique value renderer. If you're coming from ArcGIS Desktop, this probably seems like a lot of work. But it can be done with a few lines of JS code. Here's a modified version of the unique value renderer sample that gets unique values for a field, generates a color ramp and then builds a unique value renderer using the unique values and colors from the ramp:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Unique Value Renderer</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css">
<script>var dojoConfig = { parseOnLoad: true };</script>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2"></script>
<script>
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
var map;
dojo.ready(function() {
var bounds = new esri.geometry.Extent({"xmin":-14558502,"ymin":2799695,"xmax":-6731350,"ymax":6713271,"spatialReference":{"wkid":102100}});
map = new esri.Map("map", {
extent: bounds,
slider: false
});
map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
var defaultSymbol = new esri.symbol.SimpleFillSymbol().setStyle("none");
defaultSymbol.outline.setStyle("none");
// query for attribute values then find uniques
var layerUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1";
var field = "SUB_REGION";
var qt = new esri.tasks.QueryTask(layerUrl);
var q = new esri.tasks.Query();
q.returnGeometry = false;
q.outFields = [ field ];
q.where = "1=1";
var result = qt.execute(q);
result.then(function(response) {
var uniques = [];
dojo.forEach(response.features, function(f) {
if ( dojo.indexOf(uniques, f.attributes[field]) === -1 ) {
uniques.push(f.attributes[field]);
}
});
// generate a color ramp
var ramp = createRamp(uniques.length);
//create renderer
var renderer = new esri.renderer.UniqueValueRenderer(defaultSymbol, field);
// add values to the renderer with symbols using colors from the color ramp
dojo.forEach(ramp, function(c, idx) {
var symbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color(c));
// symbol.outline.setColor(c);
renderer.addValue(uniques[idx], symbol)
});
// create the feature layer
var featureLayer = new esri.layers.FeatureLayer(layerUrl, {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: [ field ]
});
featureLayer.setRenderer(renderer);
// finally, add the layer to the map
map.addLayer(featureLayer);
console.log("added feature layer");
}, function(err) {
console.log("query task to get attributes failed");
});
function createRamp(count) {
var index = 0;
var factor = parseInt(360/count);
var colors = [];
while ( index < count ) {
var hue = index * factor
colors.push(color_from_hue(hue));
index += 1;
}
return colors;
}
// source: http://rainbowcoding.com/how-to-create-rainbow-text-in-html-css-javascript/
function color_from_hue(hue) {
var h = hue/60;
var c = 255;
var x = (1 - Math.abs(h%2 - 1))*255;
var color;
var i = Math.floor(h);
if (i == 0) color = rgb_to_hex(c, x, 0);
else if (i == 1) color = rgb_to_hex(x, c, 0);
else if (i == 2) color = rgb_to_hex(0, c, x);
else if (i == 3) color = rgb_to_hex(0, x, c);
else if (i == 4) color = rgb_to_hex(x, 0, c);
else color = rgb_to_hex(c, 0, x);
return color;
}
function rgb_to_hex(red, green, blue) {
var h = ((red << 16) | (green << 8) | (blue)).toString(16);
// add the beginning zeros
while (h.length < 6) h = '0' + h;
return '#' + h;
} // end functions from rainbowcoding.com
});
</script>
</head>
<body>
<div id="map" class="claro" style="width:800px; height:400px; border:1px solid #000;"></div>
</body>
</html>
On JSFiddle: http://jsfiddle.net/xgzT2/
... View more
12-07-2012
01:57 PM
|
0
|
0
|
6796
|
|
POST
|
Hi Derek, I managed to modify my application to work with 3.2. Thanks for your help fixing the renderer issue. Glad you were able to upgrade and that I was able to help. Now I am trying to set up the legend but it is not working. The code below shows the legend only when the "Map it" button is clicked twice. I added a global variable (legendDijit), added CSS code as below and added this small piece of code to your existing code. This is a new, different issue. Please start a new thread. When you do post a new thread, please include a complete code sample that reproduces the issue. Similar to how in one of my previous posts in this thread I took the generate renderer sample and modified it to match what you were attempting to do, please take one of our samples and try to reproduce the issue you're seeing.
... View more
12-07-2012
11:24 AM
|
0
|
0
|
373
|
|
POST
|
This looks like it's NIM086349 which was introduced with service pack 1 for ArcGIS Server 10.1. Can you open a call with support and request to be added to this bug?
... View more
12-07-2012
10:25 AM
|
0
|
0
|
1467
|
|
POST
|
Currently, there's no touch support for Win8/IE10. It's coming, probably a release early next year.
... View more
12-06-2012
07:00 AM
|
0
|
0
|
1533
|
|
POST
|
Understood. Can you post code that reproduces the issue? Preferably a simplified version of what you're using.
... View more
12-06-2012
06:48 AM
|
0
|
0
|
1008
|
|
POST
|
I've seen something similar once previously but with an async GP service instead of a query task. I don't currently have a fix or a good work around. Is there a public URL for your service?
... View more
12-06-2012
06:27 AM
|
0
|
0
|
1467
|
|
POST
|
It sounds like you're populating your ComboBox with the result from a query task. The 1,000 record limit is configurable, but 1,000 records was chosen to avoid accidentally returning thousands and thousands of records to a client which is likely to slow down any application. More info in the server help: By default, ArcGIS Server map services limit the number of records returned by a query to 1,000 records. You can raise this limit in the Service Properties dialog box. The limit is important to remember when configuring the task because if you click the Get Sample Values button, only the first 1,000 records will be scanned for unique values.
... View more
12-06-2012
05:48 AM
|
0
|
0
|
1401
|
|
POST
|
Before answering your questions, I want to point out that the main use case for createMap is to create an ArcGIS API for JavaScript map from an ArcGIS.com webmap ID. Ideally, you use ArcGIS.com to author your web map (add layers, configure pop-ups, set the extent, etc.) and then use the webmap in your app by passing in the ArcGIS.com item id to createMap. The approach you're talking about also valid, but it's more work for the developer. To answer your specific questions: Yes, feature layers are supported as operational layers and are stored in the webmap JSON as a feautreColleciton. For instance, here's a webmap with US Cities loaded from a zipped shapefile. The cities are displayed as as feature layer and stored in the webmap JSON as a feature collection. We haven't officially published the spec for the webmap, but it's coming. You can take a look at the JSON that comes back from a webmap request to see the structure for how a feature collection is stored as a operational layer. The popupInfo property of the layer definition defines what to display in a popup: http://www.arcgis.com/sharing/content/items/a7fc556a1b5f470f9ea611d7424847f5/data?f=json&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback We do not publish a sample showing how to use createMap with JSON that includes feature layers from a feature collection. You can take the Create Webmap by ID sample, drop in an ID to a webmap with a feature layer and createMap will give you an ArcGIS API for JavaScript map with a feature layer.
... View more
12-05-2012
08:23 AM
|
0
|
0
|
797
|
|
POST
|
Why not use displayGraphicsOnPan: false when you create your map so that you don't need custom event handlers to hide/show your graphics?
... View more
12-05-2012
07:25 AM
|
0
|
0
|
1008
|
|
POST
|
I'm able to add it here: http://jsfiddle.net/ZEBAJ/ What are you doing differently?
... View more
12-03-2012
08:23 AM
|
0
|
0
|
3324
|
|
POST
|
How many times is onLayersAddResult firing? Can you post a full repro case? We'll be able to get to the bottom of this faster if you post code that reproduces the error.
... View more
12-03-2012
06:57 AM
|
0
|
0
|
1690
|
|
POST
|
If your data is still on your server, you can use a queryTask to query it. Specify the map extent as query.geometry and you'll get back all features on that extent. Since you're really interested in attribute info, you could also set query.returnGeometry to false so less info is sent to the client. Once the query completes, you could figure out how many features fit each renderer category.
... View more
12-03-2012
06:01 AM
|
0
|
0
|
1494
|
|
POST
|
This happens when you try to create multiple widgets with the same id. Are you trying to create a new legend without first destroying a previous one you created?
... View more
12-03-2012
05:56 AM
|
0
|
0
|
1690
|
|
POST
|
Go to the "Get the API" page in the help: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_accessapi.html That page has a link to the download page: http://www.esri.com/apps/products/download/index.cfm?fuseaction=download.all#ArcGIS_API_for_JavaScript
... View more
12-03-2012
05:55 AM
|
0
|
0
|
1674
|
|
POST
|
Thank you all for the replies. Just to confirm, in order to be able to get this projection running, we need to use ArcGIS desktop software, charges apply to get such software, correct? Thank you. Yes. You would publish an ArcGIS Server service via ArcGIS Desktop. Neither is free.
... View more
12-03-2012
05:50 AM
|
0
|
0
|
1977
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-23-2012 07:54 AM | |
| 1 | 05-28-2010 08:31 AM | |
| 1 | 11-12-2012 08:12 AM | |
| 3 | 02-23-2012 10:57 AM | |
| 1 | 06-27-2011 08:51 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|