Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I convert geometry to pbf for rendering with mapbox-gl-js #8321

Closed
zxp209 opened this issue Jun 5, 2019 · 5 comments
Closed

How do I convert geometry to pbf for rendering with mapbox-gl-js #8321

zxp209 opened this issue Jun 5, 2019 · 5 comments

Comments

@zxp209
Copy link

zxp209 commented Jun 5, 2019

mapbox-gl-js version:1.0.0

Question

I have a map webservice .I organize geometry as vector-tile.
I convert gps to pixel x y .Following is my code:
TILE_SIZE=256
zoom is tile level

public static double longitudeToPixelX(double longitude, byte zoom) {
		return (longitude + 180) / 360 * ((long) Tile.TILE_SIZE << zoom);
	}
	public static double latitudeToPixelY(double latitude, byte zoom) {
		double sinLatitude = Math.sin(latitude * (Math.PI / 180));
		long mapSize = (long) Tile.TILE_SIZE << zoom;
		double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude))
				/ (4 * Math.PI))
				* (mapSize);
		return Math.min(Math.max(0, pixelY), mapSize);
	}

public static void convert2Piexl(int x,int y,int z,Geometry geom){
		
		double px = MercatorProjection.tileXToPixelX(x);
		
		double py = MercatorProjection.tileYToPixelY(y);
		
		Coordinate[] cs = geom.getCoordinates();
		
		byte zoom = (byte)z;
		
		for(Coordinate c : cs){
			c.x = (int)(((MercatorProjection.longitudeToPixelX2(c.x, zoom)) - px) * 16);
			
			c.y = (int)(((MercatorProjection.latitudeToPixelY2(c.y, zoom)) - py) * 16);
		}
	}

Then I encode the data .mapbox-gl.js is able to decode the pbf data to geojson,but when I render the pbf, 3d building lost the front face .Following is image.
image1
image2

When I use mapbox-gl-js (version 0.4) ,rendering was fine.
How do I build the pbf that can be rendered by version 1.0.0 correctly.Are there some examples?
Thanks!

Links to related documentation

@mourner
Copy link
Member

mourner commented Jun 5, 2019

It's hard to say what exactly is wrong in your PBF encoding given that there's no sample in the ticket, so I guess it's a matter of reading through the Vector Tile Spec 2.1 (modern GL JS versions require conforming to at least 2.0) and seeing if you missed anything. Looking at the images — maybe the polygons are encoded as linestrings, or don't have the last closing point or closePath command?

@mourner
Copy link
Member

mourner commented Jun 5, 2019

For a sample code converting geometry into vector tiles, you can check out https://github.com/mapbox/vt-pbf

@mourner mourner closed this as completed Jun 5, 2019
@zxp209
Copy link
Author

zxp209 commented Jun 6, 2019

It's hard to say what exactly is wrong in your PBF encoding given that there's no sample in the ticket, so I guess it's a matter of reading through the Vector Tile Spec 2.1 (modern GL JS versions require conforming to at least 2.0) and seeing if you missed anything. Looking at the images — maybe the polygons are encoded as linestrings, or don't have the last closing point or closePath command?
Thanks reply.
I use mapbox-vector-tile-java package to encode my data.I read that package and found that contain VectorTile.java created by vector_tile.proto(2.1). My polygons are closed .Here is the cutting image from web IDE. There is no VectorTile.Tile.Feature.id.Is a problem?
pbf parser

@mourner
Copy link
Member

mourner commented Jun 6, 2019

@zxp209 there were similar issues reported earlier for an older version of PostGIS — #7767 and #7797, and their issue was incorrect winding order of polygons. Here's the same issue reported in mapbox-vector-tile-javawdtinc/mapbox-vector-tile-java#36 — this needs to be fixed on their side.

@zxp209
Copy link
Author

zxp209 commented Jun 11, 2019

@mourner Thank you very much!
Following this issue wdtinc/mapbox-vector-tile-java#36 ,the polygon became normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants