server refactoring1
This commit is contained in:
parent
e47493a229
commit
9a8a4e16b2
2 changed files with 44 additions and 34 deletions
|
@ -76,39 +76,49 @@ public class RotatedTileBox {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
RotatedTileBox tileBox = (RotatedTileBox) o;
|
RotatedTileBox tileBox = (RotatedTileBox) o;
|
||||||
return Double.compare(tileBox.lat, lat) == 0 &&
|
return this.compare(tileBox.lat, lat) &&
|
||||||
Double.compare(tileBox.lon, lon) == 0 &&
|
this.compare(tileBox.lon, lon) &&
|
||||||
Float.compare(tileBox.rotate, rotate) == 0 &&
|
this.compare(tileBox.rotate, rotate) &&
|
||||||
Float.compare(tileBox.density, density) == 0 &&
|
this.compare(tileBox.density, density) &&
|
||||||
zoom == tileBox.zoom &&
|
zoom == tileBox.zoom &&
|
||||||
Double.compare(tileBox.mapDensity, mapDensity) == 0 &&
|
this.compare(tileBox.mapDensity, mapDensity) &&
|
||||||
Double.compare(tileBox.zoomAnimation, zoomAnimation) == 0 &&
|
this.compare(tileBox.zoomAnimation, zoomAnimation) &&
|
||||||
Double.compare(tileBox.zoomFloatPart, zoomFloatPart) == 0 &&
|
this.compare(tileBox.zoomFloatPart, zoomFloatPart) &&
|
||||||
cx == tileBox.cx &&
|
cx == tileBox.cx &&
|
||||||
cy == tileBox.cy &&
|
cy == tileBox.cy &&
|
||||||
pixWidth == tileBox.pixWidth &&
|
pixWidth == tileBox.pixWidth &&
|
||||||
pixHeight == tileBox.pixHeight &&
|
pixHeight == tileBox.pixHeight &&
|
||||||
Double.compare(tileBox.zoomFactor, zoomFactor) == 0 &&
|
this.compare(tileBox.zoomFactor, zoomFactor) &&
|
||||||
Double.compare(tileBox.rotateCos, rotateCos) == 0 &&
|
this.compare(tileBox.rotateCos, rotateCos) &&
|
||||||
Double.compare(tileBox.rotateSin, rotateSin) == 0 &&
|
this.compare(tileBox.rotateSin, rotateSin) &&
|
||||||
Double.compare(tileBox.oxTile, oxTile) == 0 &&
|
this.compare(tileBox.oxTile, oxTile) &&
|
||||||
Double.compare(tileBox.oyTile, oyTile) == 0;
|
this.compare(tileBox.oyTile, oyTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double E = 0.0001;
|
||||||
|
|
||||||
|
private boolean compare(float lon, float lon1) {
|
||||||
|
return Math.abs(lon1-lon) < E;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean compare(double lon, double lon1) {
|
||||||
|
return Math.abs(lon1-lon) < E;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 1 + (int)lat +
|
int result = 1 + (int)lat +
|
||||||
3* (int)lon +
|
3* (int)(lon*1/E) +
|
||||||
5* (int)rotate +
|
5* (int)(rotate*1/E) +
|
||||||
7* (int)density +
|
7* (int)(density*1/E) +
|
||||||
11* (int)zoom +
|
11* zoom +
|
||||||
13* (int)mapDensity +
|
13* (int)(mapDensity*1/E) +
|
||||||
17* (int)zoomAnimation +
|
17* (int)(zoomAnimation*1/E) +
|
||||||
19* (int)zoomFloatPart +
|
19* (int)(zoomFloatPart*1/E) +
|
||||||
23* (int)cx +
|
23* cx +
|
||||||
29* (int)cy +
|
29* cy +
|
||||||
31* (int)pixWidth +
|
31* pixWidth +
|
||||||
37* (int)pixHeight;
|
37* pixHeight;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,10 @@ public class ApiRouter implements OsmandMapTileView.IMapImageDrawListener {
|
||||||
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(3);
|
ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||||
|
|
||||||
Map<RotatedTileBox,Bitmap> hashMap = new HashMap<>();
|
Map<RotatedTileBox, Bitmap> hashMap = new HashMap<>();
|
||||||
Map<RotatedTileBox,Bitmap> map = Collections.synchronizedMap(hashMap);
|
Map<RotatedTileBox, Bitmap> map = Collections.synchronizedMap(hashMap);
|
||||||
|
|
||||||
private NanoHTTPD.Response tileApiCall(NanoHTTPD.IHTTPSession session) {
|
private synchronized NanoHTTPD.Response tileApiCall(NanoHTTPD.IHTTPSession session) {
|
||||||
int zoom = 0;
|
int zoom = 0;
|
||||||
double lat = 0;//50.901430;
|
double lat = 0;//50.901430;
|
||||||
double lon = 0;//34.801775;
|
double lon = 0;//34.801775;
|
||||||
|
@ -84,19 +84,19 @@ public class ApiRouter implements OsmandMapTileView.IMapImageDrawListener {
|
||||||
return ErrorResponses.response500;
|
return ErrorResponses.response500;
|
||||||
}
|
}
|
||||||
mapActivity.getMapView().setMapImageDrawListener(this);
|
mapActivity.getMapView().setMapImageDrawListener(this);
|
||||||
Future<Pair<RotatedTileBox,Bitmap>> future;
|
Future<Pair<RotatedTileBox, Bitmap>> future;
|
||||||
final RotatedTileBox rotatedTileBox = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
final RotatedTileBox rotatedTileBox = new RotatedTileBox.RotatedTileBoxBuilder()
|
||||||
rotatedTileBox.setZoom(zoom);
|
.setLocation(lat, lon)
|
||||||
rotatedTileBox.setLatLonCenter(lat, lon);
|
.setZoom(zoom)
|
||||||
rotatedTileBox.setPixelDimensions(512, 512);
|
.setPixelDimensions(512, 512, 0.5f, 0.5f).build();
|
||||||
future = executor.submit(new Callable<Pair<RotatedTileBox, Bitmap>>() {
|
future = executor.submit(new Callable<Pair<RotatedTileBox, Bitmap>>() {
|
||||||
@Override
|
@Override
|
||||||
public Pair<RotatedTileBox, Bitmap> call() throws Exception {
|
public Pair<RotatedTileBox, Bitmap> call() throws Exception {
|
||||||
Bitmap bmp;
|
Bitmap bmp;
|
||||||
while((bmp = map.get(rotatedTileBox)) == null) {
|
while ((bmp = map.get(rotatedTileBox)) == null) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
return Pair.create(rotatedTileBox,bmp);
|
return Pair.create(rotatedTileBox, bmp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mapActivity.getMapView().setCurrentRotatedTileBox(rotatedTileBox);
|
mapActivity.getMapView().setCurrentRotatedTileBox(rotatedTileBox);
|
||||||
|
@ -251,7 +251,7 @@ public class ApiRouter implements OsmandMapTileView.IMapImageDrawListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(RotatedTileBox viewport, Bitmap bmp) {
|
public void onDraw(RotatedTileBox viewport, Bitmap bmp) {
|
||||||
this.map.put(viewport,bmp);
|
this.map.put(viewport, bmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ErrorResponses {
|
static class ErrorResponses {
|
||||||
|
|
Loading…
Reference in a new issue