@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,123 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
|
|
5
|
-
import Color from '../util/color';
|
|
6
|
-
import Collator from './types/collator';
|
|
7
|
-
import Formatted from './types/formatted';
|
|
8
|
-
import ResolvedImage from './types/resolved_image';
|
|
9
|
-
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array} from './types';
|
|
10
|
-
|
|
11
|
-
import type {Type} from './types';
|
|
12
|
-
|
|
13
|
-
export function validateRGBA(r: mixed, g: mixed, b: mixed, a?: mixed): string | null {
|
|
14
|
-
if (!(
|
|
15
|
-
typeof r === 'number' && r >= 0 && r <= 255 &&
|
|
16
|
-
typeof g === 'number' && g >= 0 && g <= 255 &&
|
|
17
|
-
typeof b === 'number' && b >= 0 && b <= 255
|
|
18
|
-
)) {
|
|
19
|
-
const value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];
|
|
20
|
-
return `Invalid rgba value [${value.join(', ')}]: 'r', 'g', and 'b' must be between 0 and 255.`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!(
|
|
24
|
-
typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
|
|
25
|
-
)) {
|
|
26
|
-
return `Invalid rgba value [${[r, g, b, a].join(', ')}]: 'a' must be between 0 and 1.`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type Value = null | string | boolean | number | Color | Collator | Formatted | ResolvedImage | $ReadOnlyArray<Value> | { +[string]: Value }
|
|
33
|
-
|
|
34
|
-
export function isValue(mixed: mixed): boolean {
|
|
35
|
-
if (mixed === null) {
|
|
36
|
-
return true;
|
|
37
|
-
} else if (typeof mixed === 'string') {
|
|
38
|
-
return true;
|
|
39
|
-
} else if (typeof mixed === 'boolean') {
|
|
40
|
-
return true;
|
|
41
|
-
} else if (typeof mixed === 'number') {
|
|
42
|
-
return true;
|
|
43
|
-
} else if (mixed instanceof Color) {
|
|
44
|
-
return true;
|
|
45
|
-
} else if (mixed instanceof Collator) {
|
|
46
|
-
return true;
|
|
47
|
-
} else if (mixed instanceof Formatted) {
|
|
48
|
-
return true;
|
|
49
|
-
} else if (mixed instanceof ResolvedImage) {
|
|
50
|
-
return true;
|
|
51
|
-
} else if (Array.isArray(mixed)) {
|
|
52
|
-
for (const item of mixed) {
|
|
53
|
-
if (!isValue(item)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
} else if (typeof mixed === 'object') {
|
|
59
|
-
for (const key in mixed) {
|
|
60
|
-
if (!isValue(mixed[key])) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
} else {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function typeOf(value: Value): Type {
|
|
71
|
-
if (value === null) {
|
|
72
|
-
return NullType;
|
|
73
|
-
} else if (typeof value === 'string') {
|
|
74
|
-
return StringType;
|
|
75
|
-
} else if (typeof value === 'boolean') {
|
|
76
|
-
return BooleanType;
|
|
77
|
-
} else if (typeof value === 'number') {
|
|
78
|
-
return NumberType;
|
|
79
|
-
} else if (value instanceof Color) {
|
|
80
|
-
return ColorType;
|
|
81
|
-
} else if (value instanceof Collator) {
|
|
82
|
-
return CollatorType;
|
|
83
|
-
} else if (value instanceof Formatted) {
|
|
84
|
-
return FormattedType;
|
|
85
|
-
} else if (value instanceof ResolvedImage) {
|
|
86
|
-
return ResolvedImageType;
|
|
87
|
-
} else if (Array.isArray(value)) {
|
|
88
|
-
const length = value.length;
|
|
89
|
-
let itemType: Type | typeof undefined;
|
|
90
|
-
|
|
91
|
-
for (const item of value) {
|
|
92
|
-
const t = typeOf(item);
|
|
93
|
-
if (!itemType) {
|
|
94
|
-
itemType = t;
|
|
95
|
-
} else if (itemType === t) {
|
|
96
|
-
continue;
|
|
97
|
-
} else {
|
|
98
|
-
itemType = ValueType;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return array(itemType || ValueType, length);
|
|
104
|
-
} else {
|
|
105
|
-
assert(typeof value === 'object');
|
|
106
|
-
return ObjectType;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function toString(value: Value) {
|
|
111
|
-
const type = typeof value;
|
|
112
|
-
if (value === null) {
|
|
113
|
-
return '';
|
|
114
|
-
} else if (type === 'string' || type === 'number' || type === 'boolean') {
|
|
115
|
-
return String(value);
|
|
116
|
-
} else if (value instanceof Color || value instanceof Formatted || value instanceof ResolvedImage) {
|
|
117
|
-
return value.toString();
|
|
118
|
-
} else {
|
|
119
|
-
return JSON.stringify(value);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export {Color, Collator};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
## Filter
|
|
2
|
-
|
|
3
|
-
Filter expressions are used to target specific data in a layer. This library implements the semantics specified by the [Mapbox GL JS spec](https://www.mapbox.com/mapbox-gl-style-spec/#filter).
|
|
4
|
-
|
|
5
|
-
### API
|
|
6
|
-
|
|
7
|
-
`featureFilter(filter)`
|
|
8
|
-
|
|
9
|
-
Given a filter expressed as nested arrays, return a new function
|
|
10
|
-
that evaluates whether a given feature (with a .properties or .tags property)
|
|
11
|
-
passes its test.
|
|
12
|
-
|
|
13
|
-
#### Parameters
|
|
14
|
-
|
|
15
|
-
| parameter | type | description |
|
|
16
|
-
| --------- | ----- | ---------------- |
|
|
17
|
-
| `filter` | Array | mapbox gl filter |
|
|
18
|
-
|
|
19
|
-
**Returns** `Function`, filter-evaluating function
|
|
20
|
-
|
|
21
|
-
### Usage
|
|
22
|
-
|
|
23
|
-
``` javascript
|
|
24
|
-
var ff = require('@mapbox/mapbox-gl-style-spec').featureFilter;
|
|
25
|
-
|
|
26
|
-
// will match a feature with class of street_limited,
|
|
27
|
-
// AND an admin_level less than or equal to 3,
|
|
28
|
-
// that's NOT a polygon.
|
|
29
|
-
var filter = [
|
|
30
|
-
"all",
|
|
31
|
-
["==", "class", "street_limited"],
|
|
32
|
-
["<=", "admin_level", 3],
|
|
33
|
-
["!=", "$type", "Polygon"]
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
// will match a feature that has a class of
|
|
37
|
-
// wetland OR wetland_noveg.
|
|
38
|
-
// ["in", "class", "wetland", "wetland_noveg"]
|
|
39
|
-
|
|
40
|
-
// testFilter will be a function that returns a boolean
|
|
41
|
-
var testFilter = ff(filter);
|
|
42
|
-
|
|
43
|
-
// Layer feature that you're testing. Must have type
|
|
44
|
-
// and properties keys.
|
|
45
|
-
var feature = {
|
|
46
|
-
type: 2,
|
|
47
|
-
properties: {
|
|
48
|
-
class: "street_limited",
|
|
49
|
-
admin_level: 1
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// will return a boolean based on whether the feature matched the filter
|
|
54
|
-
return testFilter({zoom: 0}, feature);
|
|
55
|
-
```
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {isExpressionFilter} from './index';
|
|
4
|
-
|
|
5
|
-
import type {FilterSpecification} from '../types';
|
|
6
|
-
|
|
7
|
-
type ExpectedTypes = {[_: string]: 'string' | 'number' | 'boolean'};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Convert the given legacy filter to (the JSON representation of) an
|
|
11
|
-
* equivalent expression
|
|
12
|
-
* @private
|
|
13
|
-
*/
|
|
14
|
-
export default function convertFilter(filter: FilterSpecification): mixed {
|
|
15
|
-
return _convertFilter(filter, {});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
* Convert the given filter to an expression, storing the expected types for
|
|
20
|
-
* any feature properties referenced in expectedTypes.
|
|
21
|
-
*
|
|
22
|
-
* These expected types are needed in order to construct preflight type checks
|
|
23
|
-
* needed for handling 'any' filters. A preflight type check is necessary in
|
|
24
|
-
* order to mimic legacy filters' semantics around expected type mismatches.
|
|
25
|
-
* For example, consider the legacy filter:
|
|
26
|
-
*
|
|
27
|
-
* ["any", ["all", [">", "y", 0], [">", "y", 0]], [">", "x", 0]]
|
|
28
|
-
*
|
|
29
|
-
* Naively, we might convert this to the expression:
|
|
30
|
-
*
|
|
31
|
-
* ["any", ["all", [">", ["get", "y"], 0], [">", ["get", "z"], 0]], [">", ["get", "x"], 0]]
|
|
32
|
-
*
|
|
33
|
-
* But if we tried to evaluate this against, say `{x: 1, y: null, z: 0}`, the
|
|
34
|
-
* [">", ["get", "y"], 0] would cause an evaluation error, leading to the
|
|
35
|
-
* entire filter returning false. Legacy filter semantics, though, ask for
|
|
36
|
-
* [">", "y", 0] to simply return `false` when `y` is of the wrong type,
|
|
37
|
-
* allowing the subsequent terms of the outer "any" expression to be evaluated
|
|
38
|
-
* (resulting, in this case, in a `true` value, because x > 0).
|
|
39
|
-
*
|
|
40
|
-
* We account for this by inserting a preflight type-checking expression before
|
|
41
|
-
* each "any" term, allowing us to avoid evaluating the actual converted filter
|
|
42
|
-
* if any type mismatches would cause it to produce an evalaution error:
|
|
43
|
-
*
|
|
44
|
-
* ["any",
|
|
45
|
-
* ["case",
|
|
46
|
-
* ["all", ["==", ["typeof", ["get", "y"]], "number"], ["==", ["typeof", ["get", "z"], "number]],
|
|
47
|
-
* ["all", [">", ["get", "y"], 0], [">", ["get", "z"], 0]],
|
|
48
|
-
* false
|
|
49
|
-
* ],
|
|
50
|
-
* ["case",
|
|
51
|
-
* ["==", ["typeof", ["get", "x"], "number"]],
|
|
52
|
-
* [">", ["get", "x"], 0],
|
|
53
|
-
* false
|
|
54
|
-
* ]
|
|
55
|
-
* ]
|
|
56
|
-
*
|
|
57
|
-
* An alternative, possibly more direct approach would be to use type checks
|
|
58
|
-
* in the conversion of each comparison operator, so that the converted version
|
|
59
|
-
* of each individual ==, >=, etc. would mimic the legacy filter semantics. The
|
|
60
|
-
* downside of this approach is that it can lead to many more type checks than
|
|
61
|
-
* would otherwise be necessary: outside the context of an "any" expression,
|
|
62
|
-
* bailing out due to a runtime type error (expression semantics) and returning
|
|
63
|
-
* false (legacy filter semantics) are equivalent: they cause the filter to
|
|
64
|
-
* produce a `false` result.
|
|
65
|
-
*/
|
|
66
|
-
function _convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes): mixed {
|
|
67
|
-
if (isExpressionFilter(filter)) { return filter; }
|
|
68
|
-
|
|
69
|
-
if (!filter) return true;
|
|
70
|
-
const op = filter[0];
|
|
71
|
-
if (filter.length <= 1) return (op !== 'any');
|
|
72
|
-
|
|
73
|
-
let converted;
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
op === '==' ||
|
|
77
|
-
op === '!=' ||
|
|
78
|
-
op === '<' ||
|
|
79
|
-
op === '>' ||
|
|
80
|
-
op === '<=' ||
|
|
81
|
-
op === '>='
|
|
82
|
-
) {
|
|
83
|
-
const [, property, value] = (filter: any);
|
|
84
|
-
converted = convertComparisonOp(property, value, op, expectedTypes);
|
|
85
|
-
} else if (op === 'any') {
|
|
86
|
-
const children = (filter: any).slice(1).map(f => {
|
|
87
|
-
const types = {};
|
|
88
|
-
const child = _convertFilter(f, types);
|
|
89
|
-
const typechecks = runtimeTypeChecks(types);
|
|
90
|
-
return typechecks === true ? child : ['case', typechecks, child, false];
|
|
91
|
-
});
|
|
92
|
-
return ['any'].concat(children);
|
|
93
|
-
} else if (op === 'all') {
|
|
94
|
-
const children = (filter: any).slice(1).map(f => _convertFilter(f, expectedTypes));
|
|
95
|
-
return children.length > 1 ? ['all'].concat(children) : [].concat(...children);
|
|
96
|
-
} else if (op === 'none') {
|
|
97
|
-
return ['!', _convertFilter(['any'].concat(filter.slice(1)), {})];
|
|
98
|
-
} else if (op === 'in') {
|
|
99
|
-
converted = convertInOp((filter[1]: any), filter.slice(2));
|
|
100
|
-
} else if (op === '!in') {
|
|
101
|
-
converted = convertInOp((filter[1]: any), filter.slice(2), true);
|
|
102
|
-
} else if (op === 'has') {
|
|
103
|
-
converted = convertHasOp((filter[1]: any));
|
|
104
|
-
} else if (op === '!has') {
|
|
105
|
-
converted = ['!', convertHasOp((filter[1]: any))];
|
|
106
|
-
} else {
|
|
107
|
-
converted = true;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return converted;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Given a set of feature properties and an expected type for each one,
|
|
114
|
-
// construct an boolean expression that tests whether each property has the
|
|
115
|
-
// right type.
|
|
116
|
-
// E.g.: for {name: 'string', population: 'number'}, return
|
|
117
|
-
// [ 'all',
|
|
118
|
-
// ['==', ['typeof', ['get', 'name'], 'string']],
|
|
119
|
-
// ['==', ['typeof', ['get', 'population'], 'number]]
|
|
120
|
-
// ]
|
|
121
|
-
function runtimeTypeChecks(expectedTypes: ExpectedTypes) {
|
|
122
|
-
const conditions = [];
|
|
123
|
-
for (const property in expectedTypes) {
|
|
124
|
-
const get = property === '$id' ? ['id'] : ['get', property];
|
|
125
|
-
conditions.push(['==', ['typeof', get], expectedTypes[property]]);
|
|
126
|
-
}
|
|
127
|
-
if (conditions.length === 0) return true;
|
|
128
|
-
if (conditions.length === 1) return conditions[0];
|
|
129
|
-
return ['all'].concat(conditions);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function convertComparisonOp(property: string, value: any, op: string, expectedTypes: ?ExpectedTypes) {
|
|
133
|
-
let get;
|
|
134
|
-
if (property === '$type') {
|
|
135
|
-
return [op, ['geometry-type'], value];
|
|
136
|
-
} else if (property === '$id') {
|
|
137
|
-
get = ['id'];
|
|
138
|
-
} else {
|
|
139
|
-
get = ['get', property];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (expectedTypes && value !== null) {
|
|
143
|
-
const type = ((typeof value): any);
|
|
144
|
-
expectedTypes[property] = type;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (op === '==' && property !== '$id' && value === null) {
|
|
148
|
-
return [
|
|
149
|
-
'all',
|
|
150
|
-
['has', property], // missing property != null for legacy filters
|
|
151
|
-
['==', get, null]
|
|
152
|
-
];
|
|
153
|
-
} else if (op === '!=' && property !== '$id' && value === null) {
|
|
154
|
-
return [
|
|
155
|
-
'any',
|
|
156
|
-
['!', ['has', property]], // missing property != null for legacy filters
|
|
157
|
-
['!=', get, null]
|
|
158
|
-
];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return [op, get, value];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function convertInOp(property: string, values: Array<any>, negate = false) {
|
|
165
|
-
if (values.length === 0) return negate;
|
|
166
|
-
|
|
167
|
-
let get;
|
|
168
|
-
if (property === '$type') {
|
|
169
|
-
get = ['geometry-type'];
|
|
170
|
-
} else if (property === '$id') {
|
|
171
|
-
get = ['id'];
|
|
172
|
-
} else {
|
|
173
|
-
get = ['get', property];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Determine if the list of values to be searched is homogenously typed.
|
|
177
|
-
// If so (and if the type is string or number), then we can use a
|
|
178
|
-
// [match, input, [...values], true, false] construction rather than a
|
|
179
|
-
// bunch of `==` tests.
|
|
180
|
-
let uniformTypes = true;
|
|
181
|
-
const type = typeof values[0];
|
|
182
|
-
for (const value of values) {
|
|
183
|
-
if (typeof value !== type) {
|
|
184
|
-
uniformTypes = false;
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (uniformTypes && (type === 'string' || type === 'number')) {
|
|
190
|
-
// Match expressions must have unique values.
|
|
191
|
-
const uniqueValues = values.sort().filter((v, i) => i === 0 || values[i - 1] !== v);
|
|
192
|
-
return ['match', get, uniqueValues, !negate, negate];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return [ negate ? 'all' : 'any' ].concat(
|
|
196
|
-
values.map(v => [negate ? '!=' : '==', get, v])
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function convertHasOp(property: string) {
|
|
201
|
-
if (property === '$type') {
|
|
202
|
-
return true;
|
|
203
|
-
} else if (property === '$id') {
|
|
204
|
-
return ['!=', ['id'], null];
|
|
205
|
-
} else {
|
|
206
|
-
return ['has', property];
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {createExpression} from '../expression';
|
|
4
|
-
import type {GlobalProperties, Feature} from '../expression';
|
|
5
|
-
import type {CanonicalTileID} from '../../source/tile_id';
|
|
6
|
-
|
|
7
|
-
type FilterExpression = (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID) => boolean;
|
|
8
|
-
export type FeatureFilter ={filter: FilterExpression, needGeometry: boolean};
|
|
9
|
-
|
|
10
|
-
export default createFilter;
|
|
11
|
-
export {isExpressionFilter};
|
|
12
|
-
|
|
13
|
-
function isExpressionFilter(filter: any) {
|
|
14
|
-
if (filter === true || filter === false) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!Array.isArray(filter) || filter.length === 0) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
switch (filter[0]) {
|
|
22
|
-
case 'has':
|
|
23
|
-
return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
|
|
24
|
-
|
|
25
|
-
case 'in':
|
|
26
|
-
return filter.length >= 3 && (typeof filter[1] !== 'string' || Array.isArray(filter[2]));
|
|
27
|
-
|
|
28
|
-
case '!in':
|
|
29
|
-
case '!has':
|
|
30
|
-
case 'none':
|
|
31
|
-
return false;
|
|
32
|
-
|
|
33
|
-
case '==':
|
|
34
|
-
case '!=':
|
|
35
|
-
case '>':
|
|
36
|
-
case '>=':
|
|
37
|
-
case '<':
|
|
38
|
-
case '<=':
|
|
39
|
-
return filter.length !== 3 || (Array.isArray(filter[1]) || Array.isArray(filter[2]));
|
|
40
|
-
|
|
41
|
-
case 'any':
|
|
42
|
-
case 'all':
|
|
43
|
-
for (const f of filter.slice(1)) {
|
|
44
|
-
if (!isExpressionFilter(f) && typeof f !== 'boolean') {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
|
|
50
|
-
default:
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const filterSpec = {
|
|
56
|
-
'type': 'boolean',
|
|
57
|
-
'default': false,
|
|
58
|
-
'transition': false,
|
|
59
|
-
'property-type': 'data-driven',
|
|
60
|
-
'expression': {
|
|
61
|
-
'interpolated': false,
|
|
62
|
-
'parameters': ['zoom', 'feature']
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Given a filter expressed as nested arrays, return a new function
|
|
68
|
-
* that evaluates whether a given feature (with a .properties or .tags property)
|
|
69
|
-
* passes its test.
|
|
70
|
-
*
|
|
71
|
-
* @private
|
|
72
|
-
* @param {Array} filter mapbox gl filter
|
|
73
|
-
* @returns {Function} filter-evaluating function
|
|
74
|
-
*/
|
|
75
|
-
function createFilter(filter: any): FeatureFilter {
|
|
76
|
-
if (filter === null || filter === undefined) {
|
|
77
|
-
return {filter: () => true, needGeometry: false};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!isExpressionFilter(filter)) {
|
|
81
|
-
filter = convertFilter(filter);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const compiled = createExpression(filter, filterSpec);
|
|
85
|
-
if (compiled.result === 'error') {
|
|
86
|
-
throw new Error(compiled.value.map(err => `${err.key}: ${err.message}`).join(', '));
|
|
87
|
-
} else {
|
|
88
|
-
const needGeometry = Array.isArray(filter) && filter.length !== 0 && filter[0] === 'within';
|
|
89
|
-
return {filter: (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID) => compiled.value.evaluate(globalProperties, feature, {}, canonical),
|
|
90
|
-
needGeometry};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Comparison function to sort numbers and strings
|
|
95
|
-
function compare(a, b) {
|
|
96
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function convertFilter(filter: ?Array<any>): mixed {
|
|
100
|
-
if (!filter) return true;
|
|
101
|
-
const op = filter[0];
|
|
102
|
-
if (filter.length <= 1) return (op !== 'any');
|
|
103
|
-
const converted =
|
|
104
|
-
op === '==' ? convertComparisonOp(filter[1], filter[2], '==') :
|
|
105
|
-
op === '!=' ? convertNegation(convertComparisonOp(filter[1], filter[2], '==')) :
|
|
106
|
-
op === '<' ||
|
|
107
|
-
op === '>' ||
|
|
108
|
-
op === '<=' ||
|
|
109
|
-
op === '>=' ? convertComparisonOp(filter[1], filter[2], op) :
|
|
110
|
-
op === 'any' ? convertDisjunctionOp(filter.slice(1)) :
|
|
111
|
-
op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) :
|
|
112
|
-
op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) :
|
|
113
|
-
op === 'in' ? convertInOp(filter[1], filter.slice(2)) :
|
|
114
|
-
op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
|
|
115
|
-
op === 'has' ? convertHasOp(filter[1]) :
|
|
116
|
-
op === '!has' ? convertNegation(convertHasOp(filter[1])) :
|
|
117
|
-
true;
|
|
118
|
-
return converted;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function convertComparisonOp(property: string, value: any, op: string) {
|
|
122
|
-
switch (property) {
|
|
123
|
-
case '$type':
|
|
124
|
-
return [`filter-type-${op}`, value];
|
|
125
|
-
case '$id':
|
|
126
|
-
return [`filter-id-${op}`, value];
|
|
127
|
-
default:
|
|
128
|
-
return [`filter-${op}`, property, value];
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function convertDisjunctionOp(filters: Array<Array<any>>) {
|
|
133
|
-
return ['any'].concat(filters.map(convertFilter));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function convertInOp(property: string, values: Array<any>) {
|
|
137
|
-
if (values.length === 0) { return false; }
|
|
138
|
-
switch (property) {
|
|
139
|
-
case '$type':
|
|
140
|
-
return [`filter-type-in`, ['literal', values]];
|
|
141
|
-
case '$id':
|
|
142
|
-
return [`filter-id-in`, ['literal', values]];
|
|
143
|
-
default:
|
|
144
|
-
if (values.length > 200 && !values.some(v => typeof v !== typeof values[0])) {
|
|
145
|
-
return ['filter-in-large', property, ['literal', values.sort(compare)]];
|
|
146
|
-
} else {
|
|
147
|
-
return ['filter-in-small', property, ['literal', values]];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function convertHasOp(property: string) {
|
|
153
|
-
switch (property) {
|
|
154
|
-
case '$type':
|
|
155
|
-
return true;
|
|
156
|
-
case '$id':
|
|
157
|
-
return [`filter-has-id`];
|
|
158
|
-
default:
|
|
159
|
-
return [`filter-has`, property];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function convertNegation(filter: mixed) {
|
|
164
|
-
return ['!', filter];
|
|
165
|
-
}
|
package/src/style-spec/format.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import reference from './reference/latest.js';
|
|
3
|
-
import stringifyPretty from 'json-stringify-pretty-compact';
|
|
4
|
-
|
|
5
|
-
function sortKeysBy(obj, reference) {
|
|
6
|
-
const result = {};
|
|
7
|
-
for (const key in reference) {
|
|
8
|
-
if (obj[key] !== undefined) {
|
|
9
|
-
result[key] = obj[key];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
for (const key in obj) {
|
|
13
|
-
if (result[key] === undefined) {
|
|
14
|
-
result[key] = obj[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Format a Mapbox GL Style. Returns a stringified style with its keys
|
|
22
|
-
* sorted in the same order as the reference style.
|
|
23
|
-
*
|
|
24
|
-
* The optional `space` argument is passed to
|
|
25
|
-
* [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
|
26
|
-
* to generate formatted output.
|
|
27
|
-
*
|
|
28
|
-
* If `space` is unspecified, a default of `2` spaces will be used.
|
|
29
|
-
*
|
|
30
|
-
* @private
|
|
31
|
-
* @param {Object} style a Mapbox GL Style
|
|
32
|
-
* @param {number} [space] space argument to pass to `JSON.stringify`
|
|
33
|
-
* @returns {string} stringified formatted JSON
|
|
34
|
-
* @example
|
|
35
|
-
* var fs = require('fs');
|
|
36
|
-
* var format = require('mapbox-gl-style-spec').format;
|
|
37
|
-
* var style = fs.readFileSync('./source.json', 'utf8');
|
|
38
|
-
* fs.writeFileSync('./dest.json', format(style));
|
|
39
|
-
* fs.writeFileSync('./dest.min.json', format(style, 0));
|
|
40
|
-
*/
|
|
41
|
-
function format(style, space = 2) {
|
|
42
|
-
style = sortKeysBy(style, reference.$root);
|
|
43
|
-
|
|
44
|
-
if (style.layers) {
|
|
45
|
-
style.layers = style.layers.map((layer) => sortKeysBy(layer, reference.layer));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return stringifyPretty(style, {indent: space});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default format;
|