diff options
author | Vladimir Agafonkin <agafonkin@gmail.com> | 2018-01-26 18:47:37 +0200 |
---|---|---|
committer | Vladimir Agafonkin <agafonkin@gmail.com> | 2018-01-26 18:47:37 +0200 |
commit | 12b2876464c0d518a21c1090b47f1fd0f2190fc3 (patch) | |
tree | d038a4b589a5c4177ae975f49ceaa6972e3fcfad | |
parent | e3dc31f93b598e56d39a042b36be4d8866cda9f2 (diff) | |
download | qtlocation-mapboxgl-12b2876464c0d518a21c1090b47f1fd0f2190fc3.tar.gz |
address review comments
-rw-r--r-- | include/mbgl/style/conversion/heatmap_color_property_value.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/heatmap_color_property_value.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/layer_type.hpp | 2 | ||||
-rwxr-xr-x | platform/darwin/scripts/generate-style-code.js | 3 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 24 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 14 | ||||
-rw-r--r-- | scripts/style-spec.js | 2 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/heatmap_bucket.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_heatmap_layer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/renderer_impl.cpp | 11 |
11 files changed, 36 insertions, 46 deletions
diff --git a/include/mbgl/style/conversion/heatmap_color_property_value.hpp b/include/mbgl/style/conversion/heatmap_color_property_value.hpp index 72b17bc112..e3689c524c 100644 --- a/include/mbgl/style/conversion/heatmap_color_property_value.hpp +++ b/include/mbgl/style/conversion/heatmap_color_property_value.hpp @@ -24,6 +24,7 @@ struct Converter<HeatmapColorPropertyValue> { if (!expression) { return {}; } + assert(*expression); if (!isFeatureConstant(**expression)) { error = { "property expressions not supported" }; return {}; @@ -43,4 +44,3 @@ struct Converter<HeatmapColorPropertyValue> { } // namespace conversion } // namespace style } // namespace mbgl - diff --git a/include/mbgl/style/heatmap_color_property_value.hpp b/include/mbgl/style/heatmap_color_property_value.hpp index 7d97b5e137..a530fc5332 100644 --- a/include/mbgl/style/heatmap_color_property_value.hpp +++ b/include/mbgl/style/heatmap_color_property_value.hpp @@ -16,7 +16,7 @@ private: std::shared_ptr<expression::Expression> value; friend bool operator==(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { - return *(lhs.value) == *(rhs.value); + return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value)); } friend bool operator!=(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { diff --git a/include/mbgl/style/layer_type.hpp b/include/mbgl/style/layer_type.hpp index 69390d642a..0987ea4d0a 100644 --- a/include/mbgl/style/layer_type.hpp +++ b/include/mbgl/style/layer_type.hpp @@ -13,7 +13,7 @@ enum class LayerType { Background, Custom, FillExtrusion, - Heatmap + Heatmap, }; } // namespace style diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index af39584c91..59654eca34 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -387,7 +387,7 @@ global.describeValue = function (value, property, layerType) { throw new Error(`No description available for ${value[0]} expression in ${property.name} of ${layerType}.`); } } - + switch (property.type) { case 'boolean': return value ? '`YES`' : '`NO`'; @@ -414,7 +414,6 @@ global.describeValue = function (value, property, layerType) { } return displayValue; case 'color': - if (property.name === 'heatmap-color') value = 'red'; let color = parseColor(value); if (!color) { throw new Error(`unrecognized color format in default value of ${property.name}`); diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 1de5c7f316..e3623a570a 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -216,7 +216,7 @@ static NSURL *MGLStyleURL_trafficNight; - (MGLSource *)sourceWithIdentifier:(NSString *)identifier { auto rawSource = self.rawStyle->getSource(identifier.UTF8String); - + return rawSource ? [self sourceFromMBGLSource:rawSource] : nil; } @@ -602,7 +602,7 @@ static NSURL *MGLStyleURL_trafficNight; auto transitionOptions = self.rawStyle->getTransitionOptions(); transitionOptions.duration = MGLDurationFromTimeInterval(transition.duration); transitionOptions.delay = MGLDurationFromTimeInterval(transition.delay); - + self.rawStyle->setTransitionOptions(transitionOptions); } @@ -613,7 +613,7 @@ static NSURL *MGLStyleURL_trafficNight; transition.delay = MGLTimeIntervalFromDuration(transitionOptions.delay.value_or(mbgl::Duration::zero())); transition.duration = MGLTimeIntervalFromDuration(transitionOptions.duration.value_or(mbgl::Duration::zero())); - + return transition; } @@ -649,7 +649,7 @@ static NSURL *MGLStyleURL_trafficNight; } else { return; } - + if (_localizesLabels) { NSString *preferredLanguage = [MGLVectorSource preferredMapboxStreetsLanguage]; NSMutableDictionary *localizedKeysByKeyBySourceIdentifier = [NSMutableDictionary dictionary]; @@ -657,17 +657,17 @@ static NSURL *MGLStyleURL_trafficNight; if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) { continue; } - + MGLVectorSource *source = (MGLVectorSource *)[self sourceWithIdentifier:layer.sourceIdentifier]; if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) { continue; } - + NSDictionary *localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier]; if (!localizedKeysByKey) { localizedKeysByKey = localizedKeysByKeyBySourceIdentifier[layer.sourceIdentifier] = [source localizedKeysByKeyForPreferredLanguage:preferredLanguage]; } - + NSString *(^stringByLocalizingString)(NSString *) = ^ NSString * (NSString *string) { NSMutableString *localizedString = string.mutableCopy; [localizedKeysByKey enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull localizedKey, BOOL * _Nonnull stop) { @@ -680,7 +680,7 @@ static NSURL *MGLStyleURL_trafficNight; }]; return localizedString; }; - + if (layer.text.expressionType == NSConstantValueExpressionType) { NSString *textField = layer.text.constantValue; NSString *localizingString = stringByLocalizingString(textField); @@ -693,10 +693,10 @@ static NSURL *MGLStyleURL_trafficNight; } } } else { - + [self.localizedLayersByIdentifier enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSDictionary<NSObject *, MGLTextLanguage *> *textFields, BOOL *done) { MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:identifier]; - + if (layer.text.expressionType == NSConstantValueExpressionType) { NSString *textField = layer.text.constantValue; [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *originalLanguage, MGLTextLanguage *textLanguage, BOOL *done) { @@ -720,7 +720,7 @@ static NSURL *MGLStyleURL_trafficNight; - (NS_ARRAY_OF(MGLStyleLayer *) *)placeStyleLayers { NSSet *streetsSourceIdentifiers = [self.mapboxStreetsSources valueForKey:@"identifier"]; - + NSSet *placeSourceLayerIdentifiers = [NSSet setWithObjects:@"marine_label", @"country_label", @"state_label", @"place_label", @"water_label", @"poi_label", @"rail_station_label", @"mountain_peak_label", nil]; NSPredicate *isPlacePredicate = [NSPredicate predicateWithBlock:^BOOL (MGLVectorStyleLayer * _Nullable layer, NSDictionary<NSString *, id> * _Nullable bindings) { return [layer isKindOfClass:[MGLVectorStyleLayer class]] && [streetsSourceIdentifiers containsObject:layer.sourceIdentifier] && [placeSourceLayerIdentifiers containsObject:layer.sourceLayerIdentifier]; @@ -730,7 +730,7 @@ static NSURL *MGLStyleURL_trafficNight; - (NS_ARRAY_OF(MGLStyleLayer *) *)roadStyleLayers { NSSet *streetsSourceIdentifiers = [self.mapboxStreetsSources valueForKey:@"identifier"]; - + NSPredicate *isPlacePredicate = [NSPredicate predicateWithBlock:^BOOL (MGLVectorStyleLayer * _Nullable layer, NSDictionary<NSString *, id> * _Nullable bindings) { return [layer isKindOfClass:[MGLVectorStyleLayer class]] && [streetsSourceIdentifiers containsObject:layer.sourceIdentifier] && [layer.sourceLayerIdentifier isEqualToString:@"road_label"]; }]; diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 879cae8a4f..787bacbcee 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -530,7 +530,7 @@ void NodeMap::release() { uv_close(reinterpret_cast<uv_handle_t *>(async), [] (uv_handle_t *h) { delete reinterpret_cast<uv_async_t *>(h); }); - + map.reset(); frontend.reset(); } @@ -558,7 +558,7 @@ void NodeMap::Cancel(const Nan::FunctionCallbackInfo<v8::Value>& info) { void NodeMap::cancel() { auto style = map->getStyle().getJSON(); - + // Reset map explicitly as it resets the renderer frontend map.reset(); @@ -707,7 +707,7 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo<v8::Value>& info) { float pixelRatio = Nan::Get(optionObject, Nan::New("pixelRatio").ToLocalChecked()).ToLocalChecked()->NumberValue(); auto imageBuffer = Nan::To<v8::Object>(info[1]).ToLocalChecked()->ToObject(); - + char * imageDataBuffer = node::Buffer::Data(imageBuffer); size_t imageLength = node::Buffer::Length(imageBuffer); @@ -717,7 +717,7 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo<v8::Value>& info) { std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(imageLength); std::copy(imageDataBuffer, imageDataBuffer + imageLength, data.get()); - + mbgl::UnassociatedImage cImage({ imageWidth, imageHeight}, std::move(data)); mbgl::PremultipliedImage cPremultipliedImage = mbgl::util::premultiply(std::move(cImage)); nodeMap->map->getStyle().addImage(std::make_unique<mbgl::style::Image>(*Nan::Utf8String(info[0]), std::move(cPremultipliedImage), pixelRatio)); @@ -1046,9 +1046,9 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>& if (!info[1]->IsObject()) { return Nan::ThrowTypeError("options argument must be an object"); } - + auto options = Nan::To<v8::Object>(info[1]).ToLocalChecked(); - + //Check if layers is set. If provided, it must be an array of strings if (Nan::Has(options, Nan::New("layers").ToLocalChecked()).FromJust()) { auto layersOption = Nan::Get(options, Nan::New("layers").ToLocalChecked()).ToLocalChecked(); @@ -1062,7 +1062,7 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>& } queryOptions.layerIDs = layersVec; } - + //Check if filter is provided. If set it must be a valid Filter object if (Nan::Has(options, Nan::New("filter").ToLocalChecked()).FromJust()) { auto filterOption = Nan::Get(options, Nan::New("filter").ToLocalChecked()).ToLocalChecked(); diff --git a/scripts/style-spec.js b/scripts/style-spec.js index 8a9c9d4144..196adc0b32 100644 --- a/scripts/style-spec.js +++ b/scripts/style-spec.js @@ -1 +1,3 @@ var spec = module.exports = require('../mapbox-gl-js/src/style-spec/reference/v8'); + +// Make temporary modifications here when Native doesn't have all features that JS has. diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index e5a57666de..98eda1df54 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -137,15 +137,14 @@ public: obj.size = image.size; } - // Creates an empty texture with the specified dimensions. + // Creates a texture from raw data Texture createTexture(const Size size, TextureFormat format = TextureFormat::RGBA, - TextureUnit unit = 0) { - return { size, createTexture(size, nullptr, format, unit) }; + TextureUnit unit = 0, + const void* data = nullptr) { + return { size, createTexture(size, data, format, unit) }; } - UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit); - void bindTexture(Texture&, TextureUnit = 0, TextureFilter = TextureFilter::Nearest, @@ -261,6 +260,7 @@ private: void updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size); UniqueBuffer createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage); void updateIndexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size); + UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit); void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit); UniqueFramebuffer createFramebuffer(); UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size); diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.cpp b/src/mbgl/renderer/buckets/heatmap_bucket.cpp index 198f977398..a185e04ad2 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.cpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.cpp @@ -90,16 +90,6 @@ void HeatmapBucket::addFeature(const GeometryTileFeature& feature, } } -template <class Property> -static float get(const RenderHeatmapLayer& layer, const std::map<std::string, HeatmapProgram::PaintPropertyBinders>& paintPropertyBinders) { - auto it = paintPropertyBinders.find(layer.getID()); - if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) { - return layer.evaluated.get<Property>().constantOr(Property::defaultValue()); - } else { - return *it->second.statistics<Property>().max(); - } -} - float HeatmapBucket::getQueryRadius(const RenderLayer& layer) const { (void)layer; return 0; diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 6f4793b31f..f39c6c3efc 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -60,7 +60,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { if (!colorRampTexture) { const auto colorRampSize = Size{256, 1}; - colorRampTexture = gl::Texture{colorRampSize, parameters.context.createTexture(colorRampSize, colorRamp.data(), gl::TextureFormat::RGBA, 1)}; + colorRampTexture = parameters.context.createTexture(colorRampSize, gl::TextureFormat::RGBA, 1, colorRamp.data()); } renderTexture->bind(); diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 94f150e7df..2d912dd26b 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -93,9 +93,9 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { // Reset zoom history state. zoomHistory.first = true; } - + assert(BackendScope::exists()); - + updateParameters.annotationManager.updateData(); const bool zoomChanged = zoomHistory.update(updateParameters.transformState.getZoom(), updateParameters.timePoint); @@ -192,7 +192,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { } } - if (layerAdded || layerChanged || zoomChanged || layer.hasTransition()) { layer.evaluate(evaluationParameters); } @@ -410,7 +409,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { if (placementChanged || symbolBucketsChanged) { placement = std::move(newPlacement); } - + placement->setRecent(parameters.timePoint); updateFadingTiles(); @@ -435,7 +434,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { parameters.imageManager.upload(parameters.context, 0); parameters.lineAtlas.upload(parameters.context, 0); - + // Update all clipping IDs + upload buckets. for (const auto& entry : renderSources) { if (entry.second->isEnabled()) { @@ -778,7 +777,7 @@ bool Renderer::Impl::hasTransitions(TimePoint timePoint) const { if (placement->hasTransitions(timePoint)) { return true; } - + if (fadingTiles) { return true; } |