Page MenuHomePhabricator

Allow automatic lat/lon/zoom based on map data
Closed, ResolvedPublic

Description

When latitude, longitude, and/or zoom are missing, we should calculate proper position and zoom dynamically on the client. Make sure to exclude extreme lat/long - this way a mapmask will not affect calculations. Mapmask uses [[36000,-180],[36000,180],[-36000,180],[-36000,-180],[36000,-180]] -- this way user can scroll left and right on the map pretty far without seeing any non-masked space

Rule for ignoring points: Use point IIF: -180 <= longitude <= 180 && -90 <= latitude <= 90 (longitude is the first value, latitude is second in geojson, but most code usually uses lat,long order). Also, to understand their meaning, try the example below.

Simple: stackoverflow solution

Harder, with some math (only if leaflet doesn't handle it): The algorithm seems fairly simple - find min/max of both lat & lon, excluding outliers. Afterwards, increase the range by a small percentage, take into account size of the map window, and calculate zoom such that it would include all of the points. Set location to the median of all points.

P.S. If you want to see what these points mean, insert a map in Visual Editor, and paste this geojson at the bottom. Try changing these numbers by hand to see how they affect the selected region:

{
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
            [-170, -83],
            [-170, 83],
            [170, 83],
            [170, -83]
]]}}]}

Details

Related Gerrit Patches:
mediawiki/extensions/Kartographer : masterAutomatically set map view if not defined explicitly

Event Timeline

Yurik created this task.Jun 13 2016, 1:58 AM
Restricted Application added a project: Discovery. · View Herald TranscriptJun 13 2016, 1:58 AM
Restricted Application added subscribers: Zppix, Aklapper. · View Herald Transcript
MaxSem claimed this task.Jun 13 2016, 6:57 PM
MaxSem moved this task from Backlog to In progress on the Maps-Sprint board.
Yurik added a comment.Jun 13 2016, 7:02 PM

@MaxSem about lat/long - should we show an error if lat is given but not long, or the opposite? Having or not having zoom is fine regardless, but having lat+long, but not zoom might be a bit tricky.

I think we should as there is no clean or sane way to adjust automatically only to one component but not another.

Change 294364 had a related patch set uploaded (by MaxSem):
WIP: Automatically set map view if not defined explicitly

https://gerrit.wikimedia.org/r/294364

Yurik updated the task description. (Show Details)Jun 15 2016, 1:19 AM
Yurik moved this task from Unsorted to General on the Maps (Kartographer) board.Jun 16 2016, 11:07 PM
Yurik moved this task from General to UI tasks on the Maps (Kartographer) board.

Change 294364 merged by jenkins-bot:
Automatically set map view if not defined explicitly

https://gerrit.wikimedia.org/r/294364

JGirault closed this task as Resolved.Jun 22 2016, 9:30 PM