Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev branch #66

Merged
merged 15 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added StartMapLocationSystem.
  • Loading branch information
ISeleznev-HORIS authored and IKupriyanov-HORIS committed Dec 18, 2019
commit 9f7baeda5b9477fab6d10f58ca046b51dead2adc
7 changes: 5 additions & 2 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/LiveMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ class LiveMap(
RegionIdGeocodingSystem(componentManager, myGeocodingProvider),
CentroidGeocodingSystem(componentManager, myGeocodingProvider),
BBoxGeocodingSystem(componentManager, myGeocodingProvider),
LocationGeocodingSystem(componentManager, myGeocodingProvider, true),
LocationCalculateSystem(componentManager, true),

LocationCounterSystem(componentManager, true),
LocationGeocodingSystem(componentManager, myGeocodingProvider),
LocationCalculateSystem(componentManager),
StartMapLocationSystem(componentManager, true, null),

ApplyPointSystem(componentManager),

Expand Down
31 changes: 5 additions & 26 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/LiveMapFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package jetbrains.livemap

import jetbrains.datalore.base.async.Async
import jetbrains.datalore.base.async.Asyncs
import jetbrains.datalore.base.typedGeometry.center
import jetbrains.livemap.camera.Viewport
import jetbrains.livemap.camera.ViewportHelper
Expand All @@ -26,6 +27,7 @@ class LiveMapFactory(private val myLiveMapSpec: LiveMapSpec) : BaseLiveMapFactor
myMapProjection = createMapProjection(myLiveMapSpec.projectionType, mapRect)
val multiMapHelper = ViewportHelper(mapRect, myLiveMapSpec.isLoopX, myLiveMapSpec.isLoopY)
myMapRuler = multiMapHelper

myViewport = Viewport.create(
multiMapHelper,
myLiveMapSpec.size.toClientPoint(),
Expand All @@ -34,32 +36,9 @@ class LiveMapFactory(private val myLiveMapSpec: LiveMapSpec) : BaseLiveMapFactor
}

override fun createLiveMap(): Async<BaseLiveMap> {
val mapDataGeocodingHelper = MapDataGeocodingHelper(
myLiveMapSpec.size,
myLiveMapSpec.geocodingService,
myLiveMapSpec.layerProvider.layers,
myLiveMapSpec.level,
myLiveMapSpec.parent,
myLiveMapSpec.location,
myLiveMapSpec.zoom,
myMapRuler,
myMapProjection,
true //for BBoxEmptinessChecker
)
myViewport.zoom = 1

return mapDataGeocodingHelper.geocodeMapData()
.map { mapPosition ->
mapPosition
?.let { createLiveMap(it.zoom, it.coordinate) }
?: error("Map position must to be not null")
}
}

private fun createLiveMap(zoom: Int, center: WorldPoint): BaseLiveMap {
myViewport.zoom = zoom
myViewport.position = center

return LiveMap(
return Asyncs.constant(LiveMap(
myMapProjection,
myViewport,
myLiveMapSpec.layerProvider,
Expand All @@ -72,6 +51,6 @@ class LiveMapFactory(private val myLiveMapSpec: LiveMapSpec) : BaseLiveMapFactor
myLiveMapSpec.level,
myLiveMapSpec.parent
)
)
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import jetbrains.datalore.base.typedGeometry.center
import jetbrains.gis.geoprotocol.FeatureLevel
import jetbrains.gis.geoprotocol.GeocodingService
import jetbrains.gis.geoprotocol.MapRegion
import jetbrains.livemap.MapWidgetUtil.DEFAULT_LOCATION
import jetbrains.livemap.MapWidgetUtil.convertToWorldRects
import jetbrains.livemap.mapobjects.MapLayer
import jetbrains.livemap.mapobjects.MapLayerKind
import jetbrains.livemap.projections.MapProjection
import jetbrains.livemap.projections.MapRuler
import jetbrains.livemap.projections.World
import jetbrains.livemap.projections.toClientPoint

internal class MapDataGeocodingHelper(
private val mySize: DoubleVector,
Expand Down Expand Up @@ -110,10 +112,8 @@ internal class MapDataGeocodingHelper(
}

private fun calculateZoom(rectangle: Rect<World>): Int {
return MapWidgetUtil.calculateMaxZoom(rectangle.dimension, mySize)
return MapWidgetUtil.calculateMaxZoom(rectangle.dimension, mySize.toClientPoint())
}

companion object {
private val DEFAULT_LOCATION = GeoRectangle(-124.76, 25.52, -66.94, 49.39)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

package jetbrains.livemap

import jetbrains.datalore.base.projectionGeometry.*
import jetbrains.datalore.base.spatial.GeoRectangle
import jetbrains.datalore.base.spatial.LonLat
import jetbrains.livemap.projections.*
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.base.geospatial.GeoRectangle
import jetbrains.datalore.base.geospatial.LonLat
Expand All @@ -21,6 +25,7 @@ import kotlin.math.min
object MapWidgetUtil {
const val MIN_ZOOM = 1
const val MAX_ZOOM = 15
val DEFAULT_LOCATION = GeoRectangle(-124.76, 25.52, -66.94, 49.39)
private const val FULL_ANGLE = 360.0
private const val STRAIGHT_ANGLE = 180.0

Expand Down Expand Up @@ -56,7 +61,7 @@ object MapWidgetUtil {
return pathList
}

internal fun calculateMaxZoom(rectSize: Vec<World>, containerSize: DoubleVector): Int {
internal fun calculateMaxZoom(rectSize: Vec<World>, containerSize: Vec<Client>): Int {
val xZoom = calculateMaxZoom(rectSize.x, containerSize.x)
val yZoom = calculateMaxZoom(rectSize.y, containerSize.y)
val zoom = min(xZoom, yZoom)
Expand Down
4 changes: 2 additions & 2 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/api/Bars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class BarsFactory(
result.add(
when {
source.point != null ->
myFactory.createStaticEntity("map_ent_s_bar", source.point!!)
myFactory.createStaticEntityWithLocation("map_ent_s_bar", source.point!!)
source.mapId != null ->
myFactory.createDynamicEntity("map_ent_d_bar_${source.mapId}", source.mapId!!)
myFactory.createDynamicEntityWithLocation("map_ent_d_bar_${source.mapId}", source.mapId!!)
else ->
error("Can't create bar entity. [point] and [mapId] is null.")
}.setInitializer { worldPoint ->
Expand Down
9 changes: 8 additions & 1 deletion livemap/src/commonMain/kotlin/jetbrains/livemap/api/Lines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import jetbrains.livemap.core.ecs.EcsEntity
import jetbrains.livemap.core.ecs.addComponents
import jetbrains.livemap.core.rendering.layers.LayerGroup
import jetbrains.livemap.entities.Entities.MapEntityFactory
import jetbrains.livemap.entities.geocoding.NeedCalculateLocationComponent
import jetbrains.livemap.entities.geocoding.NeedGeocodeLocationComponent
import jetbrains.livemap.entities.geocoding.NeedLocationComponent
import jetbrains.livemap.entities.geometry.WorldGeometryComponent
import jetbrains.livemap.entities.placement.ScreenLoopComponent
import jetbrains.livemap.entities.placement.ScreenOriginComponent
Expand Down Expand Up @@ -81,7 +84,8 @@ class LineBuilder(
myFactory.createDynamicEntity("map_ent_d_line_$mapId", mapId!!)
else ->
error("Can't create line entity. [point] and [mapId] is null.")
}.setInitializer { worldPoint ->
}
.setInitializer { worldPoint ->
val line = createLineGeometry(worldPoint, horizontal, myMapProjection.mapRect)
val bbox = createLineBBox(worldPoint, strokeWidth, horizontal, myMapProjection.mapRect)

Expand All @@ -97,5 +101,8 @@ class LineBuilder(
setLineDash([email protected])
}
}
.remove<NeedLocationComponent>()
.remove<NeedCalculateLocationComponent>()
.remove<NeedGeocodeLocationComponent>()
}
}
4 changes: 4 additions & 0 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/api/Paths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import jetbrains.livemap.core.rendering.layers.LayerGroup
import jetbrains.livemap.effects.GrowingPath.GrowingPathEffectComponent
import jetbrains.livemap.effects.GrowingPath.GrowingPathRenderer
import jetbrains.livemap.entities.Entities
import jetbrains.livemap.entities.geocoding.NeedCalculateLocationComponent
import jetbrains.livemap.entities.geocoding.NeedLocationComponent
import jetbrains.livemap.entities.geometry.WorldGeometryComponent
import jetbrains.livemap.entities.placement.ScreenLoopComponent
import jetbrains.livemap.entities.placement.ScreenOriginComponent
Expand Down Expand Up @@ -97,6 +99,8 @@ class PathBuilder(
strokeWidth = [email protected]
lineDash = [email protected]()
}
+ NeedLocationComponent()
+ NeedCalculateLocationComponent()
}

if (animation == 2) {
Expand Down
4 changes: 2 additions & 2 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/api/Pies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class PiesFactory(
result.add(
when {
source.point != null ->
myFactory.createStaticEntity("map_ent_s_pie_sector", source.point!!)
myFactory.createStaticEntityWithLocation("map_ent_s_pie_sector", source.point!!)
source.mapId != null ->
myFactory.createDynamicEntity("map_ent_d_pie_sector_${source.mapId}", source.mapId!!)
myFactory.createDynamicEntityWithLocation("map_ent_d_pie_sector_${source.mapId}", source.mapId!!)
else ->
error("Can't create pieSector entity. [point] and [mapId] is null.")
}.setInitializer { worldPoint ->
Expand Down
4 changes: 2 additions & 2 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/api/Points.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class PointBuilder(

return when {
point != null ->
myFactory.createStaticEntity("map_ent_s_point", point!!)
myFactory.createStaticEntityWithLocation("map_ent_s_point", point!!)
mapId != null ->
myFactory.createDynamicEntity("map_ent_d_point_$mapId", mapId!!)
myFactory.createDynamicEntityWithLocation("map_ent_d_point_$mapId", mapId!!)
else ->
error("Can't create point entity. [point] and [mapId] is null.")
}.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import jetbrains.livemap.entities.Entities.MapEntityFactory
import jetbrains.livemap.entities.geocoding.MapIdComponent
import jetbrains.livemap.entities.geocoding.NeedCalculateLocationComponent
import jetbrains.livemap.entities.geocoding.NeedGeocodeLocationComponent
import jetbrains.livemap.entities.geocoding.NeedLocationComponent
import jetbrains.livemap.entities.geometry.WorldGeometryComponent
import jetbrains.livemap.entities.placement.ScreenLoopComponent
import jetbrains.livemap.entities.placement.ScreenOriginComponent
Expand Down Expand Up @@ -104,6 +105,7 @@ class PolygonsBuilder(
setStrokeColor([email protected])
setStrokeWidth([email protected])
}
+ NeedLocationComponent()
+ NeedCalculateLocationComponent()
}
}
Expand All @@ -122,6 +124,7 @@ class PolygonsBuilder(
setStrokeColor([email protected])
setStrokeWidth([email protected])
}
+ NeedLocationComponent()
+ NeedGeocodeLocationComponent()
}
}
Expand Down
4 changes: 2 additions & 2 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/api/Texts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class TextBuilder(

return when {
point != null ->
myFactory.createStaticEntity("map_ent_s_text", point!!)
myFactory.createStaticEntityWithLocation("map_ent_s_text", point!!)
mapId != null ->
myFactory.createDynamicEntity("map_ent_d_text_$mapId", mapId!!)
myFactory.createDynamicEntityWithLocation("map_ent_d_text_$mapId", mapId!!)
else ->
error("Can't create text entity. [point] and [mapId] is null.")
}
Expand Down
23 changes: 16 additions & 7 deletions livemap/src/commonMain/kotlin/jetbrains/livemap/api/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,30 @@ fun createLineBBox(
}
}

fun MapEntityFactory.createStaticEntity(name: String, point: LonLatPoint): EcsEntity {
fun MapEntityFactory.createStaticEntityWithLocation(name: String, point: LonLatPoint): EcsEntity =
createStaticEntity(name, point).addComponents {
+ NeedLocationComponent()
+ NeedCalculateLocationComponent()
}

fun MapEntityFactory.createDynamicEntityWithLocation(name: String, mapId: String): EcsEntity =
createDynamicEntity(name, mapId).addComponents {
+ NeedLocationComponent()
+ NeedGeocodeLocationComponent()
}

return createMapEntity(name)
fun MapEntityFactory.createStaticEntity(name: String, point: LonLatPoint): EcsEntity =
createMapEntity(name)
.add(LonLatComponent(point))
}

fun MapEntityFactory.createDynamicEntity(name: String, mapId: String): EcsEntity {

return createMapEntity(name)
fun MapEntityFactory.createDynamicEntity(name: String, mapId: String): EcsEntity =
createMapEntity(name)
.addComponents {
+ CentroidComponent()
+ MapIdComponent(mapId)
+ NeedGeocodeLocationComponent()
}
}


internal fun EcsEntity.setInitializer(block: ComponentsList.(worldPoint: WorldPoint) -> Unit): EcsEntity {
return add(PointInitializerComponent(block))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.math.max
import kotlin.math.min

open class Viewport internal constructor(
private val helper: ViewportMath,
private val helper: ViewportHelper<World>,
val size: ClientPoint
) {

Expand Down Expand Up @@ -60,6 +60,8 @@ open class Viewport internal constructor(
.map { getViewCoord(it) }
}

fun calculateBoundingBox(bBoxes: List<Rect<World>>) = helper.calculateBoundingBox(bBoxes)

private fun updateWindow() {
window = WorldRectangle(windowOrigin, windowSize)
}
Expand All @@ -81,7 +83,7 @@ open class Viewport internal constructor(
}

companion object {
fun create(helper: ViewportMath, size: ClientPoint, position: WorldPoint): Viewport {
fun create(helper: ViewportHelper<World>, size: ClientPoint, position: WorldPoint): Viewport {
return Viewport(helper, size).apply {
this.position = position
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ abstract class AbstractSystem<T : EcsContext> protected constructor(val componen
return componentManager.getEntities(componentTypes)
}

inline fun <reified T: EcsComponent> getMutableEntities(): List<EcsEntity> {
return componentManager.getEntities(T::class).toList()
}

fun getMutableEntities(componentTypes: List<KClass<out EcsComponent>>): List<EcsEntity> {
return componentManager.getEntities(componentTypes).toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class RegionIdComponent(var regionId: String) : EcsComponent

class CentroidComponent : EcsComponent

class NeedLocationComponent : EcsComponent
class NeedGeocodeLocationComponent : EcsComponent
class WaitGeocodeLocationComponent : EcsComponent

class NeedCalculateLocationComponent : EcsComponent

Expand All @@ -34,7 +36,7 @@ class LocationComponent: EcsComponent {
}

fun isReady(): Boolean {
return myWaitingCount == locations.size
return myWaitingCount > 0 && myWaitingCount == locations.size
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import jetbrains.livemap.LiveMapSystem
import jetbrains.livemap.core.ecs.EcsComponentManager
import jetbrains.livemap.entities.placement.WorldDimensionComponent
import jetbrains.livemap.entities.placement.WorldOriginComponent
import jetbrains.livemap.projections.Coordinates.ZERO_LONLAT_POINT

class LocationCalculateSystem(
componentManager: EcsComponentManager,
private val myNeedLocation: Boolean
componentManager: EcsComponentManager
) : LiveMapSystem(componentManager) {
private lateinit var myLocation: LocationComponent

Expand All @@ -24,29 +24,25 @@ class LocationCalculateSystem(
}

override fun updateImpl(context: LiveMapContext, dt: Double) {
val entities = getMutableEntities(NEED_CALCULATE)

if (entities.isEmpty()) return
getMutableEntities(READY_CALCULATE)
.forEach { entity ->
entity.remove<NeedCalculateLocationComponent>()

if (myNeedLocation) {
myLocation.wait(entities.size)

entities.forEach {
Rect(
context.mapProjection.invert(it.get<WorldOriginComponent>().origin),
context.mapProjection.invert(it.get<WorldDimensionComponent>().dimension)
context.mapProjection.invert(entity.get<WorldOriginComponent>().origin),
entity.tryGet<WorldDimensionComponent>()?.dimension?.run(context.mapProjection::invert) ?: ZERO_LONLAT_POINT
)
.run(::convertToGeoRectangle)
.run(myLocation::add)
}
} else {
entities.forEach {
it.remove<NeedCalculateLocationComponent>()
}
}
}

companion object {
val NEED_CALCULATE = listOf(NeedCalculateLocationComponent::class)

val READY_CALCULATE = listOf(
NeedCalculateLocationComponent::class,
WorldOriginComponent::class
)
}
}
Loading