Coder Social home page Coder Social logo

Comments (25)

p-lr avatar p-lr commented on July 23, 2024 1

I've tested png tiles yesterday, it works.
I can make MapView subclassable, no problem. Same for processHit, I can do that.
All of this will be available in 2.0.0

from mapview.

p-lr avatar p-lr commented on July 23, 2024 1

I'm polishing it before the release. All's left is the readme update. Should be done by this weekend.

from mapview.

p-lr avatar p-lr commented on July 23, 2024

Do you mean that you're not able to use 512x512 tiles?
Also, could you show me how you configure the MapView (I'd like to check).

from mapview.

danramteke avatar danramteke commented on July 23, 2024

Thanks for the quick reply! I am not able to use the 128x128 tiles, nor am I able to use the 512x512 tiles either. I thought maybe using smaller tiles would help fix the BitmapFactory warning.

Sure, here is the vips command I ran (mac)

vips dzsave /path/to/my/map.png path/to/android/assets/tiles --layout=google --tile-size=128 --suffix .png --vips-progress

here is the code from the onCreate method in my Activity.

        val mapView = MapView(this)
        mapView.setBackgroundColor(resources.getColor(R.color.colorMapBackground, theme))
        val config = MapViewConfiguration(levelCount = 7, fullWidth = 12876, fullHeight = 15624,
            tileSize = 128, tileStreamProvider = MyTileStreamProvider(WeakReference(this.assets))
        ).setStartScale(1f)
            .setMaxScale(2f)
            .setMagnifyingFactor(1)
        mapView.configure(config)

        mapView.scale = 1f

        findViewById<RelativeLayout>(R.id.map_container).addView(mapView)
        this.mapView = mapView

and here is the code for MyTileStreamProvider:

class MyTileStreamProvider(private val weakAssetManager: WeakReference<AssetManager>): TileStreamProvider {
    override fun getTileStream(row: Int, col: Int, zoomLvl: Int): InputStream? {
        return try {
            val filename = "tiles/${zoomLvl}/${row}/${col}.png"
            weakAssetManager.get()!!.open(filename)
        } catch (e: Exception) {
            e.printStackTrace()
            null
        }
    }
}

Finally, here is the xml for the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="MyApp.MyMainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/map_container"
        >

   <com.google.android.material.floatingactionbutton.FloatingActionButton .../>
   <com.google.android.material.floatingactionbutton.FloatingActionButton .../>

  </RelativeLayout>
</LinearLayout>

from mapview.

p-lr avatar p-lr commented on July 23, 2024

Alright, I'm going to check on that. For my information, have you tried the (default) 256 size?

from mapview.

p-lr avatar p-lr commented on July 23, 2024

I've found the issue. The tileSize property wasn't taken into account properly.
It's fixed in the version 1.0.8
Can you try it out and tell me if it's working for you?

A new major version of MapView is coming out soon. I'm going to integrate this fix into the next version.

from mapview.

danramteke avatar danramteke commented on July 23, 2024

awesome! I'll try it out tonight

from mapview.

danramteke avatar danramteke commented on July 23, 2024

Hmm - I haven't been able to get it to work.

I created a small demo project, with just the map and this MapView component in it. I added you as a collaborator.

from mapview.

danramteke avatar danramteke commented on July 23, 2024

Update - I switch from .png to using .jpg in vips, and now the MapView component works!

from mapview.

p-lr avatar p-lr commented on July 23, 2024

Nice! When MapView 2.0.0 will be ready I will do a PR in your repo if you want.
Thanks for submitting this issue - it looks like you're the first one to try a different time size than 256.

from mapview.

danramteke avatar danramteke commented on July 23, 2024

is there any chance of supporting PNG?

And any plans for extensibility? Currently, MapView isn't subclassable; and although MarkerLayout is subclassable, its method processHit isn't overridable. I want something that sends "processHit" to a callback with the current x, y, and zoom.

from mapview.

danramteke avatar danramteke commented on July 23, 2024

Thanks so much! Your library runs smoother than the library I'm migrating from. Looking forward to 2.0.0!

from mapview.

p-lr avatar p-lr commented on July 23, 2024

I've published the version 2.0.0-beta03

The API around map rotation isn't stable yet (It's working, but I might make changes).
2.x.x is a major shift from 1.x.x as it enables map rotation. It's only an opt-in feature, while configuring the MapView, using enableRotation(). The RotatingMapFragment from the demo is an example. But I don't recommend that you use this for now.

