Files
MapLibreParticleLab/platform/macos/src/MLNMapView+Impl.mm
mwilsnd 20d9e1028c Platform flattening overhaul (#1393)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
2023-07-26 17:50:34 +02:00

102 lines
4.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#import "MLNMapView+Impl.h"
#import "MLNMapView+OpenGL.h"
#import "MLNStyle_Private.h"
#import "NSBundle+MLNAdditions.h"
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
std::unique_ptr<MLNMapViewImpl> MLNMapViewImpl::Create(MLNMapView* nativeView) {
return std::make_unique<MLNMapViewOpenGLImpl>(nativeView);
}
MLNMapViewImpl::MLNMapViewImpl(MLNMapView* nativeView_) : mapView(nativeView_) {
}
void MLNMapViewImpl::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) {
bool animated = mode == mbgl::MapObserver::CameraChangeMode::Animated;
[mapView cameraWillChangeAnimated:animated];
}
void MLNMapViewImpl::onCameraIsChanging() {
[mapView cameraIsChanging];
}
void MLNMapViewImpl::onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode) {
bool animated = mode == mbgl::MapObserver::CameraChangeMode::Animated;
[mapView cameraDidChangeAnimated:animated];
}
void MLNMapViewImpl::onWillStartLoadingMap() {
[mapView mapViewWillStartLoadingMap];
}
void MLNMapViewImpl::onDidFinishLoadingMap() {
[mapView mapViewDidFinishLoadingMap];
}
void MLNMapViewImpl::onDidFailLoadingMap(mbgl::MapLoadError mapError, const std::string& what) {
NSString *description;
MLNErrorCode code;
switch (mapError) {
case mbgl::MapLoadError::StyleParseError:
code = MLNErrorCodeParseStyleFailed;
description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style is corrupted.", @"User-friendly error description");
break;
case mbgl::MapLoadError::StyleLoadError:
code = MLNErrorCodeLoadStyleFailed;
description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can't be loaded.", @"User-friendly error description");
break;
case mbgl::MapLoadError::NotFoundError:
code = MLNErrorCodeNotFound;
description = NSLocalizedStringWithDefaultValue(@"STYLE_NOT_FOUND_DESC", nil, nil, @"The map failed to load because the style can’t be found or is incompatible.", @"User-friendly error description");
break;
default:
code = MLNErrorCodeUnknown;
description = NSLocalizedStringWithDefaultValue(@"LOAD_MAP_FAILED_DESC", nil, nil, @"The map failed to load because an unknown error occurred.", @"User-friendly error description");
}
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: description,
NSLocalizedFailureReasonErrorKey: @(what.c_str()),
};
NSError *error = [NSError errorWithDomain:MLNErrorDomain code:code userInfo:userInfo];
[mapView mapViewDidFailLoadingMapWithError:error];
}
void MLNMapViewImpl::onWillStartRenderingFrame() {
[mapView mapViewWillStartRenderingFrame];
}
void MLNMapViewImpl::onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus status) {
bool fullyRendered = status.mode == mbgl::MapObserver::RenderMode::Full;
[mapView mapViewDidFinishRenderingFrameFullyRendered:fullyRendered];
}
void MLNMapViewImpl::onWillStartRenderingMap() {
[mapView mapViewWillStartRenderingMap];
}
void MLNMapViewImpl::onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) {
bool fullyRendered = mode == mbgl::MapObserver::RenderMode::Full;
[mapView mapViewDidFinishRenderingMapFullyRendered:fullyRendered];
}
void MLNMapViewImpl::onDidBecomeIdle() {
[mapView mapViewDidBecomeIdle];
}
void MLNMapViewImpl::onDidFinishLoadingStyle() {
[mapView mapViewDidFinishLoadingStyle];
}
void MLNMapViewImpl::onSourceChanged(mbgl::style::Source& source) {
NSString *identifier = @(source.getID().c_str());
MLNSource * nativeSource = [mapView.style sourceWithIdentifier:identifier];
[mapView sourceDidChange:nativeSource];
}
bool MLNMapViewImpl::onCanRemoveUnusedStyleImage(const std::string &imageIdentifier) {
NSString *imageName = [NSString stringWithUTF8String:imageIdentifier.c_str()];
return [mapView shouldRemoveStyleImage:imageName];
}