예제 #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);
  }
예제 #2
0
  private void bindEvents() {

    searchPresenter
        .getStore()
        .addStoreListener(
            new StoreListener<LocationDTO>() {

              @Override
              public void storeDataChanged(StoreEvent<LocationDTO> event) {
                updateSearchMarkers();
              }
            });
    searchPresenter.addListener(
        Events.Select,
        new Listener<LocationEvent>() {

          @Override
          public void handleEvent(LocationEvent event) {
            if (event.getSource() != LocationMap.this) {
              onLocationSelected(event.getLocation());
            }
          }
        });

    newLocationPresenter.addListener(
        NewLocationPresenter.ACTIVE_STATE_CHANGED,
        new Listener<BaseEvent>() {
          @Override
          public void handleEvent(BaseEvent be) {
            onModeChanged();
          }
        });

    newLocationPresenter.addListener(
        NewLocationPresenter.POSITION_CHANGED,
        new Listener<BaseEvent>() {

          @Override
          public void handleEvent(BaseEvent be) {
            onNewLocationPosChanged();
          }
        });

    newLocationPresenter.addListener(
        NewLocationPresenter.BOUNDS_CHANGED,
        new Listener<BaseEvent>() {

          @Override
          public void handleEvent(BaseEvent be) {
            if (newLocationPresenter.isActive()) {
              LatLngBounds newBounds =
                  LeafletUtil.newLatLngBounds(newLocationPresenter.getBounds());
              map.fitBounds(newBounds);
            }
          }
        });
  }
예제 #3
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();
  }