Comparing version 0.0.63 to 0.0.64
@@ -1,1 +0,1 @@ | ||
function b(c){var a=Math.floor(Math.random()*1e7),b=new Date().getTime();return c+'_'+b+'_'+a}function g(d,c){c||(c=j(d.target)),c=j(c);var i=c.width(),k=c.height(),e=c.offset(),g=e.left,h=e.top,a,b;if(d.type.indexOf('mouse')!==-1)return a=d.x||d.pageX,b=d.y||d.pageY,[a-g,b-h];var f=window.event.touches[0];return a=f.pageX-g,b=f.pageY-h,a=a<i?a:i,a=a>0?a:1,b=b<k?b:k,b=b>0?b:1,[a,b]}function c(e){var c=e.length,a=0,d=h.LatLng.DEG_TO_RAD,f,g;if(c>2){for(var b=0;b<c;b++)f=e[b],g=e[(b+1)%c],a+=(g.lng-f.lng)*d*(2+Math.sin(f.lat*d)+Math.sin(g.lat*d));a=a*6378137*6378137/2}return Math.abs(a)}function d(b){var c=0,d=b.length;for(var a=0;a<d;a++){var e=(a+1)%d;c+=b[a].distanceTo(b[e])}return c}function e(d,e,f){var a=e.target,b=a.__data,c='child-'+d;f.fire(c,{layer:a,data:b})}function f(a,b,c,d){return typeof a==='function'?a(b,c,d):a}var a=require('aliyun-map-utils'),h=require('leaflet'),i=h.dmap=h.dmap||{},j=require('jquery'),k=require('./projection'),l=require('./curve_util');module.exports=i.Utils=a.merge(a,k,l,{getId:b,getPt:g,geodesicArea:c,getLengthPolyline:d,fireEvent:e,getValue:f}) | ||
function b(c){var a=Math.floor(Math.random()*1e7),b=new Date().getTime();return c+'_'+b+'_'+a}function g(d,c){c||(c=k(d.target)),c=k(c);var i=c.width(),j=c.height(),e=c.offset(),g=e.left,h=e.top,a,b;if(d.type.indexOf('mouse')!==-1)return a=d.x||d.pageX,b=d.y||d.pageY,[a-g,b-h];var f=window.event.touches[0];return a=f.pageX-g,b=f.pageY-h,a=a<i?a:i,a=a>0?a:1,b=b<j?b:j,b=b>0?b:1,[a,b]}function c(e){var c=e.length,a=0,d=i.LatLng.DEG_TO_RAD,f,g;if(c>2){for(var b=0;b<c;b++)f=e[b],g=e[(b+1)%c],a+=(g.lng-f.lng)*d*(2+Math.sin(f.lat*d)+Math.sin(g.lat*d));a=a*6378137*6378137/2}return Math.abs(a)}function d(b){var c=0,d=b.length;for(var a=0;a<d;a++){var e=(a+1)%d;c+=b[a].distanceTo(b[e])}return c}function e(d,e,f){var a=e.target,b=a.__data,c='child-'+d;f.fire(c,{layer:a,data:b})}function f(a,b,c,d){return typeof a==='function'?a(b,c,d):a}var a=require('aliyun-map-utils'),h=require('./l_utils'),i=require('leaflet'),j=i.dmap=i.dmap||{},k=require('jquery'),l=require('./projection'),m=require('./curve_util');module.exports=j.Utils=a.merge(a,l,m,h,{getId:b,getPt:g,geodesicArea:c,getLengthPolyline:d,fireEvent:e,getValue:f}) |
@@ -1,1 +0,1 @@ | ||
'use strict';function a(a,b,c,d,e){return typeof a==='function'?a(b,c,d,e):a}var b=require('leaflet'),c=require('bcore/utils'),d=c.isNone,e=require('./../core/utils').getColorFunc,f=e({from:'#002170',to:'#c5f2e7',easing:'Quadratic.Out.1.1',space:'rgb'}),g=b.Class.extend({includes:[b.Mixin.Events],addTo:function(a){return this._map=a,this.initEvents(),this.geojson&&this.initGeojson(),this},geoJson:function(a){if(!a)return;this.geojson=a;var b=this._map;if(!b)return;this.initGeojson()},initGeojson:function(){var a=this.options,c=a.popup,d=this.genStyle(a.style),e=this.geojson,f=a.geoid.bind(a),g=this.layers=[],h=this.geojsonLayer=b.geoJson(e,{style:d,onEachFeature:function(a,b){var d=f(a);g[d]=b;var e=c(a,null);c&&b.bindPopup(e)}});h.addTo(this._map)},initialize:function(a){this.options=c.deepMerge(g.options,a)},getLayer:function(a){return a&&this.layers?this.layers[a]:void 0},genStyle:function(d,e,f,g,h){var b={};for(var c in d)b[c]=a(d[c],e,f,g,h);return b},initEvents:function(){},each:function(c){if(!c)return;var a=this.layers;for(var b in a)c(a[b],b)},data:function(c){this._data=c;var e=this.options.value,f,b,g,h,a=this.range=[];for(var i in c){if(f=c[i],b=e(f),d(b))continue;d(a[0])&&(a[0]=a[1]=b),g=a[0],h=a[1],b>h&&(a[1]=b),b<g&&(a[0]=b)}},render:function(a){a&&this.data(a),this.draw()},draw:function(){var c=this._data,a=this.options,i=a.style,l=a.id.bind(a),f=a.value.bind(a),b,h,d,j,k=this.layers,e=this.range;for(var g in c)b=c[g],j=f(b),h=l(b),d=k[h],d&&d.setStyle(this.genStyle(i,j,e[0],e[1]))},hide:function(){console.log('目前无效')},getBounds:function(a){return this._map?this.geojsonLayer.getBounds():void 0},destory:function(){this.geojsonLayer&&this._map.removeLayer(this.geojsonLayer)}});g.options={geoid:function(b){var c=b.id||b.adcode;if(c)return c;var a=b.properties;return a?a.id||a.adcode:void 0},id:function(a){return a.id||a.adcode},value:function(a){return a.value},style:{fillColor:function(a,b,d){if(!a)return'rgba(0,150,200,1)';var c=(a-b)/(d-b);return f(c)},color:'transparent',weight:2,opacity:1,fillOpacity:1},popup:function(a,b){return a.properties.name}};var h=b.dmap=b.dmap||{};h.Area=g,h.area=function(a){return new g(a)},module.exports=g | ||
'use strict';function a(a,b,c,d,e){return typeof a==='function'?a(b,c,d,e):a}var b=require('leaflet'),c=require('bcore/utils'),d=c.isNone,e=require('./../core/utils').getColorFunc,f=e({from:'#002170',to:'#c5f2e7',easing:'Quadratic.Out.1.1',space:'rgb'}),g=b.Class.extend({includes:[b.Mixin.Events],addTo:function(a){return this._map=a,this.initEvents(),this.geojson&&this.initGeojson(),this},geoJson:function(a){if(!a)return;this.geojson=a;var b=this._map;if(!b)return;this.initGeojson()},initGeojson:function(){var a=this.options,c=a.popup,d=this.genStyle(a.style),e=this.geojson,f=a.geoid.bind(a),g=this.layers=[],h=this,i=this.geojsonLayer=b.geoJson(e,{style:d,onEachFeature:function(a,b){var d=f(a);g[d]=b,h.initEventChild(b,a);var e=c(a,null);c&&b.bindPopup(e)}});i.addTo(this._map)},initEventChild:function(a,e){var b={feature:e,layer:a},c=this,d=['mouseover','click','mouseout','mousedown'];d.forEach(function(d){a.on(d,function(){c.fire('child-'+b,b)})})},initialize:function(a){this.options=c.deepMerge(g.options,a)},getLayer:function(a){return a&&this.layers?this.layers[a]:void 0},genStyle:function(d,e,f,g,h){var b={};for(var c in d)b[c]=a(d[c],e,f,g,h);return b},initEvents:function(){},each:function(c){if(!c)return;var a=this.layers;for(var b in a)c(a[b],b)},data:function(c){this._data=c;var e=this.options.value,f,b,g,h,a=this.range=[];for(var i in c){if(f=c[i],b=e(f),d(b))continue;d(a[0])&&(a[0]=a[1]=b),g=a[0],h=a[1],b>h&&(a[1]=b),b<g&&(a[0]=b)}},render:function(a){a&&this.data(a),this.draw()},draw:function(){var c=this._data,a=this.options,i=a.style,l=a.id.bind(a),f=a.value.bind(a),b,h,d,j,k=this.layers,e=this.range;for(var g in c)b=c[g],j=f(b),h=l(b),d=k[h],d&&d.setStyle(this.genStyle(i,j,e[0],e[1]))},hide:function(){console.log('目前无效')},getBounds:function(a){return this._map?this.geojsonLayer.getBounds():void 0},destory:function(){this.geojsonLayer&&this._map.removeLayer(this.geojsonLayer)}});g.options={geoid:function(b){var c=b.id||b.adcode;if(c)return c;var a=b.properties;return a?a.id||a.adcode:void 0},id:function(a){return a.id||a.adcode},value:function(a){return a.value},style:{fillColor:function(a,b,d){if(!a)return'rgba(0,150,200,1)';var c=(a-b)/(d-b);return f(c)},color:'transparent',weight:2,opacity:1,fillOpacity:1},popup:function(a,b){return a.properties.name}};var h=b.dmap=b.dmap||{};h.Area=g,h.area=function(a){return new g(a)},module.exports=g |
@@ -1,1 +0,1 @@ | ||
'use strict';function a(b){this.options=c.deepMerge(a.options,b),this.initialize(b)}var b=require('leaflet'),c=require('./../core/utils'),d=c.Grid,e=c.getColorFunc,f=require('bcore/event');a.options={clusterStepByZoom:1,isAutoUpdate:!0,isNeedAggregate:!0,shape:{type:'hex',rx:20,ry:18,mouseover:{fillOpacity:.8,color:'rgba(255,255,255,0.9)'},mouseout:{fillOpacity:1,color:'rgba(255,255,255,0.0)'},style:{weight:0,fillOpacity:1,color:'rgba(255,255,255,0.0)'},click:{}},color:e('rgba(62,18,0,0.8)','rgba(255,208,122,0.8)','hsl','linear.Out.1.4'),scale:function(a){return 1},value:function(a,b,c){return Math.min(1,a.length/40)},lng:c.getLng,lat:c.getLat},a=f.extend(a,{initialize:function(a){this.events={'grid-resize':{desc:'格子大小发生变化'},'grid-mouseover':{desc:'鼠标移至格子范围'},'grid-dblclick':{desc:'双击格子'},'grid-mouseout':{desc:'鼠标移出格子范围'},'grid-click':{desc:'点击某个格子'}},this.gridMap={},this.aggregatedData={},this.getMax=a.getMax,this.getColor=c.getColorFunc(a.shape.color||a.color),this.getScale=c.getColorFunc(a.shape.scale||a.scale),this.isable=!0},addTo:function(a){if(this._map||!a)return;this._map=a,this.initDataProcesser(),this._data&&this.updateZoom()},initDataProcesser:function(){var a=this._map,c=this.options.shape;this.gridEncoder=new d().transform(function(i,m){var d=a.getSize(),e=d.x/2,f=d.y/2,h=e-i,j=f+m,k=e+i,l=f-m,g=a.containerPointToLatLng(b.point(h,j)),c=a.containerPointToLatLng(b.point(k,l));return{dlat:c.lat-g.lat,dlng:c.lng-g.lng}}).shape(c.type).rx(c.rx).ry(c.ry).update(),this.initEventsMap()},data:function(b){if(!b)return this._data;this._data=b;var a=this.options;a.isAutoUpdate&&this._map&&this.updateZoom(),this.updateColor();var c=a.shape},initEventsMap:function(){var a=this;this._map.on('moveend',function(){this.render()}.bind(this)).on('zoomend',function(){a.updateZoom()})},updateZoom:function(){var a=this.options,c=a.clusterStepByZoom,d=this._map;if(a.isNeedAggregate){var e=d.getZoom(),b=Math.floor(e/c);if(b===this.zoomLevel)return;this.gridEncoder.update(),this.zoomLevel=b,this.clean(),this.aggregate(),this.fire('grid-resize'),this._updateTransformOrigin()}},aggregate:function(){if(!this.isable)return;var b=this.gridEncoder,a=this.options,f=this._data,d=a.lat,e=a.lng;this.aggregatedData=c.mapReduce(this._data,{map:function(c,a){return{key:b.encode(d(a),e(a)),value:a}}})},getBounds:function(){var c=this._map.getBounds(),a=c._southWest,b=c._northEast,d=.5*(b.lat-a.lat),e=.5*(b.lng-a.lng);return{latMin:a.lat-d,latMax:b.lat+d,lngMin:a.lng-e,lngMax:b.lng+e}},clean:function(){var a=this.gridMap,c=this._map;for(var b in a){var d=a[b];c.removeLayer(d),delete a[b]}},disable:function(){this.isable=!1,this.clean()},enable:function(){this.isable=!0,this.draw()},link:function(){},updateShape:function(){this.clean();var b=this.options.shape,c=b.type,d=b.rx,e=b.ry,a=this.gridEncoder;a.shape(c),a.rx(d),a.ry(e),a.update(),this.aggregate(),this.draw()},updateColor:function(a,h,i,j){a||(a=this.options.color);var e=this.getColor=c.getColorFunc(a,h,i,j),b=this.gridMap,d,f;for(var g in b)d=b[g],f=d._value,d.setStyle({fillColor:e(f)})},updateOptions:function(a){this.options=c.deepMerge(this.options,a),this.updateColor(),this.updateShape()},updateScale:function(a){if(!a)return;this.scaleGridFunc=function(e,f){if(!e)return;var b=e._container;this._updateTranformOriginGird(b);var c=a(f),d='scale3d('+c+','+c+',1)';b.style.transform=d,b.style['-webkit-transform']=d,this.getScale=a}},_updateTranformOriginGird:function(b){if(!b)return;var a=b.getBBox(),c=a.width/2+a.x+'px '+(a.height/2+a.y)+'px 0px';b.style['transform-origin']=c,b.style['-webkit-transform-origin']=c},_updateTransformOrigin:function(){if(!this.scaleGridFunc)return;var a=this.gridMap,b=this;setTimeout(function(){for(var c in a)b._updateTranformOriginGird(a[c]._container)})},render:function(a){a&&this.data(a),this.draw()},each:function(d){var a=this.gridMap;for(var b in a){var c=a[b];d(c,b)}},draw:function(){if(!this.isable)return;var m=this.options,w=this.gridEncoder,h=m.shape.style,t=this.getColor,v=m.value,g=this.aggregatedData,i=this.gridMap,s=this._map,c=this.getBounds(),d,q=c.latMax,n=c.latMin,o=c.lngMax,p=c.lngMin;for(var a in g){var r=g[a],j=w.decode(a),k=j.center,u=j.pts,l=k[0],f=k[1];if(l<n||f<p||l>q||f>o)continue;var e=v(r);if(!i[a]){if(h.fillColor=t(e),d=i[a]=b.polygon(u,h).addTo(s),d._value=e,d._gridid=a,this.initEventsGrid(d),!this.scaleGridFunc)continue;this.scaleGridFunc(d,e)}}},initEventsGrid:function(a){var b=this,i=this.aggregatedData,d=this.options.shape,e=d.click||{},f=d.mouseover||{},g=d.mouseout||{},h=a._gridid,c={gridid:h,data:i[h],layer:a};a.on('mouseover',function(d){f&&a.setStyle(f),b.fire('grid-mouseover',c),a.bringToFront()}).on('mouseout',function(d){g&&a.setStyle(g),b.fire('grid-mouseout',c)}).on('mousedown',function(d){e&&a.setStyle(e),b.fire('grid-click',c)}).on('dblclick',function(a){b.fire('grid-dblclick',c)})}});var g=b.dmap=b.dmap||{};g.HeatmapGrid=a,g.heatmapGrid=function(b){return a(b)},module.exports=a | ||
'use strict';function a(b){this.options=c.deepMerge(a.options,b),this.initialize(b)}var b=require('leaflet'),c=require('./../core/utils'),d=c.Grid,e=c.getColorFunc,f=require('bcore/event');a.options={clusterStepByZoom:1,isAutoUpdate:!0,isNeedAggregate:!0,shape:{type:'hex',rx:20,ry:18,mouseover:{fillOpacity:.8,color:'rgba(255,255,255,0.9)'},mouseout:{fillOpacity:1,color:'rgba(255,255,255,0.0)'},style:{weight:0,fillOpacity:1,color:'rgba(255,255,255,0.0)'},click:{}},color:e('rgba(62,18,0,0.8)','rgba(255,208,122,0.8)','hsl','linear.Out.1.4'),scale:function(a){return 1},value:function(a,b,c){return Math.min(1,a.length/40)},lng:c.getLng,lat:c.getLat,popup:function(a){return'区域内有: '+a.length+'点'}},a=f.extend(a,{initialize:function(a){this.events={'grid-resize':{desc:'格子大小发生变化'},'grid-mouseover':{desc:'鼠标移至格子范围'},'grid-dblclick':{desc:'双击格子'},'grid-mouseout':{desc:'鼠标移出格子范围'},'grid-click':{desc:'点击某个格子'}},this.gridMap={},this.aggregatedData={},this.getMax=a.getMax,this.getColor=c.getColorFunc(a.shape.color||a.color),this.getScale=c.getColorFunc(a.shape.scale||a.scale),this.isable=!0},addTo:function(a){if(this._map||!a)return;this._map=a,this.initDataProcesser(),this._data&&this.updateZoom()},initDataProcesser:function(){var a=this._map,c=this.options.shape;this.gridEncoder=new d().transform(function(i,m){var d=a.getSize(),e=d.x/2,f=d.y/2,h=e-i,j=f+m,k=e+i,l=f-m,g=a.containerPointToLatLng(b.point(h,j)),c=a.containerPointToLatLng(b.point(k,l));return{dlat:c.lat-g.lat,dlng:c.lng-g.lng}}).shape(c.type).rx(c.rx).ry(c.ry).update(),this.initEventsMap()},initEventsMap:function(){var a=this;this._map.on('moveend',function(){this.render()}.bind(this)).on('zoomend',function(){a.updateZoom()})},updateZoom:function(){var a=this.options,c=a.clusterStepByZoom,d=this._map;if(a.isNeedAggregate){var e=d.getZoom(),b=Math.floor(e/c);if(b===this.zoomLevel)return;console.log('isNeedAggregate'),this.gridEncoder.update(),this.zoomLevel=b,this.clean(),this.aggregate(),this.fire('grid-resize'),this._updateTransformOrigin()}},aggregate:function(){if(!this.isable)return;var b=this.gridEncoder,a=this.options,f=this._data,d=a.lat,e=a.lng;this.aggregatedData=c.mapReduce(this._data,{map:function(c,a){return{key:b.encode(d(a),e(a)),value:a}}})},getBounds:function(){var c=this._map.getBounds(),a=c._southWest,b=c._northEast,d=.5*(b.lat-a.lat),e=.5*(b.lng-a.lng);return{latMin:a.lat-d,latMax:b.lat+d,lngMin:a.lng-e,lngMax:b.lng+e}},clean:function(){var a=this.gridMap,c=this._map;for(var b in a){var d=a[b];c.removeLayer(d),delete a[b]}},disable:function(){this.isable=!1,this.clean()},enable:function(){this.isable=!0,this.draw()},link:function(){},updateShape:function(){this.clean();var b=this.options.shape,c=b.type,d=b.rx,e=b.ry,a=this.gridEncoder;a.shape(c),a.rx(d),a.ry(e),a.update(),this.aggregate(),this.draw()},updateColor:function(a,h,i,j){a||(a=this.options.color);var e=this.getColor=c.getColorFunc(a,h,i,j),b=this.gridMap,d,f;for(var g in b)d=b[g],f=d._value,d.setStyle({fillColor:e(f)})},updateOptions:function(a){this.options=c.deepMerge(this.options,a),this.updateColor(),this.updateShape()},updateScale:function(a){if(!a)return;this.scaleGridFunc=function(e,f){if(!e)return;var b=e._container;this._updateTranformOriginGird(b);var c=a(f),d='scale3d('+c+','+c+',1)';b.style.transform=d,b.style['-webkit-transform']=d,this.getScale=a}},_updateTranformOriginGird:function(b){if(!b)return;var a=b.getBBox(),c=a.width/2+a.x+'px '+(a.height/2+a.y)+'px 0px';b.style['transform-origin']=c,b.style['-webkit-transform-origin']=c},_updateTransformOrigin:function(){if(!this.scaleGridFunc)return;var a=this.gridMap,b=this;setTimeout(function(){for(var c in a)b._updateTranformOriginGird(a[c]._container)})},data:function(b){if(!b)return this._data;this._data=b;var a=this.options;a.isAutoUpdate&&this._map&&this.aggregate(),this.updateColor();var c=a.shape},render:function(a){a&&this.data(a),this.draw()},each:function(d){var a=this.gridMap;for(var b in a){var c=a[b];d(c,b)}},draw:function(){if(!this.isable)return;var f=this.drawid='id_'+Math.floor(Math.random()*1e10),j=this.options,u=this.gridEncoder,h=j.shape.style,r=this.getColor,t=j.value,i=this.aggregatedData,c=this.gridMap,p=this._map,e=this.getBounds(),a,w=e.latMax,x=e.latMin,y=e.lngMax,z=e.lngMin;for(var d in i){var s=i[d],l=u.decode(d),m=l.center,v=l.pts,n=m[0],o=m[1];if(n<x||o<z||n>w||o>y)continue;var g=t(s),q=r(g);if(a=c[d],!a){if(h.fillColor=q,a=c[d]=b.polygon(v,h).addTo(p),a._value=g,a._gridid=d,a._drawid=f,this.initEventsGrid(a),!this.scaleGridFunc)continue;this.scaleGridFunc(a,g)}else a.setStyle({fillColor:q}),a._drawid=f}for(var k in c)c[k]._drawid!==f&&p.removeLayer(c[k])},initEventsGrid:function(a){var c=this,n=this.aggregatedData,g=this.options.shape,e=g.click||{},k=g.mouseover||{},i=g.mouseout||{},h=a._gridid,m=this._map,l=n[h],d={gridid:h,data:l,layer:a},f=a.getBounds(),o=f._northEast.lat,p=(f._southWest.lng+f._northEast.lng)/2,q=b.latLng(o,p),j;this.options.popup&&(j=this.options.popup(l)),a.on('mouseover',function(b){k&&a.setStyle(k),c.fire('grid-mouseover',d),a.bringToFront()}).on('mouseout',function(b){i&&a.setStyle(i),c.fire('grid-mouseout',d)}).on('mousedown',function(b){e&&a.setStyle(e),c.fire('grid-mousedown',d)}).on('click',function(){e&&a.setStyle(e),c.fire('grid-click',d),j&&setTimeout(function(){m.openPopup(j,q)})}).on('dblclick',function(a){c.fire('grid-dblclick',d)})}});var g=b.dmap=b.dmap||{};g.HeatmapGrid=a,g.heatmapGrid=function(b){return a(b)},module.exports=a |
@@ -5,3 +5,3 @@ { | ||
"description": "2d map visualization lib", | ||
"version": "0.0.63", | ||
"version": "0.0.64", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "test": "mocha -r jscoverage test" |
Sorry, the diff of this file is not supported yet
310236
100