### CMake Installation Rules for Application Bundle Source: https://github.com/olutter/map/blob/main/example/windows/CMakeLists.txt Configures the installation process for the application. It sets up the installation directory to be adjacent to the executable for running in place, ensures the install step is part of the default build, and specifies where various components like the executable, data files, libraries, and assets should be installed. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### CMake Installation Rules for Application Bundle Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. It sets the installation prefix, cleans the bundle directory on each build, and installs the executable, ICU data, Flutter library, bundled plugins, and assets into designated subdirectories within the bundle. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Flutter Linux GTK Build Setup (CMake) Source: https://github.com/olutter/map/blob/main/example/linux/flutter/CMakeLists.txt Configures the build environment for a Flutter Linux GTK application. It finds required packages like PkgConfig, GTK, GLIB, and GIO, defines the Flutter library path, sets essential variables for installation, and adds include directories and library linking for the Flutter interface target. ```cmake cmake_minimum_required(VERSION 3.10) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # Serves the same purpose as list(TRANSFORM ... PREPEND ...), # which isn't available in 3.10. function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() # === Flutter Library === # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt Initializes the CMake project, sets the minimum required version, and defines the project name and language. It also configures executable and application identifiers, and enforces modern CMake policies. Includes settings for RPATH and cross-compiling toolchains. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "Map") set(APPLICATION_ID "com.example.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### CMake Project Setup and Build Configuration Source: https://github.com/olutter/map/blob/main/example/windows/CMakeLists.txt Initializes the CMake project, sets the project name and languages, defines the executable binary name, and configures build types based on whether the generator supports multi-configuration builds. It also sets up specific flags and definitions for different build modes like Profile. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "Map") cmake_policy(SET CMP0063 NEW) get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Configure Flutter Web Service Worker and Load Entrypoint Source: https://github.com/olutter/map/blob/main/example/web/index.html This snippet configures the Flutter web application's service worker by specifying the base URL for CanvasKit assets. It then sets up an event listener for the 'load' event to download and execute the main Dart entry point, ensuring the Flutter engine is initialized and the application runs. ```javascript var serviceWorkerVersion = null; window.flutterConfiguration = { canvasKitBaseUrl: "canvaskit/" }; window.addEventListener('load', function(ev) { // Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, } }).then(function(engineInitializer) { return engineInitializer.initializeEngine(); }).then(function(appRunner) { return appRunner.runApp(); }); }); ``` -------------------------------- ### Full Map Application Example in Dart Source: https://context7.com/olutter/map/llms.txt This Dart code implements a comprehensive Flutter map application. It utilizes the MapController for managing map state, MapLayout for structuring the map interface, and TileLayer for displaying map tiles. The application supports pinch-to-zoom, panning, scroll wheel zooming, and a button to recenter the map. It also includes a dark mode toggle that switches between different tile server URLs. Dependencies include flutter, map, latlng, and cached_network_image. ```dart import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/gestures.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; import 'package:cached_network_image/cached_network_image.dart'; void main() => runApp(MaterialApp(home: FullMapApp())); class FullMapApp extends StatefulWidget { @override _FullMapAppState createState() => _FullMapAppState(); } class _FullMapAppState extends State { final controller = MapController( location: const LatLng(Angle.degree(35.68), Angle.degree(51.41)), zoom: 14, ); Offset? _dragStart; double _scaleStart = 1.0; bool _darkMode = false; void _onScaleStart(ScaleStartDetails details) { _dragStart = details.focalPoint; _scaleStart = 1.0; } void _onScaleUpdate(ScaleUpdateDetails details, MapTransformer transformer) { final scaleDiff = details.scale - _scaleStart; _scaleStart = details.scale; if (scaleDiff.abs() > 0.01) { controller.zoom += scaleDiff > 0 ? 0.02 : -0.02; controller.zoom = controller.zoom.clamp(1.0, 18.0); setState(() {}); } else { final now = details.focalPoint; final diff = now - _dragStart!; _dragStart = now; transformer.drag(diff.dx, diff.dy); setState(() {}); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flutter Map'), actions: [ IconButton( icon: Icon(Icons.wb_sunny), onPressed: () => setState(() => _darkMode = !_darkMode), ), ], ), body: MapLayout( controller: controller, builder: (context, transformer) { return GestureDetector( onScaleStart: _onScaleStart, onScaleUpdate: (details) => _onScaleUpdate(details, transformer), child: Listener( onPointerSignal: (event) { if (event is PointerScrollEvent) { final delta = event.scrollDelta.dy / -1000.0; final zoom = (controller.zoom + delta).clamp(2.0, 18.0); transformer.setZoomInPlace(zoom, event.localPosition); setState(() {}); } }, child: TileLayer( builder: (context, x, y, z) { final tilesInZoom = pow(2.0, z).floor(); x = (x % tilesInZoom + tilesInZoom) % tilesInZoom; y = (y % tilesInZoom + tilesInZoom) % tilesInZoom; final url = _darkMode ? 'https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/$z/$x/$y.png' : 'https://tile.openstreetmap.org/$z/$x/$y.png'; return CachedNetworkImage( imageUrl: url, fit: BoxFit.cover, ); }, ), ), ); }, ), floatingActionButton: FloatingActionButton( onPressed: () { controller.center = const LatLng(Angle.degree(35.68), Angle.degree(51.41)); controller.zoom = 14; setState(() {}); }, child: Icon(Icons.my_location), ), ); } } ``` -------------------------------- ### Install AOT Library Conditionally (CMake) Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt This CMake code snippet installs the AOT library only when the build type is not 'Debug'. It uses the `install` command with specified file paths, destination directory, and component. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Implement Interactive Map with Gestures (Pan, Zoom, Tap) Source: https://context7.com/olutter/map/llms.txt Provides a complete example of an interactive map in Flutter using the map package. It integrates pan (dragging), zoom (pinch gestures and scroll wheel), and tap gestures. Tapping on the map reveals the geographical coordinates of the tapped location. Dependencies include flutter/material, flutter/gestures, map/map, latlng/latlng, and cached_network_image. ```dart import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/gestures.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; import 'package:cached_network_image/cached_network_image.dart'; class InteractiveMap extends StatefulWidget { @override _InteractiveMapState createState() => _InteractiveMapState(); } class _InteractiveMapState extends State { final controller = MapController( location: const LatLng(Angle.degree(35.68), Angle.degree(51.41)), zoom: 14, ); Offset? _dragStart; double _scaleStart = 1.0; void _onScaleStart(ScaleStartDetails details) { _dragStart = details.focalPoint; _scaleStart = 1.0; } void _onScaleUpdate(ScaleUpdateDetails details, MapTransformer transformer) { final scaleDiff = details.scale - _scaleStart; _scaleStart = details.scale; if (scaleDiff > 0) { controller.zoom += 0.02; setState(() {}); } else if (scaleDiff < 0) { controller.zoom -= 0.02; setState(() {}); } else { final now = details.focalPoint; final diff = now - _dragStart!; _dragStart = now; transformer.drag(diff.dx, diff.dy); setState(() {}); } } void _onDoubleTap(MapTransformer transformer, Offset position) { final zoom = controller.zoom + 0.5; transformer.setZoomInPlace(zoom.clamp(2.0, 18.0), position); setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( body: MapLayout( controller: controller, builder: (context, transformer) { return GestureDetector( behavior: HitTestBehavior.opaque, onDoubleTapDown: (details) => _onDoubleTap(transformer, details.localPosition), onScaleStart: _onScaleStart, onScaleUpdate: (details) => _onScaleUpdate(details, transformer), onTapUp: (details) { final location = transformer.toLatLng(details.localPosition); showDialog( context: context, builder: (context) => AlertDialog( content: Text('Clicked: ${location.longitude}, ${location.latitude}'), ), ); }, child: Listener( behavior: HitTestBehavior.opaque, onPointerSignal: (event) { if (event is PointerScrollEvent) { final delta = event.scrollDelta.dy / -1000.0; final zoom = (controller.zoom + delta).clamp(2.0, 18.0); transformer.setZoomInPlace(zoom, event.localPosition); setState(() {}); } }, child: TileLayer( builder: (context, x, y, z) { final tilesInZoom = pow(2.0, z).floor(); x = (x % tilesInZoom + tilesInZoom) % tilesInZoom; y = (y % tilesInZoom + tilesInZoom) % tilesInZoom; final url = 'https://tile.openstreetmap.org/$z/$x/$y.png'; return CachedNetworkImage(imageUrl: url, fit: BoxFit.cover); }, ), ), ); }, ), ); } } ``` -------------------------------- ### Draw Lines on Flutter Map (Deprecated PolylineLayer) Source: https://context7.com/olutter/map/llms.txt This snippet illustrates drawing lines connecting multiple geographical points on a Flutter map using the PolylineLayer. It supports custom styling for the lines and includes an example for custom painting logic. Note: PolylineLayer is deprecated; ShapeLayer is recommended for new implementations. Dependencies include 'flutter/material.dart', 'map/map.dart', and 'latlng/latlng.dart'. ```dart import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; final polylineCoordinates = [ const LatLng(Angle.degree(35.68), Angle.degree(51.40)), const LatLng(Angle.degree(35.70), Angle.degree(51.42)), const LatLng(Angle.degree(35.72), Angle.degree(51.44)), const LatLng(Angle.degree(35.74), Angle.degree(51.46)), ]; final polyline = Polyline( data: polylineCoordinates, paint: Paint() ..strokeWidth = 4 ..color = Colors.red ..strokeCap = StrokeCap.round, offset: 0, // Pixel offset for parallel lines ); // Optional: custom painting callback final customPolyline = Polyline( data: polylineCoordinates, paint: Paint()..strokeWidth = 4, onPaint: (canvas, polyline, points) { // Custom rendering logic for (int i = 0; i < points.length - 1; i++) { final paint = Paint() ..strokeWidth = 4 ..color = Colors.primaries[i % Colors.primaries.length]; canvas.drawLine(points[i], points[i + 1], paint); } }, ); MapLayout( controller: controller, builder: (context, transformer) { return Stack( children: [ TileLayer(builder: (context, x, y, z) => Container()), PolylineLayer( transformer: transformer, polylines: [polyline, customPolyline], ), ], ); }, ) ``` -------------------------------- ### CMake Flutter and GTK Integration Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt Includes the Flutter build system from the 'flutter' subdirectory and finds system-level GTK+ 3.0 dependencies using PkgConfig. It also defines the APPLICATION_ID as a preprocessor macro for the application. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### CMake Executable Target Definition and Linking Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt Defines the main executable target using the `BINARY_NAME` variable. It lists the source files, including generated ones from Flutter plugins, applies standard build settings, and links necessary libraries such as 'flutter' and GTK. It also ensures the executable is built with the 'flutter_assemble' dependency. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Flutter Tool Backend Integration Source: https://github.com/olutter/map/blob/main/example/windows/flutter/CMakeLists.txt Sets up a custom command to invoke the Flutter tool backend. This command is designed to run every time due to a phony output file, ensuring the Flutter tool is executed for build steps. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### CMake Build Type and Compilation Settings Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt Configures the build type (Debug, Profile, Release) if not already set and defines a function `APPLY_STANDARD_SETTINGS` to apply common compilation features, options, and definitions to targets. This includes C++ standard, warning levels, optimization, and NDEBUG macro. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Flutter CMake Build Configuration Source: https://github.com/olutter/map/blob/main/example/windows/flutter/CMakeLists.txt Defines CMake build settings for Flutter projects. It includes setting up directories, including generated configuration, defining Flutter library paths, and managing header files. ```cmake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Flutter C++ Wrapper Configuration Source: https://github.com/olutter/map/blob/main/example/windows/flutter/CMakeLists.txt Configures static libraries for the Flutter C++ wrapper, used by both plugins and the application runner. It links against the Flutter library and sets include directories. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### CMake Target Properties for Output Directory Source: https://github.com/olutter/map/blob/main/example/linux/CMakeLists.txt Sets the runtime output directory for the executable target to a specific intermediate subdirectory. This is done to ensure that the bundled application launches correctly, as it relies on the relative location of resources. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Flutter Project and Runner Integration Source: https://github.com/olutter/map/blob/main/example/windows/CMakeLists.txt Includes Flutter-specific build rules by adding the Flutter managed directory as a subdirectory. It also includes the build rules for the application's runner, typically found in the 'runner' directory, and incorporates generated plugin build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/olutter/map/blob/main/example/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation features, options, and definitions to a given target. This includes setting the C++ standard to C++17, enabling specific compiler warnings and options, and managing exception handling. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Initialize MapController with Location and Zoom in Dart Source: https://context7.com/olutter/map/llms.txt Creates and configures a MapController instance with initial geographical location (latitude/longitude as Angle objects), zoom level, and map projection. The controller manages map state and provides programmatic control over center position and zoom level with automatic listener notifications for state changes. ```dart import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; // Create a controller with initial location (Tehran, Iran) and zoom level final controller = MapController( location: const LatLng(Angle.degree(35.68), Angle.degree(51.41)), zoom: 14, projection: const EPSG4326(), // Default projection ); // Update map center programmatically controller.center = const LatLng(Angle.degree(40.7128), Angle.degree(-74.0060)); // New York // Update zoom level controller.zoom = 10; // Access current values print('Current center: ${controller.center.latitude}, ${controller.center.longitude}'); print('Current zoom: ${controller.zoom}'); ``` -------------------------------- ### Define Flutter Windows Executable Target with CMake Source: https://github.com/olutter/map/blob/main/example/windows/runner/CMakeLists.txt Creates the main executable target for a Flutter Windows application using CMake's add_executable command. Includes core source files (flutter_window.cpp, main.cpp, utils.cpp, win32_window.cpp), Flutter-generated plugin registrant, and Windows-specific manifest/resource files. The WIN32 flag indicates a GUI application rather than console application. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Flutter Tool Backend Custom Command (CMake) Source: https://github.com/olutter/map/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom CMake command to execute the Flutter tool backend script. This command is triggered to generate the Flutter library and headers. It uses a phony target to ensure execution on every build, as direct input/output tracking for the Flutter tool is not feasible. ```cmake # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Display Map Tiles from OpenStreetMap and Google Maps in Dart Source: https://context7.com/olutter/map/llms.txt Implements a TileLayer widget that fetches and displays map tiles from various tile servers based on zoom level and viewport coordinates. Uses CachedNetworkImage for efficient tile caching and supports multiple tile URL formats including OpenStreetMap and Google Maps with automatic tile coordinate normalization for seamless panning. ```dart import 'dart:math'; import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:cached_network_image/cached_network_image.dart'; MapLayout( controller: controller, builder: (context, transformer) { return TileLayer( builder: (context, x, y, z) { // Normalize tile coordinates final tilesInZoom = pow(2.0, z).floor(); while (x < 0) { x += tilesInZoom; } while (y < 0) { y += tilesInZoom; } x %= tilesInZoom; y %= tilesInZoom; // OpenStreetMap tile URL format final url = 'https://tile.openstreetmap.org/$z/$x/$y.png'; // Google Maps tile URL format // final url = 'https://www.google.com/maps/vt/pb=!1m4!1m3!1i$z!2i$x!3i$y!2m3!1e0!2sm!3i420120488!3m7!2sen!5e1105!12m4!1e68!2m2!1sset!2sRoadmap!4e0!5m1!1e0!23i4111425'; return CachedNetworkImage( imageUrl: url, fit: BoxFit.cover, ); }, ); }, ) ``` -------------------------------- ### Initialize MapController with Location and Zoom Source: https://github.com/olutter/map/blob/main/README.md Create a MapController instance with initial latitude/longitude coordinates and zoom level. The location is specified using LatLng with Angle.degree for precise positioning. ```dart final controller = MapController( location: const LatLng(Angle.degree(Angle.degree(0)), Angle.degree(Angle.degree(0))), zoom: 2, ); ``` -------------------------------- ### Build MapLayout Widget with Coordinate Transformation in Dart Source: https://context7.com/olutter/map/llms.txt Constructs a MapLayout root widget that provides coordinate transformation utilities and builds the map interface. The builder callback receives a transformer object for converting between geographical coordinates and screen pixels, serving as the foundation for adding map layers like tiles, markers, and shapes. ```dart import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; class MyMapWidget extends StatelessWidget { final controller = MapController( location: const LatLng(Angle.degree(35.68), Angle.degree(51.41)), zoom: 14, ); @override Widget build(BuildContext context) { return MapLayout( controller: controller, tileSize: 256, // Standard tile size in pixels builder: (context, transformer) { // transformer provides coordinate conversion utilities // Build your map layers here return Stack( children: [ // Add TileLayer, markers, shapes, etc. Text('Map Center: ${controller.center}'), ], ); }, ); } } ``` -------------------------------- ### Convert LatLng to Screen Offset and vice versa with MapTransformer Source: https://context7.com/olutter/map/llms.txt Demonstrates how to convert geographical coordinates (LatLng) to screen pixel coordinates (Offset) and vice-versa using the MapTransformer. It also shows how to convert multiple coordinates at once and retrieve viewport and boundary information. This functionality is crucial for mapping applications that need to interact with map elements based on user input or display data points. ```dart import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; MapLayout( controller: controller, builder: (context, transformer) { // Convert LatLng to screen coordinates final location = const LatLng(Angle.degree(35.68), Angle.degree(51.41)); final screenPosition = transformer.toOffset(location); print('Screen position: ${screenPosition.dx}, ${screenPosition.dy}'); // Convert screen coordinates to LatLng final tapPosition = Offset(100, 200); final geoLocation = transformer.toLatLng(tapPosition); print('Geo location: ${geoLocation.latitude}, ${geoLocation.longitude}'); // Convert multiple coordinates at once final locations = [ const LatLng(Angle.degree(35.68), Angle.degree(51.41)), const LatLng(Angle.degree(35.70), Angle.degree(51.43)), ]; final screenPositions = transformer.toOffsetMany(locations); // Get current viewport bounds final viewport = transformer.getViewport(); print('Viewport: ${viewport.left}, ${viewport.top}, ${viewport.right}, ${viewport.bottom}'); // Get visible geographical boundary final boundary = transformer.getBoundary(); print('Boundary: ${boundary.topLeft} to ${boundary.bottomRight}'); return Container(); }, ) ``` -------------------------------- ### Custom CMake List Prepend Function Source: https://github.com/olutter/map/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom CMake function `list_prepend` to add a prefix to each element of a list. This is a workaround for older CMake versions (pre-3.10) that lack the `list(TRANSFORM ... PREPEND ...)` command. It takes a list name and a prefix as input and modifies the list in place. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Build Map Layout with Tile Layer and Google Maps Source: https://github.com/olutter/map/blob/main/README.md Create a complete map layout using MapLayout and TileLayer widgets with Google Maps tile provider. The builder handles tile coordinate transformation and caching through CachedNetworkImage. ```dart MapLayout( controller: controller, builder: (context, transformer) { return TileLayer( builder: (context, x, y, z) { final tilesInZoom = pow(2.0, z).floor(); while (x < 0) { x += tilesInZoom; } while (y < 0) { y += tilesInZoom; } x %= tilesInZoom; y %= tilesInZoom; //Google Maps final url = 'https://www.google.com/maps/vt/pb=!1m4!1m3!1i$z!2i$x!3i$y!2m3!1e0!2sm!3i420120488!3m7!2sen!5e1105!12m4!1e68!2m2!1sset!2sRoadmap!4e0!5m1!1e0!23i4111425'; return CachedNetworkImage( imageUrl: url, fit: BoxFit.cover, ); }, ); }, ); ``` -------------------------------- ### Link Flutter Dependencies and Configure Include Directories in CMake Source: https://github.com/olutter/map/blob/main/example/windows/runner/CMakeLists.txt Links the Flutter framework libraries (flutter and flutter_wrapper_app) to the executable target and sets the include directory path to the CMake source directory. This enables the application to access Flutter headers and libraries during compilation and linking. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Apply Standard Build Settings and Disable Windows Name Collisions Source: https://github.com/olutter/map/blob/main/example/windows/runner/CMakeLists.txt Applies Flutter's standard CMake build configuration settings to ensure consistent compilation flags and optimization levels. Also defines NOMINMAX preprocessor flag to disable Windows macros (min/max) that conflict with C++ standard library functions like std::min and std::max. ```cmake apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Import Flutter Map Package Source: https://github.com/olutter/map/blob/main/README.md Import the map package into your Dart file to access all map-related classes and widgets. ```dart import 'package:map/map.dart'; ``` -------------------------------- ### Add Flutter Version Preprocessor Definitions in CMake Source: https://github.com/olutter/map/blob/main/example/windows/runner/CMakeLists.txt Defines compile-time preprocessor macros for Flutter version information including major, minor, patch, and build numbers. These definitions are passed to the compiler for the specified target and can be accessed in C++ code via #ifdef directives or as string constants during compilation. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Add Flutter Map Package Dependency Source: https://github.com/olutter/map/blob/main/README.md Configure the map package in your Flutter project's pubspec.yaml file. This is the first step to integrate the map widget into your application. ```yaml dependencies: map: any ``` -------------------------------- ### Add Interactive Markers to Flutter Map Source: https://context7.com/olutter/map/llms.txt This snippet demonstrates how to display custom markers at specific geographical coordinates on a Flutter map. It includes functionality for tap interactions, allowing users to trigger actions when a marker is clicked. Dependencies include 'flutter/material.dart', 'map/map.dart', and 'latlng/latlng.dart'. ```dart import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; class MapWithMarkers extends StatefulWidget { @override _MapWithMarkersState createState() => _MapWithMarkersState(); } class _MapWithMarkersState extends State { final controller = MapController( location: const LatLng(Angle.degree(35.68), Angle.degree(51.41)), zoom: 14, ); final markers = [ const LatLng(Angle.degree(35.674), Angle.degree(51.41)), const LatLng(Angle.degree(35.678), Angle.degree(51.41)), const LatLng(Angle.degree(35.682), Angle.degree(51.41)), ]; Widget _buildMarker(Offset pos, Color color) { return Positioned( left: pos.dx - 24, top: pos.dy - 24, width: 48, height: 48, child: GestureDetector( child: Icon(Icons.location_on, color: color, size: 48), onTap: () { showDialog( context: context, builder: (context) => AlertDialog( content: Text('Marker clicked!'), ), ); }, ), ); } @override Widget build(BuildContext context) { return MapLayout( controller: controller, builder: (context, transformer) { final markerWidgets = markers .map((location) => transformer.toOffset(location)) .map((pos) => _buildMarker(pos, Colors.red)) .toList(); return Stack( children: [ TileLayer(builder: (context, x, y, z) { // Tile loading code here return Container(); }), ...markerWidgets, ], ); }, ); } } ``` -------------------------------- ### Add Flutter Build Assembly Dependency in CMake Source: https://github.com/olutter/map/blob/main/example/windows/runner/CMakeLists.txt Registers flutter_assemble as a build dependency for the executable target, ensuring that Flutter's build tool processes (code generation, asset compilation, etc.) are executed before the main executable is compiled and linked. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Control Map Zoom and Pan with Transformations in Flutter Source: https://context7.com/olutter/map/llms.txt This Dart code snippet demonstrates how to programmatically control map zoom and pan transformations within a Flutter application. It utilizes the map package to adjust the map's view, including zooming in/out at the center, panning the map by a specified offset, and navigating to a predefined geographical location like New York. This functionality is crucial for creating interactive map experiences. ```dart import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; MapLayout( controller: controller, builder: (context, transformer) { return Column( children: [ Expanded( child: TileLayer(builder: (context, x, y, z) => Container()), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( onPressed: () { // Zoom in at center final centerOffset = Offset( transformer.constraints.biggest.width / 2, transformer.constraints.biggest.height / 2, ); transformer.setZoomInPlace(controller.zoom + 1, centerOffset); }, child: Text('Zoom In'), ), ElevatedButton( onPressed: () { // Zoom out at center final centerOffset = Offset( transformer.constraints.biggest.width / 2, transformer.constraints.biggest.height / 2, ); transformer.setZoomInPlace(controller.zoom - 1, centerOffset); }, child: Text('Zoom Out'), ), ElevatedButton( onPressed: () { // Pan map by 100 pixels right and 50 pixels down transformer.drag(-100, -50); }, child: Text('Pan'), ), ElevatedButton( onPressed: () { // Go to specific location controller.center = const LatLng( Angle.degree(40.7128), Angle.degree(-74.0060), ); controller.zoom = 12; }, child: Text('New York'), ), ], ), ], ); }, ) ``` -------------------------------- ### Draw Polygons on Flutter Map using ShapeLayer Source: https://context7.com/olutter/map/llms.txt This snippet shows how to draw custom polygons and shapes on a Flutter map using the ShapeLayer. It utilizes a custom painter function to define the appearance of the shapes and accepts geographical coordinates as input. Dependencies include 'flutter/material.dart', 'map/map.dart', and 'latlng/latlng.dart'. ```dart import 'package:flutter/material.dart'; import 'package:map/map.dart'; import 'package:latlng/latlng.dart'; // Define a custom painter function void _polygonPainter(Canvas canvas, List points, Object? metadata) { final paint = Paint() ..style = PaintingStyle.fill ..color = Colors.blue.withOpacity(0.3); final path = Path()..addPolygon(points, true); canvas.drawPath(path, paint); // Draw border final borderPaint = Paint() ..style = PaintingStyle.stroke ..color = Colors.blue ..strokeWidth = 2; canvas.drawPath(path, borderPaint); } // Create shape with geographical coordinates final shape = Shape( points: const [ LatLng(Angle.degree(35.68), Angle.degree(51.40)), LatLng(Angle.degree(35.70), Angle.degree(51.42)), LatLng(Angle.degree(35.68), Angle.degree(51.44)), LatLng(Angle.degree(35.66), Angle.degree(51.42)), ], painter: _polygonPainter, metadata: {'name': 'Custom Area', 'id': 123}, ); // Use in MapLayout MapLayout( controller: controller, builder: (context, transformer) { return Stack( children: [ TileLayer(builder: (context, x, y, z) => Container()), ShapeLayer( transformer: transformer, shapes: [shape], ), ], ); }, ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.