Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/android-sdk-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public final class com.mapconductor.core.circle.CircleTileSet$Companion {
public final boolean canTile(com.mapconductor.core.circle.CircleState);
}
public final class com.mapconductor.core.circle.CircleTiler {
public static final double MAX_LATITUDE;
public static final double TAP_STROKE_SLACK_PX;
public static final double TAP_SLACK_METERS;
public com.mapconductor.core.circle.CircleTiler(com.mapconductor.core.circle.CircleTilingOptions);
public com.mapconductor.core.circle.CircleTiler(com.mapconductor.core.circle.CircleTilingOptions, int, kotlin.jvm.internal.DefaultConstructorMarker);
public final com.mapconductor.core.circle.CircleTilingOptions getOptions();
Expand All @@ -318,6 +321,8 @@ public final class com.mapconductor.core.circle.CircleTiler {
public final java.lang.Object clear(kotlin.coroutines.Continuation<? super kotlin.Unit>);
public com.mapconductor.core.circle.CircleTiler();
}
final class com.mapconductor.core.circle.CircleTiler$Companion {
}
public final class com.mapconductor.core.circle.CircleTilerKt {
public static final java.lang.String CIRCLE_TILE_LAYER_ID;
public static final com.mapconductor.core.raster.RasterLayerState circleTileRasterLayerState(java.lang.String, int);
Expand Down Expand Up @@ -1222,10 +1227,16 @@ public interface com.mapconductor.core.map.MapViewHolderInterface<ActualMapView,
public abstract androidx.compose.ui.geometry.Offset toScreenOffset-x-9fifI(com.mapconductor.core.features.GeoPointInterface);
public default java.lang.Object fromScreenOffset-3MmeM6k(long, kotlin.coroutines.Continuation<? super com.mapconductor.core.features.GeoPoint>);
public default com.mapconductor.core.features.GeoPoint fromScreenOffsetSync-k-4lQ0M(long);
public default com.mapconductor.core.projection.MapCoordinateSystem getCoordinateSystem();
public default com.mapconductor.core.projection.ProjectedPoint toProjectedPoint(com.mapconductor.core.features.GeoPointInterface);
public default com.mapconductor.core.features.GeoPoint fromProjectedPoint(com.mapconductor.core.projection.ProjectedPoint);
}
public final class com.mapconductor.core.map.MapViewHolderInterface$DefaultImpls {
public static <ActualMapView, ActualMap> java.lang.Object fromScreenOffset-3MmeM6k(com.mapconductor.core.map.MapViewHolderInterface<ActualMapView, ActualMap>, long, kotlin.coroutines.Continuation<? super com.mapconductor.core.features.GeoPoint>);
public static <ActualMapView, ActualMap> com.mapconductor.core.features.GeoPoint fromScreenOffsetSync-k-4lQ0M(com.mapconductor.core.map.MapViewHolderInterface<ActualMapView, ActualMap>, long);
public static <ActualMapView, ActualMap> com.mapconductor.core.projection.MapCoordinateSystem getCoordinateSystem(com.mapconductor.core.map.MapViewHolderInterface<ActualMapView, ActualMap>);
public static <ActualMapView, ActualMap> com.mapconductor.core.projection.ProjectedPoint toProjectedPoint(com.mapconductor.core.map.MapViewHolderInterface<ActualMapView, ActualMap>, com.mapconductor.core.features.GeoPointInterface);
public static <ActualMapView, ActualMap> com.mapconductor.core.features.GeoPoint fromProjectedPoint(com.mapconductor.core.map.MapViewHolderInterface<ActualMapView, ActualMap>, com.mapconductor.core.projection.ProjectedPoint);
}
public abstract class com.mapconductor.core.map.MapViewHolderStoreBaseAsync<TMapView, TMap, TOptions> extends com.mapconductor.core.map.StaticHolder<com.mapconductor.core.map.MapViewHolderInterface<TMapView, TMap>> {
public com.mapconductor.core.map.MapViewHolderStoreBaseAsync();
Expand Down Expand Up @@ -2850,6 +2861,22 @@ public final class com.mapconductor.core.projection.Earth {
public static final double SEMI_MINOR_AXIS_METERS;
public static final double ECCENTRICITY_SQUARED;
}
public final class com.mapconductor.core.projection.MapCoordinateSystem {
public static final com.mapconductor.core.projection.MapCoordinateSystem$Companion Companion;
public com.mapconductor.core.projection.MapCoordinateSystem(java.lang.String, com.mapconductor.core.projection.ProjectedUnit);
public final java.lang.String getCode();
public final com.mapconductor.core.projection.ProjectedUnit getUnit();
public final java.lang.String component1();
public final com.mapconductor.core.projection.ProjectedUnit component2();
public final com.mapconductor.core.projection.MapCoordinateSystem copy(java.lang.String, com.mapconductor.core.projection.ProjectedUnit);
public java.lang.String toString();
public int hashCode();
public boolean equals(java.lang.Object);
}
public final class com.mapconductor.core.projection.MapCoordinateSystem$Companion {
public final com.mapconductor.core.projection.MapCoordinateSystem getWebMercator();
public final com.mapconductor.core.projection.MapCoordinateSystem getWGS84();
}
public final class com.mapconductor.core.projection.ProjectedPoint {
public com.mapconductor.core.projection.ProjectedPoint(double, double);
public final double getX();
Expand All @@ -2861,6 +2888,14 @@ public final class com.mapconductor.core.projection.ProjectedPoint {
public int hashCode();
public boolean equals(java.lang.Object);
}
public final class com.mapconductor.core.projection.ProjectedUnit extends java.lang.Enum<com.mapconductor.core.projection.ProjectedUnit> {
public static final com.mapconductor.core.projection.ProjectedUnit Meters;
public static final com.mapconductor.core.projection.ProjectedUnit Degrees;
public static final com.mapconductor.core.projection.ProjectedUnit Other;
public static com.mapconductor.core.projection.ProjectedUnit[] values();
public static com.mapconductor.core.projection.ProjectedUnit valueOf(java.lang.String);
public static kotlin.enums.EnumEntries<com.mapconductor.core.projection.ProjectedUnit> getEntries();
}
public interface com.mapconductor.core.projection.ProjectionInterface {
public abstract com.mapconductor.core.projection.ProjectedPoint project(com.mapconductor.core.features.GeoPointInterface);
public abstract com.mapconductor.core.features.GeoPointInterface unproject(com.mapconductor.core.projection.ProjectedPoint);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/mapconductor/core/map/MapViewHolderInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.mapconductor.core.map
import androidx.compose.ui.geometry.Offset
import com.mapconductor.core.features.GeoPoint
import com.mapconductor.core.features.GeoPointInterface
import com.mapconductor.core.projection.MapCoordinateSystem
import com.mapconductor.core.projection.ProjectedPoint
import com.mapconductor.core.projection.WebMercator

interface MapViewHolderInterface<ActualMapView, ActualMap> {
val mapView: ActualMapView
Expand Down Expand Up @@ -36,4 +39,28 @@ interface MapViewHolderInterface<ActualMapView, ActualMap> {
* 既定 null のまま黙って無反応にしない。
*/
fun fromScreenOffsetSync(offset: Offset): GeoPoint? = null

/**
* 地図エンジンが今使っている座標系。[toProjectedPoint] の値はこの座標系になる。
*
* 既定は EPSG:3857 メートル。Mercator しか持たないエンジンと、地球儀表示中の
* エンジンはこのままでよい。地図ごとに座標系を持てるエンジン(ArcGIS など)
* だけが上書きする。
*/
val coordinateSystem: MapCoordinateSystem
get() = MapCoordinateSystem.WebMercator

/**
* 地理座標 → [coordinateSystem] の投影座標。**画面座標ではない。**
*
* 投影の定義域の外などで変換できないときは null。既定は EPSG:3857。
*/
fun toProjectedPoint(position: GeoPointInterface): ProjectedPoint? = WebMercator.project(position)

/**
* [coordinateSystem] の投影座標 → 地理座標。[toProjectedPoint] の逆。
*
* 変換できないときは null。既定は EPSG:3857。
*/
fun fromProjectedPoint(point: ProjectedPoint): GeoPoint? = GeoPoint.from(WebMercator.unproject(point))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.mapconductor.core.projection

/**
* 地図エンジンが地図を並べている座標系。**画面座標ではない。**
*
* [com.mapconductor.core.map.MapViewHolderInterface.toProjectedPoint] が返す
* [ProjectedPoint] がどの座標系の値かを示す。
*
* - [code] は `"EPSG:3857"` のような識別子。エンジンが独自に定義した投影で、
* EPSG などの番号を持たないときは null。
* - [unit] は x / y の単位。
*
* Mercator しか持たないエンジンと、地球儀表示中のエンジンは [WebMercator]
* (EPSG:3857 メートル)になる。
*/
data class MapCoordinateSystem(
val code: String?,
val unit: ProjectedUnit,
) {
companion object {
/** EPSG:3857。x / y はメートル。 */
val WebMercator = MapCoordinateSystem("EPSG:3857", ProjectedUnit.Meters)

/** EPSG:4326。x が経度、y が緯度で、単位は度。 */
val WGS84 = MapCoordinateSystem("EPSG:4326", ProjectedUnit.Degrees)
}
}

/** [ProjectedPoint] の x / y の単位。 */
enum class ProjectedUnit {
Meters,
Degrees,

/** フィートなど上の 2 つ以外、またはエンジン独自の単位。 */
Other,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.mapconductor.core.map

import androidx.compose.ui.geometry.Offset
import com.mapconductor.core.features.GeoPoint
import com.mapconductor.core.features.GeoPointInterface
import com.mapconductor.core.projection.MapCoordinateSystem
import com.mapconductor.core.projection.ProjectedPoint
import com.mapconductor.core.projection.ProjectedUnit
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test

/**
* 投影座標の既定実装。上書きしないホルダは EPSG:3857 メートルを返す。
*/
class MapViewHolderProjectedPointTest {
private class PlainHolder : MapViewHolderInterface<Unit, Unit> {
override val mapView = Unit
override val map = Unit

override fun toScreenOffset(position: GeoPointInterface): Offset? = null
}

@Test
fun defaultCoordinateSystemIsWebMercator() {
val system = PlainHolder().coordinateSystem
assertEquals("EPSG:3857", system.code)
assertEquals(ProjectedUnit.Meters, system.unit)
assertEquals(MapCoordinateSystem.WebMercator, system)
}

@Test
fun defaultProjectionIsEpsg3857Meters() {
// 東京駅。期待値は x = λ·a、y = a·ln(tan(π/4 + φ/2))(a = 6378137)。
val point = PlainHolder().toProjectedPoint(GeoPoint(35.681236, 139.767125, 0.0))
assertNotNull(point)
assertEquals(15558805.18, point!!.x, 0.01)
assertEquals(4256848.12, point.y, 0.01)
}

@Test
fun defaultRoundTripReturnsTheSamePoint() {
val holder = PlainHolder()
val original = GeoPoint(-33.8688, 151.2093, 0.0)
val back = holder.fromProjectedPoint(holder.toProjectedPoint(original)!!)
assertNotNull(back)
assertEquals(original.latitude, back!!.latitude, 1e-9)
assertEquals(original.longitude, back.longitude, 1e-9)
}

@Test
fun originMapsToNullIsland() {
val back = PlainHolder().fromProjectedPoint(ProjectedPoint(0.0, 0.0))
assertEquals(0.0, back!!.latitude, 1e-12)
assertEquals(0.0, back.longitude, 1e-12)
}
}
Loading