Skip to content

Commit

Permalink
Support image coordinate change (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Jun 25, 2024
1 parent ad2ad8c commit 7ad4166
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/core/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/conversion/coordinate.hpp>
#include <mbgl/style/conversion/filter.hpp>
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/style/conversion/layer.hpp>
Expand Down Expand Up @@ -1219,8 +1220,22 @@ void Map::updateSource(const QString &id, const QVariantMap &params) {
return;
}

if (sourceImage != nullptr && params.contains("url")) {
sourceImage->setURL(params["url"].toString().toStdString());
if (sourceImage != nullptr) {
if (params.contains("url")) {
sourceImage->setURL(params["url"].toString().toStdString());
}
if (params.contains("coordinates") && params["coordinates"].toList().size() == 4) {
mbgl::style::conversion::Error error;
std::array<mbgl::LatLng, 4> coordinates;
for (std::size_t i = 0; i < 4; i++) {
auto latLng = mbgl::style::conversion::convert<mbgl::LatLng>(
params["coordinates"].toList()[static_cast<int>(i)], error);
if (latLng) {
coordinates[i] = *latLng; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}
}
sourceImage->setCoordinates(coordinates);
}
} else if (sourceGeoJSON != nullptr && params.contains("data")) {
mbgl::style::conversion::Error error;
auto result = mbgl::style::conversion::convert<mbgl::GeoJSON>(params["data"], error);
Expand Down
13 changes: 13 additions & 0 deletions test/qml/qt6/tst_style_parameters.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ Item {
radarSourceParam.url = "https://maplibre.org/maplibre-gl-js/docs/assets/radar4.gif"
compare(radarSourceParam.url, "https://maplibre.org/maplibre-gl-js/docs/assets/radar4.gif")
wait(250)
radarSourceParam.coordinates = [
[-85.425, 46.437],
[-76.516, 46.437],
[-76.516, 37.936],
[-85.425, 37.936]
]
compare(radarSourceParam.coordinates, [
[-85.425, 46.437],
[-76.516, 46.437],
[-76.516, 37.936],
[-85.425, 37.936]
])
wait(250)
}

function test_style_2_paint_change() {
Expand Down

0 comments on commit 7ad4166

Please sign in to comment.