var map = null; var anchorIcon = null; var clusterIcon = null; var points = []; var clusters = []; function inPoly(poly, pt){ var i, j; var c = false; var npol = poly.length - 1; var x = pt.x; var y = pt.y; for (i = 0, j = npol-1; i < npol; j = i++) { if ((((poly[i].y <= y) && (y < poly[j].y)) || ((poly[j].y <= y) && (y < poly[i].y))) && (x < (poly[j].x - poly[i].x) * (y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)) c = !c; } return c; } function zoomCluster(id) { var cluster = clusters[id]; var pt = points[cluster.points[0]]; map.setCenter(pt.latlng, map.getZoom() + 2); } function getXY(latlng) { return map.getCurrentMapType().getProjection().fromLatLngToPixel(latlng, map.getZoom()); } function isNear(x1, y1, x2, y2) { return Math.abs(x2 - x1) < 20 && Math.abs(y2 - y1) < 20; } function findNearestCluster(pt) { var nearest = -1; var pos = getXY(pt); var min_dist = 9999; for (i in clusters) { var dx = clusters[i].x - pos.x; var dy = clusters[i].y - pos.y; var dist = Math.sqrt(dx * dx + dy * dy); if (nearest < 0 || dist < min_dist) { nearest = i; min_dist = dist; } } return {cluster: nearest, dist: min_dist}; } function highlight(id) { var pt = points[id]; map.setCenter(pt.latlng, map.getZoom()); clusters[pt.cluster].marker.openInfoWindowHtml(pt.desc); } function buildMap() { for (i in clusters) map.removeOverlay(clusters[i].marker); clusters = []; for (i in points) { pt = points[i]; pos = getXY(pt.latlng); for (j = 0; j < clusters.length; j++) if (isNear(pos.x, pos.y, clusters[j].x, clusters[j].y)) break; if (j == clusters.length) { clusters.push({x: pos.x, y: pos.y, points: [i]}); } else clusters[j].points.push(i); points[i].cluster = j; } for (i in clusters) { cluster = clusters[i]; if (cluster.points.length > 1) { cluster.marker = createCluster(i); } else { cluster.marker = createMarker(cluster.points[0]); } map.addOverlay(cluster.marker); } } function createCluster(id) { var cluster = clusters[id]; var pt = points[cluster.points[0]]; var marker = new GMarker(pt.latlng, {icon: clusterIcon}); GEvent.addListener(marker, "click", function() { zoomCluster(id); }); GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml('

Bu bölgede ' + cluster.points.length + ' adet koy/demir yeri bulunuyor.

Yakınlaşmak için buraya tıklayın.'); }); return marker; } function initMap(opts) { map = new GMap2(document.getElementById("map"), opts); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); anchorIcon = new GIcon(); anchorIcon.image = "images/anchor_icon.gif"; anchorIcon.shadow = "images/anchor_icon_shadow.png"; anchorIcon.iconSize = new GSize(15.0, 15.0); anchorIcon.shadowSize = new GSize(23.0, 15.0); anchorIcon.iconAnchor = new GPoint(7.0, 7.0); anchorIcon.infoWindowAnchor = new GPoint(7.0, 7.0); clusterIcon = new GIcon(); clusterIcon.image = "images/anchor_icon_purple.gif"; clusterIcon.shadow = "images/anchor_icon_shadow.png"; clusterIcon.iconSize = new GSize(15.0, 15.0); clusterIcon.shadowSize = new GSize(23.0, 15.0); clusterIcon.iconAnchor = new GPoint(7.0, 7.0); clusterIcon.infoWindowAnchor = new GPoint(7.0, 7.0); GEvent.addListener(map, "zoomend", function(oldLevel, newLevel) { buildMap(); }); }