将位置数据馈送到Esri Map并在Esri Map上以精确点的形式显示位置

Feed location data to the Esri Map and display locations on Esri Map as pinpoints(将位置数据馈送到Esri Map并在Esri Map上以精确点的形式显示位置)
本文介绍了将位置数据馈送到Esri Map并在Esri Map上以精确点的形式显示位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想传递一些位置数据(纬度、经度等)。将美国某些州的地图添加到ArcGIS Esri地图中,并在Esri地图中将这些位置显示为精确点(如Google地图)。目前,我的角度代码如下所示,我找不到任何ArcGIS文档 向Esri地图提供数据。

如果您对如何实现这一目标有任何想法,请告诉我。

esri-map-component.html

<!-- Map Div -->
<div #mapViewNode></div>

esri-map-Component.ts

// The <div> where the map is loaded
 public featureLayerUrl = environment.parcelAtlasUrl;
 public webMapId = environment.webMapId;
 @ViewChild('mapViewNode', { static: true }) private mapViewEl: ElementRef;

ngOnInit(): void {
 this.getEsriToken();
}

getEsriToken(){
 this.esriMapService.getEsriAccessToken().subscribe(
  res => {
    this.esriToken = res.token;
    if(res.token){
      this.initializeMap(this.esriToken);
    }
  },
  error =>{
  },

  () => {
  }
 );
}

