简体   繁体   English

Raphael / Mapael在排序地块上速度较慢

[英]Raphael/Mapael slow on sorting plots

I'm using Raphael and Mapael to create a US map with points of different schools across the nation. 我正在使用Raphael和Mapael来创建一张美国地图,其中包含全国各地不同学校的地点。

Right now the functionality is working great if I only have a handful of points, however after I add all of my points (around 60) it slows way down when I click the different legend buttons to sort the points into different divisions. 现在,如果我只有几个点,那么该功能就很好用,但是当我添加所有点(大约60个点)后,当我单击不同的图例按钮将点分为不同的部分时,它的速度会降低。

I needed to rework a bit of the click events code to get it to do what I wanted with sorting while using meteor, these are my click events: 我需要重做一些单击事件代码,以使其执行我在使用流星时进行排序所需的操作,这些是我的单击事件:

Template.map.events({
    'click .division1': function(event,tmp){
        if(event.currentTarget){
            var plot = Session.get('propertyMap');
            _.each(plot,function(data, key){
                if(data.type !== 'D1'){
                    var deletedPlots = [key];
                    var updatedOptions = [];
                    var newPlots = {};
                    tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
                }
                else if(data.type === 'D1'){
                    var deletedPlots = [key];
                    var updatedOptions = [];
                    var newPlots = {};
                    newPlots[key] = data;
                    tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
                }
            });
        }
    },
    'click .division2': function(event,tmp){
        if(event.currentTarget){
            var plot = Session.get('propertyMap');
            _.each(plot,function(data, key){
                if(data.type !== 'D2'){
                    var deletedPlots = [key];
                    var updatedOptions = [];
                    var newPlots = {};
                    tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
                }
                else if(data.type === 'D2'){
                    var newPlots = {};
                    newPlots[key] = data;
                    tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
                }
            });
        }
    },
    'click .division3': function(event,tmp){
        if(event.currentTarget){
            var plot = Session.get('propertyMap');
            _.each(plot,function(data, key){
                if(data.type !== 'D3'){
                    var deletedPlots = [key];
                    var updatedOptions = [];
                    var newPlots = [];
                    tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
                }
                else if(data.type === 'D3'){
                    var newPlots = {};
                    newPlots[key] = data;
                    tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
                }
            });
        }
    },
    'click .AllProperties': function(event,tmp){
        event.preventDefault();
        if(event.currentTarget){
            var deletedPlots = [];
            var updatedOptions = [];
            var newPlots = Session.get('propertyMap');
            tmp.$(".container2").trigger('update', [updatedOptions, newPlots, deletedPlots]);
        }
    }

I also have the latest version sitting on embassyofrock.com. 我还在embassyofrock.com上拥有最新版本。

My question is if anyone has an idea of why it takes the extra couple seconds to sort the plots, and if there is a solution to make it run faster? 我的问题是,是否有人知道为什么要花几秒钟的时间来对地块进行排序,以及是否有解决方案来使其运行更快? You might notice that clicking all schools re-adds the plots instantly which is what I would like the others to do as well. 您可能会注意到,单击所有学校会立即重新添加地块,这也是我希望其他学校也这样做的。

I am not familiar with Raphael and Mapael but I see a lot of iterations in your code and you seems to work with local array variables. 我不熟悉Raphael和Mapael,但是我在您的代码中看到了很多迭代,并且您似乎在使用局部数组变量。

If you load your items from something else than a meteor publication, you should try to use a minimongo local collection to store your points and their related data. 如果从流星出版物之外的其他地方加载项目,则应尝试使用minimongo本地集合来存储您的点及其相关数据。

You can declare it like this: 您可以这样声明:

var Plots = new Meteor.Collection(null);

And fill it like this: 并像这样填充它:

for (var i = 0; i < plotList.length; i++) {
    Plots .insert(plotList[i]);
}

You will then be able to update everything using mongo command and I assume it should be faster. 然后,您将能够使用mongo命令更新所有内容,并且我认为它应该更快。

If you are using a meteor publication, it means you already have a local version of the original collection, and you should work directly with it. 如果您使用的是流星出版物,则意味着您已经拥有原始收藏的本地版本,应该直接使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM