org.mapsforge.core.model.Point Java Examples

The following examples show how to use org.mapsforge.core.model.Point. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NavigationOverlay.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
private static Point getPoint(GeoPoint geoPoint, Point canvasPosition, byte zoomLevel) {
    int pixelX =
            (int) (MercatorProjection.longitudeToPixelX(geoPoint.longitude, zoomLevel) - canvasPosition.x);
    int pixelY =
            (int) (MercatorProjection.latitudeToPixelY(geoPoint.latitude, zoomLevel) - canvasPosition.y);
    return new Point(pixelX, pixelY);
}
 
Example #2
Source File: NavigationOverlay.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas) {
    // TODO Auto-generated method stub
    if (target == null || !myLocationOverlay.isMyLocationEnabled()
            || myLocationOverlay.getLastLocation() == null)
        return;
    double canvasPixelLeft =
            MercatorProjection.longitudeToPixelX(boundingBox.minLongitude, zoomLevel);
    double canvasPixelTop = MercatorProjection.latitudeToPixelY(boundingBox.maxLatitude, zoomLevel);
    Point canvasPosition = new Point(canvasPixelLeft, canvasPixelTop);

    Location startLocation = myLocationOverlay.getLastLocation();
    GeoPoint start = new GeoPoint(startLocation.getLatitude(), startLocation.getLongitude());

    List<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
    geoPoints.add(start);
    geoPoints.add(target);
    line.setPolygonalChain(new PolygonalChain(geoPoints));
    line.draw(boundingBox, zoomLevel, canvas, canvasPosition);

/*
 * double canvasPixelLeft = MercatorProjection.longitudeToPixelX( boundingBox.minLongitude,
 * zoomLevel); double canvasPixelTop = MercatorProjection.latitudeToPixelY(
 * boundingBox.maxLatitude, zoomLevel); Point canvasPosition = new Point(canvasPixelLeft,
 * canvasPixelTop); Point a = getPoint(start, canvasPosition, zoomLevel); Point b =
 * getPoint(target, canvasPosition, zoomLevel); canvas.drawLine(a.x, a.y, b.x, b.y, paint);
 */
}
 
Example #3
Source File: RotationMarker.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized boolean draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
                                 Point canvasPosition) {
    GeoPoint geoPoint = this.getGeoPoint();
    Drawable drawable = this.getDrawable();
    if (geoPoint == null || drawable == null) {
        return false;
    }

    double latitude = geoPoint.latitude;
    double longitude = geoPoint.longitude;
    int pixelX =
            (int) (MercatorProjection.longitudeToPixelX(longitude, zoomLevel) - canvasPosition.x);
    int pixelY =
            (int) (MercatorProjection.latitudeToPixelY(latitude, zoomLevel) - canvasPosition.y);

    Rect drawableBounds = drawable.copyBounds();
    int left = pixelX + drawableBounds.left;
    int top = pixelY + drawableBounds.top;
    int right = pixelX + drawableBounds.right;
    int bottom = pixelY + drawableBounds.bottom;

    if (!intersect(canvas, left, top, right, bottom)) {
        return false;
    }

    int saveCount = canvas.save();
    canvas.rotate(rotation, (float) pixelX, (float) pixelY);
    drawable.setBounds(left, top, right, bottom);
    drawable.draw(canvas);
    drawable.setBounds(drawableBounds);
    canvas.restoreToCount(saveCount);
    return true;
}
 
Example #4
Source File: MyLocationOverlay.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas) {
    if (!this.myLocationEnabled) {
        return;
    }

    double canvasPixelLeft =
            MercatorProjection.longitudeToPixelX(boundingBox.minLongitude, zoomLevel);
    double canvasPixelTop = MercatorProjection.latitudeToPixelY(boundingBox.maxLatitude, zoomLevel);
    Point canvasPosition = new Point(canvasPixelLeft, canvasPixelTop);
    this.circle.draw(boundingBox, zoomLevel, canvas, canvasPosition);
    this.marker.draw(boundingBox, zoomLevel, canvas, canvasPosition);
}
 
Example #5
Source File: MapsforgeSimpleViewer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static TileDownloadLayer createTileDownloadLayer( TileCache tileCache, IMapViewPosition mapViewPosition,
        TileSource tileSource ) {
    return new TileDownloadLayer(tileCache, mapViewPosition, tileSource, GRAPHIC_FACTORY){
        @Override
        public boolean onTap( LatLong tapLatLong, Point layerXY, Point tapXY ) {
            System.out.println("Tap on: " + tapLatLong);
            return true;
        }
    };
}
 
Example #6
Source File: MapsforgeSimpleViewer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static TileRendererLayer createTileRendererLayer( TileCache tileCache, MapDataStore mapDataStore,
        IMapViewPosition mapViewPosition ) {
    TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore, mapViewPosition, false, true, false,
            GRAPHIC_FACTORY){
        @Override
        public boolean onTap( LatLong tapLatLong, Point layerXY, Point tapXY ) {
            System.out.println("Tap on: " + tapLatLong);
            return true;
        }
    };
    tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);
    return tileRendererLayer;
}
 
Example #7
Source File: HomeActivity.java    From EasyVPN-Free with GNU General Public License v3.0 4 votes vote down vote up
private void initServerOnMap(Layers layers) {
    Type listType = new TypeToken<ArrayList<Country>>(){}.getType();
    countryLatLonList =  new Gson().fromJson(LoadData.fromFile(COUNTRY_FILE_NAME, this), listType);

    for (Server server : countryList) {
        for (Country country : countryLatLonList) {
            if (server.getCountryShort().equals(country.getCountryCode())) {
                LatLong position = new LatLong(country.getCapitalLatitude(), country.getCapitalLongitude());
                Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(ContextCompat.getDrawable(this,
                        getResources().getIdentifier(ConnectionQuality.getPointIcon(server.getQuality()),
                                "drawable",
                                getPackageName())));

                MyMarker countryMarker = new MyMarker(position, bitmap, 0, 0, server) {
                    @Override
                    public boolean onTap(LatLong geoPoint, Point viewPosition,
                                         Point tapPoint) {

                        if (contains(viewPosition, tapPoint)) {
                            onSelectCountry((Server)getRelationObject());
                            return true;
                        }
                        return false;
                    }
                };

                layers.add(countryMarker);


                String localeCountryName = localeCountries.get(country.getCountryCode()) != null ?
                        localeCountries.get(country.getCountryCode()) : country.getCountryName();

                Drawable drawable = new BitmapDrawable(getResources(), BitmapGenerator.getTextAsBitmap(localeCountryName, 20, ContextCompat.getColor(this,R.color.mapNameCountry)));
                Bitmap bitmapName = AndroidGraphicFactory.convertToBitmap(drawable);

                Marker countryNameMarker = new Marker(position, bitmapName, 0, bitmap.getHeight() / 2);

                layers.add(countryNameMarker);
            }
        }
    }
}
 
Example #8
Source File: ForgeLayer.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint)
{
}