Extending tile source info |
Tile source info class defines the storage information, tile est type (UserDefined), specific tile storage type, etc. of the tile.
The extension is as follows:
public class NationalCacheStandardTileSourceInfo extends TileSourceInfo { ... }
Methods need to be implemented:
Field/Method | Description |
public NationalCacheStandardTileSourceInfo(NationalCacheStandardTileSourceInfo info) |
Implement the copy constructor |
public TileSourceInfo copy() | Implement copy method |
public TileSourceType getType() public void setType(TileSourceType type) |
Specify the storage type, which must be set to "UserDefined" |
public TileType[] getSupportedTileTypes() | Specify the tile type supported by the storage, tile type for map tile must be specified as "image". |
public int hashCode() public boolean equals(Object obj) |
Implement the hashCode and equals methods |
Method for implementing the copy constructor is as follows:
public NationalCacheStandardTileSourceInfo(NationalCacheStandardTileSourceInfo info) { super(info); this.setOutputPath(info.getOutputPath()); }
Implement copy method:
Override public TileSourceInfo copy() { return new NationalCacheStandardTileSourceInfo(this); }
Type for extended tileset should be specified. Tile type for all extended formats should be specified as UserDefined.
public TileSourceType getType() { return TileSourceType.UserDefined; } //Tile type for all extended formats should be specified as UserDefined public void setType(TileSourceType type) { if (!(TileSourceType.UserDefined.equals(type))) { throw new IllegalArgumentException(); } super.setType(type); }
Define the storage format type of the extended tile, for example, storage format of map tile (raster format) needs to be specified as "image"
@Override public TileType[] getSupportedTileTypes() { return new TileType[] { TileType.Image }; }
public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(120000039, 120000041); String outputPath = getOutputPath(); if (outputPath != null) { builder.append(Tool.getUniqueAbsoluteFilePath(outputPath)); } if (getType() != null) { builder.append(getType()); } return builder.toHashCode(); } public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof NationalCacheStandardTileSourceInfo)) { return false; } NationalCacheStandardTileSourceInfo rhs = (NationalCacheStandardTileSourceInfo) obj; return new EqualsBuilder().append(this.getOutputPath(), rhs.getOutputPath()).append(this.getType(), rhs.getType()).isEquals(); }
The complete extension example class is as follows:
NationalCacheStandardTileSourceInfo.java
package com.supermap.services.tilesource; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import com.supermap.services.components.commontypes.TileType; import com.supermap.services.util.Tool; public class NationalCacheStandardTileSourceInfo extends TileSourceInfo { private static final long serialVersionUID = 1L; private String outputPath; public NationalCacheStandardTileSourceInfo() { super(); } //Implement copy constructor public NationalCacheStandardTileSourceInfo(NationalCacheStandardTileSourceInfo info) { super(info); this.setOutputPath(info.getOutputPath()); } //Get storage path of the tile public String getOutputPath() { return outputPath; } public void setOutputPath(String outputPath) { this.outputPath = outputPath; } public NationalCacheStandardTileSourceInfo outputPath(String outputPath) { this.setOutputPath(outputPath); return this; } public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(120000039, 120000041); String outputPath = getOutputPath(); if (outputPath != null) { builder.append(Tool.getUniqueAbsoluteFilePath(outputPath)); } if (getType() != null) { builder.append(getType()); } return builder.toHashCode(); } public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof NationalCacheStandardTileSourceInfo)) { return false; } NationalCacheStandardTileSourceInfo rhs = (NationalCacheStandardTileSourceInfo) obj; return new EqualsBuilder().append(this.getOutputPath(), rhs.getOutputPath()).append(this.getType(), rhs.getType()).isEquals(); } @Override public TileSourceInfo copy() { return new NationalCacheStandardTileSourceInfo(this); } /** * Specify the tile format type as Image */ @Override public TileType[] getSupportedTileTypes() { return new TileType[] { TileType.Image }; } /** * Return tile format */ public TileSourceType getType() { return TileSourceType.UserDefined; } /** * Specify tile storage type as UserDefined. Storage type of all extended tile formats should be specified as UserDefined */ public void setType(TileSourceType type) { if (!(TileSourceType.UserDefined.equals(type))) { throw new IllegalArgumentException(); } super.setType(type); } }