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();
  }
Example #3
0
  private void createNewLocationMarker() {
    DivIcon icon = createIcon("");

    Options markerOptions = new Options();
    markerOptions.setProperty("icon", icon);
    markerOptions.setProperty("draggable", true);

    newLocationMarker = new Marker(newLatLng(newLocationPresenter.getLatLng()), markerOptions);

    EventHandlerManager.addEventHandler(
        newLocationMarker,
        org.discotools.gwt.leaflet.client.events.handler.EventHandler.Events.dragend,
        new EventHandler<Event>() {

          @Override
          public void handle(Event event) {
            newLocationPresenter.setLatLng(
                new AiLatLng(
                    newLocationMarker.getLatLng().lat(), newLocationMarker.getLatLng().lng()));
          }
        });

    map.addLayer(newLocationMarker);
  }
Example #4
0
 /**
  * Adds the group of layers to the map.
  *
  * @param map
  * @return LayerGroup
  */
 public LayerGroup addTo(Map map) {
   LayerGroupImpl.addTo(getJSObject(), map.getJSObject());
   return this;
 }
Example #5
0
 @Override
 protected void onResize(int width, int height) {
   super.onResize(width, height);
   map.invalidateSize(false);
 }
Example #6
0
 private void panToNewLocation() {
   if (!map.getBounds().contains(newLocationMarker.getLatLng())) {
     map.panTo(newLocationMarker.getLatLng());
   }
 }
Example #7
0
 private void onLocationSelected(LocationDTO location) {
   if (location != null && location.hasCoordinates()) {
     map.panTo(new LatLng(location.getLatitude(), location.getLongitude()));
   }
 }