Beware that there are some breaking changes. Most of the time, it's just a package name change.
The ScaleChangeListener interface has been removed. If you relied on this, I can explain how to do the equivalent in 2.x.x

from mapview.

p-lr avatar p-lr commented on July 23, 2024

BTW, I'm closing this. Any feedback about the 2.0.0-beta will be appreciated (you can open other issues).

from mapview.

danramteke avatar danramteke commented on July 23, 2024

One bit of feedback: When the app loads, the map is blank until I scroll. This wasn't the case in 1.0.8. I can't quite figure out if there is some way to make the map display without the user needing to scroll? Here is an example: https://github.com/danramteke/PLMapViewStudy/tree/upgrade-2.0.0

Other than that, this is wonderful! I'm able to get the tap information I need now that MapView is subclassable

from mapview.

danramteke avatar danramteke commented on July 23, 2024

hmm I seem to have somehow gotten around the map loading as blank. I run a timer to poll if the map view has finished rendering, by comparing its height and width to 0

        val config = MapViewConfiguration(...).setStartScale(0.5f)
        mapView.configure(config)
        Timer().schedule(object : TimerTask() {
            override fun run() {
                if (mapView.width != 0 && mapView.height != 0) {
                    mapView.scrollToDefaultLocation()
                    this.cancel()
                }
            }
        }, 1, 5)

Thanks so much for this update!

from mapview.

p-lr avatar p-lr commented on July 23, 2024

Ok good to know. Thanks for the feedback.

from mapview.

p-lr avatar p-lr commented on July 23, 2024

from mapview.

p-lr avatar p-lr commented on July 23, 2024

@danramteke
I've been able to reproduce your issue with blank MapView in the beta. It was caused by the config setStartScale(1f). Any other scale would have worked.
It's fixed now, and I've published the version 2.0.0-beta04
Does this eliminates your need of callback?

BTW, I've created a "MapView 2.0.0 project" here: https://github.com/peterLaurence/MapView/projects/1
Do you have access to it?

Thanks again for your valuable feedback!

from mapview.

danramteke avatar danramteke commented on July 23, 2024

Hello, I updated to beta05, but I still need the timer to wait for the MapView to not have 0 width/height so that I can scroll to the default location in the viewport.

No worries though, the users I've talked to like the new MapView.

Yes, I have access to that project link.

from mapview.

p-lr avatar p-lr commented on July 23, 2024

from mapview.

p-lr avatar p-lr commented on July 23, 2024

It looks like your project has been removed. If I understood correctly, you need to scroll to a specific position as soon as the MapView is ready.
If I had to do this, I would do it inside onStart() lifecycle of the fragment. But I can't be sure - ideally I should try your code.

from mapview.

p-lr avatar p-lr commented on July 23, 2024

I cannot reproduce your issue. If you look at MapAloneFragment
.. and if you do this:

...
return MapView(context).apply {
     configure(config)
     scale = 0.5f
     scrollTo(3000, 3000)
}

It works as expected. I would recommend to follow the demo snippet as much as possible (adding the MapView inside onCreateView, assign an id, etc.).

from mapview.

danramteke avatar danramteke commented on July 23, 2024

No worries, the people using my app are happy with how it's working. Thanks so much for your help!

Centering on default location

Yes it scrolls to the coordinates. The difference is that it scrolls to the top left corner instead of the center. A timer fixes this.

val mapView = MapView(context).apply {
     configure(config)
     scale = 0.5f
    scrollTo(3000 - width/2.0, 3000 - height/2.0)
}

vs

val mapView = MapView(context).apply {
     configure(config)
     scale = 0.5f
}

// ...

Timer().schedule(object : TimerTask() {
  override fun run() {
    if (mapView.width != 0 && mapView.height != 0) {
      this.cancel()
      scrollTo(3000 - mapView.width/2.0, 3000 - mapView.height/2.0)
    }
  }
}, 1, 5)

Using onStart Callback

Also, I looked into onStart and that won't work for me since onStart is called every time the app comes back from the background.

Sample project

Hmm - not sure why it's missing. There's a lot of things I need to take care of today. If I have time, I'll look into why it's missing.

from mapview.

p-lr avatar p-lr commented on July 23, 2024

Thank you for this detailed answer. Now I understand the confusion. I've pushed a new branch [bounds](https://github.com/danramteke/PLMapViewStudy/tree/bounds)

It shows you how to scroll to a percent of the map's width and height, not using a timer and right after the configuration.

from mapview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.