-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from fdddf/fdddf-tilemaputil-lib
#71 瓦片图切图工具依赖库
- Loading branch information
Showing
22 changed files
with
966 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
target/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# TileMapUtils | ||
超大图片渲染切片依赖库, 支持Amazon S3协议存储;本依赖库可配合前端依赖库library_tilemap实现瓦片切片渲染。 | ||
|
||
## 逻辑详情 | ||
|
||
### validate | ||
|
||
检查图片信息是否可以切图 | ||
|
||
入参:request TileRequest | ||
出参:TileValidateResponse 或 TileRuntimeException | ||
|
||
|
||
#### TileValidateResponse中的 errorCode枚举值: | ||
* 0: 成功 | ||
* 1: 无效URL | ||
* 2: 瓦片大小不合法 | ||
* 3: 输出目录不合法 | ||
* 4: 图片类型不支持 (jpg/png) | ||
* 5: 图片尺寸太小 | ||
* 6: 可用内存不足 | ||
|
||
|
||
### tileImage | ||
|
||
瓦片图片切图 | ||
|
||
入参: | ||
* request TileRequest | ||
* callback Function<TileResponse, Boolean> | ||
|
||
出参:boolean, 实际为异步执行,需通过回调获取结果 | ||
|
||
|
||
## 使用步骤说明 | ||
|
||
1. 应用引用依赖库 | ||
2. 配置应用配置参数 | ||
* ossBucketDomain oss存储桶域名 | ||
* ossEndpoint oss存储桶域名 | ||
* ossAccessKeyId oss访问密钥id | ||
* ossAccessKeySecret oss访问密钥 | ||
* ossBucketName oss存储桶名称 | ||
* imageMaxWidth 图片最大宽度 | ||
* imageMaxHeight 图片最大高度 | ||
3. 逻辑调用示例截图 | ||
|
||
 | ||
