Skip to content

Commit

Permalink
Giving tile_map an interface overhaul
Browse files Browse the repository at this point in the history
MapQuest has turned off their public API for map tiles, so this plugin needed some work.  I have:
- Removed the MapQuest sources
- Made the interface for adding new sources more powerful
- Overhauled how sources are saved and loaded under the hood
- Added a button to reset the current tile cache

Resolves #402

Conflicts:
	tile_map/CMakeLists.txt
  • Loading branch information
pjreed committed Jul 19, 2016
1 parent 1b43f57 commit 4ecf702
Show file tree
Hide file tree
Showing 13 changed files with 764 additions and 143 deletions.
2 changes: 1 addition & 1 deletion mapviz/launch/mapviz.launch
Expand Up @@ -2,7 +2,7 @@

<env name="ROSCONSOLE_FORMAT" value="[${thread}] [${node}/${function}:${line}]: ${message}"/>

<node pkg="mapviz" type="mapviz" name="$(anon mapviz)"/>
<node pkg="mapviz" type="mapviz" name="$(anon mapviz)" required="true"/>

<node pkg="swri_transform_util" type="initialize_origin.py" name="initialize_origin" >
<param name="local_xy_frame" value="/far_field"/>
Expand Down
13 changes: 8 additions & 5 deletions tile_map/CMakeLists.txt
Expand Up @@ -61,15 +61,18 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

file (GLOB TILE_SRC_FILES
src/image_cache.cpp
src/texture_cache.cpp
src/tile_map_view.cpp)
src/image_cache.cpp
src/texture_cache.cpp
src/tile_map_view.cpp)
qt5_wrap_cpp(TILE_SRC_FILES include/tile_map/image_cache.h)
add_library(${PROJECT_NAME} ${TILE_SRC_FILES})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARIES} ${GLU_LIBRARY} ${catkin_LIBRARIES})

