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

Fit names in territorial bounds #21

Closed
faultcore opened this issue Dec 18, 2018 · 17 comments
Closed

Fit names in territorial bounds #21

faultcore opened this issue Dec 18, 2018 · 17 comments

Comments

@faultcore
Copy link

Right now we have a blind map, country names are available only in balloon with mouse on hover.
2018-12-02 12 35 38
The more info we get, the bigger and more unusable that balloon will become. One of obvious proposals is to create an MVT layer with country names (like in Europa Universalis or any paper maps). Same naming can be applied later to different admin_level

Reddit post
Describe the algorithm suitable for generating names with similar behavior.

@quorth0n
Copy link
Member

I remember reading a reddit post from the eu4 devs on this a while ago. A modified version of ST_LongestLine might be worth looking into as well.

@ataalik
Copy link
Contributor

ataalik commented Jan 13, 2019

Aren't these a bit overkill. For example in google maps the names of the countries are always at the middle point. And they are in similar font sizes on different zoom levels. Wouldn't that be easier and familiar.
An advantage of using an approach similar to Paradox's one would be country names following the viewport of the map. I.e. with a static approach like choosing the middle of the polygon or the longest line of the whole polygon once you can view only the western side of the Russia it's name would be outside of the viewport, unlike the paradox games and the map given above.

@MiklerGM
Copy link
Contributor

@ataalik you right, using same algorithm is an overkill. Simple names on map would be enough.

I check google maps and I spot some interesting facts:
They have different font sizes for different countries.
Font size changes along with zoom
They are dynamically deciding what they are showing (because of their map projection)
Country names never overlapping any major cities, as a result country names are not usually in the center or on a longest line

@faultcore
Copy link
Author

2019-01-16 17 43 17

I've also noticed this one and it looks very nice. However no cities without zoom. Maybe it's a good idea also?

@quorth0n
Copy link
Member

I believe we concluded on the last call that this would be a frontend task?

@MiklerGM
Copy link
Contributor

It would be difficult to calculate on frontend

  • prove me wrong but frontend does not have an access to geometry because it is in the MVT (only style calculations are possible)
  • Polygons should be merged at first to perform calculations of center point or longest line

@quorth0n
Copy link
Member

That's what I thought as well, I'll try and look into a PostGIS solution

@MiklerGM
Copy link
Contributor

If we want to add labels using mapbox we should serve labels (text) in MVT.

MiklerGM added a commit that referenced this issue Mar 23, 2019
@quorth0n
Copy link
Member

@MiklerGM could you link a documentation page or example showing how to serve MVT with text?

@MiklerGM
Copy link
Contributor

@whirish we are serving cities like this already.
It's a geo point + text label

@MiklerGM
Copy link
Contributor

MiklerGM commented Mar 23, 2019

This is how it works on frontend (MVT Style for cities)
https://github.com/chronhq/frontend/blob/78cf7fc47b010a29d19072170e1fc4bde93a99a2/src/models/MVTStyles/CitiesMVTStyle.js#L63

Backend

"SELECT id, wikidata_id, label,"

@quorth0n
Copy link
Member

Ah, so it's rendered on the frontend and just the text is returned in the MVT. I thought the text was being rendered on the backend, got it.

@MiklerGM
Copy link
Contributor

We can automatically fill the visual center by using P625 Coordinate Location or P5140 Coordinates of Geographic Center from wikidata.

chronhq/data#3

@quorth0n
Copy link
Member

Nice catch, do we want to add a script in microservices to do that?

@MiklerGM
Copy link
Contributor

We need to do this only once for whole db, I am not sure we need a microservice for that.

Probably I would do it as part of admin interface.

@MiklerGM
Copy link
Contributor

MiklerGM commented Dec 3, 2019

Next query will set the visual center as a centroid of the largest polygon or point on the surface if the centroid is outside of the polygon

UPDATE api_spacetimevolume SET visual_center = foo.visual_center FROM (
  SELECT *, CASE WHEN ST_Intersects(geom, centroid) IS true THEN centroid ELSE surface END AS visual_center FROM (
    SELECT id, geom, ST_Centroid(geom) as centroid, ST_PointOnSurface(geom) as surface FROM (
      SELECT id, geom FROM (
        SELECT *,
          (MAX(ST_Area(geom)) OVER (PARTITION BY id) = ST_Area(geom)) as sqft
          FROM (
            SELECT id, (ST_Dump(territory)).geom AS geom
            FROM api_spacetimevolume
          ) as foo
      ) as foo
      WHERE sqft = true
    ) as foo
  ) as foo
) as foo
WHERE foo.id = api_spacetimevolume.id;

@faultcore
Copy link
Author

Added central point to TE. A label is placed based on that point.

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

4 participants