This modified sample is from the Custom WebGL layer (https://developers.arcgis.com/javascript/latest/sample-code/custom-gl-visuals/index.html#).
To make this work for a feature layer, I did the following....
- Created a feature layer class
This modified sample is from the Custom WebGL layer (https://developers.arcgis.com/javascript/latest/sample-code/custom-gl-visuals/index.html#).
To make this work for a feature layer, I did the following....
| # Sample of how to copy a feature layer from a local ArcGIS server and publish it to AGOL. | |
| import arcgis | |
| from arcgis import features | |
| from arcgis import GIS | |
| from arcgis.gis import Item | |
| import json | |
| gis = GIS(username="username", password= "password") | |
| #Turn Feature Layer to a Feature Set |
| import arcgis | |
| from arcgis.gis import GIS | |
| # Provide credentials to the GIS object. | |
| gis = GIS(username="username", password= "password") | |
| #Get the id of the hosted feature layer | |
| item = gis.content.get("id of feature layer") | |
| #Get the feature layer itself |
| require(["esri/map", | |
| "esri/layers/ArcGISDynamicMapServiceLayer", | |
| "esri/tasks/query", | |
| "esri/tasks/QueryTask", | |
| "esri/dijit/Popup", | |
| "dojo/dom-construct", | |
| "esri/dijit/PopupTemplate", | |
| "dojo/domReady!" | |
| ], function (Map, ArcGISDynamicMapServiceLayer,Query, QueryTask, Popup, domCon, PopupTemplate) { |
| require([ | |
| "esri/Map", | |
| "esri/views/MapView", | |
| "esri/layers/FeatureLayer", | |
| "dojo/domReady!" | |
| ], | |
| function (Map, MapView, FeatureLayer) { | |
| const filter = document.getElementById('state'); | |
| //Create a new map and set the basemap to Dark gray |
This sample is a modified 4.x version from the 3.x version linked here (https://developers.arcgis.com/javascript/3/jssamples/portal_addshapefile.html).
| #Adding an item to AGOL and publishing it | |
| csv = r'path to csv' | |
| csvItem = gis.content.add({}, csv) | |
| csvFeatureLayer = csvItem.publish() | |
| #Overwriting a service | |
| #Search for the FeatureService by name | |
| MyFeatureService = gis.content.search(query='title:SampleTest AND owner:owner') | |
| #Get the id related to the Feature Service |
| // This sample uses the server to find if any points are within a certain polygon. | |
| // This option only uses one for loop to go through each polygon and then uses a spatial filter as input to the query for the points. | |
| // For this option your points would need to be on the server either through a map service or a feature layer. | |
| require(["esri/map", | |
| "esri/layers/FeatureLayer", | |
| "esri/tasks/query", | |
| "esri/tasks/QueryTask", | |
| "esri/geometry/geometryEngine", | |
| "esri/graphic", |
| #Using a feature layer | |
| import arcgis | |
| from arcgis.gis import GIS | |
| from arcgis.features import FeatureLayer | |
| gis = GIS() | |
| # Use the FeatureLayer class to get item from an service endpoint | |
| url = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/NWS_Climate_Outlooks/cpc_6_10_day_outlk/MapServer' | |
| layer = FeatureLayer(url) |
| import arcgis | |
| from arcgis.gis import GIS | |
| import requests | |
| gis = GIS(None,'username', 'password', verify_cert=False) | |
| try: | |
| featureLayerItem = gis.content.get('item id') | |
| r = requests.post('https://{0}/sharing/rest/content/items/{1}/setContentStatus'.format('org domain',featureLayerItem.id), data= {'status': 'org_authoritative','clearEmptyFields': 'false', 'f':'json', 'token': 'token'}) | |
| print(r) |