diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-07-04 18:45:02 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-07-05 11:46:24 +0300 |
commit | 494b186b1a2b08e31d3e3726897d6e157bbca3e8 (patch) | |
tree | e4de071de75ae63e98a737ca77c0d5500cae43ab | |
parent | 4c896cbb31fcb929b0e57c7bd02e519c267a1be1 (diff) | |
download | qtlocation-mapboxgl-upstream/tmpsantos-glfw_add_route_from_geojson.tar.gz |
-rw-r--r-- | platform/glfw/glfw_view.cpp | 33 | ||||
-rw-r--r-- | platform/glfw/ny_route.hpp | 190 |
2 files changed, 132 insertions, 91 deletions
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 41c3e93b35..8ec1e70cc0 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -6,10 +6,12 @@ #include <mbgl/annotation/annotation.hpp> #include <mbgl/style/style.hpp> #include <mbgl/style/sources/custom_geometry_source.hpp> +#include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/image.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/layers/fill_extrusion_layer.hpp> #include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> #include <mbgl/style/expression/dsl.hpp> #include <mbgl/util/logging.hpp> #include <mbgl/util/platform.hpp> @@ -250,6 +252,37 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, view->map->flyTo(cameraOptions, animationOptions); nextPlace = nextPlace % places.size(); } break; + case GLFW_KEY_F: { + using namespace mbgl; + using namespace mbgl::style; + using namespace mbgl::style::expression::dsl; + + auto source = std::make_unique<GeoJSONSource>("route"); + source->setGeoJSON(mapbox::geojson::parse(mbgl::platform::glfw::route)); + + auto& style = view->map->getStyle(); + style.addSource(std::move(source)); + + auto routeLayerCase = std::make_unique<LineLayer>("route-case", "route"); + routeLayerCase->setLineColor(mbgl::Color{ 0.0, 1.0, 0.0, 1.0 }); + routeLayerCase->setLineWidth(PropertyExpression<float>(get("width_case"))); + + style.addLayer(std::move(routeLayerCase)); + + auto routeLayer = std::make_unique<LineLayer>("route", "route"); + routeLayer->setLineColor(mbgl::Color{ 1.0, 0.0, 0.0, 1.0 }); + routeLayer->setLineWidth(PropertyExpression<float>(get("width"))); + + style.addLayer(std::move(routeLayer)); + + auto routeLabelLayer = std::make_unique<SymbolLayer>("route-label", "route"); + routeLabelLayer->setTextField(PropertyExpression<expression::Formatted>(toFormatted(get("label")))); + routeLabelLayer->setSymbolPlacement(SymbolPlacementType::Line); + routeLabelLayer->setSymbolSpacing(2); + + style.addLayer(std::move(routeLabelLayer)); + + } break; case GLFW_KEY_R: { view->show3DExtrusions = true; view->toggle3DExtrusions(view->show3DExtrusions); diff --git a/platform/glfw/ny_route.hpp b/platform/glfw/ny_route.hpp index c3d5157106..5c24af5849 100644 --- a/platform/glfw/ny_route.hpp +++ b/platform/glfw/ny_route.hpp @@ -6,97 +6,105 @@ namespace glfw { constexpr const char* route = R"route( { - "coordinates": [ - [ -74.013841, 40.702449 ], - [ -74.013863, 40.702462 ], - [ -74.013977, 40.702548 ], - [ -74.01404, 40.702595 ], - [ -74.014152, 40.702685 ], - [ -74.014213, 40.702749 ], - [ -74.014284, 40.702835 ], - [ -74.014333, 40.702911 ], - [ -74.014368, 40.702978 ], - [ -74.014407, 40.703066 ], - [ -74.014438, 40.703152 ], - [ -74.014449, 40.703209 ], - [ -74.01445, 40.703263 ], - [ -74.01445, 40.703332 ], - [ -74.014442, 40.703401 ], - [ -74.014404, 40.703614 ], - [ -74.014245, 40.704524 ], - [ -74.01422, 40.704633 ], - [ -74.014329, 40.704667 ], - [ -74.01445, 40.704705 ], - [ -74.014548, 40.704733 ], - [ -74.014641, 40.704756 ], - [ -74.014727, 40.704776 ], - [ -74.014841, 40.704799 ], - [ -74.014977, 40.704827 ], - [ -74.015033, 40.704838 ], - [ -74.015365, 40.704905 ], - [ -74.015454, 40.704921 ], - [ -74.015541, 40.704933 ], - [ -74.015638, 40.704945 ], - [ -74.015699, 40.70495 ], - [ -74.015755, 40.704953 ], - [ -74.01583, 40.704952 ], - [ -74.015909, 40.704949 ], - [ -74.016073, 40.704935 ], - [ -74.016157, 40.704927 ], - [ -74.016224, 40.704921 ], - [ -74.016284, 40.70491 ], - [ -74.016416, 40.704882 ], - [ -74.016424, 40.704918 ], - [ -74.016437, 40.704962 ], - [ -74.016453, 40.705007 ], - [ -74.016462, 40.705041 ], - [ -74.016467, 40.705072 ], - [ -74.016463, 40.705112 ], - [ -74.016457, 40.70515 ], - [ -74.016447, 40.705189 ], - [ -74.016151, 40.705949 ], - [ -74.016121, 40.706032 ], - [ -74.01609, 40.706121 ], - [ -74.01606, 40.706214 ], - [ -74.016037, 40.706296 ], - [ -74.016016, 40.706383 ], - [ -74.016003, 40.70645 ], - [ -74.015986, 40.706549 ], - [ -74.015971, 40.706613 ], - [ -74.015953, 40.706677 ], - [ -74.015888, 40.706844 ], - [ -74.015805, 40.707053 ], - [ -74.015735, 40.707222 ], - [ -74.015697, 40.707307 ], - [ -74.015597, 40.70752 ], - [ -74.015512, 40.707701 ], - [ -74.015476, 40.707784 ], - [ -74.015442, 40.707859 ], - [ -74.015363, 40.708065 ], - [ -74.015197, 40.708495 ], - [ -74.014864, 40.709446 ], - [ -74.01476, 40.709725 ], - [ -74.014744, 40.709777 ], - [ -74.014729, 40.709827 ], - [ -74.01472, 40.709873 ], - [ -74.014712, 40.709925 ], - [ -74.014709, 40.709998 ], - [ -74.014699, 40.710139 ], - [ -74.014689, 40.710215 ], - [ -74.014674, 40.710286 ], - [ -74.014655, 40.710373 ], - [ -74.014631, 40.710477 ], - [ -74.014602, 40.710583 ], - [ -74.014523, 40.710825 ], - [ -74.014492, 40.710899 ], - [ -74.014463, 40.710966 ], - [ -74.014434, 40.711033 ], - [ -74.014406, 40.711098 ], - [ -74.01438, 40.711171 ], - [ -74.01436, 40.71125 ], - [ -74.014147, 40.712245 ] - ], - "type": "LineString" + "type": "Feature", + "properties": { + "label": "Name of the road", + "width": 10, + "width_case": 25 + }, + "geometry": { + "coordinates": [ + [ -74.013841, 40.702449 ], + [ -74.013863, 40.702462 ], + [ -74.013977, 40.702548 ], + [ -74.01404, 40.702595 ], + [ -74.014152, 40.702685 ], + [ -74.014213, 40.702749 ], + [ -74.014284, 40.702835 ], + [ -74.014333, 40.702911 ], + [ -74.014368, 40.702978 ], + [ -74.014407, 40.703066 ], + [ -74.014438, 40.703152 ], + [ -74.014449, 40.703209 ], + [ -74.01445, 40.703263 ], + [ -74.01445, 40.703332 ], + [ -74.014442, 40.703401 ], + [ -74.014404, 40.703614 ], + [ -74.014245, 40.704524 ], + [ -74.01422, 40.704633 ], + [ -74.014329, 40.704667 ], + [ -74.01445, 40.704705 ], + [ -74.014548, 40.704733 ], + [ -74.014641, 40.704756 ], + [ -74.014727, 40.704776 ], + [ -74.014841, 40.704799 ], + [ -74.014977, 40.704827 ], + [ -74.015033, 40.704838 ], + [ -74.015365, 40.704905 ], + [ -74.015454, 40.704921 ], + [ -74.015541, 40.704933 ], + [ -74.015638, 40.704945 ], + [ -74.015699, 40.70495 ], + [ -74.015755, 40.704953 ], + [ -74.01583, 40.704952 ], + [ -74.015909, 40.704949 ], + [ -74.016073, 40.704935 ], + [ -74.016157, 40.704927 ], + [ -74.016224, 40.704921 ], + [ -74.016284, 40.70491 ], + [ -74.016416, 40.704882 ], + [ -74.016424, 40.704918 ], + [ -74.016437, 40.704962 ], + [ -74.016453, 40.705007 ], + [ -74.016462, 40.705041 ], + [ -74.016467, 40.705072 ], + [ -74.016463, 40.705112 ], + [ -74.016457, 40.70515 ], + [ -74.016447, 40.705189 ], + [ -74.016151, 40.705949 ], + [ -74.016121, 40.706032 ], + [ -74.01609, 40.706121 ], + [ -74.01606, 40.706214 ], + [ -74.016037, 40.706296 ], + [ -74.016016, 40.706383 ], + [ -74.016003, 40.70645 ], + [ -74.015986, 40.706549 ], + [ -74.015971, 40.706613 ], + [ -74.015953, 40.706677 ], + [ -74.015888, 40.706844 ], + [ -74.015805, 40.707053 ], + [ -74.015735, 40.707222 ], + [ -74.015697, 40.707307 ], + [ -74.015597, 40.70752 ], + [ -74.015512, 40.707701 ], + [ -74.015476, 40.707784 ], + [ -74.015442, 40.707859 ], + [ -74.015363, 40.708065 ], + [ -74.015197, 40.708495 ], + [ -74.014864, 40.709446 ], + [ -74.01476, 40.709725 ], + [ -74.014744, 40.709777 ], + [ -74.014729, 40.709827 ], + [ -74.01472, 40.709873 ], + [ -74.014712, 40.709925 ], + [ -74.014709, 40.709998 ], + [ -74.014699, 40.710139 ], + [ -74.014689, 40.710215 ], + [ -74.014674, 40.710286 ], + [ -74.014655, 40.710373 ], + [ -74.014631, 40.710477 ], + [ -74.014602, 40.710583 ], + [ -74.014523, 40.710825 ], + [ -74.014492, 40.710899 ], + [ -74.014463, 40.710966 ], + [ -74.014434, 40.711033 ], + [ -74.014406, 40.711098 ], + [ -74.01438, 40.711171 ], + [ -74.01436, 40.71125 ], + [ -74.014147, 40.712245 ] + ], + "type": "LineString" + } })route"; } // namespace glfw |