Topic: Draw city boundaries or polygon

Good morning everyone,
we bought the plugin and we were trying to implement a function, which in search of a specific city, draw the borders or a polygon in transparency of the whole city.

Printing the OnlineMapsGoogleGeocoding request I only found geometry_bounds_northeast and geometry_bounds_southwest, which are not enough I think to draw the exact shape.

From google maps it already exists so I thought that in reality you have to find the right command in the API, but currently I could not find it.

Can you help me?

Re: Draw city boundaries or polygon

Hello.

Unfortunately Google Geocoding API does not provide this information.
https://developers.google.com/maps/docu … ude-lookup
And I have not seen a service that gives such information.
It is possible that this is some kind of internal service not for public use.

Kind Regards,
Infinity Code Team.

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

Re: Draw city boundaries or polygon

Thanks i have migrate in OSM

Re: Draw city boundaries or polygon

Another question.

I have created, with the bounduary points, a mesh but is empty in the center, the material is setted like examples:

OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(position, Color.red, 1, new Color(1, 255, 1, 0.5f)));

but new Color(1, 255, 1, 0.5f) is not viewed.
Can you help?

5 (edited by claudio.faro 2022-05-16 14:54:32)

Re: Draw city boundaries or polygon

this is an image of polygon created

Post's attachments

Attachment icon Immagine 2022-05-16 145728.png 36.76 kb, 46 downloads since 2022-05-16 

Re: Draw city boundaries or polygon

Quote from the documentation (Troubleshooting / Known issues section):

Drawing API - polygon has no fill in «Tileset»
This problem is related to the very difficult polygon triangulation. Most likely, this problem will never be
solved.
How to work around the problem:
1. OnlineMapsDrawingElement.checkMapBoundaries = false.
This mode works correctly only if the lines do not intersect.
2. Use «Draw to Texture» mode.
3. (Not recommended) Use Drawing as Overlay.

Kind Regards,
Infinity Code Team.

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

Re: Draw city boundaries or polygon

Tnx a lot.  with  OnlineMapsDrawingElement.checkMapBoundaries = false, the polygon are filled but when change zoom level, sometimes the poly has a hole in it.

Can you explain where i found the Draw to texture mode ora Drawing as overlay?

8 (edited by claudio.faro 2022-05-17 13:53:28)

Re: Draw city boundaries or polygon

https://imgur.com/a/hYOOv1A

in this link a view of the problem.

Re: Draw city boundaries or polygon

"Draw to Texture" mode is when you use any Control other than tileset.

How to enable drawing as overlay:

OnlineMapsTileSetControl.instance.drawingMode = OnlineMapsTilesetDrawingMode.overlay;

P.S. Great video, but I don't think that's your problem big_smile

Kind Regards,
Infinity Code Team.

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

10 (edited by claudio.faro 2022-05-19 13:35:39)

Re: Draw city boundaries or polygon

Hello.

After a couple of days of testing and debuggins, I think I have found a bug in your code: specifically with the method CoordinatesToTile.
Let me explain:
I made a class that makes a request for a specific city (I'm using the city of Catania for the test).
The request returns a list of points (lat and lon).
I then took the points, and applied different implementation of Triangulate, to get this result

Link img1: https://photos.app.goo.gl/zRzLYizXEVozZJUV8

As you can see, the mesh is correctly filled, but it's position does not match the map tile, since we have not remapped the coordinates to the map space.

At this point, after looking into the plugin's code, I found the method CoordinatesToTile.
So I tried using this method to remap the list of coordinates, and this is the result:

Link img2:  https://photos.app.goo.gl/La6xqo71YHAKcvSE8

As you can see, it seems that I get the same result as your code.
After the conversion, it seems like the vertices are not connected anymore: they don't form a continuous line.
This is the reason why the triangulation does not appear to fill the poly shape.

Link img3:  https://photos.app.goo.gl/fYrPoNNRJEF362957

I am attaching to this post the code that I used.
Please advise on how to fix this problem.
Thanks

Claudio


    public void Recalculate(Vector2[] coordinates)    //each element contains lat and lon of the boundary
    {
        List<Vector2> list_point_tile = null;
        foreach (var item in coordinates)
        {
            double tx1, ty1;
            OnlineMaps map = OnlineMaps.instance;
            map.projection.CoordinatesToTile(item.x, item.y, map.zoom, out tx1, out ty1);
            Vector2 tile_point = new Vector2((float)tx1, (float)ty1);
            list_point_tile.Add(tile_point);
        }

        var vertices2D = list_point_tile.ToArray();
        var vertices3D = System.Array.ConvertAll<Vector2, Vector3>(vertices2D, v => v);

        // Use the triangulator to get indices for creating triangles
        var triangulator = new Triangulator(vertices2D);
        var indices = triangulator.Triangulate();

        // Generate a color for each vertex
        var colors = Enumerable.Range(0, vertices3D.Length)
            .Select(i => Random.ColorHSV())
            .ToArray();

        // Create the mesh
        var mesh = new Mesh
        {
            vertices = vertices3D,
            triangles = indices,
            colors = colors
        };
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();


        // Set up game object with mesh;
        var meshRenderer = gameObject.AddOrGetComponent<MeshRenderer>();
        meshRenderer.material = new Material(Shader.Find("Sprites/Default"));

        var filter = gameObject.AddOrGetComponent<MeshFilter>();
        filter.mesh = mesh;
        mesh.triangles = mesh.triangles.Reverse().ToArray();
    }
    

Re: Draw city boundaries or polygon

CoordinatesToTile converts geographic coordinates to tile position.
But a tile position is not a position in the scene and you can't use it that way.
Use OnlineMapsControlBaseDynamicMesh.GetWorldPosition instead.
https://infinity-code.com/doxygen/onlin … 6316068362

Kind Regards,
Infinity Code Team.

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