地图下载器代码结构设计及功能实现

news2024/10/6 10:31:05
    • jcef包引入

    • 表结构设计

    • 后台关键代码结构

    • 前端关键代码结构

    • 功能展示

    • 启动页

    • 底图切换

    • 绘制选择下载区域

    • 行政区划切换选择下载区域

    • 下载

    • 关键代码

import { InnerMqClient } from '../../rx/inner-mq.service';

import { SubmitService } from '../../service/submit.service';

import { MapBase } from '../../map/map-base';

import { CommonUtil } from '../../util/common-util';

import { MapPage } from '../../view/page/map/map.page';

import { MapDraw } from '../../map/draw/map-draw';

import { MapWrap } from '../../map/draw/map-wrap';

import { GeoUtil } from "../../map/geo-util";

import { Point } from "../../map/entity/Point";

export class MapMessageProcessor {

constructor(

private mqClient: InnerMqClient,

private submitService: SubmitService,

private mapBase: MapBase,

private mapPage: MapPage,

) {

/** 放大 */

mqClient.sub('ZoomIn').subscribe((res) => {

mapBase.zoomIn();

});

/** 缩小 */

mqClient.sub('ZoomOut').subscribe((res) => {

mapBase.zoomOut();

});

/** 拖动 */

mqClient.sub('Pan').subscribe((res) => {

mapBase.pan();

});

/** 显示网格 */

mqClient.sub('GridSwitch').subscribe((res) => {

let update;

if (mapBase.getGridVisible()) {

mapBase.closeGrid();

update = false;

} else {

mapBase.showGrid();

update = true;

}

let config = mapBase.getMapConfig();

if (config) {

config.grid = update;

CommonUtil.setConfigCache(config);

mapBase.setMapConfig(config);

}

});

/** 切换图层源 */

mqClient.sub('SwitchResource').subscribe((res) => {

// 切换图层

debugger

let lastType = mapBase.getCurrentCoordinateType();

mapBase.switchMapResource(res);

let currentType = mapBase.getCurrentCoordinateType();

// 保存设置

let config = mapBase.getMapConfig();

if (config) {

config.layer = res;

CommonUtil.setConfigCache(config);

mapBase.setMapConfig(config);

}

// 检查坐标类型

if (lastType != currentType) {

if (lastType == 'wgs84' && currentType == 'gcj02') {

mapBase.turnMapFeaturesFromWgs84ToGcj02();

} else if (lastType == 'gcj02' && currentType == 'wgs84') {

mapBase.turnMapFeaturesFromGcj02ToWgs84();

}

}

// 回调

setTimeout(() => {

mapPage.updateShowInfo();

});

});

/** 绘制类型切换 - */

mqClient.sub('SwitchDrawType').subscribe((res) => {

mapBase.setDrawType(res);

});

/** 绘制 - */

mqClient.sub('OpenDraw').subscribe((res) => {

mapBase.pan();

mapBase.removeDrawedFeatures();

mapBase.openDraw({

drawEnd: () => {

setTimeout(() => {

mapBase.removeDrawInteraction();

})

},

modifyEnd: () => {

}

});

});

/** 绘制指定多边形并定位 - */

mqClient.sub('DrawPolygonAndPositioning').subscribe((res) => {

mapBase.pan();

mapBase.removeDrawedFeatures();

let blocks = JSON.parse(res);

for (let i = 0; i < blocks.length; i++) {

let points: Array<Point> = [];

for (let j = 0; j < blocks[i].length; j++) {

let point = new Point(blocks[i][j].lng, blocks[i][j].lat);

if (mapBase.getCurrentCoordinateType() == 'wgs84') {

points.push(GeoUtil.gcj02_To_wgs84(point));

} else {

points.push(point);

}

}

let feature = MapDraw.createPolygonFeature(points);

MapWrap.addFeature(mapBase, mapBase.drawLayerName, feature);

}

mapBase.setFitviewFromDrawLayer();

});

/** fitview - */

mqClient.sub('Fitview').subscribe((res) => {

mapBase.setFitviewFromDrawLayer();

});

/** 删除绘制 - */

mqClient.sub('RemoveDrawedShape').subscribe((res) => {

mapBase.removeDrawedFeatures();

});

/** 提交区块下载 - */

mqClient.sub('SubmitBlockDownload').subscribe((res) => {

let data = {

tileName: this.mapBase?.getCurrentXyzName(),

mapType: CommonUtil.getMapType(this.mapBase?.getCurrentXyzName()),

tileUrl: this.mapBase?.getCurrentXyzUrlResources(),

points: this.mapBase?.getDrawedPoints(),

};

this.submitService.blockDownload(data).then((r) => {

});

});

/** 提交世界下载 - */

mqClient.sub('SubmitWorldDownload').subscribe((res) => {

let data = {

tileName: this.mapBase?.getCurrentXyzName(),

mapType: CommonUtil.getMapType(this.mapBase?.getCurrentXyzName()),

tileUrl: this.mapBase?.getCurrentXyzUrlResources()

};

this.submitService.worldDownload(data).then((r) => {

});

});

}

}

