# HG changeset patch # User veltr # Date 1380295342 -7200 # Node ID 5768acb94ca715db5882e17431b0e186e8cdc13d # Parent 5f7f0056de36750f4bed95dac453d25826f5c60e Added Map Marker grouping diff -r 5f7f0056de36 -r 5768acb94ca7 src/jocondelab/static/jocondelab/js/front-geo.js --- a/src/jocondelab/static/jocondelab/js/front-geo.js Fri Sep 27 16:38:05 2013 +0200 +++ b/src/jocondelab/static/jocondelab/js/front-geo.js Fri Sep 27 17:22:22 2013 +0200 @@ -16,6 +16,7 @@ coordIdCache = [], defaultIcon = new L.Icon.Default(), orangeIcon = new L.Icon.Default({iconUrl: urls.orange_marker }), + lightIcon = new L.Icon.Default({iconUrl: urls.light_marker }), country_uris = _(countries).pluck("dbpedia_uri"), itemCount = 12, scaleBase = Math.log(countries[0].nb_notices), @@ -23,6 +24,7 @@ hideCountryTimeout = false, preHideTimeout = false, mapDragging = false, + oms = new OverlappingMarkerSpiderfier(map), $map = $("#map"); function getData() { @@ -141,14 +143,16 @@ function showCoord(coord) { if (!coord.marker) { coord.latlng = L.latLng(coord.latitude, coord.longitude); - coord.marker = L.marker(coord.latlng).addTo(map); - coord.marker.on("click", function() { selectMarker(coord); }); - coord.marker.on("mouseover", function() { + var mk = coord.marker = L.marker(coord.latlng); + map.addLayer(mk); + oms.addMarker(mk); + mk.coord = coord; + mk.on("mouseover", function(marker) { if (!mapDragging) { showDbpedia(coord); } }); - coord.marker.on("mouseout", hideDbpedia ); + mk.on("mouseout", hideDbpedia); } } @@ -167,6 +171,7 @@ showCoord(coord); } else { if (coord.marker) { + oms.removeMarker(coord.marker); map.removeLayer(coord.marker); coord.marker = null; } @@ -236,6 +241,21 @@ debouncedGetData(); }); + oms.addListener("click", function(marker) { + if (marker.coord) { + selectMarker(marker.coord); + } + }); + oms.addListener('spiderfy', function(markers) { + _(markers).each(function(marker) { + marker.setIcon(lightIcon); + }); + }); + oms.addListener('unspiderfy', function(markers) { + _(markers).each(function(marker) { + marker.setIcon(defaultIcon); + }); + }); $(".dbpedia-overlay").mouseover(clearCountryTimeout); diff -r 5f7f0056de36 -r 5768acb94ca7 src/jocondelab/static/jocondelab/lib/images/marker-light.png Binary file src/jocondelab/static/jocondelab/lib/images/marker-light.png has changed diff -r 5f7f0056de36 -r 5768acb94ca7 src/jocondelab/static/jocondelab/lib/oms.min.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jocondelab/static/jocondelab/lib/oms.min.js Fri Sep 27 17:22:22 2013 +0200 @@ -0,0 +1,19 @@ +(function(){/* + OverlappingMarkerSpiderfier +https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet +Copyright (c) 2011 - 2012 George MacKerron +Released under the MIT licence: http://opensource.org/licenses/mit-license +Note: The Leaflet maps API must be included *before* this code +*/ +(function(){var n={}.hasOwnProperty,o=[].slice;null!=this.L&&(this.OverlappingMarkerSpiderfier=function(){function l(c,b){var a,e,g,f,d=this;this.map=c;null==b&&(b={});for(a in b)n.call(b,a)&&(e=b[a],this[a]=e);this.initMarkerArrays();this.listeners={};f=["click","zoomend"];e=0;for(g=f.length;eb)return this;a=this.markerListeners.splice(b,1)[0];c.removeEventListener("click",a);delete c._oms;this.markers.splice(b,1);return this};d.clearMarkers=function(){var c,b,a,e,g;this.unspiderfy();g=this.markers;c=a=0;for(e=g.length;aa||this.listeners[c].splice(a,1);return this};d.clearListeners=function(c){this.listeners[c]=[];return this};d.trigger=function(){var c,b,a,e,g,f;b=arguments[0];c=2<=arguments.length?o.call(arguments,1):[];b=null!=(a=this.listeners[b])?a:[];f=[];e=0;for(g=b.length;ec;a=0<=c?++f:--f)a=this.circleStartAngle+a*e,d.push(new L.Point(b.x+g*Math.cos(a),b.y+g*Math.sin(a)));return d};d.generatePtsSpiral=function(c,b){var a,e,g,f,d;g=this.spiralLengthStart;a=0;d=[];for(e=f=0;0<=c?fc;e=0<=c?++f:--f)a+=this.spiralFootSeparation/g+5.0E-4*e,e=new L.Point(b.x+g*Math.cos(a),b.y+g*Math.sin(a)),g+=i*this.spiralLengthFactor/a,d.push(e);return d};d.spiderListener=function(c){var b,a,e,g,f,d,h,i,j;b= +null!=c._omsData;(!b||!this.keepSpiderfied)&&this.unspiderfy();if(b)return this.trigger("click",c);g=[];f=[];d=this.nearbyDistance*this.nearbyDistance;e=this.map.latLngToLayerPoint(c.getLatLng());j=this.markers;h=0;for(i=j.length;h=this.circleSpiralSwitchover?this.generatePtsSpiral(k,a).reverse():this.generatePtsCircle(k,a);a=function(){var a,b,i,k=this;i=[];a=0;for(b=d.length;a urls.orange_marker = "{{STATIC_URL}}jocondelab/lib/images/marker-orange.png"; + urls.light_marker = "{{STATIC_URL}}jocondelab/lib/images/marker-light.png"; urls.ajax_geo_coords = "{% url 'ajax_geo_coords' %}"; urls.ajax_geo_search = "{% url 'ajax_geo_search' %}"; urls.countries_geo_json = "{{STATIC_URL}}jocondelab/lib/countries.geo.json";