kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Moved Custom Map classes to new folder.
Removed NOAA source from Map Source Arrays Looking at drawing overlay on long presspull/489/head
rodzic
7d386583ff
commit
38b6fe04ef
|
@ -0,0 +1,42 @@
|
|||
package com.geeksville.mesh.model.map
|
||||
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import org.osmdroid.api.IMapView
|
||||
import org.osmdroid.config.Configuration
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.MapView
|
||||
import org.osmdroid.views.overlay.Overlay
|
||||
import org.osmdroid.views.overlay.Polygon
|
||||
|
||||
|
||||
class CirclePlottingOverlay(var distanceKm: Int) : Overlay() {
|
||||
override fun onLongPress(e: MotionEvent, mapView: MapView): Boolean {
|
||||
if (Configuration.getInstance().isDebugMapView) {
|
||||
Log.d(IMapView.LOGTAG, "CirclePlottingOverlay onLongPress")
|
||||
}
|
||||
val pt = mapView.projection.fromPixels(e.x.toInt(), e.y.toInt(), null) as GeoPoint
|
||||
/*
|
||||
* <b>Note</b></b: when plotting a point off the map, the conversion from
|
||||
* screen coordinates to map coordinates will return values that are invalid from a latitude,longitude
|
||||
* perspective. Sometimes this is a wanted behavior and sometimes it isn't. We are leaving it up to you,
|
||||
* the developer using osmdroid to decide on what is right for your application. See
|
||||
* <a href="https://github.com/osmdroid/osmdroid/pull/722">https://github.com/osmdroid/osmdroid/pull/722</a>
|
||||
* for more information and the discussion associated with this.
|
||||
*/
|
||||
|
||||
//just in case the point is off the map, let's fix the coordinates
|
||||
if (pt.longitude < -180) pt.longitude = pt.longitude + 360
|
||||
if (pt.longitude > 180) pt.longitude = pt.longitude - 360
|
||||
//latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
|
||||
if (pt.latitude > 85.05112877980659) pt.latitude = 85.05112877980659
|
||||
if (pt.latitude < -85.05112877980659) pt.latitude = -85.05112877980659
|
||||
val circle: List<GeoPoint> = Polygon.pointsAsCircle(pt, distanceKm.toDouble())
|
||||
val p = Polygon(mapView)
|
||||
p.points = circle
|
||||
p.title = "A circle"
|
||||
mapView.overlayManager.add(p)
|
||||
mapView.invalidate()
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package com.geeksville.mesh.model
|
||||
package com.geeksville.mesh.model.map
|
||||
|
||||
import org.osmdroid.tileprovider.tilesource.ITileSource
|
||||
import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase
|
||||
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
|
||||
import org.osmdroid.tileprovider.tilesource.TileSourcePolicy
|
||||
import org.osmdroid.util.MapTileIndex
|
||||
import org.osmdroid.wms.WMSTileSource
|
||||
|
||||
|
||||
class CustomTileSource {
|
||||
|
@ -153,7 +152,6 @@ class CustomTileSource {
|
|||
USGS_TOPO,
|
||||
USGS_SAT,
|
||||
ESRI_IMAGERY,
|
||||
NOAA_RADAR
|
||||
)
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.geeksville.mesh.model
|
||||
package com.geeksville.mesh.model.map
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.util.Log
|
|
@ -22,8 +22,9 @@ import com.geeksville.mesh.R
|
|||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.database.entity.Packet
|
||||
import com.geeksville.mesh.databinding.MapViewBinding
|
||||
import com.geeksville.mesh.model.CustomTileSource
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.model.map.CirclePlottingOverlay
|
||||
import com.geeksville.mesh.model.map.CustomTileSource
|
||||
import com.geeksville.mesh.util.formatAgo
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
|
@ -51,7 +52,7 @@ import kotlin.math.pow
|
|||
|
||||
@AndroidEntryPoint
|
||||
class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeekBarChangeListener,
|
||||
TextWatcher {
|
||||
TextWatcher, View.OnLongClickListener {
|
||||
|
||||
private lateinit var binding: MapViewBinding
|
||||
private lateinit var map: MapView
|
||||
|
@ -127,6 +128,9 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
drawOverlays()
|
||||
}
|
||||
zoomToNodes(mapController)
|
||||
map.setOnLongClickListener(this)
|
||||
val plotter = CirclePlottingOverlay(100)
|
||||
map.overlayManager.add(plotter)
|
||||
}
|
||||
downloadBtn.setOnClickListener(this)
|
||||
}
|
||||
|
@ -499,20 +503,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
defaultMinZoom // sets the minimum zoom level (the furthest out you can zoom)
|
||||
map.setMultiTouchControls(true) // Sets gesture controls to true.
|
||||
map.zoomController.setVisibility(CustomZoomButtonsController.Visibility.NEVER) // Disables default +/- button for zooming
|
||||
map.addMapListener(onMapLongPress())
|
||||
}
|
||||
}
|
||||
|
||||
private fun onMapLongPress(): MapListener {
|
||||
return object : MapListener {
|
||||
override fun onScroll(event: ScrollEvent?): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onZoom(event: ZoomEvent?): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -568,6 +558,30 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
super.onDestroyView()
|
||||
map.onDetach()
|
||||
}
|
||||
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
|
||||
updateEstimate(false)
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
updateEstimate(false)
|
||||
}
|
||||
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
}
|
||||
|
||||
override fun onLongClick(p0: View?): Boolean {
|
||||
Log.d("MapFragment", "Long pressed map")
|
||||
return true
|
||||
}
|
||||
|
||||
private inner class MarkerWithLabel(mapView: MapView?, label: String) : Marker(mapView) {
|
||||
val mLabel = label
|
||||
|
@ -607,26 +621,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
|||
c.drawText(mLabel, (p.x - 0f), (p.y - 110f), textPaint)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
|
||||
updateEstimate(false)
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
updateEstimate(false)
|
||||
}
|
||||
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,6 +91,5 @@
|
|||
<item>USGS TOPO</item>
|
||||
<item>USGS Satellite</item>
|
||||
<item>ESRI World Overview</item>
|
||||
<item>NOAA GOES Radar</item>
|
||||
</string-array>
|
||||
</resources>
|
Ładowanie…
Reference in New Issue