<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Draw city boundaries or polygon]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1962&amp;type=atom" />
	<updated>2022-05-20T09:14:32Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1962</id>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8307#p8307" />
			<content type="html"><![CDATA[<p>CoordinatesToTile converts geographic coordinates to tile position.<br />But a tile position is not a position in the scene and you can&#039;t use it that way.<br />Use OnlineMapsControlBaseDynamicMesh.GetWorldPosition instead.<br /><a href="https://infinity-code.com/doxygen/online-maps/classOnlineMapsControlBaseDynamicMesh.html#a72cf71ab8fdc9263d81e986316068362">https://infinity-code.com/doxygen/onlin … 6316068362</a></p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-05-20T09:14:32Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8307#p8307</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8305#p8305" />
			<content type="html"><![CDATA[<p>Hello.</p><p>After a couple of days of testing and debuggins, I think I have found a bug in your code: specifically with the method CoordinatesToTile.<br />Let me explain:<br />I made a class that makes a request for a specific city (I&#039;m using the city of Catania for the test).<br />The request returns a list of points (lat and lon). <br />I then took the points, and applied different implementation of Triangulate, to get this result</p><p>Link img1: <a href="https://photos.app.goo.gl/zRzLYizXEVozZJUV8">https://photos.app.goo.gl/zRzLYizXEVozZJUV8</a></p><p>As you can see, the mesh is correctly filled, but it&#039;s position does not match the map tile, since we have not remapped the coordinates to the map space.</p><p>At this point, after looking into the plugin&#039;s code, I found the method CoordinatesToTile. <br />So I tried using this method to remap the list of coordinates, and this is the result:</p><p>Link img2:&nbsp; <a href="https://photos.app.goo.gl/La6xqo71YHAKcvSE8">https://photos.app.goo.gl/La6xqo71YHAKcvSE8</a></p><p>As you can see, it seems that I get the same result as your code. <br />After the conversion, it seems like the vertices are not connected anymore: they don&#039;t form a continuous line.<br />This is the reason why the triangulation does not appear to fill the poly shape.</p><p>Link img3:&nbsp; <a href="https://photos.app.goo.gl/fYrPoNNRJEF362957">https://photos.app.goo.gl/fYrPoNNRJEF362957</a> </p><p>I am attaching to this post the code that I used.<br />Please advise on how to fix this problem.<br />Thanks</p><p>Claudio </p><br /><div class="codebox"><pre><code>    public void Recalculate(Vector2[] coordinates)    //each element contains lat and lon of the boundary
    {
        List&lt;Vector2&gt; 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&lt;Vector2, Vector3&gt;(vertices2D, v =&gt; 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 =&gt; 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&lt;MeshRenderer&gt;();
        meshRenderer.material = new Material(Shader.Find(&quot;Sprites/Default&quot;));

        var filter = gameObject.AddOrGetComponent&lt;MeshFilter&gt;();
        filter.mesh = mesh;
        mesh.triangles = mesh.triangles.Reverse().ToArray();
    }
    </code></pre></div>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-19T11:14:42Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8305#p8305</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8302#p8302" />
			<content type="html"><![CDATA[<p>&quot;Draw to Texture&quot; mode is when you use any Control other than tileset.</p><p>How to enable drawing as overlay:<br /></p><div class="codebox"><pre><code>OnlineMapsTileSetControl.instance.drawingMode = OnlineMapsTilesetDrawingMode.overlay;</code></pre></div><p>P.S. Great video, but I don&#039;t think that&#039;s your problem <img src="https://forum.infinity-code.com/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-05-17T14:14:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8302#p8302</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8300#p8300" />
			<content type="html"><![CDATA[<p><a href="https://imgur.com/a/hYOOv1A">https://imgur.com/a/hYOOv1A</a></p><p>in this link a view of the problem.</p>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-17T09:43:07Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8300#p8300</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8299#p8299" />
			<content type="html"><![CDATA[<p>Tnx a lot.&nbsp; with&nbsp; OnlineMapsDrawingElement.checkMapBoundaries = false, the polygon are filled but when change zoom level, sometimes the poly has a hole in it.</p><p>Can you explain where i found the Draw to texture mode ora Drawing as overlay?</p>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-17T09:06:40Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8299#p8299</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8298#p8298" />
			<content type="html"><![CDATA[<p>Quote from the documentation (Troubleshooting / Known issues section):<br /></p><div class="quotebox"><blockquote><p>Drawing API - polygon has no fill in «Tileset»<br />This problem is related to the very difficult polygon triangulation. Most likely, this problem will never be<br />solved.<br />How to work around the problem:<br />1. OnlineMapsDrawingElement.checkMapBoundaries = false.<br />This mode works correctly only if the lines do not intersect.<br />2. Use «Draw to Texture» mode.<br />3. (Not recommended) Use Drawing as Overlay.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-05-16T20:50:36Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8298#p8298</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8296#p8296" />
			<content type="html"><![CDATA[<p>this is an image of polygon created</p>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-16T14:54:07Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8296#p8296</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8295#p8295" />
			<content type="html"><![CDATA[<p>Another question.</p><p>I have created, with the bounduary points, a mesh but is empty in the center, the material is setted like examples:</p><p>OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(position, Color.red, 1, new Color(1, 255, 1, 0.5f)));</p><p>but new Color(1, 255, 1, 0.5f) is not viewed.<br />Can you help?</p>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-16T14:52:46Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8295#p8295</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8291#p8291" />
			<content type="html"><![CDATA[<p>Thanks i have migrate in OSM</p>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-16T08:00:37Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8291#p8291</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8283#p8283" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Unfortunately Google Geocoding API does not provide this information.<br /><a href="https://developers.google.com/maps/documentation/geocoding/start#geocoding-request-and-response-latitudelongitude-lookup">https://developers.google.com/maps/docu … ude-lookup</a><br />And I have not seen a service that gives such information.<br />It is possible that this is some kind of internal service not for public use.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-05-11T12:42:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8283#p8283</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Draw city boundaries or polygon]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8282#p8282" />
			<content type="html"><![CDATA[<p>Good morning everyone,<br />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.</p><p>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.</p><p>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.</p><p>Can you help me?</p>]]></content>
			<author>
				<name><![CDATA[claudio.faro]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2023</uri>
			</author>
			<updated>2022-05-11T09:39:27Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8282#p8282</id>
		</entry>
</feed>
