@mapgis/mapbox-gl 16.0.1 → 16.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mapbox-gl.js +3 -3
- package/dist/mapbox-gl.js.map +1 -1
- package/package.json +1 -1
- package/.flowconfig +0 -61
- package/LICENSE.txt +0 -84
- package/README.md +0 -34
- package/build/banner.js +0 -4
- package/build/check-bundle-size.js +0 -140
- package/build/generate-access-token-script.js +0 -11
- package/build/generate-flow-typed-style-spec.js +0 -188
- package/build/generate-release-list.js +0 -21
- package/build/generate-struct-arrays.js +0 -237
- package/build/generate-style-code.js +0 -159
- package/build/mapbox-gl.js.flow +0 -3
- package/build/print-release-url.js +0 -6
- package/build/rollup_plugin_minify_style_spec.js +0 -20
- package/build/rollup_plugins.js +0 -80
- package/build/run-node +0 -3
- package/build/run-tap +0 -8
- package/build/test/build-tape.js +0 -19
- package/flow-typed/gl.js +0 -5
- package/flow-typed/jsdom.js +0 -18
- package/flow-typed/mapbox-gl-supported.js +0 -9
- package/flow-typed/mapbox-unitbezier.js +0 -14
- package/flow-typed/offscreen-canvas.js +0 -9
- package/flow-typed/pbf.js +0 -25
- package/flow-typed/point-geometry.js +0 -44
- package/flow-typed/potpack.js +0 -12
- package/flow-typed/sinon.js +0 -28
- package/flow-typed/vector-tile.js +0 -41
- package/src/css/mapbox-gl.css +0 -798
- package/src/css/svg/mapboxgl-ctrl-attrib.svg +0 -3
- package/src/css/svg/mapboxgl-ctrl-compass.svg +0 -4
- package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +0 -3
- package/src/css/svg/mapboxgl-ctrl-geolocate.svg +0 -5
- package/src/css/svg/mapboxgl-ctrl-logo.svg +0 -20
- package/src/css/svg/mapboxgl-ctrl-shrink.svg +0 -3
- package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +0 -3
- package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +0 -3
- package/src/data/array_types.js +0 -1095
- package/src/data/bucket/circle_attributes.js +0 -9
- package/src/data/bucket/circle_bucket.js +0 -204
- package/src/data/bucket/fill_attributes.js +0 -9
- package/src/data/bucket/fill_bucket.js +0 -233
- package/src/data/bucket/fill_extrusion_attributes.js +0 -10
- package/src/data/bucket/fill_extrusion_bucket.js +0 -289
- package/src/data/bucket/heatmap_bucket.js +0 -17
- package/src/data/bucket/line_attributes.js +0 -10
- package/src/data/bucket/line_bucket.js +0 -556
- package/src/data/bucket/pattern_attributes.js +0 -10
- package/src/data/bucket/pattern_bucket_features.js +0 -60
- package/src/data/bucket/symbol_attributes.js +0 -117
- package/src/data/bucket/symbol_bucket.js +0 -972
- package/src/data/bucket.js +0 -123
- package/src/data/dem_data.js +0 -125
- package/src/data/extent.js +0 -18
- package/src/data/feature_index.js +0 -321
- package/src/data/feature_position_map.js +0 -125
- package/src/data/index_array_type.js +0 -16
- package/src/data/load_geometry.js +0 -48
- package/src/data/pos_attributes.js +0 -6
- package/src/data/program_configuration.js +0 -687
- package/src/data/raster_bounds_attributes.js +0 -7
- package/src/data/segment.js +0 -76
- package/src/geo/edge_insets.js +0 -102
- package/src/geo/lng_lat.js +0 -165
- package/src/geo/lng_lat_bounds.js +0 -267
- package/src/geo/mercator_coordinate.js +0 -153
- package/src/geo/transform.js +0 -864
- package/src/gl/color_mode.js +0 -34
- package/src/gl/context.js +0 -298
- package/src/gl/cull_face_mode.js +0 -26
- package/src/gl/depth_mode.js +0 -29
- package/src/gl/framebuffer.js +0 -44
- package/src/gl/index_buffer.js +0 -55
- package/src/gl/stencil_mode.js +0 -30
- package/src/gl/types.js +0 -84
- package/src/gl/value.js +0 -520
- package/src/gl/vertex_buffer.js +0 -119
- package/src/index.js +0 -201
- package/src/render/draw_background.js +0 -57
- package/src/render/draw_circle.js +0 -113
- package/src/render/draw_collision_debug.js +0 -49
- package/src/render/draw_custom.js +0 -49
- package/src/render/draw_debug.js +0 -127
- package/src/render/draw_fill.js +0 -126
- package/src/render/draw_fill_extrusion.js +0 -96
- package/src/render/draw_heatmap.js +0 -140
- package/src/render/draw_hillshade.js +0 -108
- package/src/render/draw_line.js +0 -98
- package/src/render/draw_raster.js +0 -125
- package/src/render/draw_symbol.js +0 -394
- package/src/render/glyph_atlas.js +0 -71
- package/src/render/glyph_manager.js +0 -182
- package/src/render/image_atlas.js +0 -149
- package/src/render/image_manager.js +0 -306
- package/src/render/line_atlas.js +0 -210
- package/src/render/painter.js +0 -653
- package/src/render/program/background_program.js +0 -103
- package/src/render/program/circle_program.js +0 -69
- package/src/render/program/clipping_mask_program.js +0 -20
- package/src/render/program/collision_program.js +0 -49
- package/src/render/program/debug_program.js +0 -35
- package/src/render/program/fill_extrusion_program.js +0 -122
- package/src/render/program/fill_program.js +0 -126
- package/src/render/program/heatmap_program.js +0 -83
- package/src/render/program/hillshade_program.js +0 -122
- package/src/render/program/line_program.js +0 -207
- package/src/render/program/pattern.js +0 -102
- package/src/render/program/program_uniforms.js +0 -42
- package/src/render/program/raster_program.js +0 -92
- package/src/render/program/symbol_program.js +0 -224
- package/src/render/program.js +0 -168
- package/src/render/texture.js +0 -122
- package/src/render/uniform_binding.js +0 -147
- package/src/render/vertex_array_object.js +0 -163
- package/src/shaders/README.md +0 -42
- package/src/shaders/_prelude.fragment.glsl +0 -17
- package/src/shaders/_prelude.vertex.glsl +0 -73
- package/src/shaders/background.fragment.glsl +0 -10
- package/src/shaders/background.vertex.glsl +0 -7
- package/src/shaders/background_pattern.fragment.glsl +0 -28
- package/src/shaders/background_pattern.vertex.glsl +0 -20
- package/src/shaders/circle.fragment.glsl +0 -39
- package/src/shaders/circle.vertex.glsl +0 -64
- package/src/shaders/clipping_mask.fragment.glsl +0 -3
- package/src/shaders/clipping_mask.vertex.glsl +0 -7
- package/src/shaders/collision_box.fragment.glsl +0 -21
- package/src/shaders/collision_box.vertex.glsl +0 -27
- package/src/shaders/collision_circle.fragment.glsl +0 -34
- package/src/shaders/collision_circle.vertex.glsl +0 -36
- package/src/shaders/debug.fragment.glsl +0 -9
- package/src/shaders/debug.vertex.glsl +0 -12
- package/src/shaders/encode_attribute.js +0 -17
- package/src/shaders/fill.fragment.glsl +0 -13
- package/src/shaders/fill.vertex.glsl +0 -13
- package/src/shaders/fill_extrusion.fragment.glsl +0 -9
- package/src/shaders/fill_extrusion.vertex.glsl +0 -66
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +0 -45
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +0 -79
- package/src/shaders/fill_outline.fragment.glsl +0 -17
- package/src/shaders/fill_outline.vertex.glsl +0 -17
- package/src/shaders/fill_outline_pattern.fragment.glsl +0 -43
- package/src/shaders/fill_outline_pattern.vertex.glsl +0 -44
- package/src/shaders/fill_pattern.fragment.glsl +0 -36
- package/src/shaders/fill_pattern.vertex.glsl +0 -39
- package/src/shaders/heatmap.fragment.glsl +0 -22
- package/src/shaders/heatmap.vertex.glsl +0 -54
- package/src/shaders/heatmap_texture.fragment.glsl +0 -14
- package/src/shaders/heatmap_texture.vertex.glsl +0 -11
- package/src/shaders/hillshade.fragment.glsl +0 -52
- package/src/shaders/hillshade.vertex.glsl +0 -11
- package/src/shaders/hillshade_prepare.fragment.glsl +0 -74
- package/src/shaders/hillshade_prepare.vertex.glsl +0 -15
- package/src/shaders/index.js +0 -20
- package/src/shaders/line.fragment.glsl +0 -30
- package/src/shaders/line.vertex.glsl +0 -85
- package/src/shaders/line_gradient.fragment.glsl +0 -34
- package/src/shaders/line_gradient.vertex.glsl +0 -87
- package/src/shaders/line_pattern.fragment.glsl +0 -74
- package/src/shaders/line_pattern.vertex.glsl +0 -99
- package/src/shaders/line_sdf.fragment.glsl +0 -45
- package/src/shaders/line_sdf.vertex.glsl +0 -98
- package/src/shaders/raster.fragment.glsl +0 -52
- package/src/shaders/raster.vertex.glsl +0 -21
- package/src/shaders/shaders.js +0 -180
- package/src/shaders/symbol_icon.fragment.glsl +0 -17
- package/src/shaders/symbol_icon.vertex.glsl +0 -94
- package/src/shaders/symbol_sdf.fragment.glsl +0 -52
- package/src/shaders/symbol_sdf.vertex.glsl +0 -115
- package/src/shaders/symbol_text_and_icon.fragment.glsl +0 -68
- package/src/shaders/symbol_text_and_icon.vertex.glsl +0 -116
- package/src/source/canvas_source.js +0 -238
- package/src/source/geojson_helper.js +0 -92
- package/src/source/geojson_source.js +0 -374
- package/src/source/geojson_worker_source.js +0 -357
- package/src/source/geojson_wrapper.js +0 -94
- package/src/source/image_source.js +0 -307
- package/src/source/load_tilejson.js +0 -39
- package/src/source/mbtiles_source.js +0 -115
- package/src/source/offline_database.js +0 -61
- package/src/source/offline_database_root.js +0 -62
- package/src/source/pixels_to_tile_units.js +0 -21
- package/src/source/query_features.js +0 -208
- package/src/source/raster_dem_tile_source.js +0 -138
- package/src/source/raster_dem_tile_worker_source.js +0 -62
- package/src/source/raster_tile_offline_source.js +0 -136
- package/src/source/raster_tile_source.js +0 -177
- package/src/source/rtl_text_plugin.js +0 -138
- package/src/source/source.js +0 -137
- package/src/source/source_cache.js +0 -957
- package/src/source/source_state.js +0 -159
- package/src/source/tile.js +0 -465
- package/src/source/tile_bounds.js +0 -38
- package/src/source/tile_cache.js +0 -212
- package/src/source/tile_id.js +0 -402
- package/src/source/vector_tile_source.js +0 -192
- package/src/source/vector_tile_worker_source.js +0 -216
- package/src/source/video_source.js +0 -203
- package/src/source/worker.js +0 -237
- package/src/source/worker_source.js +0 -106
- package/src/source/worker_tile.js +0 -224
- package/src/style/create_style_layer.js +0 -36
- package/src/style/evaluation_parameters.js +0 -62
- package/src/style/light.js +0 -130
- package/src/style/load_glyph_range.js +0 -38
- package/src/style/load_sprite.js +0 -67
- package/src/style/parse_glyph_pbf.js +0 -44
- package/src/style/pauseable_placement.js +0 -132
- package/src/style/properties.js +0 -753
- package/src/style/query_utils.js +0 -43
- package/src/style/style.js +0 -1361
- package/src/style/style_glyph.js +0 -17
- package/src/style/style_image.js +0 -137
- package/src/style/style_layer/background_style_layer.js +0 -21
- package/src/style/style_layer/background_style_layer_properties.js +0 -40
- package/src/style/style_layer/circle_style_layer.js +0 -98
- package/src/style/style_layer/circle_style_layer_properties.js +0 -63
- package/src/style/style_layer/custom_style_layer.js +0 -223
- package/src/style/style_layer/fill_extrusion_style_layer.js +0 -224
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +0 -50
- package/src/style/style_layer/fill_style_layer.js +0 -67
- package/src/style/style_layer/fill_style_layer_properties.js +0 -55
- package/src/style/style_layer/heatmap_style_layer.js +0 -69
- package/src/style/style_layer/heatmap_style_layer_properties.js +0 -44
- package/src/style/style_layer/hillshade_style_layer.js +0 -25
- package/src/style/style_layer/hillshade_style_layer_properties.js +0 -46
- package/src/style/style_layer/layer_properties.js.ejs +0 -69
- package/src/style/style_layer/line_style_layer.js +0 -151
- package/src/style/style_layer/line_style_layer_properties.js +0 -71
- package/src/style/style_layer/raster_style_layer.js +0 -21
- package/src/style/style_layer/raster_style_layer_properties.js +0 -50
- package/src/style/style_layer/symbol_style_layer.js +0 -190
- package/src/style/style_layer/symbol_style_layer_properties.js +0 -153
- package/src/style/style_layer/typed_style_layer.js +0 -17
- package/src/style/style_layer.js +0 -281
- package/src/style/style_layer_index.js +0 -80
- package/src/style/validate_style.js +0 -42
- package/src/style/zoom_history.js +0 -44
- package/src/style-spec/.eslintrc +0 -5
- package/src/style-spec/CHANGELOG.md +0 -438
- package/src/style-spec/README.md +0 -59
- package/src/style-spec/bin/gl-style-composite +0 -9
- package/src/style-spec/bin/gl-style-format +0 -22
- package/src/style-spec/bin/gl-style-migrate +0 -9
- package/src/style-spec/bin/gl-style-validate +0 -50
- package/src/style-spec/composite.js +0 -50
- package/src/style-spec/declass.js +0 -42
- package/src/style-spec/deref.js +0 -52
- package/src/style-spec/diff.js +0 -393
- package/src/style-spec/dist/.gitkeep +0 -0
- package/src/style-spec/empty.js +0 -29
- package/src/style-spec/error/parsing_error.js +0 -16
- package/src/style-spec/error/validation_error.js +0 -18
- package/src/style-spec/expression/compound_expression.js +0 -162
- package/src/style-spec/expression/definitions/assertion.js +0 -130
- package/src/style-spec/expression/definitions/at.js +0 -70
- package/src/style-spec/expression/definitions/case.js +0 -85
- package/src/style-spec/expression/definitions/coalesce.js +0 -93
- package/src/style-spec/expression/definitions/coercion.js +0 -133
- package/src/style-spec/expression/definitions/collator.js +0 -78
- package/src/style-spec/expression/definitions/comparison.js +0 -184
- package/src/style-spec/expression/definitions/format.js +0 -144
- package/src/style-spec/expression/definitions/format_section_override.js +0 -54
- package/src/style-spec/expression/definitions/image.js +0 -52
- package/src/style-spec/expression/definitions/in.js +0 -92
- package/src/style-spec/expression/definitions/index.js +0 -561
- package/src/style-spec/expression/definitions/interpolate.js +0 -267
- package/src/style-spec/expression/definitions/length.js +0 -61
- package/src/style-spec/expression/definitions/let.js +0 -72
- package/src/style-spec/expression/definitions/literal.js +0 -77
- package/src/style-spec/expression/definitions/match.js +0 -158
- package/src/style-spec/expression/definitions/number_format.js +0 -142
- package/src/style-spec/expression/definitions/step.js +0 -120
- package/src/style-spec/expression/definitions/var.js +0 -46
- package/src/style-spec/expression/definitions/within.js +0 -333
- package/src/style-spec/expression/evaluation_context.js +0 -59
- package/src/style-spec/expression/expression.js +0 -27
- package/src/style-spec/expression/index.js +0 -392
- package/src/style-spec/expression/is_constant.js +0 -59
- package/src/style-spec/expression/parsing_context.js +0 -233
- package/src/style-spec/expression/parsing_error.js +0 -13
- package/src/style-spec/expression/runtime_error.js +0 -17
- package/src/style-spec/expression/scope.js +0 -36
- package/src/style-spec/expression/stops.js +0 -39
- package/src/style-spec/expression/types/collator.js +0 -61
- package/src/style-spec/expression/types/formatted.js +0 -73
- package/src/style-spec/expression/types/resolved_image.js +0 -29
- package/src/style-spec/expression/types.js +0 -106
- package/src/style-spec/expression/values.js +0 -123
- package/src/style-spec/feature_filter/README.md +0 -55
- package/src/style-spec/feature_filter/convert.js +0 -208
- package/src/style-spec/feature_filter/index.js +0 -165
- package/src/style-spec/format.js +0 -51
- package/src/style-spec/function/convert.js +0 -254
- package/src/style-spec/function/index.js +0 -262
- package/src/style-spec/group_by_layout.js +0 -75
- package/src/style-spec/migrate/expressions.js +0 -39
- package/src/style-spec/migrate/v8.js +0 -203
- package/src/style-spec/migrate/v9.js +0 -26
- package/src/style-spec/migrate.js +0 -36
- package/src/style-spec/package.json +0 -41
- package/src/style-spec/read_style.js +0 -14
- package/src/style-spec/reference/latest.js +0 -3
- package/src/style-spec/reference/v8.json +0 -5808
- package/src/style-spec/rollup.config.js +0 -45
- package/src/style-spec/style-spec.js +0 -122
- package/src/style-spec/types.js +0 -438
- package/src/style-spec/util/color.js +0 -95
- package/src/style-spec/util/color_spaces.js +0 -139
- package/src/style-spec/util/deep_equal.js +0 -28
- package/src/style-spec/util/extend.js +0 -10
- package/src/style-spec/util/get_type.js +0 -17
- package/src/style-spec/util/interpolate.js +0 -22
- package/src/style-spec/util/properties.js +0 -15
- package/src/style-spec/util/ref_properties.js +0 -2
- package/src/style-spec/util/result.js +0 -19
- package/src/style-spec/util/unbundle_jsonlint.js +0 -24
- package/src/style-spec/validate/latest.js +0 -11
- package/src/style-spec/validate/validate.js +0 -75
- package/src/style-spec/validate/validate_array.js +0 -52
- package/src/style-spec/validate/validate_boolean.js +0 -15
- package/src/style-spec/validate/validate_color.js +0 -20
- package/src/style-spec/validate/validate_constants.js +0 -13
- package/src/style-spec/validate/validate_enum.js +0 -21
- package/src/style-spec/validate/validate_expression.js +0 -43
- package/src/style-spec/validate/validate_filter.js +0 -111
- package/src/style-spec/validate/validate_formatted.js +0 -11
- package/src/style-spec/validate/validate_function.js +0 -207
- package/src/style-spec/validate/validate_glyphs_url.js +0 -21
- package/src/style-spec/validate/validate_image.js +0 -11
- package/src/style-spec/validate/validate_layer.js +0 -134
- package/src/style-spec/validate/validate_layout_property.js +0 -6
- package/src/style-spec/validate/validate_light.js +0 -47
- package/src/style-spec/validate/validate_number.js +0 -29
- package/src/style-spec/validate/validate_object.js +0 -61
- package/src/style-spec/validate/validate_paint_property.js +0 -6
- package/src/style-spec/validate/validate_property.js +0 -64
- package/src/style-spec/validate/validate_source.js +0 -111
- package/src/style-spec/validate/validate_string.js +0 -15
- package/src/style-spec/validate_mapbox_api_supported.js +0 -171
- package/src/style-spec/validate_style.js +0 -39
- package/src/style-spec/validate_style.min.js +0 -78
- package/src/style-spec/visit.js +0 -77
- package/src/symbol/anchor.js +0 -26
- package/src/symbol/check_max_angle.js +0 -81
- package/src/symbol/clip_line.js +0 -71
- package/src/symbol/collision_feature.js +0 -217
- package/src/symbol/collision_index.js +0 -372
- package/src/symbol/cross_tile_symbol_index.js +0 -301
- package/src/symbol/get_anchors.js +0 -167
- package/src/symbol/grid_index.js +0 -335
- package/src/symbol/mergelines.js +0 -82
- package/src/symbol/one_em.js +0 -4
- package/src/symbol/opacity_state.js +0 -27
- package/src/symbol/placement.js +0 -1062
- package/src/symbol/projection.js +0 -450
- package/src/symbol/quads.js +0 -334
- package/src/symbol/shaping.js +0 -816
- package/src/symbol/symbol_layout.js +0 -772
- package/src/symbol/symbol_size.js +0 -113
- package/src/symbol/transform_text.js +0 -29
- package/src/types/callback.js +0 -17
- package/src/types/cancelable.js +0 -3
- package/src/types/tilejson.js +0 -17
- package/src/types/transferable.js +0 -3
- package/src/types/window.js +0 -172
- package/src/ui/anchor.js +0 -32
- package/src/ui/bind_handlers.js +0 -202
- package/src/ui/camera.js +0 -1152
- package/src/ui/control/attribution_control.js +0 -189
- package/src/ui/control/fps_control.js +0 -185
- package/src/ui/control/fullscreen_control.js +0 -147
- package/src/ui/control/geolocate_control.js +0 -594
- package/src/ui/control/logo_control.js +0 -92
- package/src/ui/control/navigation_control.js +0 -148
- package/src/ui/control/scale_control.js +0 -142
- package/src/ui/crs.js +0 -64
- package/src/ui/default_locale.js +0 -20
- package/src/ui/events.js +0 -806
- package/src/ui/handler/box_zoom.js +0 -175
- package/src/ui/handler/dblclick_zoom.js +0 -139
- package/src/ui/handler/drag_pan.js +0 -416
- package/src/ui/handler/drag_rotate.js +0 -378
- package/src/ui/handler/keyboard.js +0 -161
- package/src/ui/handler/scroll_zoom.js +0 -333
- package/src/ui/handler/touch_zoom_rotate.js +0 -293
- package/src/ui/hash.js +0 -147
- package/src/ui/map.js +0 -2883
- package/src/ui/marker.js +0 -607
- package/src/ui/offline_map.js +0 -91
- package/src/ui/popup.js +0 -530
- package/src/util/actor.js +0 -212
- package/src/util/ajax.js +0 -371
- package/src/util/browser/web_worker.js +0 -10
- package/src/util/browser/window.js +0 -5
- package/src/util/browser.js +0 -70
- package/src/util/classify_rings.js +0 -52
- package/src/util/color_ramp.js +0 -28
- package/src/util/config.js +0 -30
- package/src/util/debug.js +0 -12
- package/src/util/dictionary_coder.js +0 -30
- package/src/util/dispatcher.js +0 -70
- package/src/util/dom.js +0 -144
- package/src/util/evented.js +0 -174
- package/src/util/find_pole_of_inaccessibility.js +0 -129
- package/src/util/global_worker_pool.js +0 -17
- package/src/util/image.js +0 -142
- package/src/util/intersection_tests.js +0 -208
- package/src/util/is_char_in_unicode_block.js +0 -311
- package/src/util/mapbox.js +0 -486
- package/src/util/offscreen_canvas_supported.js +0 -14
- package/src/util/performance.js +0 -112
- package/src/util/primitives.js +0 -145
- package/src/util/resolve_tokens.js +0 -16
- package/src/util/script_detection.js +0 -328
- package/src/util/sku_token.js +0 -42
- package/src/util/smart_wrap.js +0 -55
- package/src/util/struct_array.js +0 -243
- package/src/util/struct_array.js.ejs +0 -112
- package/src/util/struct_array_layout.js.ejs +0 -98
- package/src/util/task_queue.js +0 -68
- package/src/util/throttle.js +0 -28
- package/src/util/throttled_invoker.js +0 -46
- package/src/util/tile_cover.js +0 -101
- package/src/util/tile_request_cache.js +0 -172
- package/src/util/util.js +0 -504
- package/src/util/vectortile_to_geojson.js +0 -54
- package/src/util/verticalize_punctuation.js +0 -114
- package/src/util/web_worker.js +0 -91
- package/src/util/web_worker_transfer.js +0 -266
- package/src/util/webp_supported.js +0 -69
- package/src/util/window.js +0 -102
- package/src/util/worker_pool.js +0 -47
package/src/ui/marker.js
DELETED
|
@@ -1,607 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import DOM from '../util/dom';
|
|
4
|
-
import window from '../util/window';
|
|
5
|
-
import LngLat from '../geo/lng_lat';
|
|
6
|
-
import Point from '@mapbox/point-geometry';
|
|
7
|
-
import smartWrap from '../util/smart_wrap';
|
|
8
|
-
import {bindAll, extend} from '../util/util';
|
|
9
|
-
import {type Anchor, anchorTranslate, applyAnchorClass} from './anchor';
|
|
10
|
-
import {Event, Evented} from '../util/evented';
|
|
11
|
-
import type Map from './map';
|
|
12
|
-
import type Popup from './popup';
|
|
13
|
-
import type {LngLatLike} from "../geo/lng_lat";
|
|
14
|
-
import type {MapMouseEvent, MapTouchEvent} from './events';
|
|
15
|
-
import type {PointLike} from '@mapbox/point-geometry';
|
|
16
|
-
|
|
17
|
-
type Options = {
|
|
18
|
-
element?: HTMLElement,
|
|
19
|
-
offset?: PointLike,
|
|
20
|
-
anchor?: Anchor,
|
|
21
|
-
color?: string,
|
|
22
|
-
draggable?: boolean,
|
|
23
|
-
rotation?: number,
|
|
24
|
-
rotationAlignment?: string,
|
|
25
|
-
pitchAlignment?: string
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a marker component
|
|
30
|
-
* @param {Object} [options]
|
|
31
|
-
* @param {HTMLElement} [options.element] DOM element to use as a marker. The default is a light blue, droplet-shaped SVG marker.
|
|
32
|
-
* @param {string} [options.anchor='center'] A string indicating the part of the Marker that should be positioned closest to the coordinate set via {@link Marker#setLngLat}.
|
|
33
|
-
* Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`.
|
|
34
|
-
* @param {PointLike} [options.offset] The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up.
|
|
35
|
-
* @param {string} [options.color='#3FB1CE'] The color to use for the default marker if options.element is not provided. The default is light blue.
|
|
36
|
-
* @param {boolean} [options.draggable=false] A boolean indicating whether or not a marker is able to be dragged to a new position on the map.
|
|
37
|
-
* @param {number} [options.rotation=0] The rotation angle of the marker in degrees, relative to its respective `rotationAlignment` setting. A positive value will rotate the marker clockwise.
|
|
38
|
-
* @param {string} [options.pitchAlignment='auto'] `map` aligns the `Marker` to the plane of the map. `viewport` aligns the `Marker` to the plane of the viewport. `auto` automatically matches the value of `rotationAlignment`.
|
|
39
|
-
* @param {string} [options.rotationAlignment='auto'] `map` aligns the `Marker`'s rotation relative to the map, maintaining a bearing as the map rotates. `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations. `auto` is equivalent to `viewport`.
|
|
40
|
-
* @example
|
|
41
|
-
* var marker = new mapboxgl.Marker()
|
|
42
|
-
* .setLngLat([30.5, 50.5])
|
|
43
|
-
* .addTo(map);
|
|
44
|
-
* @see [Add custom icons with Markers](https://www.mapbox.com/mapbox-gl-js/example/custom-marker-icons/)
|
|
45
|
-
* @see [Create a draggable Marker](https://www.mapbox.com/mapbox-gl-js/example/drag-a-marker/)
|
|
46
|
-
*/
|
|
47
|
-
export default class Marker extends Evented {
|
|
48
|
-
_map: Map;
|
|
49
|
-
_anchor: Anchor;
|
|
50
|
-
_offset: Point;
|
|
51
|
-
_element: HTMLElement;
|
|
52
|
-
_popup: ?Popup;
|
|
53
|
-
_lngLat: LngLat;
|
|
54
|
-
_pos: ?Point;
|
|
55
|
-
_color: ?string;
|
|
56
|
-
_defaultMarker: boolean;
|
|
57
|
-
_draggable: boolean;
|
|
58
|
-
_state: 'inactive' | 'pending' | 'active'; // used for handling drag events
|
|
59
|
-
_positionDelta: ?number;
|
|
60
|
-
_rotation: number;
|
|
61
|
-
_pitchAlignment: string;
|
|
62
|
-
_rotationAlignment: string;
|
|
63
|
-
_originalTabIndex: ?string; // original tabindex of _element
|
|
64
|
-
|
|
65
|
-
constructor(options?: Options, legacyOptions?: Options) {
|
|
66
|
-
super();
|
|
67
|
-
// For backward compatibility -- the constructor used to accept the element as a
|
|
68
|
-
// required first argument, before it was made optional.
|
|
69
|
-
if (options instanceof window.HTMLElement || legacyOptions) {
|
|
70
|
-
options = extend({element: options}, legacyOptions);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
bindAll([
|
|
74
|
-
'_update',
|
|
75
|
-
'_onMove',
|
|
76
|
-
'_onUp',
|
|
77
|
-
'_addDragHandler',
|
|
78
|
-
'_onMapClick',
|
|
79
|
-
'_onKeyPress'
|
|
80
|
-
], this);
|
|
81
|
-
|
|
82
|
-
this._anchor = options && options.anchor || 'center';
|
|
83
|
-
this._color = options && options.color || '#3FB1CE';
|
|
84
|
-
this._draggable = options && options.draggable || false;
|
|
85
|
-
this._state = 'inactive';
|
|
86
|
-
this._rotation = options && options.rotation || 0;
|
|
87
|
-
this._rotationAlignment = options && options.rotationAlignment || 'auto';
|
|
88
|
-
this._pitchAlignment = options && options.pitchAlignment && options.pitchAlignment !== 'auto' ? options.pitchAlignment : this._rotationAlignment;
|
|
89
|
-
|
|
90
|
-
if (!options || !options.element) {
|
|
91
|
-
this._defaultMarker = true;
|
|
92
|
-
this._element = DOM.create('div');
|
|
93
|
-
this._element.setAttribute('aria-label', 'Map marker');
|
|
94
|
-
|
|
95
|
-
// create default map marker SVG
|
|
96
|
-
const svg = DOM.createNS('http://www.w3.org/2000/svg', 'svg');
|
|
97
|
-
svg.setAttributeNS(null, 'display', 'block');
|
|
98
|
-
svg.setAttributeNS(null, 'height', '41px');
|
|
99
|
-
svg.setAttributeNS(null, 'width', '27px');
|
|
100
|
-
svg.setAttributeNS(null, 'viewBox', '0 0 27 41');
|
|
101
|
-
|
|
102
|
-
const markerLarge = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
103
|
-
markerLarge.setAttributeNS(null, 'stroke', 'none');
|
|
104
|
-
markerLarge.setAttributeNS(null, 'stroke-width', '1');
|
|
105
|
-
markerLarge.setAttributeNS(null, 'fill', 'none');
|
|
106
|
-
markerLarge.setAttributeNS(null, 'fill-rule', 'evenodd');
|
|
107
|
-
|
|
108
|
-
const page1 = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
109
|
-
page1.setAttributeNS(null, 'fill-rule', 'nonzero');
|
|
110
|
-
|
|
111
|
-
const shadow = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
112
|
-
shadow.setAttributeNS(null, 'transform', 'translate(3.0, 29.0)');
|
|
113
|
-
shadow.setAttributeNS(null, 'fill', '#000000');
|
|
114
|
-
|
|
115
|
-
const ellipses = [
|
|
116
|
-
{'rx': '10.5', 'ry': '5.25002273'},
|
|
117
|
-
{'rx': '10.5', 'ry': '5.25002273'},
|
|
118
|
-
{'rx': '9.5', 'ry': '4.77275007'},
|
|
119
|
-
{'rx': '8.5', 'ry': '4.29549936'},
|
|
120
|
-
{'rx': '7.5', 'ry': '3.81822308'},
|
|
121
|
-
{'rx': '6.5', 'ry': '3.34094679'},
|
|
122
|
-
{'rx': '5.5', 'ry': '2.86367051'},
|
|
123
|
-
{'rx': '4.5', 'ry': '2.38636864'}
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
for (const data of ellipses) {
|
|
127
|
-
const ellipse = DOM.createNS('http://www.w3.org/2000/svg', 'ellipse');
|
|
128
|
-
ellipse.setAttributeNS(null, 'opacity', '0.04');
|
|
129
|
-
ellipse.setAttributeNS(null, 'cx', '10.5');
|
|
130
|
-
ellipse.setAttributeNS(null, 'cy', '5.80029008');
|
|
131
|
-
ellipse.setAttributeNS(null, 'rx', data['rx']);
|
|
132
|
-
ellipse.setAttributeNS(null, 'ry', data['ry']);
|
|
133
|
-
shadow.appendChild(ellipse);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const background = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
137
|
-
background.setAttributeNS(null, 'fill', this._color);
|
|
138
|
-
|
|
139
|
-
const bgPath = DOM.createNS('http://www.w3.org/2000/svg', 'path');
|
|
140
|
-
bgPath.setAttributeNS(null, 'd', 'M27,13.5 C27,19.074644 20.250001,27.000002 14.75,34.500002 C14.016665,35.500004 12.983335,35.500004 12.25,34.500002 C6.7499993,27.000002 0,19.222562 0,13.5 C0,6.0441559 6.0441559,0 13.5,0 C20.955844,0 27,6.0441559 27,13.5 Z');
|
|
141
|
-
|
|
142
|
-
background.appendChild(bgPath);
|
|
143
|
-
|
|
144
|
-
const border = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
145
|
-
border.setAttributeNS(null, 'opacity', '0.25');
|
|
146
|
-
border.setAttributeNS(null, 'fill', '#000000');
|
|
147
|
-
|
|
148
|
-
const borderPath = DOM.createNS('http://www.w3.org/2000/svg', 'path');
|
|
149
|
-
borderPath.setAttributeNS(null, 'd', 'M13.5,0 C6.0441559,0 0,6.0441559 0,13.5 C0,19.222562 6.7499993,27 12.25,34.5 C13,35.522727 14.016664,35.500004 14.75,34.5 C20.250001,27 27,19.074644 27,13.5 C27,6.0441559 20.955844,0 13.5,0 Z M13.5,1 C20.415404,1 26,6.584596 26,13.5 C26,15.898657 24.495584,19.181431 22.220703,22.738281 C19.945823,26.295132 16.705119,30.142167 13.943359,33.908203 C13.743445,34.180814 13.612715,34.322738 13.5,34.441406 C13.387285,34.322738 13.256555,34.180814 13.056641,33.908203 C10.284481,30.127985 7.4148684,26.314159 5.015625,22.773438 C2.6163816,19.232715 1,15.953538 1,13.5 C1,6.584596 6.584596,1 13.5,1 Z');
|
|
150
|
-
|
|
151
|
-
border.appendChild(borderPath);
|
|
152
|
-
|
|
153
|
-
const maki = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
154
|
-
maki.setAttributeNS(null, 'transform', 'translate(6.0, 7.0)');
|
|
155
|
-
maki.setAttributeNS(null, 'fill', '#FFFFFF');
|
|
156
|
-
|
|
157
|
-
const circleContainer = DOM.createNS('http://www.w3.org/2000/svg', 'g');
|
|
158
|
-
circleContainer.setAttributeNS(null, 'transform', 'translate(8.0, 8.0)');
|
|
159
|
-
|
|
160
|
-
const circle1 = DOM.createNS('http://www.w3.org/2000/svg', 'circle');
|
|
161
|
-
circle1.setAttributeNS(null, 'fill', '#000000');
|
|
162
|
-
circle1.setAttributeNS(null, 'opacity', '0.25');
|
|
163
|
-
circle1.setAttributeNS(null, 'cx', '5.5');
|
|
164
|
-
circle1.setAttributeNS(null, 'cy', '5.5');
|
|
165
|
-
circle1.setAttributeNS(null, 'r', '5.4999962');
|
|
166
|
-
|
|
167
|
-
const circle2 = DOM.createNS('http://www.w3.org/2000/svg', 'circle');
|
|
168
|
-
circle2.setAttributeNS(null, 'fill', '#FFFFFF');
|
|
169
|
-
circle2.setAttributeNS(null, 'cx', '5.5');
|
|
170
|
-
circle2.setAttributeNS(null, 'cy', '5.5');
|
|
171
|
-
circle2.setAttributeNS(null, 'r', '5.4999962');
|
|
172
|
-
|
|
173
|
-
circleContainer.appendChild(circle1);
|
|
174
|
-
circleContainer.appendChild(circle2);
|
|
175
|
-
|
|
176
|
-
page1.appendChild(shadow);
|
|
177
|
-
page1.appendChild(background);
|
|
178
|
-
page1.appendChild(border);
|
|
179
|
-
page1.appendChild(maki);
|
|
180
|
-
page1.appendChild(circleContainer);
|
|
181
|
-
|
|
182
|
-
svg.appendChild(page1);
|
|
183
|
-
|
|
184
|
-
this._element.appendChild(svg);
|
|
185
|
-
|
|
186
|
-
// if no element and no offset option given apply an offset for the default marker
|
|
187
|
-
// the -14 as the y value of the default marker offset was determined as follows
|
|
188
|
-
//
|
|
189
|
-
// the marker tip is at the center of the shadow ellipse from the default svg
|
|
190
|
-
// the y value of the center of the shadow ellipse relative to the svg top left is "shadow transform translate-y (29.0) + ellipse cy (5.80029008)"
|
|
191
|
-
// offset to the svg center "height (41 / 2)" gives (29.0 + 5.80029008) - (41 / 2) and rounded for an integer pixel offset gives 14
|
|
192
|
-
// negative is used to move the marker up from the center so the tip is at the Marker lngLat
|
|
193
|
-
this._offset = Point.convert(options && options.offset || [0, -14]);
|
|
194
|
-
} else {
|
|
195
|
-
this._element = options.element;
|
|
196
|
-
this._offset = Point.convert(options && options.offset || [0, 0]);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
this._element.classList.add('mapboxgl-marker');
|
|
200
|
-
this._element.addEventListener('dragstart', (e: DragEvent) => {
|
|
201
|
-
e.preventDefault();
|
|
202
|
-
});
|
|
203
|
-
this._element.addEventListener('mousedown', (e: MouseEvent) => {
|
|
204
|
-
// prevent focusing on click
|
|
205
|
-
e.preventDefault();
|
|
206
|
-
});
|
|
207
|
-
this._element.addEventListener('focus', () => {
|
|
208
|
-
// revert the default scrolling action of the container
|
|
209
|
-
const el = this._map.getContainer();
|
|
210
|
-
el.scrollTop = 0;
|
|
211
|
-
el.scrollLeft = 0;
|
|
212
|
-
});
|
|
213
|
-
applyAnchorClass(this._element, this._anchor, 'marker');
|
|
214
|
-
|
|
215
|
-
this._popup = null;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Attaches the marker to a map
|
|
220
|
-
* @param {Map} map The Mapbox GL JS map to add the marker to.
|
|
221
|
-
* @returns {Marker} `this`
|
|
222
|
-
*/
|
|
223
|
-
addTo(map: Map) {
|
|
224
|
-
this.remove();
|
|
225
|
-
this._map = map;
|
|
226
|
-
map.getCanvasContainer().appendChild(this._element);
|
|
227
|
-
map.on('move', this._update);
|
|
228
|
-
map.on('moveend', this._update);
|
|
229
|
-
this.setDraggable(this._draggable);
|
|
230
|
-
this._update();
|
|
231
|
-
|
|
232
|
-
// If we attached the `click` listener to the marker element, the popup
|
|
233
|
-
// would close once the event propogated to `map` due to the
|
|
234
|
-
// `Popup#_onClickClose` listener.
|
|
235
|
-
this._map.on('click', this._onMapClick);
|
|
236
|
-
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Removes the marker from a map
|
|
242
|
-
* @example
|
|
243
|
-
* var marker = new mapboxgl.Marker().addTo(map);
|
|
244
|
-
* marker.remove();
|
|
245
|
-
* @returns {Marker} `this`
|
|
246
|
-
*/
|
|
247
|
-
remove() {
|
|
248
|
-
if (this._map) {
|
|
249
|
-
this._map.off('click', this._onMapClick);
|
|
250
|
-
this._map.off('move', this._update);
|
|
251
|
-
this._map.off('moveend', this._update);
|
|
252
|
-
this._map.off('mousedown', this._addDragHandler);
|
|
253
|
-
this._map.off('touchstart', this._addDragHandler);
|
|
254
|
-
this._map.off('mouseup', this._onUp);
|
|
255
|
-
this._map.off('touchend', this._onUp);
|
|
256
|
-
this._map.off('mousemove', this._onMove);
|
|
257
|
-
this._map.off('touchmove', this._onMove);
|
|
258
|
-
delete this._map;
|
|
259
|
-
}
|
|
260
|
-
DOM.remove(this._element);
|
|
261
|
-
if (this._popup) this._popup.remove();
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Get the marker's geographical location.
|
|
267
|
-
*
|
|
268
|
-
* The longitude of the result may differ by a multiple of 360 degrees from the longitude previously
|
|
269
|
-
* set by `setLngLat` because `Marker` wraps the anchor longitude across copies of the world to keep
|
|
270
|
-
* the marker on screen.
|
|
271
|
-
*
|
|
272
|
-
* @returns {LngLat} A {@link LngLat} describing the marker's location.
|
|
273
|
-
*/
|
|
274
|
-
getLngLat() {
|
|
275
|
-
return this._lngLat;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Set the marker's geographical position and move it.
|
|
280
|
-
* @param {LngLat} lnglat A {@link LngLat} describing where the marker should be located.
|
|
281
|
-
* @returns {Marker} `this`
|
|
282
|
-
*/
|
|
283
|
-
setLngLat(lnglat: LngLatLike) {
|
|
284
|
-
this._lngLat = LngLat.convert(lnglat);
|
|
285
|
-
this._pos = null;
|
|
286
|
-
if (this._popup) this._popup.setLngLat(this._lngLat);
|
|
287
|
-
this._update();
|
|
288
|
-
return this;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Returns the `Marker`'s HTML element.
|
|
293
|
-
* @returns {HTMLElement} element
|
|
294
|
-
*/
|
|
295
|
-
getElement() {
|
|
296
|
-
return this._element;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Binds a Popup to the Marker
|
|
301
|
-
* @param popup an instance of the `Popup` class. If undefined or null, any popup
|
|
302
|
-
* set on this `Marker` instance is unset
|
|
303
|
-
* @returns {Marker} `this`
|
|
304
|
-
*/
|
|
305
|
-
setPopup(popup: ?Popup) {
|
|
306
|
-
if (this._popup) {
|
|
307
|
-
this._popup.remove();
|
|
308
|
-
this._popup = null;
|
|
309
|
-
this._element.removeEventListener('keypress', this._onKeyPress);
|
|
310
|
-
|
|
311
|
-
if (!this._originalTabIndex) {
|
|
312
|
-
this._element.removeAttribute('tabindex');
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (popup) {
|
|
317
|
-
if (!('offset' in popup.options)) {
|
|
318
|
-
const markerHeight = 41 - (5.8 / 2);
|
|
319
|
-
const markerRadius = 13.5;
|
|
320
|
-
const linearOffset = Math.sqrt(Math.pow(markerRadius, 2) / 2);
|
|
321
|
-
popup.options.offset = this._defaultMarker ? {
|
|
322
|
-
'top': [0, 0],
|
|
323
|
-
'top-left': [0, 0],
|
|
324
|
-
'top-right': [0, 0],
|
|
325
|
-
'bottom': [0, -markerHeight],
|
|
326
|
-
'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
|
|
327
|
-
'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
|
|
328
|
-
'left': [markerRadius, (markerHeight - markerRadius) * -1],
|
|
329
|
-
'right': [-markerRadius, (markerHeight - markerRadius) * -1]
|
|
330
|
-
} : this._offset;
|
|
331
|
-
}
|
|
332
|
-
this._popup = popup;
|
|
333
|
-
if (this._lngLat) this._popup.setLngLat(this._lngLat);
|
|
334
|
-
|
|
335
|
-
this._originalTabIndex = this._element.getAttribute('tabindex');
|
|
336
|
-
if (!this._originalTabIndex) {
|
|
337
|
-
this._element.setAttribute('tabindex', '0');
|
|
338
|
-
}
|
|
339
|
-
this._element.addEventListener('keypress', this._onKeyPress);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
return this;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
_onKeyPress(e: KeyboardEvent) {
|
|
346
|
-
const code = e.code;
|
|
347
|
-
const legacyCode = e.charCode || e.keyCode;
|
|
348
|
-
|
|
349
|
-
if (
|
|
350
|
-
(code === 'Space') || (code === 'Enter') ||
|
|
351
|
-
(legacyCode === 32) || (legacyCode === 13) // space or enter
|
|
352
|
-
) {
|
|
353
|
-
this.togglePopup();
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
_onMapClick(e: MapMouseEvent) {
|
|
358
|
-
const targetElement = e.originalEvent.target;
|
|
359
|
-
const element = this._element;
|
|
360
|
-
|
|
361
|
-
if (this._popup && (targetElement === element || element.contains((targetElement: any)))) {
|
|
362
|
-
this.togglePopup();
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Returns the Popup instance that is bound to the Marker
|
|
368
|
-
* @returns {Popup} popup
|
|
369
|
-
*/
|
|
370
|
-
getPopup() {
|
|
371
|
-
return this._popup;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Opens or closes the bound popup, depending on the current state
|
|
376
|
-
* @returns {Marker} `this`
|
|
377
|
-
*/
|
|
378
|
-
togglePopup() {
|
|
379
|
-
const popup = this._popup;
|
|
380
|
-
|
|
381
|
-
if (!popup) return this;
|
|
382
|
-
else if (popup.isOpen()) popup.remove();
|
|
383
|
-
else popup.addTo(this._map);
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
_update(e?: {type: 'move' | 'moveend'}) {
|
|
388
|
-
if (!this._map) return;
|
|
389
|
-
|
|
390
|
-
if (this._map.transform.renderWorldCopies) {
|
|
391
|
-
this._lngLat = smartWrap(this._lngLat, this._pos, this._map.transform);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
this._pos = this._map.project(this._lngLat)._add(this._offset);
|
|
395
|
-
|
|
396
|
-
let rotation = "";
|
|
397
|
-
if (this._rotationAlignment === "viewport" || this._rotationAlignment === "auto") {
|
|
398
|
-
rotation = `rotateZ(${this._rotation}deg)`;
|
|
399
|
-
} else if (this._rotationAlignment === "map") {
|
|
400
|
-
rotation = `rotateZ(${this._rotation - this._map.getBearing()}deg)`;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
let pitch = "";
|
|
404
|
-
if (this._pitchAlignment === "viewport" || this._pitchAlignment === "auto") {
|
|
405
|
-
pitch = "rotateX(0deg)";
|
|
406
|
-
} else if (this._pitchAlignment === "map") {
|
|
407
|
-
pitch = `rotateX(${this._map.getPitch()}deg)`;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// because rounding the coordinates at every `move` event causes stuttered zooming
|
|
411
|
-
// we only round them when _update is called with `moveend` or when its called with
|
|
412
|
-
// no arguments (when the Marker is initialized or Marker#setLngLat is invoked).
|
|
413
|
-
if (!e || e.type === "moveend") {
|
|
414
|
-
this._pos = this._pos.round();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${this._pos.x}px, ${this._pos.y}px) ${pitch} ${rotation}`);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Get the marker's offset.
|
|
422
|
-
* @returns {Point} The marker's screen coordinates in pixels.
|
|
423
|
-
*/
|
|
424
|
-
getOffset() {
|
|
425
|
-
return this._offset;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Sets the offset of the marker
|
|
430
|
-
* @param {PointLike} offset The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up.
|
|
431
|
-
* @returns {Marker} `this`
|
|
432
|
-
*/
|
|
433
|
-
setOffset(offset: PointLike) {
|
|
434
|
-
this._offset = Point.convert(offset);
|
|
435
|
-
this._update();
|
|
436
|
-
return this;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
_onMove(e: MapMouseEvent | MapTouchEvent) {
|
|
440
|
-
this._pos = e.point.sub(this._positionDelta);
|
|
441
|
-
this._lngLat = this._map.unproject(this._pos);
|
|
442
|
-
this.setLngLat(this._lngLat);
|
|
443
|
-
// suppress click event so that popups don't toggle on drag
|
|
444
|
-
this._element.style.pointerEvents = 'none';
|
|
445
|
-
|
|
446
|
-
// make sure dragstart only fires on the first move event after mousedown.
|
|
447
|
-
// this can't be on mousedown because that event doesn't necessarily
|
|
448
|
-
// imply that a drag is about to happen.
|
|
449
|
-
if (this._state === 'pending') {
|
|
450
|
-
this._state = 'active';
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Fired when dragging starts
|
|
454
|
-
*
|
|
455
|
-
* @event dragstart
|
|
456
|
-
* @memberof Marker
|
|
457
|
-
* @instance
|
|
458
|
-
* @type {Object}
|
|
459
|
-
* @property {Marker} marker object that is being dragged
|
|
460
|
-
*/
|
|
461
|
-
this.fire(new Event('dragstart'));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Fired while dragging
|
|
466
|
-
*
|
|
467
|
-
* @event drag
|
|
468
|
-
* @memberof Marker
|
|
469
|
-
* @instance
|
|
470
|
-
* @type {Object}
|
|
471
|
-
* @property {Marker} marker object that is being dragged
|
|
472
|
-
*/
|
|
473
|
-
this.fire(new Event('drag'));
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
_onUp() {
|
|
477
|
-
// revert to normal pointer event handling
|
|
478
|
-
this._element.style.pointerEvents = 'auto';
|
|
479
|
-
this._positionDelta = null;
|
|
480
|
-
this._map.off('mousemove', this._onMove);
|
|
481
|
-
this._map.off('touchmove', this._onMove);
|
|
482
|
-
|
|
483
|
-
// only fire dragend if it was preceded by at least one drag event
|
|
484
|
-
if (this._state === 'active') {
|
|
485
|
-
/**
|
|
486
|
-
* Fired when the marker is finished being dragged
|
|
487
|
-
*
|
|
488
|
-
* @event dragend
|
|
489
|
-
* @memberof Marker
|
|
490
|
-
* @instance
|
|
491
|
-
* @type {Object}
|
|
492
|
-
* @property {Marker} marker object that was dragged
|
|
493
|
-
*/
|
|
494
|
-
this.fire(new Event('dragend'));
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
this._state = 'inactive';
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
_addDragHandler(e: MapMouseEvent | MapTouchEvent) {
|
|
501
|
-
if (this._element.contains((e.originalEvent.target: any))) {
|
|
502
|
-
e.preventDefault();
|
|
503
|
-
|
|
504
|
-
// We need to calculate the pixel distance between the click point
|
|
505
|
-
// and the marker position, with the offset accounted for. Then we
|
|
506
|
-
// can subtract this distance from the mousemove event's position
|
|
507
|
-
// to calculate the new marker position.
|
|
508
|
-
// If we don't do this, the marker 'jumps' to the click position
|
|
509
|
-
// creating a jarring UX effect.
|
|
510
|
-
this._positionDelta = e.point.sub(this._pos).add(this._offset);
|
|
511
|
-
|
|
512
|
-
this._state = 'pending';
|
|
513
|
-
this._map.on('mousemove', this._onMove);
|
|
514
|
-
this._map.on('touchmove', this._onMove);
|
|
515
|
-
this._map.once('mouseup', this._onUp);
|
|
516
|
-
this._map.once('touchend', this._onUp);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Sets the `draggable` property and functionality of the marker
|
|
522
|
-
* @param {boolean} [shouldBeDraggable=false] Turns drag functionality on/off
|
|
523
|
-
* @returns {Marker} `this`
|
|
524
|
-
*/
|
|
525
|
-
setDraggable(shouldBeDraggable: boolean) {
|
|
526
|
-
this._draggable = !!shouldBeDraggable; // convert possible undefined value to false
|
|
527
|
-
|
|
528
|
-
// handle case where map may not exist yet
|
|
529
|
-
// e.g. when setDraggable is called before addTo
|
|
530
|
-
if (this._map) {
|
|
531
|
-
if (shouldBeDraggable) {
|
|
532
|
-
this._map.on('mousedown', this._addDragHandler);
|
|
533
|
-
this._map.on('touchstart', this._addDragHandler);
|
|
534
|
-
} else {
|
|
535
|
-
this._map.off('mousedown', this._addDragHandler);
|
|
536
|
-
this._map.off('touchstart', this._addDragHandler);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
return this;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Returns true if the marker can be dragged
|
|
545
|
-
* @returns {boolean} True if the marker is draggable.
|
|
546
|
-
*/
|
|
547
|
-
isDraggable() {
|
|
548
|
-
return this._draggable;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Sets the `rotation` property of the marker.
|
|
553
|
-
* @param {number} [rotation=0] The rotation angle of the marker (clockwise, in degrees), relative to its respective {@link Marker#rotationAlignment} setting.
|
|
554
|
-
* @returns {Marker} `this`
|
|
555
|
-
*/
|
|
556
|
-
setRotation(rotation: number) {
|
|
557
|
-
this._rotation = rotation || 0;
|
|
558
|
-
this._update();
|
|
559
|
-
return this;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Returns the current rotation angle of the marker (in degrees).
|
|
564
|
-
* @returns {number} The current rotation angle of the marker.
|
|
565
|
-
*/
|
|
566
|
-
getRotation() {
|
|
567
|
-
return this._rotation;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Sets the `rotationAlignment` property of the marker.
|
|
572
|
-
* @param {string} [alignment='auto'] Sets the `rotationAlignment` property of the marker.
|
|
573
|
-
* @returns {Marker} `this`
|
|
574
|
-
*/
|
|
575
|
-
setRotationAlignment(alignment: string) {
|
|
576
|
-
this._rotationAlignment = alignment || 'auto';
|
|
577
|
-
this._update();
|
|
578
|
-
return this;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Returns the current `rotationAlignment` property of the marker.
|
|
583
|
-
* @returns {string} The current rotational alignment of the marker.
|
|
584
|
-
*/
|
|
585
|
-
getRotationAlignment() {
|
|
586
|
-
return this._rotationAlignment;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Sets the `pitchAlignment` property of the marker.
|
|
591
|
-
* @param {string} [alignment] Sets the `pitchAlignment` property of the marker. If alignment is 'auto', it will automatically match `rotationAlignment`.
|
|
592
|
-
* @returns {Marker} `this`
|
|
593
|
-
*/
|
|
594
|
-
setPitchAlignment(alignment: string) {
|
|
595
|
-
this._pitchAlignment = alignment && alignment !== 'auto' ? alignment : this._rotationAlignment;
|
|
596
|
-
this._update();
|
|
597
|
-
return this;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Returns the current `pitchAlignment` property of the marker.
|
|
602
|
-
* @returns {string} The current pitch alignment of the marker in degrees.
|
|
603
|
-
*/
|
|
604
|
-
getPitchAlignment() {
|
|
605
|
-
return this._pitchAlignment;
|
|
606
|
-
}
|
|
607
|
-
}
|