mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Extract OSM tile setup to own directive
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
Darkswarm.directive 'mapOsmTiles', ($timeout) ->
|
||||
restrict: 'E'
|
||||
require: '^googleMap'
|
||||
scope: {}
|
||||
link: (scope, elem, attrs, ctrl) ->
|
||||
$timeout =>
|
||||
map = ctrl.getMap()
|
||||
|
||||
map.mapTypes.set 'OSM', new google.maps.ImageMapType
|
||||
getTileUrl: (coord, zoom) ->
|
||||
# "Wrap" x (logitude) at 180th meridian properly
|
||||
# NB: Don't touch coord.x because coord param is by reference, and changing its x property breaks something in Google's lib
|
||||
tilesPerGlobe = 1 << zoom
|
||||
x = coord.x % tilesPerGlobe
|
||||
if x < 0
|
||||
x = tilesPerGlobe + x
|
||||
# Wrap y (latitude) in a like manner if you want to enable vertical infinite scroll
|
||||
'http://tile.openstreetmap.org/' + zoom + '/' + x + '/' + coord.y + '.png'
|
||||
tileSize: new (google.maps.Size)(256, 256)
|
||||
name: 'OpenStreetMap'
|
||||
maxZoom: 18
|
||||
@@ -9,29 +9,11 @@ Darkswarm.directive 'mapSearch', ($timeout) ->
|
||||
$timeout =>
|
||||
map = ctrl.getMap()
|
||||
|
||||
# Does this *really* belong here? It's not about search.
|
||||
scope.useOsmTiles map
|
||||
|
||||
searchBox = scope.createSearchBox map
|
||||
scope.respondToSearch map, searchBox
|
||||
scope.biasResults map, searchBox
|
||||
|
||||
|
||||
scope.useOsmTiles = (map) ->
|
||||
map.mapTypes.set 'OSM', new google.maps.ImageMapType
|
||||
getTileUrl: (coord, zoom) ->
|
||||
# "Wrap" x (logitude) at 180th meridian properly
|
||||
# NB: Don't touch coord.x because coord param is by reference, and changing its x property breaks something in Google's lib
|
||||
tilesPerGlobe = 1 << zoom
|
||||
x = coord.x % tilesPerGlobe
|
||||
if x < 0
|
||||
x = tilesPerGlobe + x
|
||||
# Wrap y (latitude) in a like manner if you want to enable vertical infinite scroll
|
||||
'http://tile.openstreetmap.org/' + zoom + '/' + x + '/' + coord.y + '.png'
|
||||
tileSize: new (google.maps.Size)(256, 256)
|
||||
name: 'OpenStreetMap'
|
||||
maxZoom: 18
|
||||
|
||||
scope.createSearchBox = (map) ->
|
||||
input = document.getElementById("pac-input")
|
||||
map.controls[google.maps.ControlPosition.TOP_LEFT].push input
|
||||
|
||||
Reference in New Issue
Block a user