Esempio n. 1
0
    /**
     * Asks the MapQuest API to generate the map-image url.
     *
     * @return
     */
    public URL getTileUrl() {
      try {
        int scale = (int) MQSource.scaleList[zoomLevel.getZoomLevel()];

        // the map is generated by the center coordinate
        double lon = getCenterLon(scale);
        double lat = getCenterLat(scale);

        MQAPIWrapper apiWrapper = mqSource.getApiWrapper();

        String mapImageUrl =
            apiWrapper.getUrl(scale, lon, lat, MQSource.TILESIZE_WIDTH, MQSource.TILESIZE_HEIGHT);

        return new URL(null, mapImageUrl, CorePlugin.RELAXED_HANDLER);

      } catch (Exception e) {
        WMTPlugin.log(
            "[MQTile] Could not create the url for tile (Zoom: "
                + zoomLevel.getZoomLevel()
                + //$NON-NLS-1$
                ", X: "
                + getX()
                + ", "
                + getY(),
            e); //$NON-NLS-1$ //$NON-NLS-2$
      }

      return null;
    }
Esempio n. 2
0
    /**
     * Finds out the tile which contains the coordinate at a given zoom level.
     *
     * <p>see:
     * http://developer.mapquest.com/content/documentation/ApiDocumentation/53/JavaScript/JS_DeveloperGuide_v5.3.0.1.htm#styler-id1.17
     *
     * @param lat y
     * @param lon x
     * @param zoomLevel
     * @param wmtSource
     * @return
     */
    public MQTile getTileFromCoordinate(
        double lat, double lon, WMTZoomLevel zoomLevel, WMTSource wmtSource) {
      // normalize latitude and longitude
      lat = WMTTileFactory.normalizeDegreeValue(lat, 90);
      lon = WMTTileFactory.normalizeDegreeValue(lon, 180);

      double y =
          (lat + 90.0)
              * (MQSource.PIXELSPERLATDEGREE / MQSource.scaleList[zoomLevel.getZoomLevel()]);
      int row = (int) (y / MQSource.TILESIZE_HEIGHT);

      double x =
          (lon + 180.0)
              * (MQSource.PIXELSPERLNGDEGREE / MQSource.scaleList[zoomLevel.getZoomLevel()]);
      int col = (int) (x / MQSource.TILESIZE_WIDTH);

      WMTPlugin.debug(
          "[MQTile.getTileFromCoordinate] "
              + zoomLevel.getZoomLevel()
              + //$NON-NLS-1$
              "/"
              + col
              + "/"
              + row
              + " lon: "
              + lon
              + " lat: "
              + lat,
          Trace.MQ); // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$

      return new MQTile(col, row, (MQZoomLevel) zoomLevel, (MQSource) wmtSource);
    }
  // region Build geo-resources list for service
  public void buildGeoResources(WMTService service, List<IGeoResource> geoResources)
      throws Exception {
    geoResources.clear();

    try {
      List<?> tiledGroups = tiledPatterns.getChildren("TiledGroup"); // $NON-NLS-1$

      buildGeoResourcesFromTiledGroups(service, geoResources, tiledGroups, ""); // $NON-NLS-1$
    } catch (Exception exc) {
      WMTPlugin.log("[NASASourceManager.buildGeoResources] Failed: ", exc); // $NON-NLS-1$
      throw exc;
    }
  }
  // region Build TreeItem for Wizard
  public void buildWizardTree(TreeItem treeItem) {
    NASAControl controlFactory = new NASAControl();
    try {
      List<?> tiledGroups = tiledPatterns.getChildren("TiledGroup"); // $NON-NLS-1$

      WMTService service = serviceExtension.createService(NASASource.class);
      List<IGeoResource> geoResources = service.emptyResourcesList(null);
      geoResources.clear();

      WMTWizardTreeItemData data = new WMTWizardTreeItemData(service, controlFactory);
      treeItem.setData(data);

      buildWizardTreeFromTiledGroups(
          service, geoResources, treeItem, tiledGroups, "", controlFactory); // $NON-NLS-1$
    } catch (Exception exc) {
      WMTPlugin.log("[NASASourceManager.buildWizardTree] Failed: ", exc); // $NON-NLS-1$
    }
  }
  private NASASourceManager() {
    serviceExtension = new WMTServiceExtension();

    try {
      // open file
      URL url = NASASource.class.getResource(TILESERVICE_FILE);

      SAXBuilder builder = new SAXBuilder(false);
      URLConnection connection = url.openConnection();
      Document dom = builder.build(connection.getInputStream());

      Element root = dom.getRootElement();
      tiledPatterns = root.getChild("TiledPatterns"); // $NON-NLS-1$

    } catch (Exception exc) {
      WMTPlugin.log(
          "[NASASourceManager] Loading tileservice-file failed: " + TILESERVICE_FILE,
          exc); //$NON-NLS-1$
      tiledPatterns = null;
    }
  }