Mit getTileURL in Android-Anwendung mit GeoServer

Sind wir gerade erst anfangen zu arbeiten, mit Google Maps auf Android und haben einen GeoServer eingerichtet, um die Fliesen, die wir hinzufügen möchten, die als overlay auf der Karte. So weit, ich habe ein paar tutorials und Referenzen, um loszulegen.

Das problem: Während die url, die ich bin, zu generieren in der getTileUrl Funktion in der TileProviderFactory hat sogar wieder ein png-Bild, wenn ich einen Haltepunkt festlegen und das kopieren und einfügen der url in einen browser eingeben, es wird nicht geladen, auf die Karte als overlay auf dem Android-Gerät. Es werden keine Fehler ausgelöst wird, von was ich sehen kann, und nach der Lektüre diese ich bin nicht sicher, ob es sein wird, wie Sie angegeben haben, dass die Fehler nicht stummgeschaltet.

Was ich mich Frage ist, wenn Sie sehen, keine unmittelbaren Probleme in meinem code oder irgendwelche Vorschläge haben, zum debugging, wo ich in der Lage zu sagen, wenn die Anwendung tatsächlich die Kommunikation mit meinem GeoServer, um das Bild oder nicht. Ich habe in den log geschaut auf den GeoServer und es scheint, als ob nur mein browser-Anfragen sind durch und es ist nicht erhalten, keine Anfragen von Android (es ist ein bisschen schwer zu sagen, weil wir die anderen Anwendungen mit dem server). Das Android-Telefon angeschlossen ist, indem sowohl wifi und Mobilfunk und gps aktiviert. Als letzten Ausweg habe ich versucht, die änderung der Kachel-overlay zIndex und eine Einstellung sichtbar, aber dies scheint nicht zu keinen Unterschied machen.

EDIT: Android-Gerät ist definitiv NICHT der Kommunikation mit GeoServer an dieser Stelle.

EDIT 2: laden Können statische Bilder von websites
(wie diese) als overlays und fand, dass ich immer die folgende Ausnahme auf testen HTTP-Request auf die URL gebildet:

W/System.err(10601): java.net.SocketException: The operation timed out
W/System.err(10601): at org.apache.harmony.luni.platform.OSNetworkSystem
     .connectStreamWithTimeoutSocketImpl(Native Method)
W/System.err(10601): at org.apache.harmony.luni.net.PlainSocketImpl
     .connect(PlainSocketImpl.java:244)
W/System.err(10601): at org.apache.harmony.luni.net.PlainSocketImpl
     .connect(PlainSocketImpl.java:533)
W/System.err(10601): at java.net.Socket
     .connect(Socket.java:1074)
W/System.err(10601): at org.apache.http.conn.scheme.PlainSocketFactory
     .connectSocket(PlainSocketFactory.java:119)

Dank.

MapTestActivity

public class MapTestActivity extends FragmentActivity
    implements LocationListener, LocationSource{

    private GoogleMap mMap;
    private OnLocationChangedListener mListener;
    private LocationManager locationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_test);     
        setupLocationManager();     
        setupMapIfNeeded();
    }

    private void setupLocationManager() {
        this.locationManager = 
            (LocationManager) getSystemService(LOCATION_SERVICE);

        if (locationManager != null) {
            boolean gpsIsEnabled = locationManager.isProviderEnabled(
                    LocationManager.GPS_PROVIDER);
            boolean networkIsEnabled = locationManager.isProviderEnabled(
                    LocationManager.NETWORK_PROVIDER);

            if(gpsIsEnabled) {
                this.locationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, 5000L, 10F, this);
            }
            else if(networkIsEnabled) {
                this.locationManager.requestLocationUpdates(
                    LocationManager.NETWORK_PROVIDER, 5000L, 10F, this);
            }
            else {
                //Show an error dialog that GPS is disabled...
            }
        }
        else {
            //Show some generic error dialog because 
            //something must have gone wrong with location manager.
        }
    }

    private void setupMapIfNeeded() {
        //Do a null check to confirm that we have not already instantiated the
        //map.
        if (mMap == null) {
            //Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();
            //Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
            mMap.setLocationSource(this);
        }
    }

    private void setUpMap() {
        //TODO Auto-generated method stub
        mMap.setMyLocationEnabled(true);
        TileProvider geoServerTileProvider = TileProviderFactory
            .getGeoServerTileProvider();
        TileOverlay geoServerTileOverlay = mMap.addTileOverlay(
            new TileOverlayOptions()
                .tileProvider(geoServerTileProvider)
                .zIndex(10000)
                .visible(true));
    }
    //Non-relevant listener methods removed
}

