场景:

现在有个项目同时涉及二维、三维地图功能,明确要求使用ArcGIS 平台。目前ArcGIS API For JS有两个系列3.x和4.x,3.x只能实现二维功能,4.x主要支持三维功能,同时也支持部分二维功能,但4.x并不能完全覆盖3系列二维功能,而且接口名称方法都有变化。官网上说是如果涉及到三维功能,必须使用4.x系列。现在来看的话,4.x版本肯定得用,另外一方面由于之前项目均是基于3.x系列API,对它都有感情了,而且做了一些封装,再加上工期太紧,实在是没有时间再用4系列重写一遍,能不能同时用两套API,把二三维功能分开。

现在面临的问题是,这边前端框架采用Angular,Angular本身就是一个单页面的,你在一个页面里面通过esri-loader引入两套api ,本身就不可能,就算是把esri-loader.js源码给改了,加载了两套API,当使用require加载模块时,他还是分不清加载哪个系列的。

问题分析:

既想要两套API,又想用Angular框架,问题关键点就是在解决Angular单页面上,经过别人指点,建议通过iframe嵌入一个页面,不过这个页面就是纯html页面了,Angular里面的组件啥的就都用不了了。先试了一试。

测试效果图:

代码:

三维页面是通过irfame嵌入进来的

