Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ set(MBGL_CORE_FILES
src/mbgl/annotation/fill_annotation_impl.hpp
src/mbgl/annotation/line_annotation_impl.cpp
src/mbgl/annotation/line_annotation_impl.hpp
src/mbgl/annotation/render_annotation_source.cpp
src/mbgl/annotation/render_annotation_source.hpp
src/mbgl/annotation/shape_annotation_impl.cpp
src/mbgl/annotation/shape_annotation_impl.hpp
src/mbgl/annotation/style_sourced_annotation_impl.cpp
Expand Down Expand Up @@ -208,10 +210,23 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/render_raster_layer.hpp
src/mbgl/renderer/render_symbol_layer.cpp
src/mbgl/renderer/render_symbol_layer.hpp
src/mbgl/renderer/render_source.cpp
src/mbgl/renderer/render_source.hpp
src/mbgl/renderer/render_source_observer.hpp
src/mbgl/renderer/render_tile.cpp
src/mbgl/renderer/render_tile.hpp
src/mbgl/renderer/symbol_bucket.cpp
src/mbgl/renderer/symbol_bucket.hpp
src/mbgl/renderer/tile_pyramid.cpp
src/mbgl/renderer/tile_pyramid.hpp

# renderer/sources
src/mbgl/renderer/sources/render_geojson_source.cpp
src/mbgl/renderer/sources/render_geojson_source.hpp
src/mbgl/renderer/sources/render_raster_source.cpp
src/mbgl/renderer/sources/render_raster_source.hpp
src/mbgl/renderer/sources/render_vector_source.cpp
src/mbgl/renderer/sources/render_vector_source.hpp

# shaders
src/mbgl/shaders/circle.cpp
Expand Down Expand Up @@ -286,7 +301,6 @@ set(MBGL_CORE_FILES
include/mbgl/style/light.hpp
include/mbgl/style/position.hpp
include/mbgl/style/property_value.hpp
include/mbgl/style/query.hpp
include/mbgl/style/source.hpp
include/mbgl/style/transition_options.hpp
include/mbgl/style/types.hpp
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class Map : private util::noncopyable {
// Feature queries
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const RenderedQueryOptions& options = {});
std::vector<Feature> queryRenderedFeatures(const ScreenBox&, const RenderedQueryOptions& options = {});
std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options = {});

AnnotationIDs queryPointAnnotations(const ScreenBox&);

Expand Down
11 changes: 11 additions & 0 deletions include/mbgl/map/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ class RenderedQueryOptions {
optional<style::Filter> filter;
};

/**
* Options for query source features
*/
class SourceQueryOptions {
public:
// Required for VectorSource, ignored for GeoJSONSource
optional<std::vector<std::string>> sourceLayers;

optional<style::Filter> filter;
};

}
24 changes: 0 additions & 24 deletions include/mbgl/style/query.hpp

This file was deleted.

4 changes: 0 additions & 4 deletions include/mbgl/style/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <mbgl/util/range.hpp>
#include <mbgl/util/any.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/query.hpp>

