mapbox-gl 1.13.2
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/.flowconfig +61 -0
- package/CHANGELOG.md +2485 -0
- package/LICENSE.txt +84 -0
- package/README.md +34 -0
- package/build/banner.js +4 -0
- package/build/check-bundle-size.js +140 -0
- package/build/diff-tarball.js +18 -0
- package/build/generate-access-token-script.js +11 -0
- package/build/generate-flow-typed-style-spec.js +188 -0
- package/build/generate-release-list.js +21 -0
- package/build/generate-struct-arrays.js +243 -0
- package/build/generate-style-code.js +159 -0
- package/build/mapbox-gl.js.flow +3 -0
- package/build/print-release-url.js +6 -0
- package/build/rollup_plugin_minify_style_spec.js +24 -0
- package/build/rollup_plugins.js +80 -0
- package/build/run-node +3 -0
- package/build/run-tap +8 -0
- package/build/test/build-tape.js +19 -0
- package/dist/mapbox-gl-csp-worker.js +2 -0
- package/dist/mapbox-gl-csp-worker.js.map +1 -0
- package/dist/mapbox-gl-csp.js +2 -0
- package/dist/mapbox-gl-csp.js.map +1 -0
- package/dist/mapbox-gl-dev.js +65889 -0
- package/dist/mapbox-gl-dev.js.flow +3 -0
- package/dist/mapbox-gl-unminified.js +42889 -0
- package/dist/mapbox-gl-unminified.js.map +1 -0
- package/dist/mapbox-gl.css +1 -0
- package/dist/mapbox-gl.js +42 -0
- package/dist/mapbox-gl.js.flow +3 -0
- package/dist/mapbox-gl.js.map +1 -0
- package/dist/style-spec/index.es.js +15032 -0
- package/dist/style-spec/index.es.js.map +1 -0
- package/dist/style-spec/index.js +15058 -0
- package/dist/style-spec/index.js.map +1 -0
- package/flow-typed/gl.js +5 -0
- package/flow-typed/jsdom.js +18 -0
- package/flow-typed/mapbox-gl-supported.js +9 -0
- package/flow-typed/mapbox-unitbezier.js +14 -0
- package/flow-typed/offscreen-canvas.js +9 -0
- package/flow-typed/pbf.js +25 -0
- package/flow-typed/point-geometry.js +44 -0
- package/flow-typed/potpack.js +12 -0
- package/flow-typed/sinon.js +28 -0
- package/flow-typed/vector-tile.js +41 -0
- package/package.json +173 -0
- package/src/css/mapbox-gl.css +812 -0
- package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
- package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
- package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
- package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
- package/src/data/array_types.js +1135 -0
- package/src/data/bucket/circle_attributes.js +9 -0
- package/src/data/bucket/circle_bucket.js +201 -0
- package/src/data/bucket/fill_attributes.js +9 -0
- package/src/data/bucket/fill_bucket.js +229 -0
- package/src/data/bucket/fill_extrusion_attributes.js +10 -0
- package/src/data/bucket/fill_extrusion_bucket.js +283 -0
- package/src/data/bucket/heatmap_bucket.js +17 -0
- package/src/data/bucket/line_attributes.js +10 -0
- package/src/data/bucket/line_attributes_ext.js +10 -0
- package/src/data/bucket/line_bucket.js +594 -0
- package/src/data/bucket/pattern_attributes.js +12 -0
- package/src/data/bucket/pattern_bucket_features.js +60 -0
- package/src/data/bucket/symbol_attributes.js +117 -0
- package/src/data/bucket/symbol_bucket.js +937 -0
- package/src/data/bucket.js +123 -0
- package/src/data/dem_data.js +125 -0
- package/src/data/evaluation_feature.js +25 -0
- package/src/data/extent.js +18 -0
- package/src/data/feature_index.js +322 -0
- package/src/data/feature_position_map.js +131 -0
- package/src/data/index_array_type.js +16 -0
- package/src/data/load_geometry.js +46 -0
- package/src/data/pos_attributes.js +6 -0
- package/src/data/program_configuration.js +708 -0
- package/src/data/raster_bounds_attributes.js +7 -0
- package/src/data/segment.js +76 -0
- package/src/geo/edge_insets.js +102 -0
- package/src/geo/lng_lat.js +168 -0
- package/src/geo/lng_lat_bounds.js +276 -0
- package/src/geo/mercator_coordinate.js +150 -0
- package/src/geo/transform.js +834 -0
- package/src/gl/color_mode.js +34 -0
- package/src/gl/context.js +302 -0
- package/src/gl/cull_face_mode.js +26 -0
- package/src/gl/depth_mode.js +29 -0
- package/src/gl/framebuffer.js +44 -0
- package/src/gl/index_buffer.js +55 -0
- package/src/gl/stencil_mode.js +30 -0
- package/src/gl/types.js +84 -0
- package/src/gl/value.js +520 -0
- package/src/gl/vertex_buffer.js +119 -0
- package/src/index.js +230 -0
- package/src/render/draw_background.js +57 -0
- package/src/render/draw_circle.js +113 -0
- package/src/render/draw_collision_debug.js +172 -0
- package/src/render/draw_custom.js +49 -0
- package/src/render/draw_debug.js +127 -0
- package/src/render/draw_fill.js +124 -0
- package/src/render/draw_fill_extrusion.js +95 -0
- package/src/render/draw_heatmap.js +133 -0
- package/src/render/draw_hillshade.js +107 -0
- package/src/render/draw_line.js +125 -0
- package/src/render/draw_raster.js +125 -0
- package/src/render/draw_symbol.js +392 -0
- package/src/render/glyph_atlas.js +71 -0
- package/src/render/glyph_manager.js +182 -0
- package/src/render/image_atlas.js +149 -0
- package/src/render/image_manager.js +306 -0
- package/src/render/line_atlas.js +210 -0
- package/src/render/painter.js +654 -0
- package/src/render/program/background_program.js +103 -0
- package/src/render/program/circle_program.js +69 -0
- package/src/render/program/clipping_mask_program.js +20 -0
- package/src/render/program/collision_program.js +76 -0
- package/src/render/program/debug_program.js +35 -0
- package/src/render/program/fill_extrusion_program.js +122 -0
- package/src/render/program/fill_program.js +126 -0
- package/src/render/program/heatmap_program.js +83 -0
- package/src/render/program/hillshade_program.js +119 -0
- package/src/render/program/line_program.js +211 -0
- package/src/render/program/pattern.js +102 -0
- package/src/render/program/program_uniforms.js +42 -0
- package/src/render/program/raster_program.js +92 -0
- package/src/render/program/symbol_program.js +224 -0
- package/src/render/program.js +188 -0
- package/src/render/texture.js +122 -0
- package/src/render/uniform_binding.js +147 -0
- package/src/render/vertex_array_object.js +163 -0
- package/src/shaders/README.md +42 -0
- package/src/shaders/_prelude.fragment.glsl +17 -0
- package/src/shaders/_prelude.vertex.glsl +73 -0
- package/src/shaders/background.fragment.glsl +10 -0
- package/src/shaders/background.vertex.glsl +7 -0
- package/src/shaders/background_pattern.fragment.glsl +28 -0
- package/src/shaders/background_pattern.vertex.glsl +20 -0
- package/src/shaders/circle.fragment.glsl +39 -0
- package/src/shaders/circle.vertex.glsl +64 -0
- package/src/shaders/clipping_mask.fragment.glsl +3 -0
- package/src/shaders/clipping_mask.vertex.glsl +7 -0
- package/src/shaders/collision_box.fragment.glsl +21 -0
- package/src/shaders/collision_box.vertex.glsl +27 -0
- package/src/shaders/collision_circle.fragment.glsl +17 -0
- package/src/shaders/collision_circle.vertex.glsl +59 -0
- package/src/shaders/debug.fragment.glsl +9 -0
- package/src/shaders/debug.vertex.glsl +12 -0
- package/src/shaders/encode_attribute.js +17 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill_extrusion.fragment.glsl +9 -0
- package/src/shaders/fill_extrusion.vertex.glsl +66 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
- package/src/shaders/fill_outline.fragment.glsl +17 -0
- package/src/shaders/fill_outline.vertex.glsl +17 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
- package/src/shaders/fill_pattern.fragment.glsl +36 -0
- package/src/shaders/fill_pattern.vertex.glsl +39 -0
- package/src/shaders/heatmap.fragment.glsl +22 -0
- package/src/shaders/heatmap.vertex.glsl +54 -0
- package/src/shaders/heatmap_texture.fragment.glsl +14 -0
- package/src/shaders/heatmap_texture.vertex.glsl +11 -0
- package/src/shaders/hillshade.fragment.glsl +52 -0
- package/src/shaders/hillshade.vertex.glsl +11 -0
- package/src/shaders/hillshade_prepare.fragment.glsl +75 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/index.js +20 -0
- package/src/shaders/line.fragment.glsl +30 -0
- package/src/shaders/line.vertex.glsl +85 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.vertex.glsl +88 -0
- package/src/shaders/line_pattern.fragment.glsl +74 -0
- package/src/shaders/line_pattern.vertex.glsl +99 -0
- package/src/shaders/line_sdf.fragment.glsl +45 -0
- package/src/shaders/line_sdf.vertex.glsl +98 -0
- package/src/shaders/raster.fragment.glsl +52 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/shaders.js +185 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.vertex.glsl +94 -0
- package/src/shaders/symbol_sdf.fragment.glsl +52 -0
- package/src/shaders/symbol_sdf.vertex.glsl +115 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
- package/src/source/canvas_source.js +238 -0
- package/src/source/geojson_source.js +370 -0
- package/src/source/geojson_worker_source.js +366 -0
- package/src/source/geojson_wrapper.js +94 -0
- package/src/source/image_source.js +307 -0
- package/src/source/load_tilejson.js +39 -0
- package/src/source/pixels_to_tile_units.js +21 -0
- package/src/source/query_features.js +208 -0
- package/src/source/raster_dem_tile_source.js +138 -0
- package/src/source/raster_dem_tile_worker_source.js +62 -0
- package/src/source/raster_tile_source.js +169 -0
- package/src/source/rtl_text_plugin.js +143 -0
- package/src/source/source.js +137 -0
- package/src/source/source_cache.js +953 -0
- package/src/source/source_state.js +159 -0
- package/src/source/tile.js +458 -0
- package/src/source/tile_bounds.js +38 -0
- package/src/source/tile_cache.js +212 -0
- package/src/source/tile_id.js +199 -0
- package/src/source/vector_tile_source.js +259 -0
- package/src/source/vector_tile_worker_source.js +216 -0
- package/src/source/video_source.js +203 -0
- package/src/source/worker.js +240 -0
- package/src/source/worker_source.js +107 -0
- package/src/source/worker_tile.js +224 -0
- package/src/style/create_style_layer.js +36 -0
- package/src/style/evaluation_parameters.js +62 -0
- package/src/style/format_section_override.js +56 -0
- package/src/style/light.js +130 -0
- package/src/style/load_glyph_range.js +38 -0
- package/src/style/load_sprite.js +67 -0
- package/src/style/parse_glyph_pbf.js +44 -0
- package/src/style/pauseable_placement.js +132 -0
- package/src/style/properties.js +753 -0
- package/src/style/query_utils.js +43 -0
- package/src/style/style.js +1374 -0
- package/src/style/style_glyph.js +17 -0
- package/src/style/style_image.js +137 -0
- package/src/style/style_layer/background_style_layer.js +21 -0
- package/src/style/style_layer/background_style_layer_properties.js +40 -0
- package/src/style/style_layer/circle_style_layer.js +98 -0
- package/src/style/style_layer/circle_style_layer_properties.js +63 -0
- package/src/style/style_layer/custom_style_layer.js +223 -0
- package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
- package/src/style/style_layer/fill_style_layer.js +67 -0
- package/src/style/style_layer/fill_style_layer_properties.js +55 -0
- package/src/style/style_layer/heatmap_style_layer.js +73 -0
- package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
- package/src/style/style_layer/hillshade_style_layer.js +25 -0
- package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
- package/src/style/style_layer/layer_properties.js.ejs +69 -0
- package/src/style/style_layer/line_style_layer.js +150 -0
- package/src/style/style_layer/line_style_layer_properties.js +71 -0
- package/src/style/style_layer/raster_style_layer.js +21 -0
- package/src/style/style_layer/raster_style_layer_properties.js +50 -0
- package/src/style/style_layer/symbol_style_layer.js +190 -0
- package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
- package/src/style/style_layer/typed_style_layer.js +17 -0
- package/src/style/style_layer.js +283 -0
- package/src/style/style_layer_index.js +80 -0
- package/src/style/validate_style.js +42 -0
- package/src/style/zoom_history.js +44 -0
- package/src/style-spec/.eslintrc +5 -0
- package/src/style-spec/CHANGELOG.md +468 -0
- package/src/style-spec/README.md +59 -0
- package/src/style-spec/bin/gl-style-composite +9 -0
- package/src/style-spec/bin/gl-style-format +22 -0
- package/src/style-spec/bin/gl-style-migrate +9 -0
- package/src/style-spec/bin/gl-style-validate +50 -0
- package/src/style-spec/composite.js +50 -0
- package/src/style-spec/declass.js +42 -0
- package/src/style-spec/deref.js +52 -0
- package/src/style-spec/diff.js +393 -0
- package/src/style-spec/dist/.gitkeep +0 -0
- package/src/style-spec/dist/index.es.js +15032 -0
- package/src/style-spec/dist/index.es.js.map +1 -0
- package/src/style-spec/dist/index.js +15058 -0
- package/src/style-spec/dist/index.js.map +1 -0
- package/src/style-spec/empty.js +29 -0
- package/src/style-spec/error/parsing_error.js +16 -0
- package/src/style-spec/error/validation_error.js +18 -0
- package/src/style-spec/expression/compound_expression.js +162 -0
- package/src/style-spec/expression/definitions/assertion.js +130 -0
- package/src/style-spec/expression/definitions/at.js +70 -0
- package/src/style-spec/expression/definitions/case.js +85 -0
- package/src/style-spec/expression/definitions/coalesce.js +93 -0
- package/src/style-spec/expression/definitions/coercion.js +133 -0
- package/src/style-spec/expression/definitions/collator.js +78 -0
- package/src/style-spec/expression/definitions/comparison.js +184 -0
- package/src/style-spec/expression/definitions/format.js +144 -0
- package/src/style-spec/expression/definitions/image.js +52 -0
- package/src/style-spec/expression/definitions/in.js +72 -0
- package/src/style-spec/expression/definitions/index.js +565 -0
- package/src/style-spec/expression/definitions/index_of.js +89 -0
- package/src/style-spec/expression/definitions/interpolate.js +267 -0
- package/src/style-spec/expression/definitions/length.js +61 -0
- package/src/style-spec/expression/definitions/let.js +72 -0
- package/src/style-spec/expression/definitions/literal.js +77 -0
- package/src/style-spec/expression/definitions/match.js +158 -0
- package/src/style-spec/expression/definitions/number_format.js +142 -0
- package/src/style-spec/expression/definitions/slice.js +86 -0
- package/src/style-spec/expression/definitions/step.js +120 -0
- package/src/style-spec/expression/definitions/var.js +46 -0
- package/src/style-spec/expression/definitions/within.js +342 -0
- package/src/style-spec/expression/evaluation_context.js +59 -0
- package/src/style-spec/expression/expression.js +27 -0
- package/src/style-spec/expression/index.js +392 -0
- package/src/style-spec/expression/is_constant.js +59 -0
- package/src/style-spec/expression/parsing_context.js +233 -0
- package/src/style-spec/expression/parsing_error.js +13 -0
- package/src/style-spec/expression/runtime_error.js +17 -0
- package/src/style-spec/expression/scope.js +36 -0
- package/src/style-spec/expression/stops.js +39 -0
- package/src/style-spec/expression/types/collator.js +61 -0
- package/src/style-spec/expression/types/formatted.js +73 -0
- package/src/style-spec/expression/types/resolved_image.js +29 -0
- package/src/style-spec/expression/types.js +126 -0
- package/src/style-spec/expression/values.js +123 -0
- package/src/style-spec/feature_filter/README.md +55 -0
- package/src/style-spec/feature_filter/convert.js +208 -0
- package/src/style-spec/feature_filter/index.js +175 -0
- package/src/style-spec/format.js +51 -0
- package/src/style-spec/function/convert.js +270 -0
- package/src/style-spec/function/index.js +262 -0
- package/src/style-spec/group_by_layout.js +75 -0
- package/src/style-spec/migrate/expressions.js +39 -0
- package/src/style-spec/migrate/v8.js +203 -0
- package/src/style-spec/migrate/v9.js +26 -0
- package/src/style-spec/migrate.js +36 -0
- package/src/style-spec/package.json +41 -0
- package/src/style-spec/read_style.js +14 -0
- package/src/style-spec/reference/latest.js +3 -0
- package/src/style-spec/reference/v8.json +5914 -0
- package/src/style-spec/rollup.config.js +65 -0
- package/src/style-spec/style-spec.js +124 -0
- package/src/style-spec/types.js +432 -0
- package/src/style-spec/util/color.js +95 -0
- package/src/style-spec/util/color_spaces.js +139 -0
- package/src/style-spec/util/deep_equal.js +28 -0
- package/src/style-spec/util/extend.js +10 -0
- package/src/style-spec/util/get_type.js +17 -0
- package/src/style-spec/util/interpolate.js +22 -0
- package/src/style-spec/util/properties.js +15 -0
- package/src/style-spec/util/ref_properties.js +2 -0
- package/src/style-spec/util/result.js +19 -0
- package/src/style-spec/util/unbundle_jsonlint.js +24 -0
- package/src/style-spec/validate/latest.js +11 -0
- package/src/style-spec/validate/validate.js +75 -0
- package/src/style-spec/validate/validate_array.js +52 -0
- package/src/style-spec/validate/validate_boolean.js +15 -0
- package/src/style-spec/validate/validate_color.js +20 -0
- package/src/style-spec/validate/validate_constants.js +13 -0
- package/src/style-spec/validate/validate_enum.js +21 -0
- package/src/style-spec/validate/validate_expression.js +43 -0
- package/src/style-spec/validate/validate_filter.js +117 -0
- package/src/style-spec/validate/validate_formatted.js +11 -0
- package/src/style-spec/validate/validate_function.js +207 -0
- package/src/style-spec/validate/validate_glyphs_url.js +21 -0
- package/src/style-spec/validate/validate_image.js +11 -0
- package/src/style-spec/validate/validate_layer.js +134 -0
- package/src/style-spec/validate/validate_layout_property.js +6 -0
- package/src/style-spec/validate/validate_light.js +47 -0
- package/src/style-spec/validate/validate_number.js +29 -0
- package/src/style-spec/validate/validate_object.js +61 -0
- package/src/style-spec/validate/validate_paint_property.js +6 -0
- package/src/style-spec/validate/validate_property.js +64 -0
- package/src/style-spec/validate/validate_source.js +111 -0
- package/src/style-spec/validate/validate_string.js +15 -0
- package/src/style-spec/validate_mapbox_api_supported.js +171 -0
- package/src/style-spec/validate_style.js +39 -0
- package/src/style-spec/validate_style.min.js +78 -0
- package/src/style-spec/visit.js +77 -0
- package/src/symbol/anchor.js +26 -0
- package/src/symbol/check_max_angle.js +81 -0
- package/src/symbol/clip_line.js +71 -0
- package/src/symbol/collision_feature.js +109 -0
- package/src/symbol/collision_index.js +373 -0
- package/src/symbol/cross_tile_symbol_index.js +301 -0
- package/src/symbol/get_anchors.js +167 -0
- package/src/symbol/grid_index.js +335 -0
- package/src/symbol/mergelines.js +82 -0
- package/src/symbol/one_em.js +4 -0
- package/src/symbol/opacity_state.js +27 -0
- package/src/symbol/path_interpolator.js +61 -0
- package/src/symbol/placement.js +1124 -0
- package/src/symbol/projection.js +451 -0
- package/src/symbol/quads.js +334 -0
- package/src/symbol/shaping.js +816 -0
- package/src/symbol/symbol_layout.js +796 -0
- package/src/symbol/symbol_size.js +113 -0
- package/src/symbol/transform_text.js +29 -0
- package/src/types/callback.js +17 -0
- package/src/types/cancelable.js +3 -0
- package/src/types/tilejson.js +17 -0
- package/src/types/transferable.js +3 -0
- package/src/types/window.js +172 -0
- package/src/ui/anchor.js +32 -0
- package/src/ui/camera.js +1277 -0
- package/src/ui/control/attribution_control.js +212 -0
- package/src/ui/control/fullscreen_control.js +147 -0
- package/src/ui/control/geolocate_control.js +707 -0
- package/src/ui/control/logo_control.js +92 -0
- package/src/ui/control/navigation_control.js +257 -0
- package/src/ui/control/scale_control.js +142 -0
- package/src/ui/default_locale.js +22 -0
- package/src/ui/events.js +1301 -0
- package/src/ui/handler/box_zoom.js +170 -0
- package/src/ui/handler/click_zoom.js +52 -0
- package/src/ui/handler/handler_util.js +12 -0
- package/src/ui/handler/keyboard.js +208 -0
- package/src/ui/handler/map_event.js +156 -0
- package/src/ui/handler/mouse.js +171 -0
- package/src/ui/handler/scroll_zoom.js +350 -0
- package/src/ui/handler/shim/dblclick_zoom.js +62 -0
- package/src/ui/handler/shim/drag_pan.js +88 -0
- package/src/ui/handler/shim/drag_rotate.js +67 -0
- package/src/ui/handler/shim/touch_zoom_rotate.js +108 -0
- package/src/ui/handler/tap_drag_zoom.js +103 -0
- package/src/ui/handler/tap_recognizer.js +133 -0
- package/src/ui/handler/tap_zoom.js +93 -0
- package/src/ui/handler/touch_pan.js +101 -0
- package/src/ui/handler/touch_zoom_rotate.js +305 -0
- package/src/ui/handler_inertia.js +158 -0
- package/src/ui/handler_manager.js +531 -0
- package/src/ui/hash.js +148 -0
- package/src/ui/map.js +2874 -0
- package/src/ui/marker.js +672 -0
- package/src/ui/popup.js +640 -0
- package/src/util/actor.js +212 -0
- package/src/util/ajax.js +388 -0
- package/src/util/browser/web_worker.js +10 -0
- package/src/util/browser/window.js +6 -0
- package/src/util/browser.js +70 -0
- package/src/util/classify_rings.js +52 -0
- package/src/util/color_ramp.js +61 -0
- package/src/util/config.js +30 -0
- package/src/util/debug.js +28 -0
- package/src/util/dictionary_coder.js +30 -0
- package/src/util/dispatcher.js +70 -0
- package/src/util/dom.js +142 -0
- package/src/util/evented.js +174 -0
- package/src/util/find_pole_of_inaccessibility.js +129 -0
- package/src/util/global_worker_pool.js +35 -0
- package/src/util/image.js +142 -0
- package/src/util/intersection_tests.js +208 -0
- package/src/util/is_char_in_unicode_block.js +311 -0
- package/src/util/mapbox.js +491 -0
- package/src/util/offscreen_canvas_supported.js +14 -0
- package/src/util/performance.js +112 -0
- package/src/util/primitives.js +145 -0
- package/src/util/resolve_tokens.js +16 -0
- package/src/util/script_detection.js +328 -0
- package/src/util/sku_token.js +42 -0
- package/src/util/smart_wrap.js +55 -0
- package/src/util/struct_array.js +243 -0
- package/src/util/struct_array.js.ejs +112 -0
- package/src/util/struct_array_layout.js.ejs +98 -0
- package/src/util/task_queue.js +68 -0
- package/src/util/throttle.js +27 -0
- package/src/util/throttled_invoker.js +46 -0
- package/src/util/tile_request_cache.js +172 -0
- package/src/util/util.js +524 -0
- package/src/util/vectortile_to_geojson.js +50 -0
- package/src/util/verticalize_punctuation.js +114 -0
- package/src/util/web_worker.js +91 -0
- package/src/util/web_worker_transfer.js +266 -0
- package/src/util/webp_supported.js +69 -0
- package/src/util/window.js +102 -0
- package/src/util/worker_pool.js +57 -0
package/src/ui/popup.js
ADDED
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {extend, bindAll} from '../util/util';
|
|
4
|
+
import {Event, Evented} from '../util/evented';
|
|
5
|
+
import {MapMouseEvent} from '../ui/events';
|
|
6
|
+
import DOM from '../util/dom';
|
|
7
|
+
import LngLat from '../geo/lng_lat';
|
|
8
|
+
import Point from '@mapbox/point-geometry';
|
|
9
|
+
import window from '../util/window';
|
|
10
|
+
import smartWrap from '../util/smart_wrap';
|
|
11
|
+
import {type Anchor, anchorTranslate, applyAnchorClass} from './anchor';
|
|
12
|
+
|
|
13
|
+
import type Map from './map';
|
|
14
|
+
import type {LngLatLike} from '../geo/lng_lat';
|
|
15
|
+
import type {PointLike} from '@mapbox/point-geometry';
|
|
16
|
+
|
|
17
|
+
const defaultOptions = {
|
|
18
|
+
closeButton: true,
|
|
19
|
+
closeOnClick: true,
|
|
20
|
+
focusAfterOpen: true,
|
|
21
|
+
className: '',
|
|
22
|
+
maxWidth: "240px"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type Offset = number | PointLike | {[_: Anchor]: PointLike};
|
|
26
|
+
|
|
27
|
+
export type PopupOptions = {
|
|
28
|
+
closeButton?: boolean,
|
|
29
|
+
closeOnClick?: boolean,
|
|
30
|
+
closeOnMove?: boolean,
|
|
31
|
+
focusAfterOpen?: boolean,
|
|
32
|
+
anchor?: Anchor,
|
|
33
|
+
offset?: Offset,
|
|
34
|
+
className?: string,
|
|
35
|
+
maxWidth?: string
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const focusQuerySelector = [
|
|
39
|
+
"a[href]",
|
|
40
|
+
"[tabindex]:not([tabindex='-1'])",
|
|
41
|
+
"[contenteditable]:not([contenteditable='false'])",
|
|
42
|
+
"button:not([disabled])",
|
|
43
|
+
"input:not([disabled])",
|
|
44
|
+
"select:not([disabled])",
|
|
45
|
+
"textarea:not([disabled])",
|
|
46
|
+
].join(", ");
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A popup component.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} [options]
|
|
52
|
+
* @param {boolean} [options.closeButton=true] If `true`, a close button will appear in the
|
|
53
|
+
* top right corner of the popup.
|
|
54
|
+
* @param {boolean} [options.closeOnClick=true] If `true`, the popup will closed when the
|
|
55
|
+
* map is clicked.
|
|
56
|
+
* @param {boolean} [options.closeOnMove=false] If `true`, the popup will closed when the
|
|
57
|
+
* map moves.
|
|
58
|
+
* @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the
|
|
59
|
+
* first focusable element inside the popup.
|
|
60
|
+
* @param {string} [options.anchor] - A string indicating the part of the Popup that should
|
|
61
|
+
* be positioned closest to the coordinate set via {@link Popup#setLngLat}.
|
|
62
|
+
* Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
|
|
63
|
+
* `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
|
|
64
|
+
* dynamically set to ensure the popup falls within the map container with a preference
|
|
65
|
+
* for `'bottom'`.
|
|
66
|
+
* @param {number|PointLike|Object} [options.offset] -
|
|
67
|
+
* A pixel offset applied to the popup's location specified as:
|
|
68
|
+
* - a single number specifying a distance from the popup's location
|
|
69
|
+
* - a {@link PointLike} specifying a constant offset
|
|
70
|
+
* - an object of {@link Point}s specifing an offset for each anchor position
|
|
71
|
+
* Negative offsets indicate left and up.
|
|
72
|
+
* @param {string} [options.className] Space-separated CSS class names to add to popup container
|
|
73
|
+
* @param {string} [options.maxWidth='240px'] -
|
|
74
|
+
* A string that sets the CSS property of the popup's maximum width, eg `'300px'`.
|
|
75
|
+
* To ensure the popup resizes to fit its content, set this property to `'none'`.
|
|
76
|
+
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
77
|
+
* @example
|
|
78
|
+
* var markerHeight = 50, markerRadius = 10, linearOffset = 25;
|
|
79
|
+
* var popupOffsets = {
|
|
80
|
+
* 'top': [0, 0],
|
|
81
|
+
* 'top-left': [0,0],
|
|
82
|
+
* 'top-right': [0,0],
|
|
83
|
+
* 'bottom': [0, -markerHeight],
|
|
84
|
+
* 'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
|
|
85
|
+
* 'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
|
|
86
|
+
* 'left': [markerRadius, (markerHeight - markerRadius) * -1],
|
|
87
|
+
* 'right': [-markerRadius, (markerHeight - markerRadius) * -1]
|
|
88
|
+
* };
|
|
89
|
+
* var popup = new mapboxgl.Popup({offset: popupOffsets, className: 'my-class'})
|
|
90
|
+
* .setLngLat(e.lngLat)
|
|
91
|
+
* .setHTML("<h1>Hello World!</h1>")
|
|
92
|
+
* .setMaxWidth("300px")
|
|
93
|
+
* .addTo(map);
|
|
94
|
+
* @see [Display a popup](https://www.mapbox.com/mapbox-gl-js/example/popup/)
|
|
95
|
+
* @see [Display a popup on hover](https://www.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
|
|
96
|
+
* @see [Display a popup on click](https://www.mapbox.com/mapbox-gl-js/example/popup-on-click/)
|
|
97
|
+
* @see [Attach a popup to a marker instance](https://www.mapbox.com/mapbox-gl-js/example/set-popup/)
|
|
98
|
+
*/
|
|
99
|
+
export default class Popup extends Evented {
|
|
100
|
+
_map: Map;
|
|
101
|
+
options: PopupOptions;
|
|
102
|
+
_content: HTMLElement;
|
|
103
|
+
_container: HTMLElement;
|
|
104
|
+
_closeButton: HTMLElement;
|
|
105
|
+
_tip: HTMLElement;
|
|
106
|
+
_lngLat: LngLat;
|
|
107
|
+
_trackPointer: boolean;
|
|
108
|
+
_pos: ?Point;
|
|
109
|
+
|
|
110
|
+
constructor(options: PopupOptions) {
|
|
111
|
+
super();
|
|
112
|
+
this.options = extend(Object.create(defaultOptions), options);
|
|
113
|
+
bindAll(['_update', '_onClose', 'remove', '_onMouseMove', '_onMouseUp', '_onDrag'], this);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Adds the popup to a map.
|
|
118
|
+
*
|
|
119
|
+
* @param {Map} map The Mapbox GL JS map to add the popup to.
|
|
120
|
+
* @returns {Popup} `this`
|
|
121
|
+
* @example
|
|
122
|
+
* new mapboxgl.Popup()
|
|
123
|
+
* .setLngLat([0, 0])
|
|
124
|
+
* .setHTML("<h1>Null Island</h1>")
|
|
125
|
+
* .addTo(map);
|
|
126
|
+
* @see [Display a popup](https://docs.mapbox.com/mapbox-gl-js/example/popup/)
|
|
127
|
+
* @see [Display a popup on hover](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
|
|
128
|
+
* @see [Display a popup on click](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-click/)
|
|
129
|
+
* @see [Show polygon information on click](https://docs.mapbox.com/mapbox-gl-js/example/polygon-popup-on-click/)
|
|
130
|
+
*/
|
|
131
|
+
addTo(map: Map) {
|
|
132
|
+
if (this._map) this.remove();
|
|
133
|
+
|
|
134
|
+
this._map = map;
|
|
135
|
+
if (this.options.closeOnClick) {
|
|
136
|
+
this._map.on('click', this._onClose);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (this.options.closeOnMove) {
|
|
140
|
+
this._map.on('move', this._onClose);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this._map.on('remove', this.remove);
|
|
144
|
+
this._update();
|
|
145
|
+
this._focusFirstElement();
|
|
146
|
+
|
|
147
|
+
if (this._trackPointer) {
|
|
148
|
+
this._map.on('mousemove', this._onMouseMove);
|
|
149
|
+
this._map.on('mouseup', this._onMouseUp);
|
|
150
|
+
if (this._container) {
|
|
151
|
+
this._container.classList.add('mapboxgl-popup-track-pointer');
|
|
152
|
+
}
|
|
153
|
+
this._map._canvasContainer.classList.add('mapboxgl-track-pointer');
|
|
154
|
+
} else {
|
|
155
|
+
this._map.on('move', this._update);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Fired when the popup is opened manually or programatically.
|
|
160
|
+
*
|
|
161
|
+
* @event open
|
|
162
|
+
* @memberof Popup
|
|
163
|
+
* @instance
|
|
164
|
+
* @type {Object}
|
|
165
|
+
* @property {Popup} popup object that was opened
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Create a popup
|
|
169
|
+
* var popup = new mapboxgl.Popup();
|
|
170
|
+
* // Set an event listener that will fire
|
|
171
|
+
* // any time the popup is opened
|
|
172
|
+
* popup.on('open', function(){
|
|
173
|
+
* console.log('popup was opened');
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
*/
|
|
177
|
+
this.fire(new Event('open'));
|
|
178
|
+
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @returns {boolean} `true` if the popup is open, `false` if it is closed.
|
|
184
|
+
*/
|
|
185
|
+
isOpen() {
|
|
186
|
+
return !!this._map;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Removes the popup from the map it has been added to.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* var popup = new mapboxgl.Popup().addTo(map);
|
|
194
|
+
* popup.remove();
|
|
195
|
+
* @returns {Popup} `this`
|
|
196
|
+
*/
|
|
197
|
+
remove() {
|
|
198
|
+
if (this._content) {
|
|
199
|
+
DOM.remove(this._content);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (this._container) {
|
|
203
|
+
DOM.remove(this._container);
|
|
204
|
+
delete this._container;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (this._map) {
|
|
208
|
+
this._map.off('move', this._update);
|
|
209
|
+
this._map.off('move', this._onClose);
|
|
210
|
+
this._map.off('click', this._onClose);
|
|
211
|
+
this._map.off('remove', this.remove);
|
|
212
|
+
this._map.off('mousemove', this._onMouseMove);
|
|
213
|
+
this._map.off('mouseup', this._onMouseUp);
|
|
214
|
+
this._map.off('drag', this._onDrag);
|
|
215
|
+
delete this._map;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Fired when the popup is closed manually or programatically.
|
|
220
|
+
*
|
|
221
|
+
* @event close
|
|
222
|
+
* @memberof Popup
|
|
223
|
+
* @instance
|
|
224
|
+
* @type {Object}
|
|
225
|
+
* @property {Popup} popup object that was closed
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* // Create a popup
|
|
229
|
+
* var popup = new mapboxgl.Popup();
|
|
230
|
+
* // Set an event listener that will fire
|
|
231
|
+
* // any time the popup is closed
|
|
232
|
+
* popup.on('close', function(){
|
|
233
|
+
* console.log('popup was closed');
|
|
234
|
+
* });
|
|
235
|
+
*
|
|
236
|
+
*/
|
|
237
|
+
this.fire(new Event('close'));
|
|
238
|
+
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Returns the geographical location of the popup's anchor.
|
|
244
|
+
*
|
|
245
|
+
* The longitude of the result may differ by a multiple of 360 degrees from the longitude previously
|
|
246
|
+
* set by `setLngLat` because `Popup` wraps the anchor longitude across copies of the world to keep
|
|
247
|
+
* the popup on screen.
|
|
248
|
+
*
|
|
249
|
+
* @returns {LngLat} The geographical location of the popup's anchor.
|
|
250
|
+
*/
|
|
251
|
+
getLngLat() {
|
|
252
|
+
return this._lngLat;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior.
|
|
257
|
+
*
|
|
258
|
+
* @param lnglat The geographical location to set as the popup's anchor.
|
|
259
|
+
* @returns {Popup} `this`
|
|
260
|
+
*/
|
|
261
|
+
setLngLat(lnglat: LngLatLike) {
|
|
262
|
+
this._lngLat = LngLat.convert(lnglat);
|
|
263
|
+
this._pos = null;
|
|
264
|
+
|
|
265
|
+
this._trackPointer = false;
|
|
266
|
+
|
|
267
|
+
this._update();
|
|
268
|
+
|
|
269
|
+
if (this._map) {
|
|
270
|
+
this._map.on('move', this._update);
|
|
271
|
+
this._map.off('mousemove', this._onMouseMove);
|
|
272
|
+
if (this._container) {
|
|
273
|
+
this._container.classList.remove('mapboxgl-popup-track-pointer');
|
|
274
|
+
}
|
|
275
|
+
this._map._canvasContainer.classList.remove('mapboxgl-track-pointer');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Tracks the popup anchor to the cursor position on screens with a pointer device (it will be hidden on touchscreens). Replaces the `setLngLat` behavior.
|
|
283
|
+
* For most use cases, set `closeOnClick` and `closeButton` to `false`.
|
|
284
|
+
* @example
|
|
285
|
+
* var popup = new mapboxgl.Popup({ closeOnClick: false, closeButton: false })
|
|
286
|
+
* .setHTML("<h1>Hello World!</h1>")
|
|
287
|
+
* .trackPointer()
|
|
288
|
+
* .addTo(map);
|
|
289
|
+
* @returns {Popup} `this`
|
|
290
|
+
*/
|
|
291
|
+
trackPointer() {
|
|
292
|
+
this._trackPointer = true;
|
|
293
|
+
this._pos = null;
|
|
294
|
+
this._update();
|
|
295
|
+
if (this._map) {
|
|
296
|
+
this._map.off('move', this._update);
|
|
297
|
+
this._map.on('mousemove', this._onMouseMove);
|
|
298
|
+
this._map.on('drag', this._onDrag);
|
|
299
|
+
if (this._container) {
|
|
300
|
+
this._container.classList.add('mapboxgl-popup-track-pointer');
|
|
301
|
+
}
|
|
302
|
+
this._map._canvasContainer.classList.add('mapboxgl-track-pointer');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return this;
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Returns the `Popup`'s HTML element.
|
|
311
|
+
* @example
|
|
312
|
+
* // Change the `Popup` element's font size
|
|
313
|
+
* var popup = new mapboxgl.Popup()
|
|
314
|
+
* .setLngLat([-96, 37.8])
|
|
315
|
+
* .setHTML("<p>Hello World!</p>")
|
|
316
|
+
* .addTo(map);
|
|
317
|
+
* var popupElem = popup.getElement();
|
|
318
|
+
* popupElem.style.fontSize = "25px";
|
|
319
|
+
* @returns {HTMLElement} element
|
|
320
|
+
*/
|
|
321
|
+
getElement() {
|
|
322
|
+
return this._container;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Sets the popup's content to a string of text.
|
|
327
|
+
*
|
|
328
|
+
* This function creates a [Text](https://developer.mozilla.org/en-US/docs/Web/API/Text) node in the DOM,
|
|
329
|
+
* so it cannot insert raw HTML. Use this method for security against XSS
|
|
330
|
+
* if the popup content is user-provided.
|
|
331
|
+
*
|
|
332
|
+
* @param text Textual content for the popup.
|
|
333
|
+
* @returns {Popup} `this`
|
|
334
|
+
* @example
|
|
335
|
+
* var popup = new mapboxgl.Popup()
|
|
336
|
+
* .setLngLat(e.lngLat)
|
|
337
|
+
* .setText('Hello, world!')
|
|
338
|
+
* .addTo(map);
|
|
339
|
+
*/
|
|
340
|
+
setText(text: string) {
|
|
341
|
+
return this.setDOMContent(window.document.createTextNode(text));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Sets the popup's content to the HTML provided as a string.
|
|
346
|
+
*
|
|
347
|
+
* This method does not perform HTML filtering or sanitization, and must be
|
|
348
|
+
* used only with trusted content. Consider {@link Popup#setText} if
|
|
349
|
+
* the content is an untrusted text string.
|
|
350
|
+
*
|
|
351
|
+
* @param html A string representing HTML content for the popup.
|
|
352
|
+
* @returns {Popup} `this`
|
|
353
|
+
* @example
|
|
354
|
+
* var popup = new mapboxgl.Popup()
|
|
355
|
+
* .setLngLat(e.lngLat)
|
|
356
|
+
* .setHTML("<h1>Hello World!</h1>")
|
|
357
|
+
* .addTo(map);
|
|
358
|
+
* @see [Display a popup](https://docs.mapbox.com/mapbox-gl-js/example/popup/)
|
|
359
|
+
* @see [Display a popup on hover](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
|
|
360
|
+
* @see [Display a popup on click](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-click/)
|
|
361
|
+
* @see [Attach a popup to a marker instance](https://docs.mapbox.com/mapbox-gl-js/example/set-popup/)
|
|
362
|
+
*/
|
|
363
|
+
setHTML(html: string) {
|
|
364
|
+
const frag = window.document.createDocumentFragment();
|
|
365
|
+
const temp = window.document.createElement('body');
|
|
366
|
+
let child;
|
|
367
|
+
temp.innerHTML = html;
|
|
368
|
+
while (true) {
|
|
369
|
+
child = temp.firstChild;
|
|
370
|
+
if (!child) break;
|
|
371
|
+
frag.appendChild(child);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return this.setDOMContent(frag);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Returns the popup's maximum width.
|
|
379
|
+
*
|
|
380
|
+
* @returns {string} The maximum width of the popup.
|
|
381
|
+
*/
|
|
382
|
+
getMaxWidth() {
|
|
383
|
+
return this._container && this._container.style.maxWidth;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Sets the popup's maximum width. This is setting the CSS property `max-width`.
|
|
388
|
+
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
389
|
+
*
|
|
390
|
+
* @param maxWidth A string representing the value for the maximum width.
|
|
391
|
+
* @returns {Popup} `this`
|
|
392
|
+
*/
|
|
393
|
+
setMaxWidth(maxWidth: string) {
|
|
394
|
+
this.options.maxWidth = maxWidth;
|
|
395
|
+
this._update();
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Sets the popup's content to the element provided as a DOM node.
|
|
401
|
+
*
|
|
402
|
+
* @param htmlNode A DOM node to be used as content for the popup.
|
|
403
|
+
* @returns {Popup} `this`
|
|
404
|
+
* @example
|
|
405
|
+
* // create an element with the popup content
|
|
406
|
+
* var div = window.document.createElement('div');
|
|
407
|
+
* div.innerHTML = 'Hello, world!';
|
|
408
|
+
* var popup = new mapboxgl.Popup()
|
|
409
|
+
* .setLngLat(e.lngLat)
|
|
410
|
+
* .setDOMContent(div)
|
|
411
|
+
* .addTo(map);
|
|
412
|
+
*/
|
|
413
|
+
setDOMContent(htmlNode: Node) {
|
|
414
|
+
if (this._content) {
|
|
415
|
+
// Clear out children first.
|
|
416
|
+
while (this._content.hasChildNodes()) {
|
|
417
|
+
if (this._content.firstChild) {
|
|
418
|
+
this._content.removeChild(this._content.firstChild);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
this._content = DOM.create('div', 'mapboxgl-popup-content', this._container);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// The close button should be the last tabbable element inside the popup for a good keyboard UX.
|
|
426
|
+
this._content.appendChild(htmlNode);
|
|
427
|
+
this._createCloseButton();
|
|
428
|
+
this._update();
|
|
429
|
+
this._focusFirstElement();
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Adds a CSS class to the popup container element.
|
|
435
|
+
*
|
|
436
|
+
* @param {string} className Non-empty string with CSS class name to add to popup container
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* let popup = new mapboxgl.Popup()
|
|
440
|
+
* popup.addClassName('some-class')
|
|
441
|
+
*/
|
|
442
|
+
addClassName(className: string) {
|
|
443
|
+
if (this._container) {
|
|
444
|
+
this._container.classList.add(className);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Removes a CSS class from the popup container element.
|
|
450
|
+
*
|
|
451
|
+
* @param {string} className Non-empty string with CSS class name to remove from popup container
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* let popup = new mapboxgl.Popup()
|
|
455
|
+
* popup.removeClassName('some-class')
|
|
456
|
+
*/
|
|
457
|
+
removeClassName(className: string) {
|
|
458
|
+
if (this._container) {
|
|
459
|
+
this._container.classList.remove(className);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Sets the popup's offset.
|
|
465
|
+
*
|
|
466
|
+
* @param offset Sets the popup's offset.
|
|
467
|
+
* @returns {Popup} `this`
|
|
468
|
+
*/
|
|
469
|
+
setOffset (offset?: Offset) {
|
|
470
|
+
this.options.offset = offset;
|
|
471
|
+
this._update();
|
|
472
|
+
return this;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Add or remove the given CSS class on the popup container, depending on whether the container currently has that class.
|
|
477
|
+
*
|
|
478
|
+
* @param {string} className Non-empty string with CSS class name to add/remove
|
|
479
|
+
*
|
|
480
|
+
* @returns {boolean} if the class was removed return false, if class was added, then return true
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* let popup = new mapboxgl.Popup()
|
|
484
|
+
* popup.toggleClassName('toggleClass')
|
|
485
|
+
*/
|
|
486
|
+
toggleClassName(className: string) {
|
|
487
|
+
if (this._container) {
|
|
488
|
+
return this._container.classList.toggle(className);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
_createCloseButton() {
|
|
493
|
+
if (this.options.closeButton) {
|
|
494
|
+
this._closeButton = DOM.create('button', 'mapboxgl-popup-close-button', this._content);
|
|
495
|
+
this._closeButton.type = 'button';
|
|
496
|
+
this._closeButton.setAttribute('aria-label', 'Close popup');
|
|
497
|
+
this._closeButton.innerHTML = '×';
|
|
498
|
+
this._closeButton.addEventListener('click', this._onClose);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
_onMouseUp(event: MapMouseEvent) {
|
|
503
|
+
this._update(event.point);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
_onMouseMove(event: MapMouseEvent) {
|
|
507
|
+
this._update(event.point);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
_onDrag(event: MapMouseEvent) {
|
|
511
|
+
this._update(event.point);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
_update(cursor: ?PointLike) {
|
|
515
|
+
const hasPosition = this._lngLat || this._trackPointer;
|
|
516
|
+
|
|
517
|
+
if (!this._map || !hasPosition || !this._content) { return; }
|
|
518
|
+
|
|
519
|
+
if (!this._container) {
|
|
520
|
+
this._container = DOM.create('div', 'mapboxgl-popup', this._map.getContainer());
|
|
521
|
+
this._tip = DOM.create('div', 'mapboxgl-popup-tip', this._container);
|
|
522
|
+
this._container.appendChild(this._content);
|
|
523
|
+
if (this.options.className) {
|
|
524
|
+
this.options.className.split(' ').forEach(name =>
|
|
525
|
+
this._container.classList.add(name));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (this._trackPointer) {
|
|
529
|
+
this._container.classList.add('mapboxgl-popup-track-pointer');
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (this.options.maxWidth && this._container.style.maxWidth !== this.options.maxWidth) {
|
|
534
|
+
this._container.style.maxWidth = this.options.maxWidth;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (this._map.transform.renderWorldCopies && !this._trackPointer) {
|
|
538
|
+
this._lngLat = smartWrap(this._lngLat, this._pos, this._map.transform);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (this._trackPointer && !cursor) return;
|
|
542
|
+
|
|
543
|
+
const pos = this._pos = this._trackPointer && cursor ? cursor : this._map.project(this._lngLat);
|
|
544
|
+
|
|
545
|
+
let anchor: ?Anchor = this.options.anchor;
|
|
546
|
+
const offset = normalizeOffset(this.options.offset);
|
|
547
|
+
|
|
548
|
+
if (!anchor) {
|
|
549
|
+
const width = this._container.offsetWidth;
|
|
550
|
+
const height = this._container.offsetHeight;
|
|
551
|
+
let anchorComponents;
|
|
552
|
+
|
|
553
|
+
if (pos.y + offset.bottom.y < height) {
|
|
554
|
+
anchorComponents = ['top'];
|
|
555
|
+
} else if (pos.y > this._map.transform.height - height) {
|
|
556
|
+
anchorComponents = ['bottom'];
|
|
557
|
+
} else {
|
|
558
|
+
anchorComponents = [];
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (pos.x < width / 2) {
|
|
562
|
+
anchorComponents.push('left');
|
|
563
|
+
} else if (pos.x > this._map.transform.width - width / 2) {
|
|
564
|
+
anchorComponents.push('right');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (anchorComponents.length === 0) {
|
|
568
|
+
anchor = 'bottom';
|
|
569
|
+
} else {
|
|
570
|
+
anchor = (anchorComponents.join('-'): any);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const offsetedPos = pos.add(offset[anchor]).round();
|
|
575
|
+
DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`);
|
|
576
|
+
applyAnchorClass(this._container, anchor, 'popup');
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
_focusFirstElement() {
|
|
580
|
+
if (!this.options.focusAfterOpen || !this._container) return;
|
|
581
|
+
|
|
582
|
+
const firstFocusable = this._container.querySelector(focusQuerySelector);
|
|
583
|
+
|
|
584
|
+
if (firstFocusable) firstFocusable.focus();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
_onClose() {
|
|
588
|
+
this.remove();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function normalizeOffset(offset: ?Offset) {
|
|
593
|
+
if (!offset) {
|
|
594
|
+
return normalizeOffset(new Point(0, 0));
|
|
595
|
+
|
|
596
|
+
} else if (typeof offset === 'number') {
|
|
597
|
+
// input specifies a radius from which to calculate offsets at all positions
|
|
598
|
+
const cornerOffset = Math.round(Math.sqrt(0.5 * Math.pow(offset, 2)));
|
|
599
|
+
return {
|
|
600
|
+
'center': new Point(0, 0),
|
|
601
|
+
'top': new Point(0, offset),
|
|
602
|
+
'top-left': new Point(cornerOffset, cornerOffset),
|
|
603
|
+
'top-right': new Point(-cornerOffset, cornerOffset),
|
|
604
|
+
'bottom': new Point(0, -offset),
|
|
605
|
+
'bottom-left': new Point(cornerOffset, -cornerOffset),
|
|
606
|
+
'bottom-right': new Point(-cornerOffset, -cornerOffset),
|
|
607
|
+
'left': new Point(offset, 0),
|
|
608
|
+
'right': new Point(-offset, 0)
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
} else if (offset instanceof Point || Array.isArray(offset)) {
|
|
612
|
+
// input specifies a single offset to be applied to all positions
|
|
613
|
+
const convertedOffset = Point.convert(offset);
|
|
614
|
+
return {
|
|
615
|
+
'center': convertedOffset,
|
|
616
|
+
'top': convertedOffset,
|
|
617
|
+
'top-left': convertedOffset,
|
|
618
|
+
'top-right': convertedOffset,
|
|
619
|
+
'bottom': convertedOffset,
|
|
620
|
+
'bottom-left': convertedOffset,
|
|
621
|
+
'bottom-right': convertedOffset,
|
|
622
|
+
'left': convertedOffset,
|
|
623
|
+
'right': convertedOffset
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
} else {
|
|
627
|
+
// input specifies an offset per position
|
|
628
|
+
return {
|
|
629
|
+
'center': Point.convert(offset['center'] || [0, 0]),
|
|
630
|
+
'top': Point.convert(offset['top'] || [0, 0]),
|
|
631
|
+
'top-left': Point.convert(offset['top-left'] || [0, 0]),
|
|
632
|
+
'top-right': Point.convert(offset['top-right'] || [0, 0]),
|
|
633
|
+
'bottom': Point.convert(offset['bottom'] || [0, 0]),
|
|
634
|
+
'bottom-left': Point.convert(offset['bottom-left'] || [0, 0]),
|
|
635
|
+
'bottom-right': Point.convert(offset['bottom-right'] || [0, 0]),
|
|
636
|
+
'left': Point.convert(offset['left'] || [0, 0]),
|
|
637
|
+
'right': Point.convert(offset['right'] || [0, 0])
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|