当前位置:网站首页>ArcGIS for JS API (2) get the ID set of element services
ArcGIS for JS API (2) get the ID set of element services
2022-07-27 06:35:00 【LEILEI18A】
Catalog
0. Premise
use PotalItem Access to various services , about FeatureLayer, Need to carry out search, Buffer analysis ; If we do general element service operations , Each element service contains FeatureLayer The quantity is also different , therefore , Need to get... Dynamically ;
1. resolvent
// First of all get PotalItem library , And then operate
var item = PortalItem({
id: arcgisFeatureLayerID,
});
// Unlike FeatureLayer.when() Get... Like that , For those that are not sure to load , have access to .load(),item.load() It's also Promise asynchronous
item.load().then(function () {
var serviceUrl = item.url + "?f=pjson"; // See the picture below
layerIDs = getJSON(serviceUrl);
// Traversal read FeatureLayer aggregate
var featureLayers = [];
for (let i=0; i<layerIDs.length; i++){
featureLayers.push(
new FeatureLayer({
portalItem: {id: arcgisFeatureLayerID},
outFields: ["*"],
layerId: layerIDs[i]
});
);
}
// If you want to get FeatureLayer Field set of , Can one by one layer.when() obtain
// It can also be in item.url Back +"/{layerIDs[i]}"+"?f=pjson", use getJSON obtain
});
// Get from the service json data
function getJSON(url){
var ids;
$.ajaxSettings.async = false; //$ representative JQuery, Set up synchronization
$.getJSON(url, function(data){
ids = data.layers.map(function(w){
return w.id;
});
});
$.ajaxSettings.async = true; // Restore asynchrony
return ids;
}2. Sample image
url:LA_County_Parcels (FeatureServer) Click on JSON, It can be JSON Resolved

3. Core extension
Promise It's asynchronous , however arcgis js For multiple element layers , General version settings , Asynchronous is not easy to operate , Sometimes you need to synchronize , therefore , May adopt async function ***(){}, In the function await arcgis js Some of Promise Operation function !await Must be in async- In the function , as follows :

边栏推荐
猜你喜欢
随机推荐
Introduction to hash table
数据库命令
Random points in non overlapping rectangle (force deduction daily question)
Wireshark packet modification -- adding or modifying message fields (2)
This is my blog
Brief introduction to unity menu interface
jmeter简介
Shell语句判断练习题
Shell脚本备份MySQL数据库
Summary of test basis
Establishment of FTP server
Multi coordinate transformation
Ulcl function --5gc
shell编程规范与变量
数据库的约束以及设计
Unity practical tips (updating)
How to write yaml file in a standard way
Programming learning records - Lesson 8 [array and design Gobang, minesweeping game]
DNS domain name resolution service
Shell script loop








