update WebImage plot function

This commit is contained in:
wyq 2024-08-26 11:59:17 +08:00
parent 6a124a2344
commit e207d3821a
4 changed files with 100 additions and 6 deletions

View File

@ -345,6 +345,10 @@ public class MapGridLine extends GridLine {
}
protected void updateLonLatGridLabels() {
if (extent == null) {
return;
}
//Longitude
List<GridLabel> tLabels = new ArrayList<>();
for (int i = 0; i < this.longitudeLines.size(); i++) {

View File

@ -493,6 +493,8 @@ public class MapPlot extends Plot2D implements IWebMapPanel {
Graphic graphic = this.graphics.get(m);
if (graphic.isVisible()) {
if (graphic instanceof WebMapImage) {
this.updateXYScale(area.getWidth(), area.getHeight());
this.updateWebMapScale(area.getWidth(), area.getHeight());
this.drawWebMapImage(g, (WebMapImage) graphic, area);
continue;
}
@ -611,6 +613,65 @@ public class MapPlot extends Plot2D implements IWebMapPanel {
this.drawExtent.maxY = center.Y + ylen;
}
private void updateXYScale(double width, double height) {
updateXYScale(this.drawExtent, width, height);
updateDrawExtent();
}
private void updateXYScale(Extent aExtent, double width, double height) {
double scaleFactor, lonRan, latRan, temp;
this.xScale = width / (aExtent.maxX - aExtent.minX);
this.yScale = height / (aExtent.maxY - aExtent.minY);
if (xScale > yScale) {
xScale = yScale;
temp = aExtent.minX;
aExtent.minX = aExtent.maxX - width / xScale;
lonRan = (aExtent.minX - temp) / 2;
aExtent.minX = aExtent.minX - lonRan;
aExtent.maxX = aExtent.maxX - lonRan;
} else if (xScale < yScale) {
yScale = xScale;
temp = aExtent.minY;
aExtent.minY = aExtent.maxY - height / yScale;
latRan = (aExtent.minY - temp) / 2;
aExtent.minY = aExtent.minY - latRan;
aExtent.maxY = aExtent.maxY - latRan;
}
}
private void updateWebMapScale(double width, double height) {
updateWebMapScale(this.getWebMapImage(), width, height);
}
private void updateWebMapScale(WebMapImage layer, double width, double height) {
double webMapScale = layer.getWebMapScale();
if (!MIMath.doubleEquals(xScale, webMapScale)) {
int minZoom = layer.getTileFactory().getInfo().getMinimumZoomLevel();
int maxZoom = layer.getTileFactory().getInfo().getMaximumZoomLevel();
int newZoom = minZoom;
double scale = webMapScale;
for (int i = maxZoom; i >= minZoom; i--) {
layer.setZoom(i);
scale = getWebMapScale(layer, i, width, height);
if (xScale < scale) {
newZoom = i;
if (xScale < webMapScale) {
if (i < maxZoom) {
newZoom = i + 1;
scale = getWebMapScale(layer, newZoom, width, height);
}
}
break;
}
}
this.setScale(scale, width, height);
layer.setWebMapScale(scale);
layer.setZoom(newZoom);
}
}
void drawWebMapImage(Graphics2D g, WebMapImage graphic, Rectangle2D area) {
PointD geoCenter = this.getGeoCenter();
graphic.setAddressLocation(new GeoPosition(geoCenter.Y, geoCenter.X));
@ -748,7 +809,11 @@ public class MapPlot extends Plot2D implements IWebMapPanel {
*/
public void zoomToExtentLonLatEx(Extent aExtent) {
if (!this.projInfo.isLonLat()) {
aExtent = ProjectionUtil.getProjectionExtent(ProjectionInfo.LONG_LAT, this.projInfo, aExtent, 10);
if (this.projInfo.getProjectionName() == ProjectionNames.Mercator) {
aExtent = ProjectionUtil.getProjectionExtent(ProjectionInfo.LONG_LAT, this.projInfo, aExtent);
} else {
aExtent = ProjectionUtil.getProjectionExtent(ProjectionInfo.LONG_LAT, this.projInfo, aExtent, 10);
}
}
this.setDrawExtent(aExtent);
@ -795,6 +860,14 @@ public class MapPlot extends Plot2D implements IWebMapPanel {
}
}
@Override
public void updateDrawExtent() {
super.updateDrawExtent();
if (!this.isLonLatMap()) {
((MapGridLine) this.gridLine).setExtent(extent);
}
}
/**
* Add point graphic
*

View File

@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\grib">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\map\webmap">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar\cinrad"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\legend"/>
@ -16,15 +13,20 @@
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\webmap"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_2d.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\plot_cuace_3d_slice.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\webmap\webmap_4.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_2d.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\plot_cuace_3d_slice.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\webmap\webmap_4.py"/>
</RecentFiles>
</File>
<Font>
@ -32,5 +34,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,0" MainFormSize="1383,860"/>
<Startup MainFormLocation="-7,0" MainFormSize="1361,832"/>
</MeteoInfo>

View File

@ -105,6 +105,21 @@ public class ProjectionUtil {
return aExtent;
}
/**
* Get projected extent
*
* @param fromProj From projection
* @param toProj To projection
* @param fromExtent From extent
* @return To extent
*/
public static Extent getProjectionExtent(ProjectionInfo fromProj, ProjectionInfo toProj, Extent fromExtent) {
PointD pll = Reproject.reprojectPoint(fromExtent.minX, fromExtent.minY, fromProj, toProj);
PointD pur = Reproject.reprojectPoint(fromExtent.maxX, fromExtent.maxY, fromProj, toProj);
return new Extent(pll.X, pur.X, pll.Y, pur.Y);
}
/**
* Get projected extent
*