TileProviderFactory

public class TileProviderFactory {

    public static GeoServerTileProvider getGeoServerTileProvider() {

        String baseURL = "mytileserver.com";
        String version = "1.3.0";
        String request = "GetMap";
        String format = "image/png";
        String srs = "EPSG:900913";
        String service = "WMS";
        String width = "256";
        String height = "256";
        String styles = "";
        String layers = "wtx:road_hazards";

        final String URL_STRING = baseURL + 
                "&LAYERS=" + layers + 
                "&VERSION=" + version + 
                "&SERVICE=" + service + 
                "&REQUEST=" + request + 
                "&TRANSPARENT=TRUE&STYLES=" + styles + 
                "&FORMAT=" + format + 
                "&SRS=" + srs + 
                "&BBOX=%f,%f,%f,%f" + 
                "&WIDTH=" + width + 
                "&HEIGHT=" + height;


        GeoServerTileProvider tileProvider = 
            new GeoServerTileProvider(256,256) {

            @Override
            public synchronized URL getTileUrl(int x, int y, int zoom) {
                try {       

                    double[] bbox = getBoundingBox(x, y, zoom);

                    String s = String.format(Locale.US, URL_STRING, bbox[MINX], 
                            bbox[MINY], bbox[MAXX], bbox[MAXY]);

                    Log.d("GeoServerTileURL", s);

                    URL url = null;

                    try {
                        url = new URL(s);
                    } 
                    catch (MalformedURLException e) {
                        throw new AssertionError(e);
                    }

                    return url;
                }
                catch (RuntimeException e) {
                    Log.d("GeoServerTileException", 
                        "getTile x=" + x + ", y=" + y + 
                        ", zoomLevel=" + zoom + 
                        " raised an exception", e);
                    throw e;
                }

            }
        };
        return tileProvider;
    }
}

GeoServerTileProvider

public abstract class GeoServerTileProvider extends UrlTileProvider{

    //Web Mercator n/w corner of the map.
    private static final double[] TILE_ORIGIN = 
        { -20037508.34789244, 20037508.34789244};
    //array indexes for that data
    private static final int ORIG_X = 0; 
    private static final int ORIG_Y = 1; //"

    //Size of square world map in meters, using WebMerc projection.
    private static final double MAP_SIZE = 20037508.34789244 * 2;

    //array indexes for array to hold bounding boxes.
    protected static final int MINX = 0;
    protected static final int MINY = 1;
    protected static final int MAXX = 2;
    protected static final int MAXY = 3;

    public GeoServerTileProvider(int width, int height) {
        super(width, height);
    }

    //Return a web Mercator bounding box given tile x/y indexes and a zoom
    //level.
    protected double[] getBoundingBox(int x, int y, int zoom) {
        double tileSize = MAP_SIZE / Math.pow(2, zoom);
        double minx = TILE_ORIGIN[ORIG_X] + x * tileSize;
        double maxx = TILE_ORIGIN[ORIG_X] + (x+1) * tileSize;
        double miny = TILE_ORIGIN[ORIG_Y] - (y+1) * tileSize;
        double maxy = TILE_ORIGIN[ORIG_Y] - y * tileSize;

        double[] bbox = new double[4];
        bbox[MINX] = minx;
        bbox[MINY] = miny;
        bbox[MAXX] = maxx;
        bbox[MAXY] = maxy;
        return bbox;
    }
}
InformationsquelleAutor sugarwaffle | 2013-03-21
Schreibe einen Kommentar