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
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import ch.wsl.box.client.services.BrowserConsole
import ch.wsl.box.model.shared.GeoJson.Coordinates
import ch.wsl.box.model.shared.geo.{Box2d, MapProjection}
import scribe.Logging
import ch.wsl.typings.ol.anon.FnCall
import ch.wsl.typings.ol.extentMod.Extent
import ch.wsl.typings.ol.geomMod.Geometry
import ch.wsl.typings.ol.{extentMod, layerBaseTileMod, layerMod, projMod, projProj4Mod, projProjectionMod, sourceMod}
import ch.wsl.typings.ol.{anon, extentMod, layerBaseTileMod, layerMod, projMod, projProj4Mod, projProjectionMod, sourceMod}

import scala.scalajs.js

Expand All @@ -32,14 +31,14 @@ class BoxMapProjections(_projections:Seq[MapProjection],_defaultProjection:Strin
}


projProj4Mod.register(proj4.asInstanceOf[FnCall])
projProj4Mod.register(proj4.asInstanceOf[js.Any with anon.DefaultDatum ])

def convert(from:String,to:String):(Coordinates => Coordinates) = {
val f = projMod.getTransform(projections(from),projections(to))

{ c:Coordinates =>
val coords = js.Array(c.x, c.y)
val out:js.Array[Double] = f(coords,js.undefined,js.undefined)
val out:js.Array[Double] = f(coords,js.undefined,js.undefined,js.undefined)
Coordinates(out(0),out(1))
}
}
Expand Down Expand Up @@ -107,5 +106,5 @@ object BoxMapConstants {
// unit = "m"
)

val openStreetMapLayer = new layerMod.Tile(layerBaseTileMod.Options().setSource(new sourceMod.OSM()))
val openStreetMapLayer = new layerMod.Tile[sourceMod.OSM](layerBaseTileMod.Options[sourceMod.OSM]().setSource(new sourceMod.OSM()))
}
3 changes: 2 additions & 1 deletion client/src/main/scala/ch/wsl/box/client/geo/BoxOlMap.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.wsl.box.client.geo

