1 (edited by jnicol 2022-08-24 01:54:07)

Topic: OnClick events to change Parameters etc

Hi Guys,
I am creating my first app using the excellent Online Maps asset and I have a very noob question.  I have a simple 3D map within an AR environment and I want to use a couple of buttons in the Unity interface to learn the environment which will change the following attributes:

1. Toggle traffic on or off;
2. Change the map style from satelite to street map.

For these I am using the "CreateCustomStylesExample"script.

This script is to specifically change the map style.  I have copied and pasted my MapBox access token and also put in the zoom level and x, y (hopefully maps to lat and long coordinates but it doesn't look right to me so that might be one error). Also in the code below I had to take out the full url to post here so I know that (link) is incorrect.

 public string style1 = "(link)://a.tiles.mapbox.com/v4/mapbox.satellite/14/21.3069/-157.8583.png?access_token=obscured";
        public string style2 = "https://a.tiles.mapbox.com/v4/mapbox.streets/14/21.3069/-157.8583.png?access_token=obscured";
        public string mapboxAccessToken;

I also added in the following statement in the code which I was hoping would turn traffic on:

       public void OnClickThing()
        {
            OnlineMaps.instance.traffic = true;
        }

I click and drag the script to the On Click () "object" window for the button and the public functions do not appear.

I have also tried dragging that script onto On Click () and then put "style1" or "style2" in the MonoScript.name field.  I do not think that is right though.  Nothing happens when the buttons are pressed. 

Any pointers would be very welcome!

John

Re: OnClick events to change Parameters etc

Hello.

In the URL, you need to use tokens ({x}, {y}, {zoom}) instead of values.
When requesting a tile, tokens will be replaced with values.

What is a tile system and how it works:
https://msdn.microsoft.com/en-us/library/bb259689.aspx
http://www.maptiler.org/google-maps-coo … rojection/

It's hard to say why your method doesn't show up.
Most likely this is some simple problem, for example:
- You have not added a component to GameObject.
- You added the wrong script. For example, based on the example, you created a new script with your changes, but added the original example to GameObject.
- You didn't save the script.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: OnClick events to change Parameters etc

Thanks Alex!  I will try this out.