file (GLOB PLUGIN_SRC_FILES src/tile_map_plugin.cpp)
file (GLOB PLUGIN_UI_FILES src/*.ui)
file (GLOB PLUGIN_SRC_FILES
src/tile_map_plugin.cpp
src/tile_source.cpp)
file (GLOB PLUGIN_UI_FILES
src/tile_map_config.ui)
qt5_wrap_ui(PLUGIN_SRC_FILES ${PLUGIN_UI_FILES})
qt5_wrap_cpp(PLUGIN_SRC_FILES include/tile_map/tile_map_plugin.h)

Expand Down
1 change: 1 addition & 0 deletions tile_map/include/tile_map/image_cache.h
Expand Up @@ -99,6 +99,7 @@ namespace tile_map
void ProcessRequest(QString uri);
void ProcessReply(QNetworkReply* reply);
void NetworkError(QNetworkReply::NetworkError error);
void Clear();

private:
QNetworkAccessManager network_manager_;
Expand Down
2 changes: 2 additions & 0 deletions tile_map/include/tile_map/texture_cache.h
Expand Up @@ -56,6 +56,8 @@ namespace tile_map

TexturePtr GetTexture(size_t url_hash, const std::string& url, bool& failed);
void AddTexture(const TexturePtr& texture);

void Clear();

private:
QCache<size_t, TexturePtr> cache_;
Expand Down
24 changes: 23 additions & 1 deletion tile_map/include/tile_map/tile_map_plugin.h
Expand Up @@ -32,6 +32,7 @@

// C++ standard libraries
#include <string>
#include <map>

// Boost libraries
#include <boost/filesystem.hpp>
Expand All @@ -51,6 +52,8 @@

namespace tile_map
{
class TileSource;

class TileMapPlugin : public mapviz::MapvizPlugin
{
Q_OBJECT
Expand All @@ -77,9 +80,16 @@ namespace tile_map
void PrintWarning(const std::string& message);

protected Q_SLOTS:
void SelectSource(QString style);
void DeleteTileSource();
void SelectSource(QString source_name);
void SaveCustomSource();
void ResetTileCache();

private:
void selectTileSource(const TileSource& tile_source);
void startCustomEditing();
void stopCustomEditing();

Ui::tile_map_config ui_;
QWidget* config_widget_;

Expand All @@ -89,6 +99,18 @@ namespace tile_map
bool transformed_;

TileMapView tile_map_;
std::map<QString, TileSource> tile_sources_;

static std::string BASE_URL_KEY;
static std::string COORD_ORDER_KEY;
static std::string CUSTOM_SOURCES_KEY;
static std::string MAX_ZOOM_KEY;
static std::string NAME_KEY;
static std::string SOURCE_KEY;
static std::string SUFFIX_KEY;
static QString STAMEN_TERRAIN_NAME;
static QString STAMEN_TONER_NAME;
static QString STAMEN_WATERCOLOR_NAME;
};
}

Expand Down
24 changes: 11 additions & 13 deletions tile_map/include/tile_map/tile_map_view.h
Expand Up @@ -36,10 +36,14 @@

#include <tile_map/texture_cache.h>

#include <tile_map/tile_source.h>

#include <swri_transform_util/transform.h>

namespace tile_map
{
class TileSource;

struct Tile
{
public:
Expand All @@ -59,13 +63,11 @@ namespace tile_map
{
public:
TileMapView();

void SetBaseUrl(const std::string& url);

void SetMaxLevel(int32_t level);

void SetExtension(const std::string& extension);


void ResetCache();

void SetTileSource(const TileSource& tile_source);

void SetTransform(const swri_transform_util::Transform& transform);

void SetView(
Expand All @@ -78,14 +80,10 @@ namespace tile_map
void Draw();

private:
std::string base_url_;

std::string extension_;

TileSource tile_source_;

swri_transform_util::Transform transform_;

int32_t max_level_;

int32_t level_;

int64_t center_x_;
Expand Down
109 changes: 109 additions & 0 deletions tile_map/include/tile_map/tile_source.h
@@ -0,0 +1,109 @@
// *****************************************************************************
//
// Copyright (c) 2015, Southwest Research Institute® (SwRI®)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Southwest Research Institute® (SwRI®) nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// *****************************************************************************

#ifndef TILE_MAP_TILE_SOURCE_H
#define TILE_MAP_TILE_SOURCE_H

#include <QString>

namespace tile_map
{
/**
* Represents a network source for map tiles; contains information about how to
* connect to the source and how to retrieve tiles from it.
*
* Currently this implementation is fairly WMTS-centric, but there's no reason
* this couldn't be made a bit more generate for supporting other service formats
* in the future.
*/
class TileSource
{
public:
enum COORD_ORDER
{
// The order of the listing here should match the order listed
// in the combo box in tile_map_config.ui
ZXY,
ZYX,
XYZ,
XZY,
YXZ,
YZX
};

TileSource();

TileSource(const QString& name,
const QString& base_url,
COORD_ORDER coord_order,
bool is_custom,
int32_t max_zoom,
const QString& suffix
);

TileSource(const TileSource& tile_source);

const QString& GetBaseUrl() const;

void SetBaseUrl(const QString& base_url);

COORD_ORDER GetCoordOrder() const;

void SetCoordOrder(COORD_ORDER coord_order);

bool IsCustom() const;

void SetCustom(bool is_custom);

int32_t GetMaxZoom() const;

void SetMaxZoom(int32_t max_zoom);

const QString& GetName() const;

void SetName(const QString& name);

const QString& GetSuffix() const;

void SetSuffix(const QString& suffix);

std::string GenerateTileUrl(int32_t level, int64_t x, int64_t y) const;

private:
QString base_url_;
COORD_ORDER coord_order_;
bool is_custom_;
int32_t max_zoom_;
QString name_;
QString suffix_;
};
}

#endif //TILE_MAP_TILE_SOURCE_H
16 changes: 13 additions & 3 deletions tile_map/src/image_cache.cpp
Expand Up @@ -104,6 +104,12 @@ namespace tile_map
delete cache_thread_;
}

void ImageCache::Clear()
{
cache_.clear();
network_manager_.cache()->clear();
}

ImagePtr ImageCache::GetImage(size_t uri_hash, const std::string& uri, int32_t priority)
{
ImagePtr image;
Expand Down Expand Up @@ -160,11 +166,15 @@ namespace tile_map
request.setUrl(QUrl(uri));
request.setRawHeader("User-Agent", "mapviz-1.0");
request.setAttribute(
QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
request.setAttribute(
QNetworkRequest::HttpPipeliningAllowedAttribute,
true);

QNetworkReply *reply = network_manager_.get(request);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(NetworkError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(NetworkError(QNetworkReply::NetworkError)));
}

void ImageCache::ProcessReply(QNetworkReply* reply)
Expand Down
6 changes: 6 additions & 0 deletions tile_map/src/texture_cache.cpp
Expand Up @@ -159,4 +159,10 @@ namespace tile_map
cache_.insert(texture->url_hash, texture_ptr);
}
}

void TextureCache::Clear()
{
image_cache_->Clear();
cache_.clear();
}
}

0 comments on commit 4ecf702

Please sign in to comment.