Example #1
0
  private void updateSearchMarkers() {

    markerLayer.clearLayers();

    List<LocationDTO> locations = Lists.reverse(searchPresenter.getStore().getModels());
    LatLngBounds bounds = new LatLngBounds();

    boolean empty = true;
    for (LocationDTO location : locations) {
      if (location.hasCoordinates()) {
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

        Marker marker = createMarker(latLng, location.getMarker());
        markerLayer.addLayer(marker);

        bounds.extend(latLng);
        bindClickEvent(location, marker);

        empty = false;
      }
    }

    if (empty) {
      if (searchPresenter.getBounds() != null) {
        bounds = LeafletUtil.newLatLngBounds(searchPresenter.getBounds());
      } else {
        bounds = LeafletUtil.newLatLngBounds(searchPresenter.getCountry().getBounds());
      }
    }
    int effectiveZoom = Math.min(8, map.getBoundsZoom(bounds, false));
    map.setView(bounds.getCenter(), effectiveZoom, false);
    map.fitBounds(bounds);
  }
Example #2
0
  @Override
  protected void afterRender() {
    super.afterRender();

    Extents countryBounds = searchPresenter.getCountry().getBounds();

    MapOptions mapOptions = new MapOptions();
    mapOptions.setCenter(new LatLng(countryBounds.getCenterY(), countryBounds.getCenterX()));
    mapOptions.setZoom(6);
    mapOptions.setProperty("crs", new EPSG3857());

    TileLayer baseLayer = new TileLayer(MapboxLayers.MAPBOX_STREETS, new Options());

    markerLayer = new LayerGroup(new ILayer[0]);

    map = new Map(getElement().getElementsByTagName("div").getItem(0), mapOptions);
    map.addLayer(baseLayer);
    map.addLayer(markerLayer);

    bindEvents();
  }