inventhq / dot-globe

Dotted Globe for Swift!
MIT License
96 stars 11 forks source link

Question about dot-globe #5

Open ak3zaidan opened 11 months ago

ak3zaidan commented 11 months ago

Hello would you know how to add some sort of pin point marker to mark a location on the map, and then make the marker clickable? I want to create a snap maps clone where users can magnify the globe and see cities and display markers that can be clicked to show additional content. Is there a way to replace the earth node with a real globe instead of dots?

I also just wanted to say I love this repo

DominicHolmes commented 11 months ago

@ak3zaidan I'm not the contributor but I also found this repo a few hours ago. I need something similar for a small UI component.

I'm planning to try something similar in a fork - I need this library for a small UI component that reflects a user's choice of city. I need to animate rotational changes to the globe + add different colored dots at certain coordinates (for each location option) + add a pin for the selection. Sounds kind of similar to your use case, I'll let you know if it works out.

ak3zaidan commented 11 months ago

@DominicHolmes thanks I will also be working on this. My use case is basically what you want to achieve. Given a coordinate I want to add a dot or marker.

ak3zaidan commented 11 months ago

@DominicHolmes how did you add this repo to Xcode. When I try and fork it then add to Xcode it doesn't let me modify it. If I try to manually copy in the files the star background doesn't work (Xcode doesn't file asset even though I added it to my assets file)

grandsir commented 11 months ago

@ak3zaidan let me solve it for you

grandsir commented 11 months ago

For the first question, if you take out the dots from the globe the package loses its functionality. Main purpose of this library is to create somewhat "visual" representation of a data but not really "functional" one. Just like globe in stripe's & github's website. Github shows an arc between dots when a pr opens and stripe does it when a transaction happens.

If you want to create an interactive globe with this package, I've doubt this package will even be useful for you. but, I'm also working in a package called Interactive-Globe, which will be a combination of Dot-globe and my Interactive-Map repo.

Also, thanks for the positive feedback :)

ak3zaidan commented 11 months ago

@grandsir thanks for the input boss. I couldn't quite find a repo on your GitHub named Interactive-Globe. Im sorry if I misunderstood, Is this repo not intended to be public at the moment.

DominicHolmes commented 11 months ago

@ak3zaidan in general to edit packages, you can point your dependency at your fork, and then drag in the files to make it locally editable. See documentation here

Also, I misread the part about the dots, I agree that if you want a real map you'll want to find a different library

DominicHolmes commented 11 months ago

@grandsir I'm a bit stuck understanding your math in generateTextureMap(). In particular I think I'm misunderstanding these lines:

let xPixel = Int(u * floatWorldMapImageWidth)
let yPixel = Int(v * floatWorldMapImageHeight)

Since the image is 2048x1024, I would expect xPixel to be [0, 2048] and yPixel to be in [0,1024]. But xPixel is much higher than that -- is this a bug or am I misunderstanding these variables?

I've successfully re-implemented your dot placement code using other methods (golden spiral), but I like the look of the placement of the dots in your implementation better. Do you have any links to the math you're using / the name of the method?

grandsir commented 11 months ago

@grandsir thanks for the input boss. I couldn't quite find a repo on your GitHub named Interactive-Globe. Im sorry if I misunderstood, Is this repo not intended to be public at the moment.

@ak3zaidan it is not public yet. Due to school & company duties it'll be delayed a little bit. But i'll eventually release it at some point.

grandsir commented 11 months ago

I've successfully re-implemented your dot placement code using other methods (golden spiral), but I like the look of the placement of the dots in your implementation better. Do you have any links to the math you're using / the name of the method?

I use sunflower phyllotaxis for that.

grandsir commented 11 months ago

Since the image is 2048x1024, I would expect xPixel to be [0, 2048] and yPixel to be in [0,1024]. But xPixel is much higher than that -- is this a bug or am I misunderstanding these variables?

It's not a bug; rather, it's a somewhat unconventional approach I employed to display the dots on the screen. Because the coordinates are transformed into an SCNGeometrySource, the specific values of x and y become inconsequential, as they will ultimately be projected as different coordinates on the actual globe.

ak3zaidan commented 11 months ago

@grandsir anyway you could share it with me early and I could help with the project, Im pretty good with swift UI. I have my own app 'Hustles' that I want to integrate this sort of functionality into asap. Kind of my graduation capstone project, so Id appreciate it.

ak3zaidan commented 10 months ago

@DominicHolmes were you able to achieve or find such behavior?

DominicHolmes commented 10 months ago

Hey @ak3zaidan , I just pushed what I have to my fork. Keep in mind this code is super messy, unused commented-out code everywhere...

Here's a video

Not sure how much of this applies to your project. But what I did achieve, is figuring out how to relate CLLocationCoordinates to a point on the globe. I hardcoded the coordinates for New York, but basically there are some algorithms that:

My plan was to expose a list of coordinates as a SwiftUI binding, and let users focus on each point (basically as a beautiful thing to live alongside my location picker).

What I didn't solve, and was having a lot of trouble with, was getting the camera to smoothly animate and center on a coordinate. I thought this would be easy, but I think I was running into "gimbal lock", which I don't fully understand.

I've moved onto other stuff but hopefully this is useful

ak3zaidan commented 10 months ago

@DominicHolmes thanks, would you possibly know how to add the dot as a button instead? I tried doing so but couldn't figure out.

DominicHolmes commented 10 months ago

@ak3zaidan not sure, I am also a novice at SceneKit.

The dot is just an SKNode though, so you just need to google "detect taps on an SKNode" or something similar.

ak3zaidan commented 9 months ago

@DominicHolmes I figured out how to rotate the globe to the right dot position. Just thought Id let you know since you shared your code. The code for the fixed function is here: https://stackoverflow.com/questions/77569918/swift-prevent-scene-point-of-view-reset-prior-to-camera-action/77575019#77575019