Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
WMTS: working with introspection; missing external URL and TileMatrix…
Browse files Browse the repository at this point in the history
…Limits
  • Loading branch information
vaclavblazek committed Apr 5, 2019
1 parent b1f5e75 commit 79335dd
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 117 deletions.
2 changes: 1 addition & 1 deletion externals/libgeo
Submodule libgeo updated 2 files
+14 −0 geo/srsdef.cpp
+7 −0 geo/srsdef.hpp
2 changes: 1 addition & 1 deletion externals/vts-libs
7 changes: 6 additions & 1 deletion mapproxy/src/mapproxy/fileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace constants {
const std::string LayerJson("layer.json");
const std::string CesiumConf("cesium.conf");

const char *WmtsCapabilities("WMTSCapabilities.xml");
const std::string WmtsCapabilities("WMTSCapabilities.xml");

const std::string DisableBrowserHeader("X-Mapproxy-Disable-Browser");

Expand Down Expand Up @@ -663,3 +663,8 @@ Sink::FileInfo WmtsFileInfo::sinkFileInfo(std::time_t lastModified) const

return {};
}

const std::string& WmtsFileInfo::capabilitesName()
{
return constants::WmtsCapabilities;
}
2 changes: 2 additions & 0 deletions mapproxy/src/mapproxy/fileinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ struct WmtsFileInfo {
/** Valid only when type == Type::support;
*/
const vs::SupportFile *support;

static const std::string& capabilitesName();
};

#endif // mapproxy_fileinfo_hpp_included_
40 changes: 23 additions & 17 deletions mapproxy/src/mapproxy/generator/tms-raster-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,39 @@ const vre::Wmts& TmsRasterBase::getWmts() const
return *wmts_;
}

namespace {

bool hasIntrospection(const std::string &query)
WmtsResources TmsRasterBase::wmtsResources(const WmtsFileInfo &fileInfo) const
{
return !uq::empty(uq::find(uq::splitQuery(query), "is"));
}
const auto &fi(fileInfo.fileInfo);
const bool introspection
(!uq::empty(uq::find(uq::splitQuery(fi.query), "is")));

} // namespace
WmtsResources resources;

WmtsLayer TmsRasterBase::wmtsLayer(bool introspection) const
{
WmtsLayer layer(resource());
resources.layers.emplace_back(resource());
auto &layer(resources.layers.back());

layer.format = format_;

// build root path
if (introspection) {
// this is URL used in introspection -> local
layer.rootPath = "./";
layer.format = format_;
// used in introspection -> local, can be relative from wmts interface
// to vts interface
const auto resdiff
(resolveRoot
(id(), fi.interface
, id(), fi.interface.as(GeneratorInterface::Interface::vts)));

layer.rootPath =
prependRoot(std::string(), resource(), resdiff);

resources.capabilitiesUrl = "./" + fileInfo.capabilitesName();
} else {
LOG(warn4) << "TODO: Use external path; must be configured.";
layer.rootPath = "./";
layer.format = format_;
resources.capabilitiesUrl = "./" + fileInfo.capabilitesName();
}

return layer;
return resources;
}

Generator::Task TmsRasterBase
Expand All @@ -115,9 +123,7 @@ ::wmtsInterface(const FileInfo &fileInfo, Sink &sink) const
break;

case WmtsFileInfo::Type::capabilities:
sink.content
(wmtsCapabilities({wmtsLayer(hasIntrospection(fileInfo.query))})
, fi.sinkFileInfo());
sink.content(wmtsCapabilities(wmtsResources(fi)), fi.sinkFileInfo());
return {};

case WmtsFileInfo::Type::support:
Expand Down
2 changes: 1 addition & 1 deletion mapproxy/src/mapproxy/generator/tms-raster-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TmsRasterBase : public Generator {

Task wmtsInterface(const FileInfo &fileInfo, Sink &sink) const;

WmtsLayer wmtsLayer(bool introspection) const;
WmtsResources wmtsResources(const WmtsFileInfo &fileInfo) const;

const vre::Wmts& getWmts() const;

Expand Down
27 changes: 16 additions & 11 deletions mapproxy/src/mapproxy/ol/ol.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var map;

function startBrowser() {
var getWidth = ol.extent.getWidth;
var getTopLeft = ol.extent.getTopLeft;
var getProjection = ol.proj.get;
var transform = ol.proj.transform;
var WMTS = ol.source.WMTS;

var Map = ol.Map;
Expand All @@ -15,32 +14,38 @@ function startBrowser() {

var parser = new WMTSCapabilities();

var map;

fetch('./WMTSCapabilities.xml?is=1').then(function(response) {
return response.text();
}).then(function(text) {
var capabilities = parser.read(text);
console.dir(capabilities);

// TODO: use first layer from capabilities
// use first layer
var layer = capabilities.Contents.Layer[0];

// use single tile matrix
var options = optionsFromCapabilities(capabilities, {
layer: 'bmng',
matrixSet: 'EPSG:3857'
layer: layer.Identifier
});

console.dir(options);
// get center of WGS84 bounding box and convert it to SRS of tile matrix
var bb = layer.WGS84BoundingBox;
var center = transform([ (bb[0] + bb[2]) / 2, (bb[1] + bb[3]) / 2 ]
, getProjection("CRS:84")
, options.projection);

map = new Map({
layers: [
new TileLayer({
opacity: 1,
source: new WMTS(options)
opacity: 1
, source: new WMTS(options)
})
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 0
center: center
, zoom: 0
})
});
});
Expand Down
4 changes: 3 additions & 1 deletion mapproxy/src/mapproxy/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ struct GeneratorInterface {

operator Type() const { return type; }

GeneratorInterface as(Interface other) const { return { type, other }; }

bool operator==(const GeneratorInterface &o) const;
bool operator!=(const GeneratorInterface &o) const;
};
Expand Down Expand Up @@ -477,7 +479,7 @@ inline ResourceRoot resolveRoot(const Resource &thisResource
}

inline bool GeneratorInterface::operator==(const GeneratorInterface &o) const {
return (type == o.type) && (interface != o.interface);
return (type == o.type) && (interface == o.interface);
}

inline bool GeneratorInterface::operator!=(const GeneratorInterface &o) const {
Expand Down
Loading

0 comments on commit 79335dd

Please sign in to comment.