3d.html

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Webview</title>
</head>
<link rel="stylesheet" href="http://localhost/arcgis_js_v410_api/arcgis_js_api/library/4.10/esri/css/main.css">
<script src="http://localhost/arcgis_js_v410_api/arcgis_js_api/library/4.10/init.js" data-esri-loader="loaded"></script><body><!--<app-map></app-map>--><div id="viewDiv" style="width: 700px; height: 500px"></div><script>require(["esri/Map","esri/views/SceneView"], function (Map, SceneView) {var map = new Map({basemap: "streets",ground: "world-elevation"});var view = new SceneView({container: "viewDiv",     // Reference to the scene div created in step 5map: map,                 // Reference to the map object created before the scenescale: 50000000,          // Sets the initial scale to 1:50,000,000center: [-101.17, 21.78]  // Sets the center point of view with lon/lat});});</script>
</body></html>

左侧菜单2

menu2.component.html

<div><iframe id="iframe3D" [src]="iframe" frameborder="0" style="width: 100%;height: 500px"></iframe>
</div>

menu2.component.ts

import { Component, OnInit } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';@Component({selector: 'app-menu2',templateUrl: './menu2.component.html',
})
export class Menu2Component implements OnInit {iframe: SafeResourceUrl;constructor(public sanitizer: DomSanitizer) { }ngOnInit() {let src = "assets/test.html";this.iframe = this.sanitizer.bypassSecurityTrustResourceUrl(src);}request(){}}

左侧菜单1

menu1.component.html

<app-map></app-map>

组件map

map.component.html

<div id="viewDiv" style="width: 700px; height: 500px"></div>

map.component.ts

import { Component, OnInit } from '@angular/core';
import { loadModules, loadCss } from 'esri-loader';
import  esriLoader  from 'esri-loader';@Component({selector: 'app-map',templateUrl: './map.component.html',//styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {constructor() { }ngOnInit() {const options = {url: 'http://localhost/arcgis_js_v410_api/arcgis_js_api/library/4.10/init.js'};loadCss('http://localhost/arcgis_js_v410_api/arcgis_js_api/library/4.10/esri/css/main.css');//esriLoader.loadScript(options);loadModules(['esri/views/MapView', 'esri/WebMap'],options).then(([MapView, WebMap]) => {// then we load a web map from an idvar webmap = new WebMap({portalItem: { // autocasts as new PortalItem()id: 'f2e9b762544945f390ca4ac3671cfa72'}});// and we show that map in a container w/ id #viewDivvar view = new MapView({map: webmap,container: 'viewDiv'});}).catch(err => {// handle any errorsconsole.error(err);});}}

Angular项目中,基于esriLoader+iframe实现不同页面调用3.x与4.x ArcGIS JS API相关推荐

  1. vue项目中,用iframe嵌套其他页面在IE浏览器打开空白而在谷歌打开正常的问题

    问题 在vue项目中,某个页面里面用iframe嵌套了另一个vue项目的一个页面,在谷歌浏览器中打开,iframe的内容正常显示:在ie浏览器中打开,iframe的内容是空白的,没有报错. 原因 用的 ...

  2. react项目中使用esri-loader加载天地图

    1.在项目中安装esri-loader npm install esri-loader // or yarn add esri-loader 2.加载代码如下: 代码是基于react hook编写: ...

  3. 在angular项目中集成海康视频web插件 V1.4.1

    在近期的angular项目中,需要跟海康iSecure Center平台对接,实现监控点视频的实时和录像播放功能. 对接过程并不顺畅. 本来已经通过视频流转http-flv协议,利用flvjs实现了基 ...

  4. Angular项目中使用echarts中国地图

    首先要在Angular项目中安装echarts的依赖: npm install echarts --save npm install ngx-echarts --save 第二.在创建包含地图的Ang ...

  5. 在angular 项目中使用 `npm run build` 出现 `* exceeded maximum budget` 警告或错误

    在angular 项目中使用 npm run build 出现 * exceeded maximum budget 警告或错误 Warning or Error in exceeded maximum ...

  6. 在Angular项目中引入NG-ZORRO

    在Angular项目中引入NG-ZORRO 1.前置 2.安装NG-ZORRO并进行初始化配置 3.引入样式 4.引入组件 1.前置 首先创建一个angular项目:angular创建一个新项目的步骤 ...

  7. ThinkPHP6项目基操(13.实战部分 项目中的自定义异常处理总结 错误页面API错误)

    项目中的自定义异常处理总结 错误页面&API错误 前言 一.异常分类 1. 控制器找不到 2. 方法找不到 3. 请求资源不存在 4. 系统內部异常.HTTP异常等 二.异常处理 1. 前置处 ...

  8. vue项目中使用vant时tabbar遮挡页面解决方法

    标题vue项目中使用Vant时tabbar遮挡页面解决方法 单页面使用: 页面底部可以增加一个div,<div style="height: 5rem;"></d ...

  9. 基于ArcGIS JS API实现的两种距离和面积测量方式

    文章目录 前言 开发思路 主要代码 效果测试 效果图 测试页面 开发总结 参考链接 前言 在一些地图地图应用中,距离.面积测量属于基础功能.ArcGIS API for JavaScript有单独提供 ...

最新文章

  1. 开发系统平台常用的-MVC设计模式简介
  2. (gnome-ssh-askpass:609): Gtk-WARNING **: cannot open display:
  3. python全栈工程师薪水_不止 20K,Python 工程师薪资再飙升(内附转型指南)
  4. php修改数组元素,php数组特定元素修改方法
  5. DDD理论学习系列(3)-- 限界上下文
  6. 点到线段的距离_直线垂直,垂线的性质,点到直线的距离
  7. QML工作笔记-使用QML中的Date将时间戳和指定格式时间互转
  8. 信息学奥赛一本通 1229:电池的寿命 | OpenJudge NOI 4.6 2469:电池的寿命
  9. Latex编译pdf后的字体嵌入问题
  10. 【树莓派】Linux指令使用记录
  11. python函数可以提高代码执行速度吗_Python代码运行速度慢?这五种方法很管用
  12. 面向对象的程序设计-电梯调度系统的设计、优化与测试
  13. matlab 7 安装序列号,Matlab7序列号
  14. CMDN Club每周精选(第7期)
  15. app邀请分享免填邀请码解决方案-邀请机制的要点、形式
  16. 小程序安全沙箱技术,将恶意代码装进“笼子”里
  17. uiautomation 模块
  18. idea中执行“npm”命令,提示‘npm‘ 不是内部或外部命令,也不是可运行的程序
  19. 【001】python调用VBA方式_#py
  20. STM32变频器 源程序是经批量验证过的原始代码,仅支持VF控制,C语言实现,完全开源,Keil uVision4编译无错误

热门文章

  1. Erlang vs Java memory architecture (zz)
  2. 思维训练素材整理【初级中阶高阶辅导】
  3. EMF+GEF的属性页问题
  4. 【RegExp】JavaScript中正则表达式判断匹配规则以及常用方法
  5. jenkin系列_调度jmeter实现分布式测试
  6. C#封装类似任务管理器CPU使用记录图
  7. AI算法工程师必备技术,快快积累!
  8. 【机器学习】HOG+SVM进行车辆检测的流程及源码
  9. matlab怎么求矩阵的范数
  10. 如何下载咸鱼app里面的视频