package com.jmd.http;

import java.io.File;

import java.io.IOException;

import java.util.HashMap;

import org.apache.commons.io.FileUtils;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;

import com.jmd.entity.result.DownloadResult;

import com.jmd.inst.DownloadAmountInstance;

import com.jmd.util.CommonUtils;

@Component

public class HttpDownload {

@Autowired

private HttpClient http;

@Autowired

private DownloadAmountInstance downloadAmountInstance;

/** 通过URL下载文件 */

public DownloadResult downloadTile(String url, HashMap<String, String> headers, int imgType, String path,

int retry) {

DownloadResult result = new DownloadResult();

boolean success = false;

byte[] bytes = http.getFileBytes(url, headers);

if (null != bytes) {

byte[] imgData = imageSwitch(imgType, bytes);

try {

if (null != imgData) {

// result.setImgData(imgData);

File file = new File(path);

FileUtils.writeByteArrayToFile(file, imgData);

if (file.exists() && file.isFile()) {

downloadAmountInstance.add(file.length());

success = true;

}

}

} catch (IOException e) {

success = false;

e.printStackTrace();

}

}

if (success) {

result.setSuccess(true);

} else if (Thread.currentThread().isInterrupted()) {

result.setSuccess(false);

} else {

retry = retry - 1;

if (retry >= 0) {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

}

return downloadTile(url, headers, imgType, path, retry);

} else {

result.setSuccess(false);

}

}

return result;

}

/** 下载的图片进行转码 */

private byte[] imageSwitch(int imgType, byte[] imgData) {

if (imgType == 0) {

// 保持PNG

return imgData;

} else if (imgType == 1 || imgType == 2 || imgType == 3) {

// 转换为JPG

float quality = 0.9f;

switch (imgType) {

case 1:

quality = 0.2f;

break;

case 2:

quality = 0.6f;

break;

case 3:

quality = 0.9f;

break;

default:

break;

}

try {

return CommonUtils.png2jpg(imgData, quality);

} catch (IOException e) {

e.printStackTrace();

}

}

return null;

}

}

如果对您有帮助

感谢支持技术分享,请扫码点赞支持:

技术合作交流qq:2401315930

编辑

编辑

编辑

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/157212.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

马蹄集 字符判断

字符判断 难度&#xff1a;白银 时间限制&#xff1a;1秒 巴占用内存&#xff1a;64M 输入一个字符&#xff0c;判断是数字字符、大写字母、小写字母、算术运算符、 关系运算符、逻辑运算符&#xff0c;还是其他字符&#xff0c;分别输出Number?”, "Capital letter?”,…

Springboot集成knife4j文档时,接口信息没有显示

我使用的 SpringBoot、knife4j 版本jar包如下所示&#xff1a;<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.5.RELEASE</version><relativePath/> …

kube-bench初体验

kube-bench是一个通过运行CIS Kubernetes benchmark中记录的checker来检查Kubernetes是否安全部署的工具。测试&#xff0c;找gap&#xff0c;audit&#xff0c;都可以啊关于CIS k8s benchmark 参见 CIS Kubernetes Benchmarks (cisecurity.org)就是说&#xff0c;想做k8s加固&…

再学C语言32:函数——多源代码文件程序及其编译

使用多个函数时&#xff0c;最简单的方法是将所有函数放在同一文件中&#xff0c;就像编译单个函数的文件一样对该文件进行编译 具体的编译过程根据操作系统不同而具有差异性 Window系统下的编译器是面向工程的 工程&#xff08;project&#xff09;&#xff1a;描述了一个特…

【Linux】项目自动化构建工具—make/makefile

文章目录1. 什么是make/makefile&#xff1f;2. make/makefile的使用2.1 实例代码2.2 依赖关系和依赖方法2.3 项目清理2.4 make是如何确定是否编译的3. Linux第一个小程序—进度条3.1 \r 和 \n3.2 进度条小程序1. 什么是make/makefile&#xff1f; make是一个命令工具&#xf…

【Spring6源码・IOC】Bean的初始化 - 终结篇

前面两篇&#xff0c;我们着重讲解了一下《BeanDefinition的加载》和《bean的实例化》。 这一篇我们来讲解一下bean的初始化。 我们这里的案例依旧是以SpringBoot3.0、JDK17为前提&#xff0c;案例代码如下&#xff1a; Component public class A {Autowiredprivate B b;}Com…

Windows+iis+php+mysql搭建wordpress

准备工作 WindowsServer一台 IIS&#xff0c;在Server上开启 PHP:PHP: Downloads Mysql:MySQL :: MySQL Downloads wordpress下载 | WordPress.org China 简体中文 PHP程序在IIS上以fastcgi方式运行&#xff0c;在安装mysql和php之前确保vc库已安装。 IIS确保开启CGI模块…

JAVA开发(AOP之ProceedingJoinPoint)

我们在开发过程中经常使用到自定义注解来实现在一些类或者方法执行过程中切面&#xff0c;统一实现某些业务操作。例如自定义注解import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang…

YOLOv7:面向实时检测的目标检测器 | 附结构图

YOLOv7 在 5 FPS 到 160 FPS 范围内的速度和准确度都超过了所有已知的目标检测器&#xff0c;并且在 GPU V100 上 30 FPS 或更高的所有已知实时目标检测器中具有最高的准确度 56.8% AP。 YOLOv7-E6 目标检测器&#xff08;56 FPS V100&#xff0c;55.9% AP&#xff09;比基于Tr…

小孩护眼灯什么牌子的好?分享四款最好的台灯品牌

最近发现&#xff0c;在接送我家神兽上下学时&#xff0c;小朋友们会揉眼睛&#xff0c;眼睛始终没睁开的感觉&#xff0c;还有不少小学就戴上了眼镜&#xff0c;我深知戴眼镜&#xff0c;真的很麻烦&#xff0c;所以更加看重孩子的护眼工作。市面上越来越多护眼灯&#xff0c;…

Java高手速成 | 实现人物拼图游戏

拼图游戏指将一幅图片分割成若干拼块&#xff0c;并随机打乱顺序&#xff0c;当将所有拼块都放回原位置时就完成了拼图(游戏结束)。 01、游戏介绍 在游戏中&#xff0c;拼块以随机顺序排列&#xff0c;网格上有一个位置是空的。完成拼图的方法是利用这个空位置移动拼块&#xf…

服务搭建常见问题

怎么将myeclipse项目部署到tomcat服务器 https://www.laike.net/article-162-238315-0.html eclipse提示错误&#xff1a;save could not be completed Dynamic Web Module 4.0 requires Java 1.8 or newer. https://blog.csdn.net/xixihaha_coder/article/details/118345378 …

微星 MPG B460I GAMING EDGE WIFI +i5-10400电脑 Hackintosh 黑苹果efi引导文件

硬件型号驱动情况主板微星 MPG B460I GAMING EDGE WIFI (MS-7C86)&#xff08;LPC Controller B460芯片组&#xff09;处理器英特尔 Core i5-10400 2.90GHz 六核已驱动内存16 GB ( 芝奇 DDR4 2666MHz 8GB x 2 )已驱动硬盘朗科科技 NVMe SSD 480GB (480 GB / 固态硬盘)已驱动显…

React学习笔记:实用又好用的Hooks函数

React框架以前是采用Class类编程&#xff0c;在类编程中使用生命周期比较方便&#xff0c;但是随着迭代更新&#xff0c;官方开始推荐使用函数式编程&#xff0c;但是函数式编程就没有状态这一个概念&#xff0c;于是乎官方就定义了一系列钩子函数来弥补在这一缺陷&#xff0c;…

Rabbitmq(七) -- rabbitmq的工作模式

1. 简单模式&#xff1a;无需交换机 消息产生消息&#xff0c;将消息放入队列消息的消费者(consumer) 监听 消息队列,如果队列中有消息,就消费掉,消息被拿走后,自动从队列中删除(隐患 消息可能没有被消费者正确处理,已经从队列中消失了,造成消息的丢失&#xff0c;这里可以设置…

VTK-数据集vtkUnstructuredGrid

前言&#xff1a;本博文主要介绍vtkUnstructuredGrid的特点、结构组成&#xff0c;vtkUnstructuredGrid的创建方法&#xff0c;及其vtkUnstructuredGrid相关的接口及示例。 特点 非结构化网格数据&#xff0c;是最常见的数据集类型&#xff0c;它的拓扑结构和几何结构都是非结…

Pycharm调试功能介绍

文章目录pycharm中的debug模式debug的断点调试pycharm中的debug模式 在pycharm中&#xff0c;一共有4中方法开启debug调试&#xff0c;如下&#xff1a; 点击导航栏的run >> debug 双击打开py文件 >> 右上角点击小虫子图标。 写好if name ‘main’: >> 点…

React 类组件你不知道的细节+案例

React基础-组件-类组件 1.组件概述 目标&#xff1a;了解React组件的作用和创建组件的方式 什么是组件组件的设计思想 1.what is 组件啊&#xff1f; 在前端开发中组件就是用户界面当中一块独立的区域,在组件内部会包含这块区域中的视图代码,样式代码以及逻辑代码 React是采用…

Cadence PCB仿真使用Allegro PCB SI配置差分对的方法图文教程

⏪《上一篇》   🏡《总目录》   ⏩《下一篇》 目录 1,概述2,配置方法3,总结1,概述 本文简单介绍使用Allegro PCB SI配置差分对的方法。 2,配置方法 第1步:打开待仿真的PCB文件,并确认软件为Allegro PCB SI 如果,打开软件不是Allegro PCB SI则可这样切换 执行Fil…

天下苦“个人公众号认证”久矣,吾闻今可

大家好&#xff0c;我是小悟 一看到个人公众号可以认证&#xff0c;便以迅雷不及掩耳之势准备资料&#xff0c;一顿操作猛如虎后&#xff0c;我的号终于认证啦。 看到别人的个人公众号有认证的&#xff0c;这两天我就在想要怎么才能认证&#xff0c;于是就去搜索相关的内容&am…