Skip to content

Instantly share code, notes, and snippets.

@crschmidt
Created May 27, 2011 12:59
Show Gist options
  • Save crschmidt/995190 to your computer and use it in GitHub Desktop.
Save crschmidt/995190 to your computer and use it in GitHub Desktop.
var map, map_canvas, latlng, center;
function init() {
map = new OpenLayers.Map('map_canvas');
layer = new OpenLayers.Layer.OSM("OSM Map");
map.addLayer(layer);
pattern = new OpenLayers.Layer.XYZ("Folded", "fake_url", {
isBaseLayer: false,
getURL: function() {
return "/static/interface/karte-bg-kachel1.png";
},
sphericalMercator: true
});
map.addLayer(pattern);
markers = new OpenLayers.Layer.Vector( "Markers" );
map.addLayer(markers);
map.setCenter(
new OpenLayers.LonLat(8.57431411743164, 50.51604627013405).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 13
);
var places;
if (window.churchesJsonUrl != undefined) {
$.getJSON(churchesJsonUrl, function(data) {
places = data;
$.each(places, placeOnMap);
});
}
function placeOnMap(index, elem) {
var geom = new OpenLayers.Geometry.Point(elem.lng, elem.lat).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
var marker = new OpenLayers.Feature.Vector(geom, {}, {'externalGraphic': elem.pin.url, 'graphicWidth': elem.pin.width, 'graphicHeight': elem.pin.height, 'graphicXOffset': -elem.pin.x, 'graphicYOffset': -elem.pin.y});
markers.addMarker(marker);
}
}
function startFuzzy() {
map_canvas.css('position', 'absolute');
if(window.church != undefined) {
center = new google.maps.LatLng(church.lat, church.lng);
recenter();
}
function recenter() {
google.maps.event.trigger(map, 'resize');
map.setCenter(center);
}
google.maps.event.trigger(map, 'resize');
if ($('#start_address').length > 0) {
var directionDisplay, navmap;
var directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer();
var options = {
center: new google.maps.LatLng(church.lat, church.lng),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
scaleControl: false,
disableDefaultUI: true
}
navmap = new google.maps.Map($("#navmap")[0], options);
directionsDisplay.setMap(navmap);
directionsDisplay.setPanel($("#route_description")[0]);
function calcRoute() {
var start = $('#start_address').val();
var end = new google.maps.LatLng(church.lat, church.lng);
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.METRIC
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
return false;
}
$('#calcroute').submit(calcRoute);
$('#start_navigation').click(calcRoute);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment