|
POST
|
That worked great (after I fixed my own mistakes). Thanks! If anyone else is looking for CSS references, you can find them by going to the API Reference tab on the Javascript API main page > esri/widgets > Legend (or whatever widget you're working with) > Legend.scss file will be listed on the page.
... View more
03-08-2018
09:23 AM
|
1
|
0
|
6308
|
|
POST
|
I determined that I can change the Alias of the field (and overwrite the service) and this will fix the heading on the map. But still, the heading cannot be removed entirely.
... View more
03-08-2018
08:00 AM
|
0
|
2
|
6308
|
|
POST
|
I've got this legend: I would really like to remove the "OfficialQH" heading as that is the name of the attribute field. I went back into ArcMap and cleared the heading and overwrote the service but it has not changed. Is there a way to change this? I'm not sure there is based on the unique value renderer seen on my rest services page. It appears to take that heading from the "Field 1" field and it's not like I can remove it otherwise I would have no way to symbolize the my different values. I can see on my rest services page that the unique value render looks like so: Renderer:Unique Value Renderer: Field 1: OfficialQH Field 2: null Field 3: null Field Delimiter: , Default Symbol: N/A Default Label: null UniqueValueInfos: Value: 0 Label: Not Quail Habitat Description: Symbol:Style: esriSFSSolid Color: [225, 225, 225, 255] Outline:Style: esriSLSSolid Color: [0, 0, 0, 255] Width: 1 Value: 1 Label: Quail Habitat Description: Symbol:Style: esriSFSSolid Color: [56, 168, 0, 255] Outline:Style: esriSLSSolid Color: [0, 0, 0, 255] Width: 1 Javascript legend code: //Add a legend to the view
var legend = new Legend({
view: view,
layerInfos: [{
layer: featureLayer,
title: "Quail Habitat Status"
}]
});
view.ui.add(legend, "bottom-right");
... View more
03-08-2018
06:43 AM
|
1
|
8
|
8058
|
|
POST
|
I figured it out and it has nothing to do with the function. It is because I was using "status" as my variable name. The word "status" must be some sort of reserved word because when I changed the variable name to something else ("myStatus" for instance), it started working. Full script: var map, myStatus;
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"dojo/domReady!"
],
function(
Map, MapView,
FeatureLayer
) {
map = new Map({
basemap: "dark-gray"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-77.069, 36.950],
zoom: 14
});
/********************
* Add feature layer
********************/
// Carbon storage of trees in Warren Wilson College.
var popup = {
title: "{StateID}, Point {Point}, Patch {PatchNum}",
content: "<ul><li>Canopy Deciduous: {CnpyDecid}%</li>" +
"<li>Canopy Coniferous: {CnpyConif}%</li>" +
"<li>Bare Ground: {BareGround}%</li>" +
"<li>Habitat Status: {OfficialQH:myStatus}</li></ul>"
};
var featureLayer = new FeatureLayer({
url: "https://xxx/MapServer/0",
outFields: ["*"],
popupTemplate: popup
});
map.add(featureLayer);
featureLayer.refreshInterval = 3;
myStatus = function(value, key, data) {
var result = "";
switch (value) {
case 1:
result = "Yes";
break;
case 0:
result = "No";
break;
default:
result = "Maybe";
break;
};
return result;
};
});
... View more
03-06-2018
07:47 AM
|
2
|
0
|
2062
|
|
POST
|
Hi Munachiso, could you please look at this example (I have copied it directly from the first link in my original post if you want to see it formatted for easier reading)? This is the entire script and I do not see anywhere that they are performing a query. They are simply calling the function in the popupTemplate using the attribute field of interest and somehow the value, key, and data parameters are magically gotten. var populationChange; require([ "esri/Map", "esri/views/MapView", "esri/layers/Layer", "dojo/dom", "dojo/number", "dojo/on", "dojo/domReady!" ], function( Map, MapView, Layer, dom, number, on ) { var map = new Map({ basemap: "dark-gray" }); // Create the MapView var view = new MapView({ container: "viewDiv", map: map, zoom: 7, center: [-87, 34] }); Layer.fromPortalItem({ portalItem: { // autocasts as new PortalItem() id: "e8f85b4982a24210b9c8aa20ba4e1bf7" } }) .then(function(layer) { // add the layer to the map map.add(layer); // create a new popupTemplate for the layer // format the numeric field values using out of the box // NumberFormat function. Call populationChange() custom // function to calculate percent change for the county. var popupTemplate = { // autocasts as new PopupTemplate() title: "Population in {NAME}", content: "As of 2010, the population in this area was <b>{POP2010:NumberFormat}</b> " + "and the density was <b>{POP10_SQMI:NumberFormat}</b> sq mi. " + "As of 2013, the population here was <b>{POP2013:NumberFormat}</b> " + "and the density was <b>{POP13_SQMI:NumberFormat}</b> sq mi. <br/> <br/>" + "Percent change is {POP2013:populationChange}" }; layer.popupTemplate = popupTemplate; populationChange = function(value, key, data) { // calculate the population percent change from 2010 to 2013. var diff = data.POP2013 - data.POP2010; var pctChange = (diff * 100) / data.POP2010; var result = diff > 0 ? "up.png" : "down.png"; // add green arrow if the percent change is positive. // red arrow for negatice percent change. return "<img src='" + result + "'/>" + "<span style='color: " + (pctChange < 0 ? "red" : "green") + ";'>" + number.format(pctChange, { places: 3 }) + "%</span>"; } }); });
... View more
03-06-2018
06:56 AM
|
0
|
0
|
2062
|
|
POST
|
I have a field called "OfficialQH" that holds either a 0 or a 1. I want to display those values as "No", or "Yes", respectively. I'm a javascript novice and I have a feeling I'm missing something silly, but this is what I've got. I have been following along with these examples: PopupTemplate - use functions to set content | ArcGIS API for JavaScript 4.6 Format info window content | ArcGIS API for JavaScript 3.23 I'm not sure I'm using "value" in my switch statement correctly. I understand that the key is the field name, the value is what is associated with the key in that record, and the data allows you to access other attributes of that record (I think?). So when {OfficialQH:status} gets hit because a feature was clicked, I expect it to call the status function, pass in key = OfficialQH, value = 1 (or 0 depending on the feature clicked), data = other available attributes of record. Then in the switch statement, it reads the value and assigns the result variable a "Yes" or "No" string, then returns the result to hopefully display in the popup. Is my logic flawed? Am I missing a pesky parentheses or bracket? Is there another way I should be using value/key/data? var popup = {
title: "{StateID}, Point {Point}, Patch {PatchNum}",
content: "<ul><li>Canopy Deciduous: {CnpyDecid}%</li>" +
"<li>Canopy Coniferous: {CnpyConif}%</li>" +
"<li>Bare Ground: {BareGround}%</li>" +
"<li>Habitat Status: {OfficialQH:status}</li></ul>"
};
var featureLayer = new FeatureLayer({
url: "https://xxx/MapServer/0",
outFields: ["*"],
popupTemplate: popup
});
map.add(featureLayer);
featureLayer.refreshInterval = 3;
status = function (value, key, data) {
var result = "";
switch (value) {
case 1:
result = "Yes";
break;
case 0:
result = "No";
break;
};
return result;
};
... View more
03-05-2018
12:56 PM
|
0
|
3
|
2678
|
|
POST
|
In thinking about this, I think what you would have to do to get it to work is every time the render changes (based on some check box or something the user clicks), you'd have to remove the feature layer from the map, re-instantiate it with the chosen renderer, and re-add it back to the map. Found an example here: Javascript API: How can I change renderer on the fly with feature layer hosted on ArcGIS Online? - Geographic Informatio… That link shows two examples, one the original poster got working by removing/re-adding the layer and a second one where the person update the legend and re-drew the featurelayer (but apparently the original poster couldn't get that one working).
... View more
03-05-2018
08:37 AM
|
0
|
0
|
3162
|
|
POST
|
Thanks for your feedback, but it looks like someone is doing it using one layer and different renderers: https://community.esri.com/thread/179528 I might try it both ways and see what happens.
... View more
03-05-2018
08:03 AM
|
0
|
3
|
3162
|
|
POST
|
I will be creating a web map using the Javascript API but I'm really new to the whole thing and I'm wondering if this is possible. I have a vector layer which contains attributes on habitat status, coarse habitat classification, and fine habitat classification. I would like to allow users to switch between symbologies based on these attributes. For example, the habitat status attribute holds 0s and 1s, thus it's symbology would show two different colors. The coarse habitat classification attribute holds about twenty different codes, thus it's symbology would show twenty different colors. The fine habitat classification attributes holds even more codes, thus more colors. To achieve this, do I need to create different symbology renderers and then activate them based on clicks to some button or something on the interface? Or do I need to publish the same layer symbolized in the ways I want as three separate services?
... View more
03-05-2018
07:51 AM
|
0
|
6
|
3589
|
|
POST
|
So in theory, I could add the field ahead of time and then just calculate that field in the script with my new user since my user can edit but can't "create"?
... View more
02-27-2018
08:59 AM
|
0
|
1
|
2274
|
|
POST
|
I am a newbie to this whole database user/role management thing. I have a dbo-owned database where I created an "Editor" role. I assigned this role to a new user I created. I then changed the privileges on one feature class to allow any user in the Editor role to select, insert, update, and delete. I then run my python script using a connection file derived from the new user's credentials. In the script, I attempt to add a field to the feature class mentioned above. I received an error message saying I have insufficient permissions, but I am unsure why. I have a hunch it is because this user is not the owner of the data, but if it has editing permissions I figured it would be able to add a field despite not being the owner. I am able to edit successfully with this user, but I cannot add fields. There are no locks on the database. The database is not versioned. I am working in 10.5.
... View more
02-27-2018
08:47 AM
|
0
|
3
|
2941
|
|
POST
|
Alright, after much tinkering, I finally got it to work. It took two things: 1) I had to create the User through SQL Server Management Studio instead of using the various geoprocessing tools. I'm still not entirely sure why, but it worked. First (as db_owner) I created a new login (Security > Logins (right-click) > New Login > fill out username, password fields and check appropriate boxes. Then I created the user in the database of interest and created a schema by the same name and assigned it to the user (Database of interest > Security > Users (right click) > New User... and Database of Interest > Security > Schemas (right-click) > New Schema...). Then I tested this connection in ArcCatalog. The user should connect but since it doesn't have any data privileges yet, it won't be able to see any data in the database. When I determined that connection was successful, I tested the connection in SSMS; again it should connect but you shouldn't be able to see any of your feature classes or tables since the user has no privileges yet. Next, I went to Catalog and added an "Editor" role. Steps to do this include creating a DB connection using my db_owner user (my windows authentication in this case), right-click the connection > Administration > Create and Manage Roles. Filled out with "Editor", GRANT, and the name of the user I just created in SSMS. I then went to each feature class and right clicked > Manage > Privileges > Add > "Editor". Then I selected all checkboxes for Select, Insert, Update, Delete. Clicked Ok and returned to SSMS where I connected as my db_owner account. Went to the database of interest > Security folder > Users > opened properties for my new user and made sure it looked like so (Securables and Extended Properties are empty): 2) In my python script, I removed "sde:sqlserver:" from my instance name and ran the process. This time it connected successfully to my database using my new, database-authenticated user. import arcpy
arcpy.CreateDatabaseConnection_management(out_folder_path='C:\Users\xxx\Desktop\GIS_Testing',
out_name='HBMTest.sde', database_platform='SQL_SERVER',
instance='myServerName',
account_authentication='DATABASE_AUTH', username='HabitatTestWriter',
password='xxx',
save_user_pass='SAVE_USERNAME', database='HBMTest')
arcpy.env.workspace = r'C:\Users\xxx\Desktop\GIS_Testing\HBMTest.sde'
featClasses = arcpy.ListFeatureClasses()
tables = arcpy.ListTables()
for fc in featClasses:
print fc
... View more
02-27-2018
06:44 AM
|
1
|
0
|
3725
|
|
POST
|
So I deleted the user and recreated it from the SSMS side. Now I can create a connection with it in both ArcCatalog and SSMS. The problem remains that the connection cannot be made in standalone scripting however.
... View more
02-27-2018
04:51 AM
|
0
|
0
|
3725
|
|
POST
|
Nothing happens. Still no feature classes are listed. Do I possibly need to use the Change Privileges geoprocessing tool to assign view/edit privileges to the various tables in the database? Just found this tool, have never used it (this is my first time setting up an enterprise geodatabase).
... View more
02-26-2018
12:48 PM
|
0
|
4
|
3725
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-18-2020 10:31 AM | |
| 2 | 09-16-2025 02:17 PM | |
| 3 | 09-12-2025 09:26 AM | |
| 1 | 08-16-2023 05:11 PM | |
| 1 | 02-27-2024 06:48 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-16-2025
02:16 PM
|