Skip to content

Instantly share code, notes, and snippets.

@christianhent christianhent/main.js
Last active Nov 3, 2015

Embed
What would you like to do?
Gerade noch so unter 100 Zeilen
$(document).ready(function () {
var obj = {};
obj.jqxhr = $.getJSON('/data/styles.json', function () {
}).done(function (data) {
obj.styles = data;
});
obj.curvature = 0.5;
obj.markers = [];
obj.bounds = new google.maps.LatLngBounds();
obj.curveMarker = null;
obj.icon = '';
obj.map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 2,
zoomControl: false,
scaleControl: false,
scrollwheel: false,
disableDoubleClickZoom: true,
streetViewControl: false,
rotateControl: false,
panControl: false,
draggable: false
});
obj.bounds = new google.maps.LatLngBounds();
obj.iw = new google.maps.InfoWindow();
obj.jqxhr = $.getJSON('/data/usergroups.json', function () {
}).done(function (data) {
$.each(data, function (key, val) {
//var id = val.id;
//var html = '<p>' + val.name + '</p>';
var latlng = new google.maps.LatLng(val.adr.geo['lat'], val.adr.geo['lng']);
var marker = new google.maps.Marker({
position: latlng,
map: obj.map,
draggable: false,
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillOpacity: 1.0,
fillColor: val.ico.fill.toString(),
strokeOpacity: 1.0,
strokeColor: val.ico.stroke.toString(),
strokeWeight: 2.0,
scale: parseFloat(val.ico.scale)
},
zIndex: parseInt(val.id),
id: val.id,
title: val.name,
desc: val.sum
});
obj.bounds.extend(marker.position);
marker.setMap(obj.map);
obj.markers.push(marker);
google.maps.event.addListener(marker, 'click', function () {
});
});
obj.map.fitBounds(obj.bounds);
obj.map.setOptions({styles: obj.styles});
google.maps.event.addListener(obj.map, 'projection_changed', function () {
addCurveMarkers();
});
function addCurveMarkers() {
var projection = obj.map.getProjection();
var curr, next, prev, e, m, o, c, pos1, pos2, p1, p2, pathDef, scale, symbol;
var l = obj.markers.length;
for (var i = 0; i < l; i++) {
if (i + 1 == l) break;
curr = obj.markers[i];
prev = obj.markers[(i + l - 1) % l];
next = obj.markers[(i + 1) % l];
pos1 = curr.getPosition();
pos2 = next.getPosition();
p1 = projection.fromLatLngToPoint(pos1);
p2 = projection.fromLatLngToPoint(pos2);
e = new google.maps.Point(p2.x - p1.x, p2.y - p1.y);
m = new google.maps.Point(e.x / 2, e.y / 2);
o = new google.maps.Point(e.y, -e.x);
c = new google.maps.Point(m.x + obj.curvature * o.x, m.y + obj.curvature * o.y);
pathDef = 'M 0,0 ' + 'q ' + c.x + ',' + c.y + ' ' + e.x + ',' + e.y;
scale = 1 / (Math.pow(2, -obj.map.getZoom()));
symbol = {
path: pathDef,
scale: scale,
strokeWeight: 3,
strokeColor: curr.icon.strokeColor
};
obj.curveMarker = new google.maps.Marker({
position: pos1,
clickable: false,
icon: symbol,
zIndex: 0,
map: obj.map
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.