import ch.wsl.box.client.Context.services
import ch.wsl.box.client.geo.OlTypes.BoxBaseLayer
import ch.wsl.box.client.services.BrowserConsole
import io.circe.Json
import io.udash.{Property, ReadableProperty}
Expand Down Expand Up @@ -32,7 +33,7 @@ trait BoxOlMap {
def loadBase(l: Option[MapParamsLayers])(implicit ex:ExecutionContext): Future[Boolean] = {
l match {
case None => {
mapActions.setBaseLayer(BoxMapConstants.openStreetMapLayer)
mapActions.setBaseLayer(BoxMapConstants.openStreetMapLayer.asInstanceOf[BoxBaseLayer])
Future.successful(true)
}
case Some(layer) => MapUtils.loadWmtsLayer(
Expand Down
18 changes: 10 additions & 8 deletions client/src/main/scala/ch/wsl/box/client/geo/MapActions.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.wsl.box.client.geo


import ch.wsl.box.client.geo.OlTypes.{BoxBaseLayer, BoxFeatureType, BoxVectorSourceType}
import ch.wsl.box.client.services.BrowserConsole
import ch.wsl.box.client.utils.Debounce
import ch.wsl.box.model.shared.GeoJson.{CRS, Coordinates, Polygon}
Expand All @@ -12,7 +13,8 @@ import io.circe.syntax.EncoderOps
import scalatags.JsDom.all.s
import scribe.Logging
import ch.wsl.typings.ol.mapBrowserEventMod.MapBrowserEvent
import ch.wsl.typings.ol.{featureMod, formatGeoJSONMod, geomGeometryMod, layerBaseMod, layerBaseVectorMod, layerMod, mapBrowserEventMod, mod, olStrings, sourceMod, sourceVectorMod}
import ch.wsl.typings.ol.{featureMod, formatGeoJSONMod, geomGeometryMod, layerBaseMod, layerBaseVectorMod, layerMod, layerVectorMod, mapBrowserEventMod, mod, olStrings, sourceMod, sourceVectorMod}
import org.scalablytyped.runtime.StringDictionary

import scala.collection.mutable
import scala.concurrent.{ExecutionContext, Promise}
Expand All @@ -25,7 +27,7 @@ class MapActions(map: => Option[mod.Map],crs:CRS) extends Logging {

import ch.wsl.box.client.Context._

def setBaseLayer(baseLayer: layerBaseMod.default) = {
def setBaseLayer(baseLayer: BoxBaseLayer) = {
val promise = Promise[Boolean]()
logger.info(s"Set base layer $baseLayer with $map")
BrowserConsole.log(baseLayer)
Expand Down Expand Up @@ -69,13 +71,13 @@ class MapActions(map: => Option[mod.Map],crs:CRS) extends Logging {
})
}

private val lookupLayers = mutable.Map[String,(sourceMod.Vector[geomGeometryMod.default],layerMod.Vector[_])]()
private val lookupLayers = mutable.Map[String,(BoxVectorSourceType,layerMod.Vector[BoxVectorSourceType,BoxFeatureType])]()
private def createAndGetSource(layer:MapLookup) = {
lookupLayers.get(layer.id) match {
case Some(value) => value
case None => {
val vectorSource = new sourceMod.Vector[geomGeometryMod.default](sourceVectorMod.Options())
val featuresLayer = new layerMod.Vector(layerBaseVectorMod.Options()
val vectorSource = new sourceMod.Vector[BoxFeatureType](sourceVectorMod.Options())
val featuresLayer = new layerMod.Vector[BoxVectorSourceType,BoxFeatureType](layerVectorMod.Options[BoxVectorSourceType,BoxFeatureType]()
.setSource(vectorSource)
.setStyle(MapStyle.vectorStyle(layer.color))
)
Expand All @@ -89,18 +91,18 @@ class MapActions(map: => Option[mod.Map],crs:CRS) extends Logging {

val (vectorSource,featuresLayer) = createAndGetSource(layer)

map.get.removeLayer(featuresLayer)
map.get.removeLayer(featuresLayer.asInstanceOf[BoxBaseLayer])
vectorSource.getFeatures().foreach(f => vectorSource.removeFeature(f))

val query = layer.query.getOrElse(JSONQuery.empty).limit(10000).withData(data,services.clientSession.lang()).withExtent(layer.column,calculateExtent(crs))

services.rest.geoData(layer.kind, services.clientSession.lang(), layer.entity, layer.column, GeoDataRequest(query,Seq()),false).foreach { geoms =>
val features = geoms.map(MapUtils.boxFeatureToOlFeature)

vectorSource.addFeatures(features.toJSArray.asInstanceOf[js.Array[ch.wsl.typings.ol.renderFeatureMod.default]])
vectorSource.addFeatures(features.toJSArray)


map.get.getLayers().insertAt(1, featuresLayer)
map.get.getLayers().insertAt(1, featuresLayer.asInstanceOf[BoxBaseLayer])

map.get.render()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.udash.bootstrap.utils.BootstrapStyles
import io.udash._
import org.scalajs.dom.{Event, Node}
import scalatags.JsDom.all._
import ch.wsl.typings.ol.renderFeatureMod
import ch.wsl.typings.ol.{extentMod, renderFeatureMod}
import ch.wsl.typings.ol.viewMod.FitOptions

import scala.concurrent.ExecutionContext
Expand Down Expand Up @@ -67,7 +67,7 @@ class MapControlStandaloneDropdown(params:MapControlsParams, layerSelector:Modif
button(ClientConf.style.mapButton)(
if(geometry.isEmpty) disabled := true else Seq[Modifier](),
onclick :+= { (e: Event) =>
sourceMap(_.getExtent()).foreach(e => map.getView().fit(e, FitOptions().setPaddingVarargs(10, 10, 10, 10).setMinResolution(0.5)))
sourceMap(_.getExtent().asInstanceOf[extentMod.Extent]).foreach(e => map.getView().fit(e, FitOptions().setPaddingVarargs(10, 10, 10, 10).setMinResolution(0.5)))
e.preventDefault()
}
)(Icons.search).render,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.wsl.box.client.geo


import ch.wsl.box.client.geo.OlTypes.BoxFeatureType
import ch.wsl.box.client.services.{ClientConf, Labels}
import ch.wsl.box.client.styles.{BootstrapCol, Icons}
import ch.wsl.box.client.views.components.widget.WidgetUtils
Expand All @@ -11,7 +12,7 @@ import io.udash.bootstrap.utils.BootstrapStyles
import io.udash._
import org.scalajs.dom.{Event, Node}
import scalatags.JsDom.all._
import ch.wsl.typings.ol.{featureMod, geomGeometryMod, geomMod, renderFeatureMod}
import ch.wsl.typings.ol.{extentMod, featureMod, geomGeometryMod, geomMod, renderFeatureMod}
import ch.wsl.typings.ol.viewMod.FitOptions
import io.udash.bootstrap.tooltip.Tooltip
import org.scalajs.dom
Expand Down Expand Up @@ -44,7 +45,7 @@ class MapControlStandaloneExpanded(params:MapControlsParams, title:String, selec

x.combine(y){ case (x,y) => MapUtils.parseCoordinates(params.projections,s"$x, $y")}.listen {
case Some(point) => {
val feature = new featureMod.default[geomGeometryMod.default](new geomMod.Point(point)).asInstanceOf[ch.wsl.typings.ol.renderFeatureMod.default]
val feature = new BoxFeatureType(new geomMod.Point(point))
sourceMap(_.clear())
sourceMap(_.addFeature(feature))
}
Expand Down Expand Up @@ -118,7 +119,7 @@ class MapControlStandaloneExpanded(params:MapControlsParams, title:String, selec
button(ClientConf.style.mapButton)(
if(geometry.isEmpty) disabled := true else Seq[Modifier](),
onclick :+= { (e: Event) =>
sourceMap(_.getExtent()).foreach(e => map.getView().fit(e, FitOptions().setPaddingVarargs(10, 10, 10, 10).setMinResolution(0.5)))
sourceMap(_.getExtent().asInstanceOf[extentMod.Extent]).foreach(e => map.getView().fit(e, FitOptions().setPaddingVarargs(10, 10, 10, 10).setMinResolution(0.5)))
e.preventDefault()
}
)(Icons.search).render,
Expand Down
49 changes: 28 additions & 21 deletions client/src/main/scala/ch/wsl/box/client/geo/MapControls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import scalatags.JsDom.all._
import scribe.Logging
import ch.wsl.typings.ol.interactionSelectMod.SelectEvent
import ch.wsl.typings.ol.mod.{MapBrowserEvent, Overlay}
import ch.wsl.typings.ol.{eventsEventMod, featureMod, formatGeoJSONMod, geomGeometryMod, geomMod, interactionDrawMod, interactionModifyMod, interactionSelectMod, interactionSnapMod, interactionTranslateMod, layerMod, mod, objectMod, olStrings, overlayMod, projMod, renderFeatureMod, sourceMod, sourceVectorEventTypeMod}
import ch.wsl.typings.ol.{eventsEventMod, featureMod, formatGeoJSONMod, geomGeometryMod, geomMod, interactionDrawMod, interactionModifyMod, interactionSelectMod, interactionSnapMod, interactionTranslateMod, layerMod, mod, objectMod, olStrings, overlayMod, projMod, renderFeatureMod, sourceMod, sourceVectorEventTypeMod, sourceVectorMod}

import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}
import scala.scalajs.js
import scala.scalajs.js.{URIUtils, |}
import scala.util.Try
import OlTypes._
import org.scalablytyped.runtime.StringDictionary


object Control {
Expand All @@ -60,7 +62,7 @@ object Control {

case class BoxLayer(
uuid:UUID,
olLayer: layerMod.Vector[_],
olLayer: layerMod.Vector[BoxVectorSourceType,BoxFeatureType],
features:MapParamsFeatures
)

Expand All @@ -78,13 +80,13 @@ case class MapControlsParams(
) {


def layerSource: ReadableProperty[Option[layerMod.Vector[_]]] = layer.transform(_.map(_.olLayer))
def vectorSource: ReadableProperty[Option[sourceMod.Vector[geomGeometryMod.default]]] = layerSource.transform(_.map(toVectorSource))
def sourceMap[T](f:sourceMod.Vector[geomGeometryMod.default] => T):Option[T] = vectorSource.get.map(f)
def layerSource: ReadableProperty[Option[layerMod.Vector[BoxVectorSourceType,BoxFeatureType]]] = layer.transform(_.map(_.olLayer))
def vectorSource: ReadableProperty[Option[BoxVectorSourceType]] = layerSource.transform(_.map(toVectorSource))
def sourceMap[T](f:BoxVectorSourceType => T):Option[T] = vectorSource.get.map(f)
}

object MapControlsParams{
def toVectorSource(l:layerMod.Vector[_]) = l.getSource().asInstanceOf[sourceMod.Vector[geomGeometryMod.default]]
def toVectorSource(l:layerMod.Vector[BoxVectorSourceType,BoxFeatureType]) = l.getSource().asInstanceOf[BoxVectorSourceType]
}


Expand All @@ -110,7 +112,7 @@ abstract class MapControls(params:MapControlsParams)(implicit ec:ExecutionContex
protected val insertCoordinateField = Property("")
protected val insertCoordinateHandler = ((e: Event) => {
MapUtils.parseCoordinates(projections,insertCoordinateField.get).foreach { p =>
val feature = new featureMod.default[geomGeometryMod.default](new geomMod.Point(p)).asInstanceOf[ch.wsl.typings.ol.renderFeatureMod.default]
val feature = new BoxFeatureType(new geomMod.Point(p))
sourceMap(_.addFeature(feature))
}
e.preventDefault()
Expand Down Expand Up @@ -167,7 +169,7 @@ abstract class MapControls(params:MapControlsParams)(implicit ec:ExecutionContex
}

toInsert.foreach { f =>
val geom = new formatGeoJSONMod.default().readFeature(convertJsonToJs(f.asJson).asInstanceOf[js.Object]).asInstanceOf[ch.wsl.typings.ol.renderFeatureMod.default]
val geom = new formatGeoJSONMod.default().readFeature(convertJsonToJs(f.asJson).asInstanceOf[js.Object]).asInstanceOf[BoxFeatureType]
sourceMap(_.addFeature(geom))
}

Expand All @@ -178,26 +180,30 @@ abstract class MapControls(params:MapControlsParams)(implicit ec:ExecutionContex

}

def findFeature(g: Geometry): Option[featureMod.default[geomGeometryMod.default]] = {
def findFeature(g: Geometry): Option[BoxFeatureType] = {
if (vectorSource != null) {
val geoJson = new formatGeoJSONMod.default().writeFeaturesObject(sourceMap(_.getFeatures()).getOrElse(js.Array()))

val fut: js.Array[BoxFeatureType] = sourceMap(_.getFeatures()).getOrElse(js.Array())


val geoJson = new formatGeoJSONMod.default().writeFeaturesObject(fut.map(_.asInstanceOf[renderFeatureMod.default]))
convertJsToJson(geoJson.asInstanceOf[js.Any]).flatMap(FeatureCollection.decode).toOption.flatMap { collection =>

val geometries = collection.features.map(_.geometry)
logger.info(s"$geometries")
geometries.find(_.toSingle.contains(g)).flatMap { contanierFeature =>

sourceMap(_.getFeatures().toSeq).toList.flatten.find { f =>
val coords = Try(f.getFlatCoordinates()).toOption
val coords = MapUtils.getCoordinates(f)
coords.exists(c => contanierFeature.equalsToFlattenCoords(c.toSeq))
}
}.map(f => renderFeatureMod.toFeature(f))
}
}
} else None
}


private var selected: Option[featureMod.default[geomGeometryMod.default]] = None
private var selected: Option[BoxFeatureType] = None

def highlight(g: Geometry): Unit = {
selected.foreach(_.setStyle(MapStyle.vectorStyle()))
Expand Down Expand Up @@ -364,7 +370,7 @@ abstract class MapControls(params:MapControlsParams)(implicit ec:ExecutionContex
drawHole
)

private var oldVectorSource:Option[sourceMod.Vector[geomGeometryMod.default]] = None
private var oldVectorSource:Option[BoxVectorSourceType] = None

val changedFeatures: js.Function1[eventsEventMod.BaseEvent,Unit] = (e) => {

Expand Down Expand Up @@ -452,24 +458,25 @@ abstract class MapControls(params:MapControlsParams)(implicit ec:ExecutionContex
)
//drawPolygon.on_change(olStrings.change,e => changedFeatures())

snap = new interactionSnapMod.default(interactionSnapMod.Options().setSource(vs))
snap = new interactionSnapMod.default(interactionSnapMod.Options().setSource(vs.asInstanceOf[sourceVectorMod.default[renderFeatureMod.default]]))

def lsFixTypes = ls.olLayer.asInstanceOf[


val layers = js.Array(ls.olLayer).asInstanceOf[js.Array[
ch.wsl.typings.ol.layerLayerMod.default[
ch.wsl.typings.ol.sourceSourceMod.default,
ch.wsl.typings.ol.layerLayerMod.default[Any, /* ol.ol/layer/Layer.default<any> */ Any]
ch.wsl.typings.ol.layerLayerMod.default[Any, /* ol.ol/layer/Layer.default<any> */ Any, StringDictionary[Any]],
StringDictionary[Any]
]
]

val layers = js.Array(lsFixTypes)
]]

drag = new interactionTranslateMod.default(interactionTranslateMod.Options().setLayers(layers))

delete = new interactionSelectMod.default(interactionSelectMod.Options().setLayers(layers))

delete.asInstanceOf[js.Dynamic].on(olStrings.select, (e: objectMod.ObjectEvent | SelectEvent | eventsEventMod.default) => {
if (window.confirm(Labels.form.removeMap)) {
e.asInstanceOf[SelectEvent].selected.foreach(x => sourceMap(_.removeFeature(x)))
e.asInstanceOf[SelectEvent].selected.foreach(x => sourceMap(_.removeFeature(x.asInstanceOf[BoxFeatureType])))
changedFeatures(e.asInstanceOf[eventsEventMod.BaseEvent])
} else {
delete.getFeatures().clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.udash.bootstrap.utils.BootstrapStyles
import io.udash._
import org.scalajs.dom.{Event, Node}
import scalatags.JsDom.all._
import ch.wsl.typings.ol.renderFeatureMod
import ch.wsl.typings.ol.{extentMod, renderFeatureMod}
import ch.wsl.typings.ol.viewMod.FitOptions
import org.scalajs.dom
import org.scalajs.dom.html.Input
Expand Down Expand Up @@ -71,7 +71,7 @@ class MapControlsIcons(params:MapControlsParams)(implicit ec:ExecutionContext) e
if (geometry.nonEmpty) controlButton(Icons.trash, SharedLabels.map.delete, Control.DELETE,nested) else frag(),
if (geometry.nonEmpty) button(ClientConf.style.mapButton)(
onclick :+= { (e: Event) =>
sourceMap(_.getExtent()).foreach(e => map.getView().fit(e, FitOptions().setPaddingVarargs(10, 10, 10, 10).setMinResolution(0.5)))
sourceMap(_.getExtent().asInstanceOf[extentMod.Extent]).foreach(e => map.getView().fit(e, FitOptions().setPaddingVarargs(10, 10, 10, 10).setMinResolution(0.5)))
e.preventDefault()
}
)(Icons.search).render else frag(),
Expand Down
19 changes: 10 additions & 9 deletions client/src/main/scala/ch/wsl/box/client/geo/MapGeolocation.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ch.wsl.box.client.geo

import ch.wsl.box.client.geo.OlTypes.{BoxBaseLayer, BoxFeatureType, BoxProperyType, BoxVectorSourceType}
import ch.wsl.box.client.styles.Icons
import ch.wsl.typings.ol
import ch.wsl.typings.ol.geomMod.Point
import ch.wsl.typings.ol.{controlControlMod, controlMod, geolocationMod, geomGeometryMod, geomMod, imageMod, layerBaseVectorMod, layerMod, mod, renderFeatureMod, sourceMod, sourceVectorMod, styleMod}
import ch.wsl.typings.ol.{controlControlMod, controlMod, geolocationMod, geomGeometryMod, geomMod, imageMod, layerBaseVectorMod, layerMod, layerVectorMod, mod, renderFeatureMod, sourceMod, sourceVectorMod, styleMod}
import org.scalajs.dom.{Event, HTMLInputElement, PositionOptions}
import scalatags.JsDom.all.{`class`, `type`, div, input, onchange, style}

Expand All @@ -18,13 +19,13 @@ class MapGeolocation(map:mod.Map) {
.setProjection(map.getView().getProjection())
)

val accuracyFeature = new mod.Feature[geomMod.Geometry]()
val positionFeature = new mod.Feature[Point]()
val accuracyFeature = new BoxFeatureType()
val positionFeature = new BoxFeatureType()

val gpsVectorSource = new sourceMod.Vector[geomGeometryMod.default](sourceVectorMod.Options())
gpsVectorSource.addFeature(accuracyFeature.asInstanceOf[renderFeatureMod.default])
gpsVectorSource.addFeature(positionFeature.asInstanceOf[renderFeatureMod.default])
val gpsFeaturesLayer = new layerMod.Vector(layerBaseVectorMod.Options()
val gpsVectorSource = new BoxVectorSourceType(sourceVectorMod.Options[BoxFeatureType]())
gpsVectorSource.addFeature(accuracyFeature)
gpsVectorSource.addFeature(positionFeature)
val gpsFeaturesLayer = new layerMod.Vector[BoxVectorSourceType,BoxFeatureType](layerVectorMod.Options[BoxVectorSourceType,BoxFeatureType]()
.setSource(gpsVectorSource)
)

Expand Down Expand Up @@ -56,10 +57,10 @@ class MapGeolocation(map:mod.Map) {
onchange :+= {(e:Event) =>
if(e.target.asInstanceOf[HTMLInputElement].checked) {
geolocation.setTracking(true)
map.addLayer(gpsFeaturesLayer)
map.addLayer(gpsFeaturesLayer.asInstanceOf[BoxBaseLayer])
} else {
geolocation.setTracking(false)
map.removeLayer(gpsFeaturesLayer)
map.removeLayer(gpsFeaturesLayer.asInstanceOf[BoxBaseLayer])
}


Expand Down
2 changes: 1 addition & 1 deletion client/src/main/scala/ch/wsl/box/client/geo/MapStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object MapStyle {
)
}

def vectorStyle(color:String = "rgb(237, 28, 36)"): js.Array[ch.wsl.typings.ol.styleStyleMod.Style] = js.Array(
def vectorStyle(color:String = "rgb(237, 28, 36)"):js.Array[ch.wsl.typings.ol.styleStyleMod.Style] = js.Array(
simpleStyle(color),
new styleMod.Style(styleStyleMod.Options()
.setImage(
Expand Down
Loading
Loading