ArcGIS js api 手动构建FeatureLayer

Posted 疯子加天才

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcGIS js api 手动构建FeatureLayer相关的知识,希望对你有一定的参考价值。

坐标系

var spatialReference = new SpatialReference(4326);
1
要素坐标点

var pointArr = [
new Point(116.94431351934418, 36.642791191513744, spatialReference),
new Point(116.94313181636085,36.644263733181496, spatialReference),
new Point(116.94323946773243, 36.644333923319806, spatialReference),
new Point(116.94214699103674, 36.64316768441554, spatialReference),
new Point(116.94173145496477, 36.643359669286696, spatialReference),
new Point(116.94251530866333, 36.644235392555245, spatialReference),
];

构建features


var features = [];
for (var i = 0; i < pointArr.length; i++) {
var graphics = new Graphic(pointArr[i], pointSymbol, { "OBJECTID": i, "LON": pointArr[i].x, "LAT": pointArr[i].y });
features.push(graphics);
}

构建fields

var fields = [
{ name: "OBJECTID", type: "esriFieldTypeOID", alias: "OBJECTID" },
{ name: "LON", type: "esriFieldTypeDouble", alias: "LON" },
{ name: "LAT", type: "esriFieldTypeDouble", alias: "LAT" }
];

构建featuresSet

var featureSetJson = {
displayFieldName: "",
geometryType: "esriGeometryPoint",
fieldAliases: {
OBJECTID: "OBJECTID",
LON: "LON",
LAT: "LAT"
},
fields: fields,
spatialReference: spatialReference,
features: features
};
var featuresSet = new FeatureSet(featureSetJson);

构建featureCollection

var layerDefinition = {
"geometryType": "esriGeometryPoint",
"fields": fields
};

var featureCollection = {
layerDefinition: layerDefinition,
featureSet: featuresSet
};

构建FeatureLayer

var featureLayer = new FeatureLayer(featureCollection);
1
完整代码

require([
"esri/map",
"esri/SpatialReference",
"esri/layers/FeatureLayer",
"esri/geometry/Point",
"esri/tasks/FeatureSet",
"esri/graphic",
"dojo/domReady!"
],
function (Map, SpatialReference, FeatureLayer, Point, FeatureSet, Graphic) {
var map = new Map("viewDiv", {
basemap: "streets",
center: [116.943089, 36.643737],
zoom: 18
});
var spatialReference = new SpatialReference(4326);

var pointArr = [
new Point(116.94431351934418, 36.642791191513744, spatialReference),
new Point(116.94313181636085,36.644263733181496, spatialReference),
new Point(116.94323946773243, 36.644333923319806, spatialReference),
new Point(116.94214699103674, 36.64316768441554, spatialReference),
new Point(116.94173145496477, 36.643359669286696, spatialReference),
new Point(116.94251530866333, 36.644235392555245, spatialReference),
];

var features = [];
for (var i = 0; i < pointArr.length; i++) {
var graphics = new Graphic(pointArr[i], pointSymbol, { "OBJECTID": i, "LON": pointArr[i].x, "LAT": pointArr[i].y });
features.push(graphics);
}

var fields = [
{ name: "OBJECTID", type: "esriFieldTypeOID", alias: "OBJECTID" },
{ name: "LON", type: "esriFieldTypeDouble", alias: "LON" },
{ name: "LAT", type: "esriFieldTypeDouble", alias: "LAT" }
];

var featureSetJson = {
displayFieldName: "",
geometryType: "esriGeometryPoint",
fieldAliases: {
OBJECTID: "OBJECTID",
LON: "LON",
LAT: "LAT"
},
fields: fields,
spatialReference: spatialReference,
features: features
};
var featuresSet = new FeatureSet(featureSetJson);

var layerDefinition = {
"geometryType": "esriGeometryPoint",
"fields": fields
};

var featureCollection = {
layerDefinition: layerDefinition,
featureSet: featuresSet
};

var featureLayer = new FeatureLayer(featureCollection);
map.addLayer(featureLayer);
})



api参考
https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#featurelayer2
https://developers.arcgis.com/javascript/3/jsapi/featureset-amd.html#featureset2
有疑问可加1936057493
---------------------
作者:cjchnvs
来源:CSDN
原文:https://blog.csdn.net/qq_22267353/article/details/81233263
版权声明:本文为博主原创文章,转载请附上博文链接!

以上是关于ArcGIS js api 手动构建FeatureLayer的主要内容,如果未能解决你的问题,请参考以下文章

为什么dojo构建将所有包创建为层?

Arcgis api 离线部署

arcgis 中feature 是啥意思

vue-cli&webpack&arcgis API For JS的天坑之路

arcgis中的一个feature中,怎样在两个空间上存在包含关系的多边形中选取较大的一个?

ArcGIS应用(十四)Arcgis 生成要素子集Subset Feature