forked from dc-js/dc.leaflet.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc.leaflet.min.js
21 lines (20 loc) · 9.21 KB
/
dc.leaflet.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*!
* dc.leaflet 0.3.1
* http://dc-js.github.io/dc.leaflet.js/
* Copyright 2014-2015 Boyan Yurukov and the dc.leaflet Developers
* https://github.com/dc-js/dc.leaflet.js/blob/master/AUTHORS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
!function(){function a(a){"use strict";var b={version:"0.3.1"};return b.leafletBase=function(b){b=a.marginMixin(a.baseChart(b)),b.margins({left:0,top:0,right:0,bottom:0});var c,d=!1,e=!1,f=!1,g={},h=function(a){var c=a.selectAll("div.dc-leaflet").data([0]).enter().append("div").attr("class","dc-leaflet").style("width",b.effectiveWidth()+"px").style("height",b.effectiveHeight()+"px");return L.map(c.node(),d)},i=function(a){L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'© <a href="https://openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(a)};return b.createLeaflet=function(a){return arguments.length?(h=a,b):h},b._doRender=function(){if(b.map())console.warn("WARNING: Leaflet map already rendered.");else{c=h(b.root());for(var a in g)c.on(a,g[a]);e&&f&&c.setView(b.toLocArray(e),f),b.tiles()(c),b._postRender()}return b._doRedraw()},b._doRedraw=function(){return b},b._postRender=function(){return b},b.mapOptions=function(a){return arguments.length?(d=a,b):d},b.center=function(a){return arguments.length?(e=a,b):e},b.zoom=function(a){return arguments.length?(f=a,b):f},b.tiles=function(a){return arguments.length?(i=a,b):i},b.map=function(){return c},b.toLocArray=function(a){return"string"==typeof a&&(a=a.split(",")),a},a.override(b,"on",function(a,d){var e=["zoomend","moveend"];return e.indexOf(a)>=0?(c?c.on(a,d):g[a]=d,this):b._on(a,d)}),b},b.legend=function(){function a(){return L.Control.extend({options:{position:e},onAdd:function(a){return this._div=L.DomUtil.create("div","info legend"),a.on("moveend",this._update,this),this._update(),this._div},_update:function(){if(b.colorDomain()){var a,c=b.colorDomain()[0],d=b.colorDomain()[1],e=b.colors().range(),f=b.colors().range().length,g=(d-c)/f,h=[];for(h[0]=Math.round(c),a=1;a<f;a++)h[a]=Math.round((.5+(a-1))*g+c);L.DomUtil.create("div","info legend");for(this._div.innerHTML="",a=0;a<h.length;a++)this._div.innerHTML+='<i style="background:'+e[a]+'"></i> '+h[a]+(h[a+1]?"–"+h[a+1]+"<br>":"+")}}})}var b,c={},d=null,e="bottomleft";return c.parent=function(a){return arguments.length?(b=a,this):b},c.LegendClass=function(b){return arguments.length?(a=b,c):a},c.render=function(){if(!d){var a=c.LegendClass()();d=new a,d.addTo(b.map())}return c.redraw()},c.redraw=function(){return d._update(),c},c.leafletLegend=function(){return d},c.position=function(a){return arguments.length?(e=a,c):e},c},b.markerChart=function(c,d){var e=b.leafletBase({}),f=!0,g=!1,h=!1,i=!1,j=!0,k=!1,l=!1,m=!1,n=!1,o=[],p=!1;e.renderTitle(!0);var q=function(a){return e.keyAccessor()(a)},r=function(a,b){var c=new L.Marker(e.toLocArray(e.locationAccessor()(a)),{title:e.renderTitle()?e.title()(a):"",alt:e.renderTitle()?e.title()(a):"",icon:s(),clickable:e.renderPopup()||e.brushOn()&&!k,draggable:!1});return c},s=function(a,b){return new L.Icon.Default},t=function(a,b){return e.title()(a)};e._postRender=function(){e.brushOn()&&(k&&e.filterHandler(x),e.map().on("zoomend moveend",w,this),k||e.map().on("click",w,this),e.map().on("zoomstart",v,this)),n=g?new L.MarkerClusterGroup(h?h:null):new L.LayerGroup,e.map().addLayer(n)},e._doRedraw=function(){var a=e._computeOrderedGroups(e.data()).filter(function(a){return 0!==e.valueAccessor()(a)});if(!p||p.toString()!==a.toString()){p=a,i&&(o=[]),n.clearLayers();var b=[];a.forEach(function(a,c){var d=e.keyAccessor()(a),f=null;f=!i&&d in o?o[d]:u(a,d),e.cluster()?b.push(f):n.addLayer(f)}),e.cluster()&&b.length>0&&n.addLayers(b)}},e.locationAccessor=function(a){return arguments.length?(q=a,e):q},e.marker=function(a){return arguments.length?(r=a,e):r},e.icon=function(a){return arguments.length?(s=a,e):s},e.popup=function(a){return arguments.length?(t=a,e):t},e.renderPopup=function(a){return arguments.length?(f=a,e):f},e.cluster=function(a){return arguments.length?(g=a,e):g},e.clusterOptions=function(a){return arguments.length?(h=a,e):h},e.rebuildMarkers=function(a){return arguments.length?(i=a,e):i},e.brushOn=function(a){return arguments.length?(j=a,e):j},e.filterByArea=function(a){return arguments.length?(k=a,e):k},e.markerGroup=function(){return n};var u=function(a,b){var c=r(a);return c.key=b,e.renderPopup()&&c.bindPopup(e.popup()(a,c)),e.brushOn()&&!k&&c.on("click",y),o[b]=c,c},v=function(a){m=!0},w=function(b){if("moveend"!==b.type||!m&&!b.hard)if(m=!1,k){var c;c=e.map().getCenter().equals(e.center())&&e.map().getZoom()===e.zoom()?null:e.map().getBounds(),a.events.trigger(function(){e.filter(null),c&&(l=!0,e.filter(c),l=!1),a.redrawAll(e.chartGroup())})}else e.filter()&&("click"===b.type||o.indexOf(e.filter())!==-1&&!e.map().getBounds().contains(o[e.filter()].getLatLng()))&&a.events.trigger(function(){e.filter(null),f&&e.map().closePopup(),a.redrawAll(e.chartGroup())})},x=function(a,b){e.dimension().filter(null),b&&b.length>0&&(e.dimension().filterFunction(function(a){if(!(a in o))return!1;var c=o[a].getLatLng();return c&&b[0].contains(c)}),l||e.map().getBounds().toString===b[0].toString()||e.map().fitBounds(b[0]))},y=function(b){if(b.target){var c=b.target.key;a.events.trigger(function(){e.filter(c),a.redrawAll(e.chartGroup())})}};return e.anchor(c,d)},b.choroplethChart=function(c,d){var e=a.colorChart(b.leafletBase({})),f=!1,g=[],h=!1,i=!0,j=!0,k={fillColor:"black",color:"gray",opacity:.4,fillOpacity:.6,weight:1},l=function(a){return a.key},m=function(a){var b=e.featureOptions();b instanceof Function&&(b=b(a)),b=JSON.parse(JSON.stringify(b));var c=g[e.featureKeyAccessor()(a)];return c&&c.d&&(b.fillColor=e.getColor(c.d,c.i),e.filters().indexOf(c.d.key)!==-1&&(b.opacity=.8,b.fillOpacity=1)),b},n=function(a,b){return e.title()(a)};e._postRender=function(){f=L.geoJson(e.geojson(),{style:e.featureStyle(),onEachFeature:o}),e.map().addLayer(f)},a.override(e,"_doRedraw",function(){return f.clearLayers(),g=[],e._computeOrderedGroups(e.data()).forEach(function(a,b){g[e.keyAccessor()(a)]={d:a,i:b}}),f.addData(e.geojson()),e.__doRedraw()}),e.geojson=function(a){return arguments.length?(h=a,e):h},e.featureOptions=function(a){return arguments.length?(k=a,e):k},e.featureKeyAccessor=function(a){return arguments.length?(l=a,e):l},e.featureStyle=function(a){return arguments.length?(m=a,e):m},e.popup=function(a){return arguments.length?(n=a,e):n},e.renderPopup=function(a){return arguments.length?(i=a,e):i},e.brushOn=function(a){return arguments.length?(j=a,e):j};var o=function(a,b){var c=g[e.featureKeyAccessor()(a)];c&&c.d&&(b.key=c.d.key,e.renderPopup()&&b.bindPopup(e.popup()(c.d,a)),e.brushOn()&&b.on("click",p))},p=function(b){if(b.target){var c=b.target.key;a.events.trigger(function(){e.filter(c),a.redrawAll(e.chartGroup())})}};return e.anchor(c,d)},b.bubbleChart=function(c,d){function e(b){var c=[];i.eachLayer(function(a){var d=a.getLatLng();b.boxZoomBounds.contains(d)&&c.push(a.key)}),a.events.trigger(function(a){f.replaceFilter([c]),f.redrawGroup()})}var f=b.leafletBase({}),g="blue",h="gray",i=!1,j=function(a){return f.keyAccessor()(a)},k=d3.scale.linear().domain([0,100]),l=!0,m=function(a,b){var c=f.locationAccessor()(a),d=f.toLocArray(c),e=L.latLng(+d[0],+d[1]),g=L.circleMarker(e);g.setRadius(f.r()(f.valueAccessor()(a))),g.on("mouseover",function(b){console.log(f.title()(a))});var h=f.keyAccessor()(a),i=-1!==f.filters().indexOf(h);return g.options.color=i?f.selectedColor():f.unselectedColor(),g};f.r=function(a){return arguments.length?(k=a,f):k},f.brushOn=function(a){return arguments.length?(l=a,f):l},f.locationAccessor=function(a){return arguments.length?(j=a,f):j},f.selectedColor=function(a){return arguments.length?(g=a,f):g},f.unselectedColor=function(a){return arguments.length?(h=a,f):h};var n=function(a,b){var c=f.marker()(a);return c.key=b,f.brushOn()&&c.on("click",o),c};f.marker=function(a){return arguments.length?(m=a,f):m},f._postRender=function(){f.brushOn()&&f.map().on("click",function(a){f.filter(null),f.redrawGroup()}),f.map().on("boxzoomend",e,this),i=new L.LayerGroup,f.map().addLayer(i)},f._doRedraw=function(){var a=f._computeOrderedGroups(f.data()).filter(function(a){return 0!==f.valueAccessor()(a)});i.clearLayers(),a.forEach(function(a,b){var c=f.keyAccessor()(a),d=null;d=n(a,c),i.addLayer(d)})};var o=function(b){if(!b.target)return void a.events.trigger(function(){f.filter(null),f.redrawGroup()});var c=b.target.key;b.originalEvent.ctrlKey||b.originalEvent.metaKey?f.filter(c):f.replaceFilter([[c]]),f.redrawGroup()};return f.anchor(c,d)},b.d3=d3,b.crossfilter=crossfilter,b.dc=a,b}if("function"==typeof define&&define.amd)define(["dc"],a);else if("object"==typeof module&&module.exports){var b=require("dc");module.exports=a(b)}else this.dc_leaflet=a(dc)}();
//# sourceMappingURL=dc.leaflet.min.js.map