// Initialize MapView and return an instance of MapView
initializeMap(esriToken) {
const container = this.mapViewEl.nativeElement;
config.apiKey = esriToken;

//load the webMap
const webmap = new WebMap({
      portalItem: {
        id: this.webMapId
      }
    });

//load the ParcelAtlas feature layer
const layer = new FeatureLayer({
    url: this.featureLayerUrl,
    });
  webmap.add(layer);


const view = new MapView({
  container,
  map: webmap
});
this.view = view;
return this.view.when();

推荐答案

您可以通过多种方式将数据添加到地图。您可以使用FeatureLayerGraphicLayer,甚至可以将其添加到视图图形集合。

在我为您制作的这个示例中,我将建议您使用FeatureLayer。虽然它不使用角度,但您可以很容易地转换为您的代码。要对客户端上的数据使用FeatureLayer,您需要:

  • Graphic的集合设置source属性,在示例中我使用了Object数组(它自动强制转换为预期的),
  • 设置geometryType,在本例中为point
  • objectIDField

我假设您有开头的数据,如果您在运行应用程序时需要添加/更新/删除数据,可以使用FeatureLayer的方法applyEdits

ArcGIS JS API - FeatureLayer

示例:

数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Pinpoint Example</title>
    <style>
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/css/main.css">
    <script src="https://js.arcgis.com/4.21/"></script>

    <script>
        require([
            "esri/Map",
            "esri/views/MapView",
            "esri/layers/FeatureLayer",
            "esri/popup/content/CustomContent"
        ], function (Map, MapView, FeatureLayer, CustomContent) {

            const data = [
                {
                    lat: 32.727482,
                    lon: -117.1560632,
                    name: "Automotive Museum",
                    addrs: "2080 Pan American Plaza, San Diego, CA 92101, United States",
                    url: "http://sdautomuseum.org/"
                },
                {
                    lat: 32.7136902,
                    lon: -117.1763293,
                    name: "USS Midway Museum",
                    addrs: "910 N Harbor Dr, San Diego, CA 92101, United States",
                    url: "http://www.midway.org/"
                },
                {
                    lat: 32.7641112,
                    lon: -117.2284536,
                    name: "SeaWorld",
                    addrs: "500 Sea World Dr, San Diego, CA 92109, United States",
                    url: "https://seaworld.com/san-diego"
                },
                {
                    lat: 32.7360032,
                    lon: -117.1557741,
                    name: "Zoo",
                    addrs: "2920 Zoo Dr, San Diego, CA 92101, United States",
                    url: "https://zoo.sandiegozoo.org/"
                }
            ];

            const map = new Map({
                basemap: "streets-navigation-vector"
            });

            const view = new MapView({
                container: "viewDiv",
                map: map,
                zoom: 12,
                center: {
                    latitude: 32.7353,
                    longitude: -117.1490
                }
            });

            const layer = new FeatureLayer({
                source: data.map((d, i) => (
                    {
                        geometry: {
                            type: "point",
                            longitude: d.lon,
                            latitude: d.lat
                        },
                        attributes: {
                            ObjectID: i,
                            ...d
                        }
                    }
                )),
                fields: [
                    {
                        name: "ObjectID",
                        alias: "ObjectID",
                        type: "oid"
                    },
                    {
                        name: "name",
                        alias: "Name",
                        type: "string"
                    },
                    {
                        name: "addrs",
                        alias: "addrs",
                        type: "string"
                    },
                    {
                        name: "url",
                        alias: "url",
                        type: "string"
                    },
                    {
                        name: "lat",
                        alias: "Latitude",
                        type: "double"
                    },
                    {
                        name: "lon",
                        alias: "Longitude",
                        type: "double"
                    },
                ],
                objectIDField: ["ObjectID"],
                geometryType: "point",
                renderer: {
                    type: "simple",
                    symbol: {
                        type: "text",
                        color: "red",
                        text: "ue61d",
                        font: {
                            size: 30,
                            family: "CalciteWebCoreIcons"
                        }
                    }
                },
                popupTemplate: {
                    title: "{name}",
                    content: [
                        {
                            type: "fields",
                            fieldInfos: [
                                {
                                    fieldName: "addrs",
                                    label: "Address"
                                },
                                {
                                    fieldName: "lat",
                                    label: "Latitude",
                                    format: {
                                        places: 2
                                    }
                                },
                                {
                                    fieldName: "lon",
                                    label: "Longitude",
                                    format: {
                                        places: 2
                                    }
                                }
                            ]
                        },
                        new CustomContent({
                            outFields: ["*"],
                            creator: (event) => {
                                const a = document.createElement("a");
                                a.href = event.graphic.attributes.url;
                                a.target = "_blank";
                                a.innerText = event.graphic.attributes.url;
                                return a;
                            }
                        })
                    ],
                    outFields: ["*"]
                }
            });

            map.add(layer);

        });
    </script>
</head>

<body>
    <div id="viewDiv"></div>
</body>

</html>

这篇关于将位置数据馈送到Esri Map并在Esri Map上以精确点的形式显示位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

本文给大家介绍Javascript js中实现和PHP一样的时间戳格式化函数的方法,具有一定的参考借鉴价值,需要的朋友可以参考下,我们知道在php中有一个date()函数,可以方便的把时间戳格式化为时间字符串。可是在js中,我们要想实现这种效果,要写好
需求是模板字符串中不允许出现script 标签、不允许有javascript: 和 .js 文件引用,主要方法如下: clearScriptTag (str) { const reg = /script[^]*([\S\s]*?)\/script/gim; // 清除标签内 相关 xss 安全代码 const reg1 = /javascript:/gim; const reg2 = / *.js/gim; if (reg.test(str)) { str
javascript中Replace全部替换字符用法实例代码,替换1次和多次,主要是正则表达式 var r= "1\n2\n3\n";//将字母\n替换成分号alert(r.replace("\n",";"));//结果:1;2\n3\n 只替换了第一个var r= "1\n2\n3\n";//将字母\n替换成分号alert(r.replace(/\n/g, ";"));//结果:1;2;3; replac
js输出当前日期和时间的实例代码,具体实例代码如下,有兴趣的朋友可以尝试运行下。 !doctype htmlhtml lang="en" head meta charset="UTF-8" title获取当前时间/title /head body script type="text/javascript" /** *获取当前时间 *format=1精确到天 *format=2精确到秒 */ function
p5.js WebGL 3d graphics covered by 2d background when rotated(P5.js旋转时被2D背景覆盖的WebGL 3D图形)
Static vector field with classic arrows at every point on p5.js(P5.js上每个点都有经典箭头的静态向量场)