Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Promote Style to public API #9280

Merged
merged 4 commits into from
Jun 22, 2017
Merged

Promote Style to public API #9280

merged 4 commits into from
Jun 22, 2017

Conversation

jfirebaugh
Copy link
Contributor

Make style.hpp a public header, provide Style& Map::getStyle(), and move runtime-styling APIs that previously lived on Map to Style. This is a refactor made relatively easy by the async rendering changes. It reduces the responsibilities of the Map object itself and is a prerequisite for #6386. @1ec5, can you review what else is needed from core to support #6386? In particular, do we need Map::setStyle(std::unique_ptr<Style>)? Does Style need to be constructible without the Scheduler&, FileSource&, float pixelRatio arguments? I think we can hide those if need be.

@jfirebaugh jfirebaugh added Core The cross-platform C++ core, aka mbgl refactor labels Jun 15, 2017
@jfirebaugh jfirebaugh requested a review from 1ec5 June 15, 2017 19:19
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this gets us a lot further towards #6386.

do we need Map::setStyle(std::unique_ptr<Style>)

Yes, especially for implementing -[MGLStyle initWithURL:] and -[MGLStyle initWithJSON:] (see below), but also by analogy with the existing -[MGLMapView setStyleURL:]. The style sharing proposed in #6386 (comment) would probably complicate things, but it doesn’t strictly need to be part of the current effort.

Does Style need to be constructible without the Scheduler&, FileSource&, float pixelRatio arguments?

The file source and pixel ratio can be obtained via singletons, so the MGLStyle initializer could pass them in internally, just as -[MGLMapView commonInit] does today. (The ability to pass in a pixel ratio would recall #7819, in any case.) I’m less sure about Scheduler – it would be great if we could hide that parameter.

style::TransitionOptions getTransitionOptions() const;
void setTransitionOptions(const style::TransitionOptions&);

// Style
void setStyleURL(const std::string&);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this method, the workflow is to create the map, then set its style to a URL. #6386 also proposes exposing an -[MGLStyle initWithURL:]. I think this would require a way to initialize an mbgl::style::Style with nothing but a URL, so that later on mbgl::Map::setStyle() could be called, passing in that style. Do you see any complications with that approach? -[MGLStyle initWithJSONData:] (analogous to setStyleJSON()) is also a highly requested feature.

CGFloat pitch = _mbglMap->getStyle().getDefaultPitch();
CLLocationDirection heading = mbgl::util::wrap(_mbglMap->getStyle().getDefaultBearing(), 0., 360.);
CLLocationDistance distance = MGLAltitudeForZoomLevel(_mbglMap->getStyle().getDefaultZoom(), pitch, 0, self.frame.size);
self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(_mbglMap->getStyle().getDefaultLatLng())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, we’d add more internal properties to MGLStyle so that calls to _mbglMap->getStyle() become largely unnecessary in MGLMapView’s implementation.

@jfirebaugh jfirebaugh force-pushed the public-style branch 3 times, most recently from b1074fd to dd314a1 Compare June 21, 2017 15:21
@jfirebaugh
Copy link
Contributor Author

Cool -- I moved the JSON and URL loading methods from Map to Style as well, and added Map::setStyle.

I’m less sure about Scheduler – it would be great if we could hide that parameter.

Now that the loading methods are on Style, these parameters are all necessary. SDKs can pass the same Scheduler& as they pass to the Map constructor.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good for now! There's a possibility that we'll learn about more needs as we dig into the SDK side of the the MGLStyle refactoring, but the major work is taken care of here.

Copy link
Contributor

@ivovandongen ivovandongen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Also ran the additional Android UI tests without problems.

@@ -166,14 +153,12 @@ Map::Impl::Impl(Map& map_,
}
}) {
style = std::make_unique<Style>(scheduler, fileSource, pixelRatio);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this pr. But why aren't we initialising this in the member initialisation list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should be.

void setTransitionOptions(const TransitionOptions&);

// Light
Light* getLight();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use indentation here that is more common? Not sure if this helps with readability, but it prevents using standard formatting tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make clear the parallelism with the const version of the accessor -- you can immediately see where the consts are added, that they are in the right place, and that there aren't any other differences in the signatures. I'm opposed to using formatting tools that can't handle nuances like this.

loaded = false;
url = url_;

styleRequest = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? The next line would already destruct any previous style before assignment right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary, I'll remove it.

}

Layer* Style::Impl::addLayer(std::unique_ptr<Layer> layer, optional<std::string> before) {
// TODO: verify source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great you got rid of BackendScope here!

@jfirebaugh jfirebaugh merged commit 40e4755 into master Jun 22, 2017
@jfirebaugh jfirebaugh deleted the public-style branch June 22, 2017 15:04
@tobrun tobrun mentioned this pull request Jan 19, 2018
10 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants