markers added
This commit is contained in:
parent
122d77f205
commit
79240f34d7
3 changed files with 83 additions and 42 deletions
|
@ -19,6 +19,8 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script type="text/javascript" src="/scripts/js.cookie.js"></script>
|
<script type="text/javascript" src="/scripts/js.cookie.js"></script>
|
||||||
|
<script type="text/javascript" src="/scripts/go.js?v=5"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function getMarkerContent(feature) {
|
function getMarkerContent(feature) {
|
||||||
var p = feature.properties;
|
var p = feature.properties;
|
||||||
|
@ -43,16 +45,29 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupMarkers(){
|
function setupMarkers(){
|
||||||
var points = window.osmand.favoritePoints;
|
$.ajax({
|
||||||
points.forEach(e => {
|
type: 'GET',
|
||||||
var point = {};
|
url: "/favorites",
|
||||||
point.lat = e.latitude;
|
async: false,
|
||||||
point.lon = e.longitude;
|
contentType: "application/json",
|
||||||
window.goMap.map.addMarker(point);
|
dataType: 'json',
|
||||||
})
|
complete: function(r) {
|
||||||
|
var points = JSON.parse(r.responseText);
|
||||||
|
points.forEach(e => {
|
||||||
|
var point = {};
|
||||||
|
point.lat = e.latitude;
|
||||||
|
point.lon = e.longitude;
|
||||||
|
window.goMap.map.addMarker(point);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function(e) {
|
||||||
|
alert("Error happened while getting favourite points "+e.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
//TODO add document ready or map ready event
|
||||||
|
setTimeout(function(){ setupMarkers(); }, 4000);
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="/scripts/go.js?v=5"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="gocontainer" id="gocontainer">
|
<div class="gocontainer" id="gocontainer">
|
||||||
|
@ -65,27 +80,6 @@
|
||||||
<div class="clear:both;"></div>
|
<div class="clear:both;"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
<div class="gofooter">
|
|
||||||
<div class="gobadges">
|
|
||||||
<div class="badgecontainer google">
|
|
||||||
<a href="https://play.google.com/store/apps/details?id=net.osmand.plus">
|
|
||||||
<img alt="Get it on Google Play"
|
|
||||||
src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="badgecontainer apple">
|
|
||||||
<a href="https://itunes.apple.com/us/app/id934850257"><img
|
|
||||||
src="images/app-store-badge.png"></a>
|
|
||||||
</div>
|
|
||||||
<div class="badgecontainer amazon">
|
|
||||||
<a href="http://www.amazon.com/gp/product/B00D0SEGMC/ref=mas_pm_OsmAnd-Maps-Navigation">
|
|
||||||
<img alt="Get it on Amazon" src="images/amazon-apps-store.png">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="clear">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="overlay" style="display:none;"></div>
|
<div class="overlay" style="display:none;"></div>
|
||||||
<div class="popup" style="display:none;">
|
<div class="popup" style="display:none;">
|
||||||
<div class="logo"></div>
|
<div class="logo"></div>
|
||||||
|
|
18
OsmAnd/src/net/osmand/plus/server/ApiEndpoint.java
Normal file
18
OsmAnd/src/net/osmand/plus/server/ApiEndpoint.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package net.osmand.plus.server;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import fi.iki.elonen.NanoHTTPD;
|
||||||
|
|
||||||
|
public class ApiEndpoint{
|
||||||
|
public String uri = "";
|
||||||
|
public ApiCall apiCall;
|
||||||
|
|
||||||
|
public NanoHTTPD.Response run(NanoHTTPD.IHTTPSession session){
|
||||||
|
return apiCall.call(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ApiCall{
|
||||||
|
NanoHTTPD.Response call(NanoHTTPD.IHTTPSession session);
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,11 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import fi.iki.elonen.NanoHTTPD;
|
import fi.iki.elonen.NanoHTTPD;
|
||||||
|
|
||||||
|
@ -28,6 +32,23 @@ public class ApiRouter {
|
||||||
|
|
||||||
private final String FOLDER_NAME = "server";
|
private final String FOLDER_NAME = "server";
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
|
private Map<String, ApiEndpoint> endpoints = new HashMap<>();
|
||||||
|
|
||||||
|
public ApiRouter(){
|
||||||
|
initFavorites();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initFavorites() {
|
||||||
|
ApiEndpoint favorites = new ApiEndpoint();
|
||||||
|
favorites.uri = "/favorites";
|
||||||
|
favorites.apiCall = new ApiEndpoint.ApiCall(){
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response call(NanoHTTPD.IHTTPSession session) {
|
||||||
|
return newFixedLengthResponse(getFavoritesJson());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
endpoints.put(favorites.uri,favorites);
|
||||||
|
}
|
||||||
|
|
||||||
public void setAndroidContext(OsmandApplication androidContext) {
|
public void setAndroidContext(OsmandApplication androidContext) {
|
||||||
this.androidContext = androidContext;
|
this.androidContext = androidContext;
|
||||||
|
@ -35,14 +56,15 @@ 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());
|
||||||
if (session.getUri().equals("/")) return getStatic("/go.html");
|
String uri = session.getUri();
|
||||||
if (session.getUri().contains("/scripts/") ||
|
if (uri.equals("/")) return getStatic("/go.html");
|
||||||
session.getUri().contains("/images/") ||
|
if (uri.contains("/scripts/") ||
|
||||||
session.getUri().contains("/css/") ||
|
uri.contains("/images/") ||
|
||||||
session.getUri().contains("/fonts/") ||
|
uri.contains("/css/") ||
|
||||||
session.getUri().contains("/favicon.ico")
|
uri.contains("/fonts/") ||
|
||||||
) return getStatic(session.getUri());
|
uri.contains("/favicon.ico")
|
||||||
if (isApiUrl(session.getUri())){
|
) return getStatic(uri);
|
||||||
|
if (isApiUrl(uri)){
|
||||||
return routeApi(session);
|
return routeApi(session);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -51,11 +73,19 @@ public class ApiRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private NanoHTTPD.Response routeApi(NanoHTTPD.IHTTPSession session) {
|
private NanoHTTPD.Response routeApi(NanoHTTPD.IHTTPSession session) {
|
||||||
return newFixedLengthResponse("");
|
String uri = session.getUri();
|
||||||
|
ApiEndpoint endpoint = endpoints.get(uri);
|
||||||
|
if (endpoint != null){
|
||||||
|
return endpoint.apiCall.call(session);
|
||||||
|
}
|
||||||
|
return ErrorResponses.response404;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isApiUrl(String uri) {
|
private boolean isApiUrl(String uri) {
|
||||||
return uri.endsWith("/favorites");
|
for (String endpoint : endpoints.keySet()){
|
||||||
|
if (endpoint.equals(uri)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NanoHTTPD.Response routeContent(NanoHTTPD.IHTTPSession session) {
|
private NanoHTTPD.Response routeContent(NanoHTTPD.IHTTPSession session) {
|
||||||
|
@ -63,7 +93,6 @@ public class ApiRouter {
|
||||||
//add index page
|
//add index page
|
||||||
String responseText = getHtmlPage(url);
|
String responseText = getHtmlPage(url);
|
||||||
if (responseText != null) {
|
if (responseText != null) {
|
||||||
responseText = addFavoritesToResponse(responseText);
|
|
||||||
return newFixedLengthResponse(responseText);
|
return newFixedLengthResponse(responseText);
|
||||||
} else {
|
} else {
|
||||||
return ErrorResponses.response404;
|
return ErrorResponses.response404;
|
||||||
|
@ -130,7 +159,7 @@ public class ApiRouter {
|
||||||
return responseText;
|
return responseText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String addFavoritesToResponse(String responseText) {
|
private String getFavoritesJson() {
|
||||||
List<FavouritePoint> points = androidContext.getFavorites().getFavouritePoints();
|
List<FavouritePoint> points = androidContext.getFavorites().getFavouritePoints();
|
||||||
StringBuilder text = new StringBuilder();
|
StringBuilder text = new StringBuilder();
|
||||||
for (FavouritePoint p : points) {
|
for (FavouritePoint p : points) {
|
||||||
|
@ -138,7 +167,7 @@ public class ApiRouter {
|
||||||
text.append(json);
|
text.append(json);
|
||||||
text.append(",");
|
text.append(",");
|
||||||
}
|
}
|
||||||
return responseText + "<script>var osmand = {}; window.osmand.favoritePoints = [" + text.toString() + "];setupMarkers();</script>";
|
return "[" + text.substring(0,text.length()-1) + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String jsonFromFavorite(FavouritePoint favouritePoint) {
|
private String jsonFromFavorite(FavouritePoint favouritePoint) {
|
||||||
|
|
Loading…
Reference in a new issue