diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-15 14:09:06 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-16 12:26:35 -0700 |
commit | cc1ea759a681cadcfd06fd7bdda79ca6deb38c62 (patch) | |
tree | 97ece422b0516b11979c84b8136f95aeabb1aa91 /platform | |
parent | c0f6e5ccefc67dbdaa6ab7c7ea75a2a2d0c3f2ae (diff) | |
download | qtlocation-mapboxgl-cc1ea759a681cadcfd06fd7bdda79ca6deb38c62.tar.gz |
[core, node, darwin, android, qt] Make image ID part of Image
More like Source and Layer.
Diffstat (limited to 'platform')
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 10 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 2 | ||||
-rw-r--r-- | platform/glfw/glfw_view.cpp | 8 | ||||
-rw-r--r-- | platform/glfw/glfw_view.hpp | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 2 | ||||
-rw-r--r-- | platform/ios/src/UIImage+MGLAdditions.h | 2 | ||||
-rw-r--r-- | platform/ios/src/UIImage+MGLAdditions.mm | 5 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 2 | ||||
-rw-r--r-- | platform/macos/src/NSImage+MGLAdditions.h | 2 | ||||
-rw-r--r-- | platform/macos/src/NSImage+MGLAdditions.mm | 9 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 2 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 7 |
12 files changed, 29 insertions, 24 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 1e2464f1a0..51ce9c031d 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -735,8 +735,8 @@ void NativeMapView::addAnnotationIcon(JNIEnv& env, jni::String symbol, jint w, j } jni::GetArrayRegion(env, *jpixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get())); - map->addAnnotationImage(symbolName, - std::make_unique<mbgl::style::Image>(std::move(premultipliedImage), float(scale))); + map->addAnnotationImage(std::make_unique<mbgl::style::Image>( + symbolName, std::move(premultipliedImage), float(scale))); } jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, jni::String symbolName) { @@ -1037,8 +1037,10 @@ void NativeMapView::addImage(JNIEnv& env, jni::String name, jni::jint w, jni::ji jni::GetArrayRegion(env, *pixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get())); - map->addImage(jni::Make<std::string>(env, name), - std::make_unique<mbgl::style::Image>(std::move(premultipliedImage), float(scale))); + map->addImage(std::make_unique<mbgl::style::Image>( + jni::Make<std::string>(env, name), + std::move(premultipliedImage), + float(scale))); } void NativeMapView::removeImage(JNIEnv& env, jni::String name) { diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 2c54b11634..5f26b4fed2 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -510,7 +510,7 @@ static NSURL *MGLStyleURL_emerald; format:@"Cannot assign image %@ to a nil name.", image]; } - self.mapView.mbglMap->addImage([name UTF8String], image.mgl_styleImage); + self.mapView.mbglMap->addImage([image mgl_styleImageWithIdentifier:name]); } - (void)removeImageForName:(NSString *)name diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index d3a6347110..29cd0dd7c3 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -131,7 +131,7 @@ GLFWView::~GLFWView() { void GLFWView::setMap(mbgl::Map *map_) { map = map_; - map->addAnnotationImage("default_marker", makeImage(22, 22, 1)); + map->addAnnotationImage(makeImage("default_marker", 22, 22, 1)); } void GLFWView::updateAssumedState() { @@ -255,7 +255,7 @@ mbgl::Point<double> GLFWView::makeRandomPoint() const { } std::unique_ptr<mbgl::style::Image> -GLFWView::makeImage(int width, int height, float pixelRatio) { +GLFWView::makeImage(const std::string& id, int width, int height, float pixelRatio) { const int r = 255 * (double(std::rand()) / RAND_MAX); const int g = 255 * (double(std::rand()) / RAND_MAX); const int b = 255 * (double(std::rand()) / RAND_MAX); @@ -280,7 +280,7 @@ GLFWView::makeImage(int width, int height, float pixelRatio) { } } - return std::make_unique<mbgl::style::Image>(std::move(image), pixelRatio); + return std::make_unique<mbgl::style::Image>(id, std::move(image), pixelRatio); } void GLFWView::nextOrientation() { @@ -297,7 +297,7 @@ void GLFWView::addRandomCustomPointAnnotations(int count) { for (int i = 0; i < count; i++) { static int spriteID = 1; const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++); - map->addAnnotationImage(name, makeImage(22, 22, 1)); + map->addAnnotationImage(makeImage(name, 22, 22, 1)); spriteIDs.push_back(name); annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), name })); } diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp index 77f4f64b01..b5fd5856f4 100644 --- a/platform/glfw/glfw_view.hpp +++ b/platform/glfw/glfw_view.hpp @@ -61,7 +61,7 @@ private: mbgl::Color makeRandomColor() const; mbgl::Point<double> makeRandomPoint() const; - static std::unique_ptr<mbgl::style::Image> makeImage(int width, int height, float pixelRatio); + static std::unique_ptr<mbgl::style::Image> makeImage(const std::string& id, int width, int height, float pixelRatio); void nextOrientation(); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index a4c9f5194c..8cba1187ea 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3449,7 +3449,7 @@ public: annotationImage.delegate = self; // add sprite - _mbglMap->addAnnotationImage(iconIdentifier.UTF8String, annotationImage.image.mgl_styleImage); + _mbglMap->addAnnotationImage([annotationImage.image mgl_styleImageWithIdentifier:iconIdentifier]); // Create a slop area with a “radius” equal in size to the annotation // image’s alignment rect, allowing the eventual tap to be on any point diff --git a/platform/ios/src/UIImage+MGLAdditions.h b/platform/ios/src/UIImage+MGLAdditions.h index 642355d412..0b4cb4c015 100644 --- a/platform/ios/src/UIImage+MGLAdditions.h +++ b/platform/ios/src/UIImage+MGLAdditions.h @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage; -- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage; +- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier; @end diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm index 4ced1e30d5..b10c48a62a 100644 --- a/platform/ios/src/UIImage+MGLAdditions.mm +++ b/platform/ios/src/UIImage+MGLAdditions.mm @@ -22,9 +22,10 @@ return self; } -- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage { +- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier { BOOL isTemplate = self.renderingMode == UIImageRenderingModeAlwaysTemplate; - return std::make_unique<mbgl::style::Image>(MGLPremultipliedImageFromCGImage(self.CGImage), + return std::make_unique<mbgl::style::Image>([identifier UTF8String], + MGLPremultipliedImageFromCGImage(self.CGImage), float(self.scale), isTemplate); } diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index a36766b745..59951f946d 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1949,7 +1949,7 @@ public: return; } - _mbglMap->addAnnotationImage(iconIdentifier.UTF8String, annotationImage.image.mgl_styleImage); + _mbglMap->addAnnotationImage([annotationImage.image mgl_styleImageWithIdentifier:iconIdentifier]); // Create a slop area with a “radius” equal to the annotation image’s entire // size, allowing the eventual click to be on any point within this image. diff --git a/platform/macos/src/NSImage+MGLAdditions.h b/platform/macos/src/NSImage+MGLAdditions.h index d3cc80615b..1bcec00e8b 100644 --- a/platform/macos/src/NSImage+MGLAdditions.h +++ b/platform/macos/src/NSImage+MGLAdditions.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)image; -- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage; +- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier; @end diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm index fee3fe2751..6bb8fca68b 100644 --- a/platform/macos/src/NSImage+MGLAdditions.mm +++ b/platform/macos/src/NSImage+MGLAdditions.mm @@ -30,7 +30,7 @@ return self; } -- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage { +- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier { // Create a bitmap image representation from the image, respecting backing // scale factor and any resizing done on the image at runtime. // http://www.cocoabuilder.com/archive/cocoa/82430-nsimage-getting-raw-bitmap-data.html#82431 @@ -40,9 +40,10 @@ mbgl::PremultipliedImage cPremultipliedImage({ static_cast<uint32_t>(rep.pixelsWide), static_cast<uint32_t>(rep.pixelsHigh) }); std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.bytes(), cPremultipliedImage.data.get()); - return std::make_unique<mbgl::style::Image>(std::move(cPremultipliedImage), - (float)(rep.pixelsWide / self.size.width), - [self isTemplate]); + return std::make_unique<mbgl::style::Image>([identifier UTF8String], + std::move(cPremultipliedImage), + (float)(rep.pixelsWide / self.size.width), + [self isTemplate]); } @end diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index b174893e78..7261b33740 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -664,7 +664,7 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo<v8::Value>& info) { mbgl::UnassociatedImage cImage({ imageWidth, imageHeight}, std::move(data)); mbgl::PremultipliedImage cPremultipliedImage = mbgl::util::premultiply(std::move(cImage)); - nodeMap->map->addImage(*Nan::Utf8String(info[0]), std::make_unique<mbgl::style::Image>(std::move(cPremultipliedImage), pixelRatio)); + nodeMap->map->addImage(std::make_unique<mbgl::style::Image>(*Nan::Utf8String(info[0]), std::move(cPremultipliedImage), pixelRatio)); } void NodeMap::RemoveImage(const Nan::FunctionCallbackInfo<v8::Value>& info) { diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index bfc014dcd0..01471bf733 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -78,7 +78,7 @@ mbgl::Size sanitizedSize(const QSize& size) { }; }; -std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) { +std::unique_ptr<mbgl::style::Image> toStyleImage(const QString &id, const QImage &sprite) { const QImage swapped = sprite .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); @@ -87,6 +87,7 @@ std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) { memcpy(img.get(), swapped.constBits(), swapped.byteCount()); return std::make_unique<mbgl::style::Image>( + id.toStdString(), mbgl::PremultipliedImage( { static_cast<uint32_t>(swapped.width()), static_cast<uint32_t>(swapped.height()) }, std::move(img)), @@ -1027,7 +1028,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon) { if (icon.isNull()) return; - d_ptr->mapObj->addAnnotationImage(name.toStdString(), toStyleImage(icon)); + d_ptr->mapObj->addAnnotationImage(toStyleImage(name, icon)); } /*! @@ -1329,7 +1330,7 @@ void QMapboxGL::addImage(const QString &id, const QImage &image) { if (image.isNull()) return; - d_ptr->mapObj->addImage(id.toStdString(), toStyleImage(image)); + d_ptr->mapObj->addImage(toStyleImage(id, image)); } /*! |