#include <memory>
#include <string>
Expand Down Expand Up @@ -57,9 +56,6 @@ class Source : public mbgl::util::noncopyable {
std::unique_ptr<Source> copy(const std::string& id) const;

optional<std::string> getAttribution() const;
optional<Range<uint8_t>> getZoomRange() const;

std::vector<Feature> querySourceFeatures(const SourceQueryOptions& options = {});

// Private implementation
class Impl;
Expand Down
19 changes: 1 addition & 18 deletions include/mbgl/style/sources/geojson_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>

#include <mapbox/geojson.hpp>

namespace mapbox {

namespace geojsonvt {
class GeoJSONVT;
} // namespace geojsonvt

namespace supercluster {
class Supercluster;
} // namespace supercluster

} // namespace mapbox

namespace mbgl {
namespace style {

using GeoJSONVTPointer = std::unique_ptr<mapbox::geojsonvt::GeoJSONVT>;
using SuperclusterPointer = std::unique_ptr<mapbox::supercluster::Supercluster>;

struct GeoJSONOptions {
// GeoJSON-VT options
uint8_t maxzoom = 18;
Expand All @@ -38,7 +21,7 @@ struct GeoJSONOptions {

class GeoJSONSource : public Source {
public:
GeoJSONSource(const std::string& id, const GeoJSONOptions options_ = GeoJSONOptions());
GeoJSONSource(const std::string& id, const GeoJSONOptions& = {});

void setURL(const std::string& url);
void setGeoJSON(const GeoJSON&);
Expand Down
6 changes: 4 additions & 2 deletions platform/android/src/style/sources/geojson_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ namespace android {
using namespace mbgl::android::conversion;
using namespace mbgl::android::geojson;

auto filter = toFilter(env, jfilter);
auto features = source.querySourceFeatures({ {}, filter });
std::vector<mbgl::Feature> features;
if (map) {
features = map->querySourceFeatures(source.getID(), { {}, toFilter(env, jfilter) });
}
return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
}

Expand Down
7 changes: 4 additions & 3 deletions platform/android/src/style/sources/vector_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ namespace android {
using namespace mbgl::android::conversion;
using namespace mbgl::android::geojson;

mbgl::optional<std::vector<std::string>> sourceLayerIds = { toVector(env, jSourceLayerIds) };
auto filter = toFilter(env, jfilter);
auto features = source.querySourceFeatures({ sourceLayerIds, filter });
std::vector<mbgl::Feature> features;
if (map) {
features = map->querySourceFeatures(source.getID(), { toVector(env, jSourceLayerIds), toFilter(env, jfilter) });
}
return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
}

Expand Down
5 changes: 4 additions & 1 deletion platform/darwin/src/MGLShapeSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ - (NSString *)description {
optionalFilter = predicate.mgl_filter;
}

std::vector<mbgl::Feature> features = self.rawSource->querySourceFeatures({ {}, optionalFilter });
std::vector<mbgl::Feature> features;
if (self.mapView) {
features = self.mapView.mbglMap->querySourceFeatures(self.rawSource->getID(), { {}, optionalFilter });
}
return MGLFeaturesFromMBGLFeatures(features);
}

Expand Down
4 changes: 4 additions & 0 deletions platform/darwin/src/MGLSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ @interface MGLSource ()
// special internal source types like mbgl::AnnotationSource.
@property (nonatomic, readonly) mbgl::style::Source *rawSource;

@property (nonatomic, readonly, weak) MGLMapView *mapView;

@end

@implementation MGLSource {
Expand Down Expand Up @@ -48,12 +50,14 @@ - (void)addToMapView:(MGLMapView *)mapView {
"to the style more than once is invalid.", self, mapView.style];
}

_mapView = mapView;
mapView.mbglMap->addSource(std::move(_pendingSource));
}

- (void)removeFromMapView:(MGLMapView *)mapView {
if (self.rawSource == mapView.mbglMap->getSource(self.identifier.UTF8String)) {
_pendingSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
_mapView = nil;
}
}

Expand Down
8 changes: 8 additions & 0 deletions platform/darwin/src/MGLSource_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ struct SourceWrapper {
*/
@property (nonatomic, readonly) mbgl::style::Source *rawSource;

/**
The map view whose style currently contains the source.

If the source is not currently part of any map view’s style, this property is
set to `nil`.
*/
@property (nonatomic, readonly, weak) MGLMapView *mapView;

/**
Adds the mbgl source that this object represents to the mbgl map.

Expand Down
7 changes: 6 additions & 1 deletion platform/darwin/src/MGLVectorSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#import "MGLFeature_Private.h"
#import "MGLSource_Private.h"
#import "MGLTileSource_Private.h"
#import "MGLMapView_Private.h"
#import "NSPredicate+MGLAdditions.h"
#import "NSURL+MGLAdditions.h"

#include <mbgl/map/map.hpp>
#include <mbgl/style/sources/vector_source.hpp>

@interface MGLVectorSource ()
Expand Down Expand Up @@ -59,7 +61,10 @@ - (NSString *)attributionHTMLString {
optionalFilter = predicate.mgl_filter;
}

std::vector<mbgl::Feature> features = self.rawSource->querySourceFeatures({ optionalSourceLayerIDs, optionalFilter });
std::vector<mbgl::Feature> features;
if (self.mapView) {
features = self.mapView.mbglMap->querySourceFeatures(self.rawSource->getID(), { optionalSourceLayerIDs, optionalFilter });
}
return MGLFeaturesFromMBGLFeatures(features);
}

Expand Down
60 changes: 6 additions & 54 deletions platform/darwin/test/MGLSourceQueryTests.m
Original file line number Diff line number Diff line change
@@ -1,73 +1,25 @@
#import <Mapbox/Mapbox.h>

#import "NSBundle+MGLAdditions.h"

#import <XCTest/XCTest.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#endif

@interface MGLSourceQueryTests : XCTestCase <MGLMapViewDelegate>

@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) MGLStyle *style;

@end

@implementation MGLSourceQueryTests {
XCTestExpectation *_styleLoadingExpectation;
}

- (void)setUp {
[super setUp];

[MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];
NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"query-style" withExtension:@"json"];
self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) styleURL:styleURL];
self.mapView.delegate = self;
if (!self.mapView.style) {
_styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."];
[self waitForExpectationsWithTimeout:1 handler:nil];
}
}

- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
XCTAssertNotNil(mapView.style);
XCTAssertEqual(mapView.style, style);

[_styleLoadingExpectation fulfill];
}

- (void)tearDown {
_styleLoadingExpectation = nil;
self.mapView = nil;

[super tearDown];
}

- (MGLStyle *)style {
return self.mapView.style;
}
@implementation MGLSourceQueryTests

- (void) testQueryVectorSource {
MGLVectorSource *source = (MGLVectorSource *)[self.style sourceWithIdentifier:@"source5"];

MGLVectorSource *source = [[MGLVectorSource alloc] initWithIdentifier:@"vector" tileURLTemplates:@[@"fake"] options:nil];
NSSet *sourceLayers = [NSSet setWithObjects:@"buildings", @"water", nil];
NSArray* features = [source featuresInSourceLayersWithIdentifiers:sourceLayers predicate:nil];
// Source won't be loaded yet, so features is 0
// Source not added yet, so features is 0
XCTAssertEqual([features count], 0);
}

- (void) testQueryShapeSource {
MGLShapeSource *source = (MGLShapeSource *)[self.style sourceWithIdentifier:@"source4"];

NSPredicate *eqPredicate = [NSPredicate predicateWithFormat:@"key1 == 'value1'"];
NSArray* features = [source featuresMatchingPredicate:eqPredicate];
// Source won't be loaded yet, so features is 0
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape" shape:[MGLShapeCollection shapeCollectionWithShapes:@[]] options:nil];
NSArray* features = [source featuresMatchingPredicate:nil];
// Source not added yet, so features is 0
XCTAssertEqual([features count], 0);

}

@end
Loading