Skip to content

Instantly share code, notes, and snippets.

@mikeatlas
Last active August 30, 2017 17:53

Revisions

  1. Mike Atlas revised this gist Oct 24, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.coffee
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    Array.prototype.splitAtEvery = (callback) ->
    sections = []
    arrayClone = this.slice(0)
  2. Mike Atlas revised this gist Oct 24, 2014. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions gistfile1.coffee
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,3 @@
    ![screen shot 2014-10-24 at 11 13 54 am](https://cloud.githubusercontent.com/assets/12704/4776974/83068afa-5bc8-11e4-9df7-c7017c5c13e1.png)

    ![screen shot 2014-10-24 at 5 44 53 pm](https://cloud.githubusercontent.com/assets/12704/4776975/87f5f1ae-5bc8-11e4-856b-7e4aaebc8e43.png)

    Array.prototype.splitAtEvery = (callback) ->
    sections = []
  3. Mike Atlas revised this gist Oct 24, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.coffee
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    ![screen shot 2014-10-24 at 11 13 54 am](https://cloud.githubusercontent.com/assets/12704/4776974/83068afa-5bc8-11e4-9df7-c7017c5c13e1.png)

    ![screen shot 2014-10-24 at 5 44 53 pm](https://cloud.githubusercontent.com/assets/12704/4776975/87f5f1ae-5bc8-11e4-856b-7e4aaebc8e43.png)

    Array.prototype.splitAtEvery = (callback) ->
    sections = []
    arrayClone = this.slice(0)
  4. Mike Atlas revised this gist Oct 24, 2014. 1 changed file with 40 additions and 41 deletions.
    81 changes: 40 additions & 41 deletions gistfile1.coffee
    Original file line number Diff line number Diff line change
    @@ -1,44 +1,43 @@
    Array.prototype.splitAtEvery = (callback) ->
    sections = []
    arrayClone = this.slice(0)
    $.each(arrayClone, (idx, item) =>
    sectionsLength = 0
    _.each(sections, (section) =>
    sectionsLength += section.length;
    )
    if callback(this, idx, item) == true
    sections.push(arrayClone.slice(0, idx+1-sectionsLength))
    arrayClone = arrayClone.slice(idx+1-sectionsLength, arrayClone.length)
    return
    )
    sections.push(arrayClone)
    return sections
    Array.prototype.splitAtEvery = (callback) ->
    sections = []
    arrayClone = this.slice(0)
    $.each(arrayClone, (idx, item) =>
    sectionsLength = 0
    _.each(sections, (section) =>
    sectionsLength += section.length;
    )
    if callback(this, idx, item) == true
    sections.push(arrayClone.slice(0, idx+1-sectionsLength))
    arrayClone = arrayClone.slice(idx+1-sectionsLength, arrayClone.length)
    return
    )
    sections.push(arrayClone)
    return sections

    drawPolylines = (latLons, leafletMap) ->
    normalizeIndexes = []
    $.each(latLons, (i, latLon) =>
    last = latLons[i-1]
    if last?
    if Math.abs(latLon.lng - last.lng) > 180
    normalizeIndexes.push(i)
    )

    drawPolylines = (latLons, leafletMap) ->
    normalizeIndexes = []
    normalizeIndexesRef = normalizeIndexes.slice(0)
    $.each(normalizeIndexes, (i, normalizeIndex) =>
    flipDirection = if latLons[normalizeIndexesRef[i]].lng < 0 then -1 else 1
    latLons.splice(normalizeIndexesRef[i], 0, L.latLng(latLons[normalizeIndexesRef[i]].lat, flipDirection * -179.99999))
    latLons.splice(normalizeIndexesRef[i]+1, 0, L.latLng(latLons[normalizeIndexesRef[i]].lat, flipDirection * 179.99999))
    normalizeIndexesRef = _.map(normalizeIndexesRef, (idx) => idx+2)
    )

    $.each(latLons, (i, latLon) =>
    last = latLons[i-1]
    if last?
    if Math.abs(latLon.lng - last.lng) > 180
    normalizeIndexes.push(i)
    )

    normalizeIndexesRef = normalizeIndexes.slice(0)
    $.each(normalizeIndexes, (i, normalizeIndex) =>
    flipDirection = if latLons[normalizeIndexesRef[i]].lng < 0 then -1 else 1
    latLons.splice(normalizeIndexesRef[i], 0, L.latLng(latLons[normalizeIndexesRef[i]].lat, flipDirection * -179.99999))
    latLons.splice(normalizeIndexesRef[i]+1, 0, L.latLng(latLons[normalizeIndexesRef[i]].lat, flipDirection * 179.99999))
    normalizeIndexesRef = _.map(normalizeIndexesRef, (idx) => idx+2)
    )
    sections = latLons.splitAtEvery((array, i, val) ->
    return (Math.abs(val.lng) == 179.99999) && \
    (Math.abs(array[i+1].lng) == 179.99999)
    )

    sections = latLons.splitAtEvery((array, i, val) ->
    return (Math.abs(val.lng) == 179.99999) && \
    (Math.abs(array[i+1].lng) == 179.99999)
    )

    $.each(sections, (i, section) ->
    polyline = L.polyline(section, {color:'#0099cc'}).addTo(leafletMap);
    )

    return latLons
    $.each(sections, (i, section) ->
    polyline = L.polyline(section, {color:'#0099cc'}).addTo(leafletMap);
    )

    return latLons
  5. Mike Atlas created this gist Oct 24, 2014.
    44 changes: 44 additions & 0 deletions gistfile1.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    Array.prototype.splitAtEvery = (callback) ->
    sections = []
    arrayClone = this.slice(0)
    $.each(arrayClone, (idx, item) =>
    sectionsLength = 0
    _.each(sections, (section) =>
    sectionsLength += section.length;
    )
    if callback(this, idx, item) == true
    sections.push(arrayClone.slice(0, idx+1-sectionsLength))
    arrayClone = arrayClone.slice(idx+1-sectionsLength, arrayClone.length)
    return
    )
    sections.push(arrayClone)
    return sections

    drawPolylines = (latLons, leafletMap) ->
    normalizeIndexes = []

    $.each(latLons, (i, latLon) =>
    last = latLons[i-1]
    if last?
    if Math.abs(latLon.lng - last.lng) > 180
    normalizeIndexes.push(i)
    )

    normalizeIndexesRef = normalizeIndexes.slice(0)
    $.each(normalizeIndexes, (i, normalizeIndex) =>
    flipDirection = if latLons[normalizeIndexesRef[i]].lng < 0 then -1 else 1
    latLons.splice(normalizeIndexesRef[i], 0, L.latLng(latLons[normalizeIndexesRef[i]].lat, flipDirection * -179.99999))
    latLons.splice(normalizeIndexesRef[i]+1, 0, L.latLng(latLons[normalizeIndexesRef[i]].lat, flipDirection * 179.99999))
    normalizeIndexesRef = _.map(normalizeIndexesRef, (idx) => idx+2)
    )

    sections = latLons.splitAtEvery((array, i, val) ->
    return (Math.abs(val.lng) == 179.99999) && \
    (Math.abs(array[i+1].lng) == 179.99999)
    )

    $.each(sections, (i, section) ->
    polyline = L.polyline(section, {color:'#0099cc'}).addTo(leafletMap);
    )

    return latLons