fast-circles
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "fast-circles", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"homepage": "https://github.com/uniphil/fast-circles", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -65,3 +65,3 @@ 'use strict'; | ||
eachVisibleLayer: function(cb) { | ||
this.group.eachLayer(function(l) { | ||
this._group.eachLayer(function(l) { | ||
cb(l.circleId, l); | ||
@@ -68,0 +68,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.fastCircles=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";require("leaflet");var utils=require("./utils");L.FastCircles=L.Class.extend({options:{radius:16,onEachFeature:function(){}},initialize:function(centres,options){L.Util.setOptions(this,options);this._group=L.layerGroup();this._centres=centres.map(function(centre){return{latlng:L.latLng([centre[0],centre[1]]),id:centre[2],layer:null}});this._byId=this._centres.reduce(function(map,c){map[c.id]=c;return map},{})},showCircle:function(id){this._showCircle(this._byId[id])},eachCircle:function(cb){this._centres.forEach(cb)},getCircle:function(id){return this._byId[id]},eachVisibleLayer:function(cb){this.group.eachLayer(function(l){cb(l.circleId,l)})},getLayer:function(id){this.showCircle(id);return this._byId[id].layer},onAdd:function(map){map.addLayer(this._group);map.on("moveend",this._update,this);this._map=map;this._update()},onRemove:function(map){map.removeLayer(this._group);map.off("moveend",this._update,this);this._map=null},addTo:function(map){map.addLayer(this);return this},_showCircle:function(centre){if(centre.layer===null){centre.layer=L.circleMarker(centre.latlng,this.options);centre.layer.circleId=centre.id;this.options.onEachFeature(centre.id,centre.layer)}this._group.addLayer(centre.layer)},_hideCircle:function(centre){if(centre.layer!==null){this._group.removeLayer(centre.layer)}},_update:function(){var mapSize=this._map.getSize(),mapGrid=utils.getGrid(mapSize.x,mapSize.y),rad=this.options.radius,protoCircle=utils.getCircle(rad),pos,shows,layer;this._centres.forEach(function(centre){pos=this._map.latLngToContainerPoint(centre.latlng).round();shows=utils.overlay(mapGrid,protoCircle,[pos.x-rad,pos.y-rad]);if(shows){this._showCircle(centre)}else{this._hideCircle(centre)}},this);var tf=+new Date}});L.fastCircles=function(centres,radius,options){return new L.FastCircles(centres,radius,options)}},{"./utils":3,leaflet:2}],2:[function(require,module,exports){},{}],3:[function(require,module,exports){"use strict";function getGrid(width,height){var rows=[],row,rowno,colno;for(rowno=0;rowno<height;rowno++){row=[];for(colno=0;colno<width;colno++){row.push(0)}rows.push(row)}return rows}function getCircle(radius){var w=radius*2,h=w,grid=getGrid(w,h),lrrowno,lrcolno,r,filled;for(lrrowno=0;lrrowno<radius;lrrowno++){for(lrcolno=0;lrcolno<radius;lrcolno++){r=Math.sqrt(Math.pow(lrrowno+.5,2)+Math.pow(lrcolno+.5,2));filled=r<=radius?1:0;grid[radius+lrrowno][radius+lrcolno]=filled;grid[radius-lrcolno][radius+lrrowno]=filled;grid[radius-lrrowno][radius-lrcolno]=filled;grid[radius+lrcolno][radius-lrrowno]=filled}}return grid}function rectSize(arr){if(arr.length===0){return[0,0]}else{return[arr[0].length,arr.length]}}function overlay(dest,src,origin){var srcSize,destSize,start,end,srcRowno,srcColno,destRowno,destColno,srcVal,mutated=false;srcSize=rectSize(src);destSize=rectSize(dest);start=origin.map(function(n){return-Math.min(0,n)});end=srcSize.map(function(n,ax){return Math.min(n,destSize[ax]-origin[ax])});for(srcRowno=start[1];srcRowno<end[1];srcRowno++){destRowno=origin[1]+srcRowno;for(srcColno=start[0];srcColno<end[0];srcColno++){destColno=origin[0]+srcColno;srcVal=src[srcRowno][srcColno];if(srcVal===0){continue}else if(dest[destRowno][destColno]===1){continue}else{dest[destRowno][destColno]=1;mutated=true}}}return mutated}module.exports={getGrid:getGrid,getCircle:getCircle,rectSize:rectSize,overlay:overlay}},{}]},{},[1])(1)}); | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.fastCircles=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";require("leaflet");var utils=require("./utils");L.FastCircles=L.Class.extend({options:{radius:16,onEachFeature:function(){}},initialize:function(centres,options){L.Util.setOptions(this,options);this._group=L.layerGroup();this._centres=centres.map(function(centre){return{latlng:L.latLng([centre[0],centre[1]]),id:centre[2],layer:null}});this._byId=this._centres.reduce(function(map,c){map[c.id]=c;return map},{})},showCircle:function(id){this._showCircle(this._byId[id])},eachCircle:function(cb){this._centres.forEach(cb)},getCircle:function(id){return this._byId[id]},eachVisibleLayer:function(cb){this._group.eachLayer(function(l){cb(l.circleId,l)})},getLayer:function(id){this.showCircle(id);return this._byId[id].layer},onAdd:function(map){map.addLayer(this._group);map.on("moveend",this._update,this);this._map=map;this._update()},onRemove:function(map){map.removeLayer(this._group);map.off("moveend",this._update,this);this._map=null},addTo:function(map){map.addLayer(this);return this},_showCircle:function(centre){if(centre.layer===null){centre.layer=L.circleMarker(centre.latlng,this.options);centre.layer.circleId=centre.id;this.options.onEachFeature(centre.id,centre.layer)}this._group.addLayer(centre.layer)},_hideCircle:function(centre){if(centre.layer!==null){this._group.removeLayer(centre.layer)}},_update:function(){var mapSize=this._map.getSize(),mapGrid=utils.getGrid(mapSize.x,mapSize.y),rad=this.options.radius,protoCircle=utils.getCircle(rad),pos,shows,layer;this._centres.forEach(function(centre){pos=this._map.latLngToContainerPoint(centre.latlng).round();shows=utils.overlay(mapGrid,protoCircle,[pos.x-rad,pos.y-rad]);if(shows){this._showCircle(centre)}else{this._hideCircle(centre)}},this);var tf=+new Date}});L.fastCircles=function(centres,radius,options){return new L.FastCircles(centres,radius,options)}},{"./utils":3,leaflet:2}],2:[function(require,module,exports){},{}],3:[function(require,module,exports){"use strict";function getGrid(width,height){var rows=[],row,rowno,colno;for(rowno=0;rowno<height;rowno++){row=[];for(colno=0;colno<width;colno++){row.push(0)}rows.push(row)}return rows}function getCircle(radius){var w=radius*2,h=w,grid=getGrid(w,h),lrrowno,lrcolno,r,filled;for(lrrowno=0;lrrowno<radius;lrrowno++){for(lrcolno=0;lrcolno<radius;lrcolno++){r=Math.sqrt(Math.pow(lrrowno+.5,2)+Math.pow(lrcolno+.5,2));filled=r<=radius?1:0;grid[radius+lrrowno][radius+lrcolno]=filled;grid[radius-lrcolno][radius+lrrowno]=filled;grid[radius-lrrowno][radius-lrcolno]=filled;grid[radius+lrcolno][radius-lrrowno]=filled}}return grid}function rectSize(arr){if(arr.length===0){return[0,0]}else{return[arr[0].length,arr.length]}}function overlay(dest,src,origin){var srcSize,destSize,start,end,srcRowno,srcColno,destRowno,destColno,srcVal,mutated=false;srcSize=rectSize(src);destSize=rectSize(dest);start=origin.map(function(n){return-Math.min(0,n)});end=srcSize.map(function(n,ax){return Math.min(n,destSize[ax]-origin[ax])});for(srcRowno=start[1];srcRowno<end[1];srcRowno++){destRowno=origin[1]+srcRowno;for(srcColno=start[0];srcColno<end[0];srcColno++){destColno=origin[0]+srcColno;srcVal=src[srcRowno][srcColno];if(srcVal===0){continue}else if(dest[destRowno][destColno]===1){continue}else{dest[destRowno][destColno]=1;mutated=true}}}return mutated}module.exports={getGrid:getGrid,getCircle:getCircle,rectSize:rectSize,overlay:overlay}},{}]},{},[1])(1)}); |
@@ -66,3 +66,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.fastCircles = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
eachVisibleLayer: function(cb) { | ||
this.group.eachLayer(function(l) { | ||
this._group.eachLayer(function(l) { | ||
cb(l.circleId, l); | ||
@@ -69,0 +69,0 @@ }); |
{ | ||
"name": "fast-circles", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "draw lots of markers quickly without clustering", | ||
@@ -5,0 +5,0 @@ "main": "leaflet.fast-circles.min.js", |
20985