still cleanup
This commit is contained in:
parent
1f8dbb7694
commit
2869cae3a0
7 changed files with 69 additions and 92 deletions
|
@ -2,8 +2,6 @@ package net.osmand.data;
|
||||||
|
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class RotatedTileBox {
|
public class RotatedTileBox {
|
||||||
|
|
||||||
/// primary fields
|
/// primary fields
|
||||||
|
@ -124,11 +122,11 @@ public class RotatedTileBox {
|
||||||
public double getCenterTileX(){
|
public double getCenterTileX(){
|
||||||
return oxTile;
|
return oxTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCenter31X(){
|
public int getCenter31X(){
|
||||||
return MapUtils.get31TileNumberX(lon);
|
return MapUtils.get31TileNumberX(lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCenter31Y(){
|
public int getCenter31Y(){
|
||||||
return MapUtils.get31TileNumberY(lat);
|
return MapUtils.get31TileNumberY(lat);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +189,7 @@ public class RotatedTileBox {
|
||||||
float right = (float) MapUtils.getLongitudeFromTile(zoom, alignTile(tileBounds.right));
|
float right = (float) MapUtils.getLongitudeFromTile(zoom, alignTile(tileBounds.right));
|
||||||
latLonBounds = new QuadRect(left, top, right, bottom);
|
latLonBounds = new QuadRect(left, top, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double alignTile(double tile) {
|
private double alignTile(double tile) {
|
||||||
if(tile < 0) {
|
if(tile < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -234,7 +232,7 @@ public class RotatedTileBox {
|
||||||
double yTile = MapUtils.getTileNumberY(zoom, latitude);
|
double yTile = MapUtils.getTileNumberY(zoom, latitude);
|
||||||
return getPixXFromTile(xTile, yTile);
|
return getPixXFromTile(xTile, yTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPixXFromTile(double tileX, double tileY, float zoom) {
|
public float getPixXFromTile(double tileX, double tileY, float zoom) {
|
||||||
double pw = MapUtils.getPowZoom(zoom - this.zoom);
|
double pw = MapUtils.getPowZoom(zoom - this.zoom);
|
||||||
double xTile = tileX / pw;
|
double xTile = tileX / pw;
|
||||||
|
@ -261,7 +259,7 @@ public class RotatedTileBox {
|
||||||
double yTile = MapUtils.getTileNumberY(zoom, latitude);
|
double yTile = MapUtils.getTileNumberY(zoom, latitude);
|
||||||
return getPixYFromTile(xTile, yTile);
|
return getPixYFromTile(xTile, yTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPixYFromTile(double tileX, double tileY, float zoom) {
|
public float getPixYFromTile(double tileX, double tileY, float zoom) {
|
||||||
double pw = MapUtils.getPowZoom(zoom - this.zoom);
|
double pw = MapUtils.getPowZoom(zoom - this.zoom);
|
||||||
double xTile = (tileX / pw);
|
double xTile = (tileX / pw);
|
||||||
|
@ -311,11 +309,11 @@ public class RotatedTileBox {
|
||||||
checkTileRectangleCalculated();
|
checkTileRectangleCalculated();
|
||||||
return latLonBounds;
|
return latLonBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getRotateCos() {
|
public double getRotateCos() {
|
||||||
return rotateCos;
|
return rotateCos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getRotateSin() {
|
public double getRotateSin() {
|
||||||
return rotateSin;
|
return rotateSin;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +361,7 @@ public class RotatedTileBox {
|
||||||
public double getZoomAnimation() {
|
public double getZoomAnimation() {
|
||||||
return zoomAnimation;
|
return zoomAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getZoomFloatPart() {
|
public double getZoomFloatPart() {
|
||||||
return zoomFloatPart;
|
return zoomFloatPart;
|
||||||
}
|
}
|
||||||
|
@ -374,7 +372,7 @@ public class RotatedTileBox {
|
||||||
this.zoom = zoom;
|
this.zoom = zoom;
|
||||||
calculateDerivedFields();
|
calculateDerivedFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZoomAndAnimation(int zoom, double zoomAnimation) {
|
public void setZoomAndAnimation(int zoom, double zoomAnimation) {
|
||||||
this.zoomAnimation = zoomAnimation;
|
this.zoomAnimation = zoomAnimation;
|
||||||
this.zoom = zoom;
|
this.zoom = zoom;
|
||||||
|
@ -393,20 +391,20 @@ public class RotatedTileBox {
|
||||||
MapUtils.getLongitudeFromTile(zoom, alignTile(tileLT.x)));
|
MapUtils.getLongitudeFromTile(zoom, alignTile(tileLT.x)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuadPointDouble getLeftTopTile(double zoom) {
|
public QuadPointDouble getLeftTopTile(double zoom) {
|
||||||
checkTileRectangleCalculated();
|
checkTileRectangleCalculated();
|
||||||
return new QuadPointDouble((tileLT.x * MapUtils.getPowZoom(zoom - this.zoom)),
|
return new QuadPointDouble((tileLT.x * MapUtils.getPowZoom(zoom - this.zoom)),
|
||||||
(tileLT.y * MapUtils.getPowZoom(zoom - this.zoom)));
|
(tileLT.y * MapUtils.getPowZoom(zoom - this.zoom)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public QuadPointDouble getRightBottomTile(float zoom) {
|
public QuadPointDouble getRightBottomTile(float zoom) {
|
||||||
checkTileRectangleCalculated();
|
checkTileRectangleCalculated();
|
||||||
return new QuadPointDouble((tileRB.x * MapUtils.getPowZoom(zoom - this.zoom)),
|
return new QuadPointDouble((tileRB.x * MapUtils.getPowZoom(zoom - this.zoom)),
|
||||||
(tileRB.y * MapUtils.getPowZoom(zoom - this.zoom)));
|
(tileRB.y * MapUtils.getPowZoom(zoom - this.zoom)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkTileRectangleCalculated() {
|
private void checkTileRectangleCalculated() {
|
||||||
if(tileBounds == null){
|
if(tileBounds == null){
|
||||||
|
@ -424,7 +422,7 @@ public class RotatedTileBox {
|
||||||
this.mapDensity = mapDensity;
|
this.mapDensity = mapDensity;
|
||||||
calculateDerivedFields();
|
calculateDerivedFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMapDensity() {
|
public double getMapDensity() {
|
||||||
return mapDensity;
|
return mapDensity;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +471,7 @@ public class RotatedTileBox {
|
||||||
double ty = getPixYFromTile(qp.x, qp.y);
|
double ty = getPixYFromTile(qp.x, qp.y);
|
||||||
return tx >= 0 && tx <= pixWidth && ty >= 0 && ty <= pixHeight;
|
return tx >= 0 && tx <= pixWidth && ty >= 0 && ty <= pixHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsTilePoint(QuadPointDouble qp) {
|
public boolean containsTilePoint(QuadPointDouble qp) {
|
||||||
double tx = getPixXFromTile(qp.x, qp.y);
|
double tx = getPixXFromTile(qp.x, qp.y);
|
||||||
double ty = getPixYFromTile(qp.x, qp.y);
|
double ty = getPixYFromTile(qp.x, qp.y);
|
||||||
|
@ -485,7 +483,7 @@ public class RotatedTileBox {
|
||||||
double ty = getPixYFromLatLon(lat, lon);
|
double ty = getPixYFromLatLon(lat, lon);
|
||||||
return tx >= 0 && tx <= pixWidth && ty >= 0 && ty <= pixHeight;
|
return tx >= 0 && tx <= pixWidth && ty >= 0 && ty <= pixHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsLatLon(LatLon latLon) {
|
public boolean containsLatLon(LatLon latLon) {
|
||||||
double tx = getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
double tx = getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
double ty = getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
double ty = getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
|
@ -532,7 +530,7 @@ public class RotatedTileBox {
|
||||||
zoomSet = true;
|
zoomSet = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RotatedTileBoxBuilder setLocation(double lat, double lon) {
|
public RotatedTileBoxBuilder setLocation(double lat, double lon) {
|
||||||
tb.lat = lat;
|
tb.lat = lat;
|
||||||
tb.lon = lon;
|
tb.lon = lon;
|
||||||
|
@ -594,6 +592,6 @@ public class RotatedTileBox {
|
||||||
+ pixHeight + "]";
|
+ pixHeight + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,7 @@
|
||||||
<meta-data android:name="com.sec.minimode.icon.landscape.normal" android:resource="@mipmap/icon" android:value="" />
|
<meta-data android:name="com.sec.minimode.icon.landscape.normal" android:resource="@mipmap/icon" android:value="" />
|
||||||
<activity android:name="net.osmand.plus.activities.HelpActivity" />
|
<activity android:name="net.osmand.plus.activities.HelpActivity" />
|
||||||
<activity android:name="net.osmand.plus.activities.ExitActivity" />
|
<activity android:name="net.osmand.plus.activities.ExitActivity" />
|
||||||
<activity android:name=".activities.ServerActivity"
|
<activity android:name=".activities.ServerActivity" />
|
||||||
android:label="@string/shared_string_settings"
|
|
||||||
android:configChanges="keyboardHidden|orientation" />
|
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
|
|
@ -1,51 +1,29 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="10px">
|
android:orientation="vertical"
|
||||||
<RelativeLayout
|
android:padding="10px">
|
||||||
android:id="@+id/RelativeLayout03"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginTop="20px"
|
|
||||||
android:layout_marginBottom="40px">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/TextView02"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:autoLink="web"
|
|
||||||
android:text="Click button to start server"></TextView>
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/Button01"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/RelativeLayout03"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_marginBottom="40px"
|
|
||||||
android:text="Start"></Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/Button03"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/Button01"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:text="Stop"></Button>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView1"
|
android:id="@+id/server_status_textview"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignRight="@+id/Button03"
|
android:textAlignment="center"
|
||||||
android:fitsSystemWindows="true"
|
android:autoLink="web"
|
||||||
android:lines="14"
|
android:text="@string/click_button_to_start_server"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:gravity="center_horizontal"/>
|
||||||
android:textSize="8dp" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
<Button
|
||||||
|
android:id="@+id/server_start_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/global_start"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/server_stop_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/global_stop"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -11,6 +11,10 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="global_start">Start</string>
|
||||||
|
<string name="global_stop">Stop</string>
|
||||||
|
<string name="click_button_to_start_server">Click button to start server</string>
|
||||||
|
<string name="click_button_to_stop_server">Click second button to deactivate server</string>
|
||||||
<string name="web_server">Web server</string>
|
<string name="web_server">Web server</string>
|
||||||
<string name="one_point_error">Please add at least two points.</string>
|
<string name="one_point_error">Please add at least two points.</string>
|
||||||
<string name="shared_string_is_saved">is saved</string>
|
<string name="shared_string_is_saved">is saved</string>
|
||||||
|
|
|
@ -27,20 +27,20 @@ public class ServerActivity extends AppCompatActivity {
|
||||||
enableStrictMode();
|
enableStrictMode();
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.server_activity);
|
setContentView(R.layout.server_activity);
|
||||||
findViewById(R.id.Button01).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.server_start_button).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
updateTextView("Click second button to deactivate server");
|
updateTextView(getString(R.string.click_button_to_stop_server));
|
||||||
initServer();
|
initServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
findViewById(R.id.Button03).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.server_stop_button).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
updateTextView("Click first button to activate server");
|
updateTextView(getString(R.string.click_button_to_start_server));
|
||||||
deInitServer();
|
deInitServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class ServerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
private void updateTextView(String text) {
|
private void updateTextView(String text) {
|
||||||
((TextView) findViewById(R.id.TextView02)).setText(text);
|
((TextView) findViewById(R.id.server_status_textview)).setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initServer() {
|
private void initServer() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import fi.iki.elonen.NanoHTTPD;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.server.endpoints.TileEndpoint;
|
import net.osmand.plus.server.endpoints.TileEndpoint;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -45,13 +46,17 @@ public class ApiRouter {
|
||||||
public NanoHTTPD.Response route(NanoHTTPD.IHTTPSession session) {
|
public NanoHTTPD.Response route(NanoHTTPD.IHTTPSession session) {
|
||||||
Log.d("SERVER", "URI: " + session.getUri());
|
Log.d("SERVER", "URI: " + session.getUri());
|
||||||
String uri = session.getUri();
|
String uri = session.getUri();
|
||||||
if (uri.equals("/")) return getStatic("/go.html");
|
if (uri.equals("/")) {
|
||||||
|
return getStatic("/go.html");
|
||||||
|
}
|
||||||
if (uri.contains("/scripts/") ||
|
if (uri.contains("/scripts/") ||
|
||||||
uri.contains("/images/") ||
|
uri.contains("/images/") ||
|
||||||
uri.contains("/css/") ||
|
uri.contains("/css/") ||
|
||||||
uri.contains("/fonts/") ||
|
uri.contains("/fonts/") ||
|
||||||
uri.contains("/favicon.ico")
|
uri.contains("/favicon.ico")
|
||||||
) return getStatic(uri);
|
) {
|
||||||
|
return getStatic(uri);
|
||||||
|
}
|
||||||
if (isApiUrl(uri)) {
|
if (isApiUrl(uri)) {
|
||||||
return routeApi(session);
|
return routeApi(session);
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,6 +91,7 @@ public class ApiRouter {
|
||||||
private NanoHTTPD.Response routeContent(NanoHTTPD.IHTTPSession session) {
|
private NanoHTTPD.Response routeContent(NanoHTTPD.IHTTPSession session) {
|
||||||
String url = session.getUri();
|
String url = session.getUri();
|
||||||
//add index page
|
//add index page
|
||||||
|
//return getStatic(session.getUri());
|
||||||
String responseText = getHtmlPage(url);
|
String responseText = getHtmlPage(url);
|
||||||
if (responseText != null) {
|
if (responseText != null) {
|
||||||
return newFixedLengthResponse(responseText);
|
return newFixedLengthResponse(responseText);
|
||||||
|
@ -126,6 +132,13 @@ public class ApiRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readHTMLFromFile(String filename) {
|
private String readHTMLFromFile(String filename) {
|
||||||
|
// try {
|
||||||
|
// InputStream is = application.getAssets().open(FOLDER_NAME + filename);
|
||||||
|
// return Algorithms.readFromInputStream(is,false).toString();
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
InputStream is = application.getAssets().open(FOLDER_NAME + filename);
|
InputStream is = application.getAssets().open(FOLDER_NAME + filename);
|
||||||
|
|
|
@ -578,7 +578,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
|
private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
|
||||||
if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
|
if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -615,7 +615,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
additional.calculateFPS(start, end);
|
additional.calculateFPS(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshMapInternal(DrawSettings drawSettings) {
|
private void refreshMapInternal(DrawSettings drawSettings) {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -868,20 +868,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
return currentViewport;
|
return currentViewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentRotatedTileBox(net.osmand.data.RotatedTileBox tileBox) {
|
|
||||||
float rx = (float) tileBox.getCenterPixelX() / tileBox.getPixWidth();
|
|
||||||
float ry = (float) tileBox.getCenterPixelY() / tileBox.getPixHeight();
|
|
||||||
if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
|
|
||||||
ry -= 0.35;
|
|
||||||
}
|
|
||||||
tileBox.setCenterLocation(rx, ry);
|
|
||||||
LatLon screenCenter = tileBox.getLatLonFromPixel(tileBox.getPixWidth() / 2f, tileBox.getPixHeight() / 2f);
|
|
||||||
mapRatioX = 0;
|
|
||||||
mapRatioY = 0;
|
|
||||||
setLatLon(screenCenter.getLatitude(), screenCenter.getLongitude());
|
|
||||||
currentViewport = tileBox;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getDensity() {
|
public float getDensity() {
|
||||||
return currentViewport.getDensity();
|
return currentViewport.getDensity();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue