@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
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import ImageSource from './image_source';
|
|
4
|
-
|
|
5
|
-
import window from '../util/window';
|
|
6
|
-
import rasterBoundsAttributes from '../data/raster_bounds_attributes';
|
|
7
|
-
import SegmentVector from '../data/segment';
|
|
8
|
-
import Texture from '../render/texture';
|
|
9
|
-
import {ErrorEvent} from '../util/evented';
|
|
10
|
-
import ValidationError from '../style-spec/error/validation_error';
|
|
11
|
-
|
|
12
|
-
import type Map from '../ui/map';
|
|
13
|
-
import type Dispatcher from '../util/dispatcher';
|
|
14
|
-
import type {Evented} from '../util/evented';
|
|
15
|
-
|
|
16
|
-
export type CanvasSourceSpecification = {|
|
|
17
|
-
"type": "canvas",
|
|
18
|
-
"coordinates": [[number, number], [number, number], [number, number], [number, number]],
|
|
19
|
-
"animate"?: boolean,
|
|
20
|
-
"canvas": string | HTMLCanvasElement
|
|
21
|
-
|};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Options to add a canvas source type to the map.
|
|
25
|
-
*
|
|
26
|
-
* @typedef {Object} CanvasSourceOptions
|
|
27
|
-
* @property {string} type Source type. Must be `"canvas"`.
|
|
28
|
-
* @property {string|HTMLCanvasElement} canvas Canvas source from which to read pixels. Can be a string representing the ID of the canvas element, or the `HTMLCanvasElement` itself.
|
|
29
|
-
* @property {Array<Array<number>>} coordinates Four geographical coordinates denoting where to place the corners of the canvas, specified in `[longitude, latitude]` pairs.
|
|
30
|
-
* @property {boolean} [animate=true] Whether the canvas source is animated. If the canvas is static (i.e. pixels do not need to be re-read on every frame), `animate` should be set to `false` to improve performance.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A data source containing the contents of an HTML canvas. See {@link CanvasSourceOptions} for detailed documentation of options.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* // add to map
|
|
38
|
-
* map.addSource('some id', {
|
|
39
|
-
* type: 'canvas',
|
|
40
|
-
* canvas: 'idOfMyHTMLCanvas',
|
|
41
|
-
* animate: true,
|
|
42
|
-
* coordinates: [
|
|
43
|
-
* [-76.54, 39.18],
|
|
44
|
-
* [-76.52, 39.18],
|
|
45
|
-
* [-76.52, 39.17],
|
|
46
|
-
* [-76.54, 39.17]
|
|
47
|
-
* ]
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* // update
|
|
51
|
-
* var mySource = map.getSource('some id');
|
|
52
|
-
* mySource.setCoordinates([
|
|
53
|
-
* [-76.54335737228394, 39.18579907229748],
|
|
54
|
-
* [-76.52803659439087, 39.1838364847587],
|
|
55
|
-
* [-76.5295386314392, 39.17683392507606],
|
|
56
|
-
* [-76.54520273208618, 39.17876344106642]
|
|
57
|
-
* ]);
|
|
58
|
-
*
|
|
59
|
-
* map.removeSource('some id'); // remove
|
|
60
|
-
*/
|
|
61
|
-
class CanvasSource extends ImageSource {
|
|
62
|
-
options: CanvasSourceSpecification;
|
|
63
|
-
animate: boolean;
|
|
64
|
-
canvas: HTMLCanvasElement;
|
|
65
|
-
width: number;
|
|
66
|
-
height: number;
|
|
67
|
-
play: () => void;
|
|
68
|
-
pause: () => void;
|
|
69
|
-
_playing: boolean;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @private
|
|
73
|
-
*/
|
|
74
|
-
constructor(id: string, options: CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) {
|
|
75
|
-
super(id, options, dispatcher, eventedParent);
|
|
76
|
-
|
|
77
|
-
// We build in some validation here, since canvas sources aren't included in the style spec:
|
|
78
|
-
if (!options.coordinates) {
|
|
79
|
-
this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, 'missing required property "coordinates"')));
|
|
80
|
-
} else if (!Array.isArray(options.coordinates) || options.coordinates.length !== 4 ||
|
|
81
|
-
options.coordinates.some(c => !Array.isArray(c) || c.length !== 2 || c.some(l => typeof l !== 'number'))) {
|
|
82
|
-
this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, '"coordinates" property must be an array of 4 longitude/latitude array pairs')));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (options.animate && typeof options.animate !== 'boolean') {
|
|
86
|
-
this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, 'optional "animate" property must be a boolean value')));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!options.canvas) {
|
|
90
|
-
this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, 'missing required property "canvas"')));
|
|
91
|
-
} else if (typeof options.canvas !== 'string' && !(options.canvas instanceof window.HTMLCanvasElement)) {
|
|
92
|
-
this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, '"canvas" must be either a string representing the ID of the canvas element from which to read, or an HTMLCanvasElement instance')));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.options = options;
|
|
96
|
-
this.animate = options.animate !== undefined ? options.animate : true;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Enables animation. The image will be copied from the canvas to the map on each frame.
|
|
101
|
-
* @method play
|
|
102
|
-
* @instance
|
|
103
|
-
* @memberof CanvasSource
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Disables animation. The map will display a static copy of the canvas image.
|
|
108
|
-
* @method pause
|
|
109
|
-
* @instance
|
|
110
|
-
* @memberof CanvasSource
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
load() {
|
|
114
|
-
this._loaded = true;
|
|
115
|
-
if (!this.canvas) {
|
|
116
|
-
this.canvas = (this.options.canvas instanceof window.HTMLCanvasElement) ?
|
|
117
|
-
this.options.canvas :
|
|
118
|
-
window.document.getElementById(this.options.canvas);
|
|
119
|
-
}
|
|
120
|
-
this.width = this.canvas.width;
|
|
121
|
-
this.height = this.canvas.height;
|
|
122
|
-
|
|
123
|
-
if (this._hasInvalidDimensions()) {
|
|
124
|
-
this.fire(new ErrorEvent(new Error('Canvas dimensions cannot be less than or equal to zero.')));
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this.play = function() {
|
|
129
|
-
this._playing = true;
|
|
130
|
-
this.map.triggerRepaint();
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
this.pause = function() {
|
|
134
|
-
if (this._playing) {
|
|
135
|
-
this.prepare();
|
|
136
|
-
this._playing = false;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
this._finishLoading();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Returns the HTML `canvas` element.
|
|
145
|
-
*
|
|
146
|
-
* @returns {HTMLCanvasElement} The HTML `canvas` element.
|
|
147
|
-
*/
|
|
148
|
-
getCanvas() {
|
|
149
|
-
return this.canvas;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
onAdd(map: Map) {
|
|
153
|
-
this.map = map;
|
|
154
|
-
this.load();
|
|
155
|
-
if (this.canvas) {
|
|
156
|
-
if (this.animate) this.play();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
onRemove() {
|
|
161
|
-
this.pause();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Sets the canvas's coordinates and re-renders the map.
|
|
166
|
-
*
|
|
167
|
-
* @method setCoordinates
|
|
168
|
-
* @instance
|
|
169
|
-
* @memberof CanvasSource
|
|
170
|
-
* @param {Array<Array<number>>} coordinates Four geographical coordinates,
|
|
171
|
-
* represented as arrays of longitude and latitude numbers, which define the corners of the canvas.
|
|
172
|
-
* The coordinates start at the top left corner of the canvas and proceed in clockwise order.
|
|
173
|
-
* They do not have to represent a rectangle.
|
|
174
|
-
* @returns {CanvasSource} this
|
|
175
|
-
*/
|
|
176
|
-
// setCoordinates inherited from ImageSource
|
|
177
|
-
|
|
178
|
-
prepare() {
|
|
179
|
-
let resize = false;
|
|
180
|
-
if (this.canvas.width !== this.width) {
|
|
181
|
-
this.width = this.canvas.width;
|
|
182
|
-
resize = true;
|
|
183
|
-
}
|
|
184
|
-
if (this.canvas.height !== this.height) {
|
|
185
|
-
this.height = this.canvas.height;
|
|
186
|
-
resize = true;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (this._hasInvalidDimensions()) return;
|
|
190
|
-
|
|
191
|
-
if (Object.keys(this.tiles).length === 0) return; // not enough data for current position
|
|
192
|
-
|
|
193
|
-
const context = this.map.painter.context;
|
|
194
|
-
const gl = context.gl;
|
|
195
|
-
|
|
196
|
-
if (!this.boundsBuffer) {
|
|
197
|
-
this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (!this.boundsSegments) {
|
|
201
|
-
this.boundsSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (!this.texture) {
|
|
205
|
-
this.texture = new Texture(context, this.canvas, gl.RGBA, {premultiply: true});
|
|
206
|
-
} else if (resize || this._playing) {
|
|
207
|
-
this.texture.update(this.canvas, {premultiply: true});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
for (const w in this.tiles) {
|
|
211
|
-
const tile = this.tiles[w];
|
|
212
|
-
if (tile.state !== 'loaded') {
|
|
213
|
-
tile.state = 'loaded';
|
|
214
|
-
tile.texture = this.texture;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
serialize(): Object {
|
|
220
|
-
return {
|
|
221
|
-
type: 'canvas',
|
|
222
|
-
coordinates: this.coordinates
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
hasTransition() {
|
|
227
|
-
return this._playing;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
_hasInvalidDimensions() {
|
|
231
|
-
for (const x of [this.canvas.width, this.canvas.height]) {
|
|
232
|
-
if (isNaN(x) || x <= 0) return true;
|
|
233
|
-
}
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export default CanvasSource;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {*} data
|
|
4
|
-
* @param {*} crs
|
|
5
|
-
*/
|
|
6
|
-
export function loopData(data, crs) {
|
|
7
|
-
if (data.type === "FeatureCollection") {
|
|
8
|
-
data = loopFeatureCollection(data);
|
|
9
|
-
} else if (data.type === "Point") {
|
|
10
|
-
data = oopPoint(data);
|
|
11
|
-
} else if (data.type === "LineString" || data.type === "MultiPoint") {
|
|
12
|
-
data = loopLine(data);
|
|
13
|
-
} else if (data.type === "Polygon" || data.type === "MultiLineString") {
|
|
14
|
-
data = loopPolygon(data);
|
|
15
|
-
} else if (data.type === "MultiPolygon") {
|
|
16
|
-
data = loopMultiPolygon(data);
|
|
17
|
-
}
|
|
18
|
-
console.log("loopdata", data);
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 原先的 90 ~ -90 -> 90 ~ -270, 按照对应的百分比处理
|
|
24
|
-
* @param {*} lat
|
|
25
|
-
*/
|
|
26
|
-
function fixLat(lat) {
|
|
27
|
-
let percent = (90 + lat) / 180;
|
|
28
|
-
let zero = 90 * percent;
|
|
29
|
-
return zero || (45 + zero / 2);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function loopFeatureCollection(data) {
|
|
33
|
-
data.features = data.features.map(f => {
|
|
34
|
-
if (f.geometry.type === "Point") {
|
|
35
|
-
f = loopPoint(f);
|
|
36
|
-
} else if (
|
|
37
|
-
f.geometry.type === "LineString" ||
|
|
38
|
-
data.type === "MultiPoint"
|
|
39
|
-
) {
|
|
40
|
-
f = loopLine(f);
|
|
41
|
-
} else if (
|
|
42
|
-
f.geometry.type === "Polygon" ||
|
|
43
|
-
data.type === "MultiLineString"
|
|
44
|
-
) {
|
|
45
|
-
f = loopPolygon(f);
|
|
46
|
-
} else if (f.geometry.type === "MultiPolygon") {
|
|
47
|
-
f = loopMultiPolygon(f);
|
|
48
|
-
}
|
|
49
|
-
return f;
|
|
50
|
-
});
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// "coordinates": [102,0.5]
|
|
55
|
-
function loopPoint(feature) {
|
|
56
|
-
feature.geometry.coordinates[1] = fixLat(feature.geometry.coordinates[1]);
|
|
57
|
-
return feature;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// "coordinates": [[102, 0], [103, 1], [104, 0],[105, 1]]
|
|
61
|
-
function loopLine(feature) {
|
|
62
|
-
feature.geometry.coordinates = feature.geometry.coordinates.map(p => {
|
|
63
|
-
p[1] = fixLat(p[1]);
|
|
64
|
-
return p;
|
|
65
|
-
});
|
|
66
|
-
return feature;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function loopPolygon(feature) {
|
|
70
|
-
feature.geometry.coordinates = feature.geometry.coordinates.map(r => {
|
|
71
|
-
r = r.map(p => {
|
|
72
|
-
p[1] = fixLat(p[1]);
|
|
73
|
-
return p;
|
|
74
|
-
});
|
|
75
|
-
return r;
|
|
76
|
-
});
|
|
77
|
-
return feature;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function loopMultiPolygon(feature) {
|
|
81
|
-
feature.geometry.coordinates = feature.geometry.coordinates.map(m => {
|
|
82
|
-
m.map(r => {
|
|
83
|
-
r = r.map(p => {
|
|
84
|
-
p[1] = fixLat(p[1]);
|
|
85
|
-
return p;
|
|
86
|
-
});
|
|
87
|
-
return r;
|
|
88
|
-
});
|
|
89
|
-
return m;
|
|
90
|
-
});
|
|
91
|
-
return feature;
|
|
92
|
-
}
|
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {Event, ErrorEvent, Evented} from '../util/evented';
|
|
4
|
-
|
|
5
|
-
import {extend} from '../util/util';
|
|
6
|
-
import EXTENT from '../data/extent';
|
|
7
|
-
import {ResourceType} from '../util/ajax';
|
|
8
|
-
import browser from '../util/browser';
|
|
9
|
-
|
|
10
|
-
import type {Source} from './source';
|
|
11
|
-
import type Map from '../ui/map';
|
|
12
|
-
import type Dispatcher from '../util/dispatcher';
|
|
13
|
-
import type Tile from './tile';
|
|
14
|
-
import type Actor from '../util/actor';
|
|
15
|
-
import type {Callback} from '../types/callback';
|
|
16
|
-
import type {GeoJSON, GeoJSONFeature} from '@mapbox/geojson-types';
|
|
17
|
-
import type {GeoJSONSourceSpecification, PromoteIdSpecification} from '../style-spec/types';
|
|
18
|
-
|
|
19
|
-
import {loopData} from './geojson_helper';
|
|
20
|
-
import CRS from '../ui/crs';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A source containing GeoJSON.
|
|
24
|
-
* (See the [Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson) for detailed documentation of options.)
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* map.addSource('some id', {
|
|
28
|
-
* type: 'geojson',
|
|
29
|
-
* data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* map.addSource('some id', {
|
|
34
|
-
* type: 'geojson',
|
|
35
|
-
* data: {
|
|
36
|
-
* "type": "FeatureCollection",
|
|
37
|
-
* "features": [{
|
|
38
|
-
* "type": "Feature",
|
|
39
|
-
* "properties": {},
|
|
40
|
-
* "geometry": {
|
|
41
|
-
* "type": "Point",
|
|
42
|
-
* "coordinates": [
|
|
43
|
-
* -76.53063297271729,
|
|
44
|
-
* 39.18174077994108
|
|
45
|
-
* ]
|
|
46
|
-
* }
|
|
47
|
-
* }]
|
|
48
|
-
* }
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* map.getSource('some id').setData({
|
|
53
|
-
* "type": "FeatureCollection",
|
|
54
|
-
* "features": [{
|
|
55
|
-
* "type": "Feature",
|
|
56
|
-
* "properties": { "name": "Null Island" },
|
|
57
|
-
* "geometry": {
|
|
58
|
-
* "type": "Point",
|
|
59
|
-
* "coordinates": [ 0, 0 ]
|
|
60
|
-
* }
|
|
61
|
-
* }]
|
|
62
|
-
* });
|
|
63
|
-
* @see [Draw GeoJSON points](https://www.mapbox.com/mapbox-gl-js/example/geojson-markers/)
|
|
64
|
-
* @see [Add a GeoJSON line](https://www.mapbox.com/mapbox-gl-js/example/geojson-line/)
|
|
65
|
-
* @see [Create a heatmap from points](https://www.mapbox.com/mapbox-gl-js/example/heatmap/)
|
|
66
|
-
* @see [Create and style clusters](https://www.mapbox.com/mapbox-gl-js/example/cluster/)
|
|
67
|
-
*/
|
|
68
|
-
class GeoJSONSource extends Evented implements Source {
|
|
69
|
-
crs: string;
|
|
70
|
-
|
|
71
|
-
type: 'geojson';
|
|
72
|
-
id: string;
|
|
73
|
-
minzoom: number;
|
|
74
|
-
maxzoom: number;
|
|
75
|
-
tileSize: number;
|
|
76
|
-
attribution: string;
|
|
77
|
-
promoteId: ?PromoteIdSpecification;
|
|
78
|
-
|
|
79
|
-
isTileClipped: boolean;
|
|
80
|
-
reparseOverscaled: boolean;
|
|
81
|
-
_data: GeoJSON | string;
|
|
82
|
-
_options: any;
|
|
83
|
-
workerOptions: any;
|
|
84
|
-
map: Map;
|
|
85
|
-
actor: Actor;
|
|
86
|
-
_loaded: boolean;
|
|
87
|
-
_collectResourceTiming: boolean;
|
|
88
|
-
_resourceTiming: Array<PerformanceResourceTiming>;
|
|
89
|
-
_removed: boolean;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @private
|
|
93
|
-
*/
|
|
94
|
-
constructor(id: string, options: GeoJSONSourceSpecification & {workerOptions?: any, collectResourceTiming: boolean}, dispatcher: Dispatcher, eventedParent: Evented) {
|
|
95
|
-
super();
|
|
96
|
-
|
|
97
|
-
this.id = id;
|
|
98
|
-
|
|
99
|
-
// `type` is a property rather than a constant to make it easy for 3rd
|
|
100
|
-
// parties to use GeoJSONSource to build their own source types.
|
|
101
|
-
this.type = 'geojson';
|
|
102
|
-
|
|
103
|
-
this.minzoom = 0;
|
|
104
|
-
this.maxzoom = 18;
|
|
105
|
-
this.tileSize = 512;
|
|
106
|
-
this.isTileClipped = true;
|
|
107
|
-
this.reparseOverscaled = true;
|
|
108
|
-
this._removed = false;
|
|
109
|
-
this._loaded = false;
|
|
110
|
-
|
|
111
|
-
this.actor = dispatcher.getActor();
|
|
112
|
-
this.setEventedParent(eventedParent);
|
|
113
|
-
|
|
114
|
-
this.crs = this.getCrs();
|
|
115
|
-
this._data = options.data;// this.fixCrsData(options.data);
|
|
116
|
-
this._options = extend({}, options);
|
|
117
|
-
|
|
118
|
-
this._collectResourceTiming = options.collectResourceTiming;
|
|
119
|
-
this._resourceTiming = [];
|
|
120
|
-
|
|
121
|
-
if (options.maxzoom !== undefined) this.maxzoom = options.maxzoom;
|
|
122
|
-
if (options.type) this.type = options.type;
|
|
123
|
-
if (options.attribution) this.attribution = options.attribution;
|
|
124
|
-
this.promoteId = options.promoteId;
|
|
125
|
-
|
|
126
|
-
const scale = EXTENT / this.tileSize;
|
|
127
|
-
|
|
128
|
-
// sent to the worker, along with `url: ...` or `data: literal geojson`,
|
|
129
|
-
// so that it can load/parse/index the geojson data
|
|
130
|
-
// extending with `options.workerOptions` helps to make it easy for
|
|
131
|
-
// third-party sources to hack/reuse GeoJSONSource.
|
|
132
|
-
this.workerOptions = extend({
|
|
133
|
-
crs: this.crs,
|
|
134
|
-
source: this.id,
|
|
135
|
-
cluster: options.cluster || false,
|
|
136
|
-
geojsonVtOptions: {
|
|
137
|
-
buffer: (options.buffer !== undefined ? options.buffer : 128) * scale,
|
|
138
|
-
tolerance: (options.tolerance !== undefined ? options.tolerance : 0.375) * scale,
|
|
139
|
-
extent: EXTENT,
|
|
140
|
-
maxZoom: this.maxzoom,
|
|
141
|
-
lineMetrics: options.lineMetrics || false,
|
|
142
|
-
generateId: options.generateId || false,
|
|
143
|
-
crs: this.getCrs(),
|
|
144
|
-
},
|
|
145
|
-
superclusterOptions: {
|
|
146
|
-
maxZoom: options.clusterMaxZoom !== undefined ?
|
|
147
|
-
Math.min(options.clusterMaxZoom, this.maxzoom - 1) :
|
|
148
|
-
(this.maxzoom - 1),
|
|
149
|
-
extent: EXTENT,
|
|
150
|
-
radius: (options.clusterRadius || 50) * scale,
|
|
151
|
-
log: false,
|
|
152
|
-
generateId: options.generateId || false,
|
|
153
|
-
crs: this.getCrs(),
|
|
154
|
-
},
|
|
155
|
-
clusterProperties: options.clusterProperties
|
|
156
|
-
}, options.workerOptions);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
getCrs() {
|
|
160
|
-
return 'EPSG:3857';
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
fixCrsData(data) {
|
|
164
|
-
if (this.getCrs() !== CRS.EPSG3857.getEpsgCode()) {
|
|
165
|
-
// console.log('before loop', data);
|
|
166
|
-
data = loopData(data);
|
|
167
|
-
// console.log('after loop', data);
|
|
168
|
-
}
|
|
169
|
-
return data;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
load() {
|
|
173
|
-
this.fire(new Event('dataloading', {dataType: 'source'}));
|
|
174
|
-
this._updateWorkerData((err) => {
|
|
175
|
-
if (err) {
|
|
176
|
-
this.fire(new ErrorEvent(err));
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const data: Object = {dataType: 'source', sourceDataType: 'metadata'};
|
|
181
|
-
if (this._collectResourceTiming && this._resourceTiming && (this._resourceTiming.length > 0)) {
|
|
182
|
-
data.resourceTiming = this._resourceTiming;
|
|
183
|
-
this._resourceTiming = [];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// although GeoJSON sources contain no metadata, we fire this event to let the SourceCache
|
|
187
|
-
// know its ok to start requesting tiles.
|
|
188
|
-
this.fire(new Event('data', data));
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
onAdd(map: Map) {
|
|
193
|
-
this.map = map;
|
|
194
|
-
this.load();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Sets the GeoJSON data and re-renders the map.
|
|
199
|
-
*
|
|
200
|
-
* @param {Object|string} data A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.
|
|
201
|
-
* @returns {GeoJSONSource} this
|
|
202
|
-
*/
|
|
203
|
-
setData(data: GeoJSON | string) {
|
|
204
|
-
this._data = data;
|
|
205
|
-
this.fire(new Event('dataloading', {dataType: 'source'}));
|
|
206
|
-
this._updateWorkerData((err) => {
|
|
207
|
-
if (err) {
|
|
208
|
-
this.fire(new ErrorEvent(err));
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const data: Object = {dataType: 'source', sourceDataType: 'content'};
|
|
213
|
-
if (this._collectResourceTiming && this._resourceTiming && (this._resourceTiming.length > 0)) {
|
|
214
|
-
data.resourceTiming = this._resourceTiming;
|
|
215
|
-
this._resourceTiming = [];
|
|
216
|
-
}
|
|
217
|
-
this.fire(new Event('data', data));
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
return this;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* For clustered sources, fetches the zoom at which the given cluster expands.
|
|
225
|
-
*
|
|
226
|
-
* @param clusterId The value of the cluster's `cluster_id` property.
|
|
227
|
-
* @param callback A callback to be called when the zoom value is retrieved (`(error, zoom) => { ... }`).
|
|
228
|
-
* @returns {GeoJSONSource} this
|
|
229
|
-
*/
|
|
230
|
-
getClusterExpansionZoom(clusterId: number, callback: Callback<number>) {
|
|
231
|
-
this.actor.send('geojson.getClusterExpansionZoom', {clusterId, source: this.id}, callback);
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* For clustered sources, fetches the children of the given cluster on the next zoom level (as an array of GeoJSON features).
|
|
237
|
-
*
|
|
238
|
-
* @param clusterId The value of the cluster's `cluster_id` property.
|
|
239
|
-
* @param callback A callback to be called when the features are retrieved (`(error, features) => { ... }`).
|
|
240
|
-
* @returns {GeoJSONSource} this
|
|
241
|
-
*/
|
|
242
|
-
getClusterChildren(clusterId: number, callback: Callback<Array<GeoJSONFeature>>) {
|
|
243
|
-
this.actor.send('geojson.getClusterChildren', {clusterId, source: this.id}, callback);
|
|
244
|
-
return this;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* For clustered sources, fetches the original points that belong to the cluster (as an array of GeoJSON features).
|
|
249
|
-
*
|
|
250
|
-
* @param clusterId The value of the cluster's `cluster_id` property.
|
|
251
|
-
* @param limit The maximum number of features to return.
|
|
252
|
-
* @param offset The number of features to skip (e.g. for pagination).
|
|
253
|
-
* @param callback A callback to be called when the features are retrieved (`(error, features) => { ... }`).
|
|
254
|
-
* @returns {GeoJSONSource} this
|
|
255
|
-
*/
|
|
256
|
-
getClusterLeaves(clusterId: number, limit: number, offset: number, callback: Callback<Array<GeoJSONFeature>>) {
|
|
257
|
-
this.actor.send('geojson.getClusterLeaves', {
|
|
258
|
-
source: this.id,
|
|
259
|
-
clusterId,
|
|
260
|
-
limit,
|
|
261
|
-
offset
|
|
262
|
-
}, callback);
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/*
|
|
267
|
-
* Responsible for invoking WorkerSource's geojson.loadData target, which
|
|
268
|
-
* handles loading the geojson data and preparing to serve it up as tiles,
|
|
269
|
-
* using geojson-vt or supercluster as appropriate.
|
|
270
|
-
*/
|
|
271
|
-
_updateWorkerData(callback: Callback<void>) {
|
|
272
|
-
this._loaded = false;
|
|
273
|
-
const options = extend({}, this.workerOptions);
|
|
274
|
-
let data = this._data;
|
|
275
|
-
|
|
276
|
-
if (typeof data === 'string') {
|
|
277
|
-
options.request = this.map._requestManager.transformRequest(browser.resolveURL(data), ResourceType.Source);
|
|
278
|
-
options.request.collectResourceTiming = this._collectResourceTiming;
|
|
279
|
-
} else {
|
|
280
|
-
options.data = JSON.stringify(data);
|
|
281
|
-
}
|
|
282
|
-
// target {this.type}.loadData rather than literally geojson.loadData,
|
|
283
|
-
// so that other geojson-like source types can easily reuse this
|
|
284
|
-
// implementation
|
|
285
|
-
this.actor.send(`${this.type}.loadData`, options, (err, result) => {
|
|
286
|
-
if (this._removed || (result && result.abandoned)) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
this._loaded = true;
|
|
291
|
-
|
|
292
|
-
if (result && result.resourceTiming && result.resourceTiming[this.id])
|
|
293
|
-
this._resourceTiming = result.resourceTiming[this.id].slice(0);
|
|
294
|
-
// Any `loadData` calls that piled up while we were processing
|
|
295
|
-
// this one will get coalesced into a single call when this
|
|
296
|
-
// 'coalesce' message is processed.
|
|
297
|
-
// We would self-send from the worker if we had access to its
|
|
298
|
-
// message queue. Waiting instead for the 'coalesce' to round-trip
|
|
299
|
-
// through the foreground just means we're throttling the worker
|
|
300
|
-
// to run at a little less than full-throttle.
|
|
301
|
-
this.actor.send(`${this.type}.coalesce`, {source: options.source}, null);
|
|
302
|
-
callback(err);
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
loaded(): boolean {
|
|
307
|
-
return this._loaded;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
loadTile(tile: Tile, callback: Callback<void>) {
|
|
311
|
-
const message = !tile.actor ? 'loadTile' : 'reloadTile';
|
|
312
|
-
tile.actor = this.actor;
|
|
313
|
-
const params = {
|
|
314
|
-
type: this.type,
|
|
315
|
-
uid: tile.uid,
|
|
316
|
-
tileID: tile.tileID,
|
|
317
|
-
zoom: tile.tileID.overscaledZ,
|
|
318
|
-
maxZoom: this.maxzoom,
|
|
319
|
-
tileSize: this.tileSize,
|
|
320
|
-
source: this.id,
|
|
321
|
-
pixelRatio: browser.devicePixelRatio,
|
|
322
|
-
showCollisionBoxes: this.map.showCollisionBoxes,
|
|
323
|
-
promoteId: this.promoteId
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
tile.request = this.actor.send(message, params, (err, data) => {
|
|
327
|
-
delete tile.request;
|
|
328
|
-
tile.unloadVectorData();
|
|
329
|
-
|
|
330
|
-
if (tile.aborted) {
|
|
331
|
-
return callback(null);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (err) {
|
|
335
|
-
return callback(err);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
tile.loadVectorData(data, this.map.painter, message === 'reloadTile');
|
|
339
|
-
|
|
340
|
-
return callback(null);
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
abortTile(tile: Tile) {
|
|
345
|
-
if (tile.request) {
|
|
346
|
-
tile.request.cancel();
|
|
347
|
-
delete tile.request;
|
|
348
|
-
}
|
|
349
|
-
tile.aborted = true;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
unloadTile(tile: Tile) {
|
|
353
|
-
tile.unloadVectorData();
|
|
354
|
-
this.actor.send('removeTile', {uid: tile.uid, type: this.type, source: this.id});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
onRemove() {
|
|
358
|
-
this._removed = true;
|
|
359
|
-
this.actor.send('removeSource', {type: this.type, source: this.id});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
serialize() {
|
|
363
|
-
return extend({}, this._options, {
|
|
364
|
-
type: this.type,
|
|
365
|
-
data: this._data
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
hasTransition() {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export default GeoJSONSource;
|