• 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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    后端程序员必备的 Linux 基础知识+常见命令(近万字总结)
    信息收集流程
    在不影响程序使用的情况下添加shellcode
    使用Zolom内存解析运行python脚本(不落地)
    要点3:输入函数对比与自定义输入方式
    要点2:循环、条件控制
    对等连接和云联网
    上传自定义镜像到腾讯云
    Windows 激活
    MySQL错误(报错)一览表(对照表)
  • 原文地址:https://www.cnblogs.com/telwanggs/p/10107957.html
Copyright © 2020-2023  润新知