|
||
## 应用演示链接 | ||
|
||
[使用了本依赖库的制品应用链接] | ||
|
||
https://dev-tilemap-qa.app.codewave.163.com/maps |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1 change: 1 addition & 0 deletions
1
TileMapUtils_fdddf/jar/nasl-metadata-maven-plugin-1.3.0/install.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml" |
1 change: 1 addition & 0 deletions
1
TileMapUtils_fdddf/jar/nasl-metadata-maven-plugin-1.3.0/install.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml" |
Binary file added
BIN
+24.1 KB
TileMapUtils_fdddf/jar/nasl-metadata-maven-plugin-1.3.0/nasl-metadata-maven-plugin-1.3.0.jar
Binary file not shown.
74 changes: 74 additions & 0 deletions
74
TileMapUtils_fdddf/jar/nasl-metadata-maven-plugin-1.3.0/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.netease.lowcode</groupId> | ||
<artifactId>nasl-metadata-maven-plugin</artifactId> | ||
<version>1.3.0</version> | ||
<packaging>maven-plugin</packaging> | ||
|
||
<name>Nasl Metadata Maven Plugin</name> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-project</artifactId> | ||
<version>2.0.10</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<version>3.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-compiler-manager</artifactId> | ||
<version>2.8.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>3.0.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.shared</groupId> | ||
<artifactId>maven-common-artifact-filters</artifactId> | ||
<version>3.0.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-aether-provider</artifactId> | ||
<version>3.3.9</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.aether</groupId> | ||
<artifactId>aether-api</artifactId> | ||
<version>1.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>3.2</version> | ||
<configuration> | ||
<goalPrefix>nasl-metadata-maven-plugin</goalPrefix> | ||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.9.RELEASE</version><!--与当前制品应用默认版本统一--> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<groupId>fdddf</groupId> | ||
<name>TileMapUtils</name> | ||
<description>超大图片分割瓦片,支持Amazon S3协议存储</description> | ||
<artifactId>TileMapUtils</artifactId> | ||
<version>1.2.12</version> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<nasl.ide.version>3.3</nasl.ide.version> | ||
</properties> | ||
<dependencies> | ||
<!--本案例是本地系统引入nasl-metadata-collector-0.8.0.jar的方式。 | ||
若把nasl-metadata-collector-0.8.0.jar安装到自己的maven仓库, | ||
注意修改artifactId和groupId的情况下,不要使用<scope>system</scope>,会在发布时造成依赖中断。 | ||
不修改artifactId和groupId的情况下,nasl-metadata-maven-plugin会做特殊处理--> | ||
<dependency> | ||
<artifactId>nasl-metadata-collector</artifactId> | ||
<groupId>com.netease.lowcode</groupId> | ||
<version>0.8.0</version> | ||
<optional>true</optional> | ||
<scope>system</scope> | ||
<systemPath>${project.basedir}/jar/nasl-metadata-collector-0.8.0.jar</systemPath> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<version>1.2.83</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 --> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-s3</artifactId> | ||
<version>1.12.440</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/commons-io/commons-io --> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.16.1</version> | ||
</dependency> | ||
<!--制品应用使用Springboot框架,父应用引用了的包,为了防止版本冲突,scope可设置为provided--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-redis</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.netease.lowcode</groupId> | ||
<artifactId>nasl-metadata-maven-plugin</artifactId> | ||
<version>1.3.0</version> | ||
<configuration> | ||
<jarWithDependencies>false</jarWithDependencies> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>archive</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
88 changes: 88 additions & 0 deletions
88
TileMapUtils_fdddf/src/main/java/com/fdddf/tilemap/AmazonOSS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.fdddf.tilemap; | ||
|
||
import com.amazonaws.AmazonServiceException; | ||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.InputStream; | ||
|
||
public class AmazonOSS { | ||
|
||
private final String accessKeyId; | ||
private final String accessKeySecret; | ||
private final String endpoint; | ||
private final String bucketName; | ||
private final String bucketDomain; | ||
private final AmazonS3 s3Client; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AmazonOSS.class); | ||
|
||
public AmazonOSS(String accessKeyId, String accessKeySecret, String endpoint, String bucketName, String bucketDomain) { | ||
this.accessKeyId = accessKeyId; | ||
this.accessKeySecret = accessKeySecret; | ||
if (!endpoint.startsWith("http")) { | ||
endpoint = "https://" + endpoint; | ||
} | ||
if (!bucketDomain.startsWith("http")) { | ||
bucketDomain = "https://" + bucketDomain; | ||
} | ||
this.bucketDomain = bucketDomain; | ||
this.endpoint = endpoint; | ||
this.bucketName = bucketName; | ||
|
||
this.s3Client = this.getS3Client(); | ||
} | ||
|
||
public String getBucketDomain() { | ||
return bucketDomain; | ||
} | ||
|
||
private AmazonS3 getS3Client() { | ||
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKeyId, accessKeySecret); | ||
AWSStaticCredentialsProvider provider = new AWSStaticCredentialsProvider(credentials); | ||
return AmazonS3ClientBuilder.standard() | ||
.withCredentials(provider) | ||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, "")) | ||
.withPathStyleAccessEnabled(false) | ||
.withChunkedEncodingDisabled(true) | ||
.build(); | ||
} | ||
|
||
/** | ||
* 上传文件到OSS | ||
* | ||
* @param filepath 文件路径 | ||
* @return 文件访问地址 | ||
*/ | ||
public String putFile(String filepath, InputStream inputStream, ObjectMetadata metadata) { | ||
logger.info("will put attachment to oss: {}", filepath); | ||
|
||
String url = bucketDomain + "/" + filepath; | ||
if (s3Client.doesObjectExist(bucketName, filepath)) { | ||
return url; | ||
} | ||
|
||
try { | ||
PutObjectRequest request = new PutObjectRequest(bucketName, filepath, inputStream, metadata); | ||
s3Client.putObject(request); | ||
return url; | ||
} catch (AmazonServiceException e) { | ||
logger.error("Caught an OSSException, which means your request made it to OSS, " | ||
+ "but was rejected with an error response for some reason.", e); | ||
System.out.printf("Error Message:%s%n", e.getErrorMessage()); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void clean() { | ||
s3Client.shutdown(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
TileMapUtils_fdddf/src/main/java/com/fdddf/tilemap/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.fdddf.tilemap; | ||
|
||
public enum ErrorCode { | ||
SUCCESS(0, "success"), | ||
INVALID_URL(1, "invalid url"), | ||
INVALID_TILE_SIZE(2, "invalid tile size"), | ||
INVALID_OUTPUT_DIRECTORY(3, "invalid output directory, " + | ||
"it should starts with file:// or just a folder name for OSS usage"), | ||
INVALID_IMAGE_TYPE(4, "image type is not supported, only support png and jpg"), | ||
INVALID_IMAGE_SIZE(5, "invalid image size"), | ||
INVALID_MEMORY_LIMIT(6, "no enough memory to process image"), | ||
; | ||
|
||
final long code; | ||
final String message; | ||
|
||
ErrorCode(final int i, String message) { | ||
this.code = i; | ||
this.message = message; | ||
} | ||
} |
Oops, something went wrong.