Uploaded image for project: 'ZK Gmaps'
  1. ZK Gmaps
  2. ZKGMAPS-5

Poor performance when too many markers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • 3.0.4

      Reproducing steps:

      1. Load the page
      2. Enter the number of markers, and click on 'Generate'

      try 1000, 2000, 3000, 4000, 5000, ... markers

      too_many_markers.zul
      <vlayout width="100%" height="100%"
          apply="org.zkoss.bind.BindComposer"
          viewModel="@id('vm') @init('bugs.TooManyMarkersViewModel')">
          <hlayout>
              Number of markers:
              <intbox value="@bind(vm.numMarkers)" constraint="no empty, no negative, no zero"/>
              <button label="Generate" onClick="@command('generate')"/>
          </hlayout>
          <gmaps id="map" children="@load(vm.model)" lat="25.0661365" lng="121.48981605" zoom="15" hflex="1" vflex="1">
              <template name="children" var="location">
                  <gmarker lat="@load(location.latitude)" lng="@load(location.longitude)"/>       
              </template>
          </gmaps>
      </vlayout>
      
      TooManyMarkerViewModel.zul
      public class TooManyMarkersViewModel {
          
          @Wire
          private Gmaps map;
      
          public static class Location {
              private double latitude;
              private double longitude;
              
              public Location(double latitude, double longitude) {
                  this.latitude = latitude;
                  this.longitude = longitude;
              }
              
              public double getLatitude() {
                  return this.latitude;
              }
              
              public double getLongitude() {
                  return this.longitude;
              }
          }
          
          public static final Random RANDOM = new Random();
          
          private int numMarkers = 1000;
          private ListModelList<Location> model = new ListModelList<Location>();
          
          @AfterCompose
          public void doAfterCompose(@ContextParam(ContextType.VIEW) Component comp) {
              Selectors.wireComponents(comp, this, true);
              
              generateMarkers();
          }
          
          @Command("generate")
          @NotifyChange("model")
          public void generateMarkers() {
              model.clear();
              for (int i = 0; i < numMarkers; i++) {
                  double latitude = (RANDOM.nextDouble() * 0.0269384) + 25.0526673;
                  double longitude = (RANDOM.nextDouble() * 0.0595021) + 121.460065;
                  
                  model.add(new Location(latitude, longitude));
              }
              map.invalidate();
          }
      
          public int getNumMarkers() {
              return numMarkers;
          }
          
          public void setNumMarkers(int numMarkers) {
              this.numMarkers = numMarkers;
          }
      
          public ListModelList<Location> getModel() {
              return model;
          }
          
      }
      

            Jenkins Jenkins
            neillee neillee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: