Skip to content

Commit d3d164b

Browse files
authored
Merge pull request #139 from fdddf/fdddf-tilemaputil-lib
#71 瓦片图切图工具依赖库
2 parents ffa1dbb + a937650 commit d3d164b

22 files changed

+966
-0
lines changed

TileMapUtils_fdddf/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
target/
3+
.DS_Store

TileMapUtils_fdddf/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# TileMapUtils
2+
超大图片渲染切片依赖库, 支持Amazon S3协议存储;本依赖库可配合前端依赖库library_tilemap实现瓦片切片渲染。
3+
4+
## 逻辑详情
5+
6+
### validate
7+
8+
检查图片信息是否可以切图
9+
10+
入参:request TileRequest
11+
出参:TileValidateResponse 或 TileRuntimeException
12+
13+
14+
#### TileValidateResponse中的 errorCode枚举值:
15+
* 0: 成功
16+
* 1: 无效URL
17+
* 2: 瓦片大小不合法
18+
* 3: 输出目录不合法
19+
* 4: 图片类型不支持 (jpg/png)
20+
* 5: 图片尺寸太小
21+
* 6: 可用内存不足
22+
23+
24+
### tileImage
25+
26+
瓦片图片切图
27+
28+
入参:
29+
* request TileRequest
30+
* callback Function<TileResponse, Boolean>
31+
32+
出参:boolean, 实际为异步执行,需通过回调获取结果
33+
34+
35+
## 使用步骤说明
36+
37+
1. 应用引用依赖库
38+
2. 配置应用配置参数
39+
* ossBucketDomain oss存储桶域名
40+
* ossEndpoint oss存储桶域名
41+
* ossAccessKeyId oss访问密钥id
42+
* ossAccessKeySecret oss访问密钥
43+
* ossBucketName oss存储桶名称
44+
* imageMaxWidth 图片最大宽度
45+
* imageMaxHeight 图片最大高度
46+
3. 逻辑调用示例截图
47+
48+
![Snipaste_2024-05-14_01-08-16.jpg](Snipaste_2024-05-14_01-08-16.jpg)
49+
50+
## 应用演示链接
51+
52+
[使用了本依赖库的制品应用链接]
53+
54+
https://dev-tilemap-qa.app.codewave.163.com/maps
Loading
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.netease.lowcode</groupId>
6+
<artifactId>nasl-metadata-maven-plugin</artifactId>
7+
<version>1.3.0</version>
8+
<packaging>maven-plugin</packaging>
9+
10+
<name>Nasl Metadata Maven Plugin</name>
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.apache.maven</groupId>
18+
<artifactId>maven-plugin-api</artifactId>
19+
<version>2.0</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.apache.maven</groupId>
23+
<artifactId>maven-project</artifactId>
24+
<version>2.0.10</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.maven.plugin-tools</groupId>
28+
<artifactId>maven-plugin-annotations</artifactId>
29+
<version>3.2</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.codehaus.plexus</groupId>
34+
<artifactId>plexus-compiler-manager</artifactId>
35+
<version>2.8.4</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.codehaus.plexus</groupId>
39+
<artifactId>plexus-utils</artifactId>
40+
<version>3.0.8</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.apache.maven.shared</groupId>
44+
<artifactId>maven-common-artifact-filters</artifactId>
45+
<version>3.0.1</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.apache.maven</groupId>
50+
<artifactId>maven-aether-provider</artifactId>
51+
<version>3.3.9</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.eclipse.aether</groupId>
56+
<artifactId>aether-api</artifactId>
57+
<version>1.1.0</version>
58+
</dependency>
59+
</dependencies>
60+
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-plugin-plugin</artifactId>
66+
<version>3.2</version>
67+
<configuration>
68+
<goalPrefix>nasl-metadata-maven-plugin</goalPrefix>
69+
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
70+
</configuration>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>

