floledermann / mapzr.com

mapzr.com - a "swiss army knife" for working with maps on the web.
http://mapzr.com
1 stars 0 forks source link

Short URLs for geo links #6

Open floledermann opened 6 years ago

floledermann commented 6 years ago

We could link to a point using an URL scheme of http://mapzr.com/#p123456

Additionally, we could encode the coords using this approach:

function makeEncoder(baseString) {

  var len = baseString.length
  var d = {}
  var i = 0

  // map char -> value
  var (var i=0; i<len; i++) {
    d[baseString[i]] = i
  }

  if Object.keys(d).length != len {
    throw Exception("Duplicate characters in encoding string")
  }

  return {  
    encode: x => {
      if (x==0) return baseString[0]
      var l = ""
      while (x > 0) {
        l += baseString[x % len])
        x = Math.floor(x/len)
      }
      return l
    },
    decode: s => {
      sum(d[ch] * len**i for (i,ch) in enumerate(s))
    }
  }
}

var {encode, decode} = makeEncoder("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")

(This is for encoding numbers only, we would need to extend this to support an alphabet with a few more chars like . ; - etc.)

(Pseudo code, not fully translated from Python yet)

For a link, the sidebar with links to mapping services (OSM, Google Maps etc. see #1) should open automatically.