当前位置:网站首页>ArcGIS JS 地图内外网环境判断问题
ArcGIS JS 地图内外网环境判断问题
2022-07-28 05:52:00 【不超限】
为了实现内网环境下读取内网服务器资源,外网环境下读取简化版的内容。
计划通过访问内网接口,如果返回成功,则说明是内网环境;如果未返回内容,则是外网。
地图库已经通过TypeScript搭建,较复杂,代码量较大。
方案一
通过dojo.xhr模块,请求测试接口,并设置参数为 {sync:true,timeout:200}
由于已有的地图库为同步结构,因此,在此处使用同步请求,并设置超时为200,待200ms后,判断出内外网环境后再执行后续代码。
测试后发现,功能上实现要求。效果上,timeout参数无效,该请求一般是卡住21秒左右,才能判断出内外网环境。
查询dojo官方资料,同步请求时,timeout参数无效。
20多秒的延迟无法接受,没法用。只能换方案
方案二
使用异步请求方案
通过测试发现,xhr请求时,可以较快的判断出是内外网环境,因此决定采用异步的方法。
由于已有的代码结构大多为同步写法,使用异步时,可能会存在内外网环境判断未完成,地图初始化工作未完成时,后续相关代码库已经开始执行,导致产生很多未知的undefined之类的对象未获取到的问题。
最终通过自定义Accessor类,使用watchUtils.whenTrue()方法,来解决该问题。
参考帖子
ArcGIS JS自定义Accessor,并通过watchUtils相关方法watch属性_不超限的博客-CSDN博客
检索了很多资料,前端没有发现合适的方法可以检测内外网。如果有更好的解决方案,欢迎大家分享
边栏推荐
- 微信小程序隐藏滚动条的方法
- Student duty problems
- 通过sed 修改conf文件
- 牛客Mysql——SQL必知必会
- Image segmentation method
- It has been rectified seven times and took half a month. Painful EMC summary
- ThreadLocal things
- Continous Gesture Recognition with hand-orented spatiotemporal feature
- Cdn.jsdelivr.net is not available, what should I do
- Introduction to magnetic ring selection and EMC rectification skills
猜你喜欢

DNA修饰金属锇Os纳米颗粒OsNPS-DNA|DNA修饰金属铱纳米颗粒IrNPS-DNA

Continous Gesture Recognition with hand-orented spatiotemporal feature

What is the root cause of EMC's problems?

收藏 | 结合个人经验,我总结了这7点EMC相关知识

Essential performance optimization topics in the interview~

Overview of distributed system development

Safflower STL

【干货】32个EMC标准电路分享!

Dynamic memory management knowledge points

Learning to estimate 3D hand pose from single RGB image & amp notes
随机推荐
The "nuclear bomb level" log4j vulnerability is still widespread and has a continuing impact
ArcGIS JS自定义Accessor,并通过watchUtils相关方法watch属性
Tutorial (7.0) 06. Zero trust network access ztna * forticlient EMS * Fortinet network security expert NSE 5
guava之限流RateLimiter
How to connect the uniapp project to the real mobile phone for debugging
guava之EventBus
两个链表的第一个公共节点——每日两题
JS upload file method
收藏 | 结合个人经验,我总结了这7点EMC相关知识
DNA修饰贵金属纳米颗粒|DNA修饰纳米铜颗粒CuNPS-DNA|研究要点
大话持久性与redolog
合并两个排序的链表——每日两题
CLion调试redis6源码
Nodejs operation mongodb
[shaders realize negative anti color effect _shader effect Chapter 11]
js二级联动院系
Modify the conf file through sed
High performance memory queue -disruptor
0727~面试题梳理
常用电子产品行业标准及认证