TileMapUtils_fdddf/pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.2.9.RELEASE</version><!--与当前制品应用默认版本统一-->
10+
<relativePath/> <!-- lookup parent from repository -->
11+
</parent>
12+
13+
<groupId>fdddf</groupId>
14+
<name>TileMapUtils</name>
15+
<description>超大图片分割瓦片,支持Amazon S3协议存储</description>
16+
<artifactId>TileMapUtils</artifactId>
17+
<version>1.2.12</version>
18+
19+
<properties>
20+
<maven.compiler.source>8</maven.compiler.source>
21+
<maven.compiler.target>8</maven.compiler.target>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<nasl.ide.version>3.3</nasl.ide.version>
24+
</properties>
25+
<dependencies>
26+
<!--本案例是本地系统引入nasl-metadata-collector-0.8.0.jar的方式。
27+
若把nasl-metadata-collector-0.8.0.jar安装到自己的maven仓库,
28+
注意修改artifactId和groupId的情况下,不要使用<scope>system</scope>,会在发布时造成依赖中断。
29+
不修改artifactId和groupId的情况下,nasl-metadata-maven-plugin会做特殊处理-->
30+
<dependency>
31+
<artifactId>nasl-metadata-collector</artifactId>
32+
<groupId>com.netease.lowcode</groupId>
33+
<version>0.8.0</version>
34+
<optional>true</optional>
35+
<scope>system</scope>
36+
<systemPath>${project.basedir}/jar/nasl-metadata-collector-0.8.0.jar</systemPath>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.alibaba</groupId>
40+
<artifactId>fastjson</artifactId>
41+
<version>1.2.83</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.slf4j</groupId>
45+
<artifactId>slf4j-api</artifactId>
46+
<scope>provided</scope>
47+
</dependency>
48+
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
49+
<dependency>
50+
<groupId>com.amazonaws</groupId>
51+
<artifactId>aws-java-sdk-s3</artifactId>
52+
<version>1.12.440</version>
53+
</dependency>
54+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
55+
<dependency>
56+
<groupId>commons-io</groupId>
57+
<artifactId>commons-io</artifactId>
58+
<version>2.16.1</version>
59+
</dependency>
60+
<!--制品应用使用Springboot框架,父应用引用了的包,为了防止版本冲突,scope可设置为provided-->
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-web</artifactId>
64+
<scope>provided</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-starter-test</artifactId>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-starter-data-redis</artifactId>
74+
</dependency>
75+
</dependencies>
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>com.netease.lowcode</groupId>
80+
<artifactId>nasl-metadata-maven-plugin</artifactId>
81+
<version>1.3.0</version>
82+
<configuration>
83+
<jarWithDependencies>false</jarWithDependencies>
84+
</configuration>
85+
<executions>
86+
<execution>
87+
<goals>
88+
<goal>archive</goal>
89+
</goals>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
</plugins>
94+
</build>
95+
</project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.fdddf.tilemap;
2+
3+
import com.amazonaws.AmazonServiceException;
4+
import com.amazonaws.auth.AWSStaticCredentialsProvider;
5+
import com.amazonaws.auth.BasicAWSCredentials;
6+
import com.amazonaws.client.builder.AwsClientBuilder;
7+
import com.amazonaws.services.s3.AmazonS3;
8+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
9+
import com.amazonaws.services.s3.model.ObjectMetadata;
10+
import com.amazonaws.services.s3.model.PutObjectRequest;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import java.io.InputStream;
15+
16+
public class AmazonOSS {
17+
18+
private final String accessKeyId;
19+
private final String accessKeySecret;
20+
private final String endpoint;
21+
private final String bucketName;
22+
private final String bucketDomain;
23+
private final AmazonS3 s3Client;
24+
25+
private static final Logger logger = LoggerFactory.getLogger(AmazonOSS.class);
26+
27+
public AmazonOSS(String accessKeyId, String accessKeySecret, String endpoint, String bucketName, String bucketDomain) {
28+
this.accessKeyId = accessKeyId;
29+
this.accessKeySecret = accessKeySecret;
30+
if (!endpoint.startsWith("http")) {
31+
endpoint = "https://" + endpoint;
32+
}
33+
if (!bucketDomain.startsWith("http")) {
34+
bucketDomain = "https://" + bucketDomain;
35+
}
36+
this.bucketDomain = bucketDomain;
37+
this.endpoint = endpoint;
38+
this.bucketName = bucketName;
39+
40+
this.s3Client = this.getS3Client();
41+
}
42+
43+
public String getBucketDomain() {
44+
return bucketDomain;
45+
}
46+
47+
private AmazonS3 getS3Client() {
48+
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKeyId, accessKeySecret);
49+
AWSStaticCredentialsProvider provider = new AWSStaticCredentialsProvider(credentials);
50+
return AmazonS3ClientBuilder.standard()
51+
.withCredentials(provider)
52+
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, ""))
53+
.withPathStyleAccessEnabled(false)
54+
.withChunkedEncodingDisabled(true)
55+
.build();
56+
}
57+
58+
/**
59+
* 上传文件到OSS
60+
*
61+
* @param filepath 文件路径
62+
* @return 文件访问地址
63+
*/
64+
public String putFile(String filepath, InputStream inputStream, ObjectMetadata metadata) {
65+
logger.info("will put attachment to oss: {}", filepath);
66+
67+
String url = bucketDomain + "/" + filepath;
68+
if (s3Client.doesObjectExist(bucketName, filepath)) {
69+
return url;
70+
}
71+
72+
try {
73+
PutObjectRequest request = new PutObjectRequest(bucketName, filepath, inputStream, metadata);
74+
s3Client.putObject(request);
75+
return url;
76+
} catch (AmazonServiceException e) {
77+
logger.error("Caught an OSSException, which means your request made it to OSS, "
78+
+ "but was rejected with an error response for some reason.", e);
79+
System.out.printf("Error Message:%s%n", e.getErrorMessage());
80+
throw new RuntimeException(e);
81+
}
82+
}
83+
84+
public void clean() {
85+
s3Client.shutdown();
86+
}
87+
88+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fdddf.tilemap;
2+
3+
public enum ErrorCode {
4+
SUCCESS(0, "success"),
5+
INVALID_URL(1, "invalid url"),
6+
INVALID_TILE_SIZE(2, "invalid tile size"),
7+
INVALID_OUTPUT_DIRECTORY(3, "invalid output directory, " +
8+
"it should starts with file:// or just a folder name for OSS usage"),
9+
INVALID_IMAGE_TYPE(4, "image type is not supported, only support png and jpg"),
10+
INVALID_IMAGE_SIZE(5, "invalid image size"),
11+
INVALID_MEMORY_LIMIT(6, "no enough memory to process image"),
12+
;
13+
14+
final long code;
15+
final String message;
16+
17+
ErrorCode(final int i, String message) {
18+
this.code = i;
19+
this.message = message;
20+
}
21+
}

0 commit comments

Comments
 (0)