maplibre-preview 0.0.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73a995cfb9db9269d680e9e479fa85baf0581c6e2425eb03d00a233715ce06aa
4
- data.tar.gz: c9735545dca13f01336ac4f53c5193053bfdb86d628798b4713cb0c0e2b53399
3
+ metadata.gz: df12e7c5527319ba509cd5640dd3af10977259fcfc1272aeb53511d298670caa
4
+ data.tar.gz: eb0ef8cf653b812c7b29c99cbf69848b7f1ab71d34ba5718da5bf84ac0c6b9f1
5
5
  SHA512:
6
- metadata.gz: c7d3f4d15e5ff4f04100de5c8c7bebb591a8600082b035a7276a7aed179d346206749c04c09e9155e6eb71ad16ca6c0c1514d858409a1c720125a7602d7e3fef
7
- data.tar.gz: 5eb357401784c1174cc384c351b5af172945d985eb1141e4058381a15276720d003fb2fa52b97b82e73afb40c3a7655a9b254f6772fec8582f0fd78628d70bf7
6
+ metadata.gz: e7a98ded840731605fd20f1dd17fff9d0d2957f70c5f08aa24fd3cb4aa6b790f9b37445e23bb44096d85c2dfd6e77c5715c532dfb10332f1d0370273667bab9c
7
+ data.tar.gz: e51939f434f6535a0ba22226fd9b3721cc3b953353d0401b87aab2536c6a059cfa95f1997f2be79cfeccc2e52b020f6c9f80504e0ec1dfbf9835d29b6fabade2
@@ -0,0 +1,16 @@
1
+ on: { push: { branches: [master,main] } }
2
+
3
+ jobs:
4
+ build_and_publish:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v3
8
+ - uses: ruby/setup-ruby@v1
9
+ with: { ruby-version: '3.3.1' }
10
+ - run: |
11
+ mkdir -p ~/.gem && touch ~/.gem/credentials && chmod 0600 ~/.gem/credentials
12
+ printf -- "---\n:rubygems_api_key: ${API_KEY}\n" > ~/.gem/credentials
13
+ bundle install && rake push
14
+ env:
15
+ API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
16
+ GITHUB_RUN_NUMBER: ${{ github.run_number }}
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --warnings
data/.rubocop.yml ADDED
@@ -0,0 +1,260 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ # TargetRubyVersion: 3.1.2 read from .ruby-version
7
+ NewCops: enable
8
+ Exclude:
9
+ - benchmarks/*.rb
10
+ - "*.gemspec"
11
+
12
+ Layout/SpaceAroundMethodCallOperator:
13
+ Enabled: false
14
+
15
+ Layout/SpaceInLambdaLiteral:
16
+ Enabled: false
17
+
18
+ Layout/MultilineMethodCallIndentation:
19
+ Enabled: true
20
+ EnforcedStyle: indented
21
+
22
+ Layout/FirstArrayElementIndentation:
23
+ EnforcedStyle: consistent
24
+
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ Enabled: true
27
+ EnforcedStyle: no_space
28
+ EnforcedStyleForEmptyBraces: no_space
29
+
30
+ Layout/LineLength:
31
+ Max: 100
32
+ Exclude:
33
+ - "spec/**/*.rb"
34
+
35
+ Lint/AmbiguousBlockAssociation:
36
+ Enabled: true
37
+ # because 'expect { foo }.to change { bar }' is fine
38
+ Exclude:
39
+ - "spec/**/*.rb"
40
+
41
+ Lint/BooleanSymbol:
42
+ Enabled: false
43
+
44
+ Lint/ConstantDefinitionInBlock:
45
+ Exclude:
46
+ - "spec/**/*.rb"
47
+
48
+ Lint/RaiseException:
49
+ Enabled: false
50
+
51
+ Lint/StructNewOverride:
52
+ Enabled: false
53
+
54
+ Lint/SuppressedException:
55
+ Exclude:
56
+ - "spec/spec_helper.rb"
57
+
58
+ Lint/LiteralAsCondition:
59
+ Exclude:
60
+ - "spec/**/*.rb"
61
+
62
+ Naming/PredicateName:
63
+ Enabled: false
64
+
65
+ Naming/FileName:
66
+ Exclude:
67
+ - "lib/*-*.rb"
68
+
69
+ Naming/MethodName:
70
+ Enabled: false
71
+
72
+ Naming/MethodParameterName:
73
+ Enabled: false
74
+
75
+ Naming/MemoizedInstanceVariableName:
76
+ Enabled: false
77
+
78
+ Metrics/MethodLength:
79
+ Enabled: false
80
+
81
+ Metrics/ClassLength:
82
+ Enabled: false
83
+
84
+ Metrics/BlockLength:
85
+ Enabled: false
86
+
87
+ Metrics/AbcSize:
88
+ Max: 25
89
+
90
+ Metrics/CyclomaticComplexity:
91
+ Enabled: true
92
+ Max: 12
93
+
94
+ Style/ExponentialNotation:
95
+ Enabled: false
96
+
97
+ Style/HashEachMethods:
98
+ Enabled: false
99
+
100
+ Style/HashTransformKeys:
101
+ Enabled: false
102
+
103
+ Style/HashTransformValues:
104
+ Enabled: false
105
+
106
+ Style/AccessModifierDeclarations:
107
+ Enabled: false
108
+
109
+ Style/Alias:
110
+ Enabled: true
111
+ EnforcedStyle: prefer_alias_method
112
+
113
+ Style/AsciiComments:
114
+ Enabled: false
115
+
116
+ Style/BlockDelimiters:
117
+ Enabled: false
118
+
119
+ Style/ClassAndModuleChildren:
120
+ Exclude:
121
+ - "spec/**/*.rb"
122
+
123
+ Style/ConditionalAssignment:
124
+ Enabled: false
125
+
126
+ Style/DateTime:
127
+ Enabled: false
128
+
129
+ Style/Documentation:
130
+ Enabled: false
131
+
132
+ Style/EachWithObject:
133
+ Enabled: false
134
+
135
+ Style/FormatString:
136
+ Enabled: false
137
+
138
+ Style/FormatStringToken:
139
+ Enabled: false
140
+
141
+ Style/GuardClause:
142
+ Enabled: false
143
+
144
+ Style/IfUnlessModifier:
145
+ Enabled: false
146
+
147
+ Style/Lambda:
148
+ Enabled: false
149
+
150
+ Style/LambdaCall:
151
+ Enabled: false
152
+
153
+ Style/ParallelAssignment:
154
+ Enabled: false
155
+
156
+ Style/StabbyLambdaParentheses:
157
+ Enabled: false
158
+
159
+ #Style/StringLiterals:
160
+ # Enabled: true
161
+ # EnforcedStyle: double_quotes
162
+ # ConsistentQuotesInMultiline: false
163
+ #
164
+ #Style/StringLiteralsInInterpolation:
165
+ # Enabled: true
166
+ # EnforcedStyle: double_quotes
167
+
168
+ Style/SymbolArray:
169
+ Exclude:
170
+ - "spec/**/*.rb"
171
+
172
+ Style/TrailingUnderscoreVariable:
173
+ Enabled: false
174
+
175
+ Style/MultipleComparison:
176
+ Enabled: false
177
+
178
+ Style/Next:
179
+ Enabled: false
180
+
181
+ Style/AccessorGrouping:
182
+ Enabled: false
183
+
184
+ Style/EmptyLiteral:
185
+ Enabled: false
186
+
187
+ Style/Semicolon:
188
+ Exclude:
189
+ - "spec/**/*.rb"
190
+
191
+ Style/HashAsLastArrayItem:
192
+ Exclude:
193
+ - "spec/**/*.rb"
194
+
195
+ Style/CaseEquality:
196
+ Exclude:
197
+ - "lib/dry/monads/**/*.rb"
198
+ - "lib/dry/struct/**/*.rb"
199
+ - "lib/dry/types/**/*.rb"
200
+ - "spec/**/*.rb"
201
+
202
+ Style/ExplicitBlockArgument:
203
+ Exclude:
204
+ - "lib/dry/types/**/*.rb"
205
+
206
+ Style/CombinableLoops:
207
+ Enabled: false
208
+
209
+ Style/EmptyElse:
210
+ Enabled: false
211
+
212
+ Style/DoubleNegation:
213
+ Enabled: false
214
+
215
+ Style/MultilineBlockChain:
216
+ Enabled: false
217
+
218
+ Style/NumberedParametersLimit:
219
+ Max: 2
220
+
221
+ Lint/UnusedBlockArgument:
222
+ Exclude:
223
+ - "spec/**/*.rb"
224
+
225
+ Lint/Debugger:
226
+ Exclude:
227
+ - "bin/console"
228
+
229
+ Lint/BinaryOperatorWithIdenticalOperands:
230
+ Exclude:
231
+ - "spec/**/*.rb"
232
+
233
+ Metrics/ParameterLists:
234
+ Exclude:
235
+ - "spec/**/*.rb"
236
+
237
+ Lint/EmptyBlock:
238
+ Exclude:
239
+ - "spec/**/*.rb"
240
+
241
+ Lint/UselessMethodDefinition:
242
+ Exclude:
243
+ - "spec/**/*.rb"
244
+
245
+ Lint/SelfAssignment:
246
+ Enabled: false
247
+
248
+ Lint/EmptyClass:
249
+ Enabled: false
250
+
251
+ Naming/ConstantName:
252
+ Exclude:
253
+ - "spec/**/*.rb"
254
+
255
+ Naming/VariableNumber:
256
+ Exclude:
257
+ - "spec/**/*.rb"
258
+
259
+ Naming/BinaryOperatorParameterName:
260
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ ## [1.0.0] - 2025-09-29
4
+
5
+ ### Added
6
+ - **Extracted MapLibre development tools** from existing tiles-proxy-cache project
7
+ - **Sinatra extension** for easy integration into existing applications
8
+ - **StaticMiddleware** for serving gem assets (JS files) without conflicts
9
+ - **Helper methods** for rendering map development interface
10
+ - **Standalone application** for testing and development purposes
11
+
12
+ ### Extracted Features
13
+ - **Advanced layer filtering** with metadata support (from `filters.js`)
14
+ - **Terrain visualization** and elevation profiles (from `contour.js`)
15
+ - **Performance monitoring** and metrics display
16
+ - **Interactive style debugging** tools
17
+ - **Contour line generation** for terrain data using MapLibre Contour
18
+ - **Hover and click modes** for feature inspection
19
+ - **MapLibre GL JS integration** with version 5.7.3
20
+
21
+ ### Refactored Components
22
+ - **Slim templates** (`map.slim`, `map_layout.slim`) adapted for gem structure
23
+ - **JavaScript modules** (`filters.js`, `contour.js`) preserved with original functionality
24
+ - **View rendering** with dynamic path resolution for gem integration
25
+ - **Configuration system** with sensible defaults for MapLibre development
26
+
27
+ ### Technical Implementation
28
+ - **Ruby >= 2.7.0** support with modern gem structure
29
+ - **Sinatra 2.1+** compatibility and extension system
30
+ - **Rack middleware** for asset serving without path conflicts
31
+ - **Comprehensive test suite** with RSpec for all components
32
+ - **Clean gem structure** optimized for integration use cases
33
+
34
+ ### Migration Notes
35
+ This gem extracts the MapLibre development tools that were previously embedded in the tiles-proxy-cache project, making them reusable across different Sinatra applications. The original functionality has been preserved while adding proper gem structure and integration capabilities.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alexandr Ludov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,312 @@
1
+ # MapLibre Preview
2
+
3
+ A Ruby gem providing development tools for MapLibre GL JS styles with advanced filtering, terrain visualization, and performance monitoring capabilities. Designed for seamless integration into Sinatra applications.
4
+
5
+ [![Ruby](https://img.shields.io/badge/ruby-2.7+-red.svg)](https://ruby-lang.org)
6
+ [![Sinatra](https://img.shields.io/badge/sinatra-web_framework-lightgrey.svg)](http://sinatrarb.com/)
7
+ [![MapLibre](https://img.shields.io/badge/maplibre-gl_js-blue.svg)](https://maplibre.org/)
8
+ [![Русский](https://img.shields.io/badge/русский-документация-orange.svg)](docs/README_RU.md)
9
+
10
+ ## Key Features
11
+
12
+ - **Advanced Layer Filtering**: Metadata-driven layer filtering with support for complex filter expressions
13
+ - **Terrain Visualization**: Full terrain support with elevation profiles and contour line generation
14
+ - **Performance Monitoring**: Real-time FPS, memory usage, and tile loading metrics
15
+ - **Interactive Debugging**: Hover and click modes for feature inspection
16
+ - **Sinatra Integration**: Seamless integration as Sinatra extension with helper methods
17
+ - **Static Asset Serving**: Built-in middleware for serving JavaScript modules without conflicts
18
+
19
+ ## Architecture Overview
20
+
21
+ The gem consists of several integrated components:
22
+
23
+ ### Core Components
24
+
25
+ - **[Main Module](lib/maplibre-preview.rb)** - Core gem functionality including Sinatra extension, Rack middleware, helper methods, and standalone application
26
+ - **[Slim Templates](lib/maplibre-preview/views/)** - HTML templates for map interface
27
+ - **[JavaScript Modules](lib/maplibre-preview/public/js/)** - Client-side filtering and terrain logic
28
+
29
+ ### Data Flow
30
+
31
+ 1. **Sinatra Integration** → Register extension → Configure options → Use helpers
32
+ 2. **Asset Serving** → StaticMiddleware intercepts `/js/*` requests → Serves from gem
33
+ 3. **Map Rendering** → Helper methods render Slim templates → Include external dependencies
34
+ 4. **Client Interaction** → JavaScript modules handle filtering and terrain features
35
+
36
+ ## Quick Start
37
+
38
+ ### Installation
39
+
40
+ Add to your Gemfile:
41
+
42
+ ```ruby
43
+ gem 'maplibre-preview'
44
+ ```
45
+
46
+ Then run:
47
+
48
+ ```bash
49
+ bundle install
50
+ ```
51
+
52
+ ### Basic Integration
53
+
54
+ ```ruby
55
+ require 'maplibre-preview'
56
+
57
+ class MyApp < Sinatra::Base
58
+ register MapLibrePreview::Extension
59
+
60
+ get '/map' do
61
+ render_maplibre_preview
62
+ end
63
+ end
64
+ ```
65
+
66
+ ### Passing Style URL
67
+
68
+ There are several ways to pass a style URL to the map:
69
+
70
+ **1. Via URL parameter:**
71
+ ```
72
+ http://localhost:9292/map?style_url=https://example.com/style.json
73
+ ```
74
+
75
+ **2. Via route parameter:**
76
+ ```ruby
77
+ get '/map' do
78
+ params[:style_url] = 'https://example.com/style.json'
79
+ render_maplibre_preview
80
+ end
81
+ ```
82
+
83
+ **3. Via source parameter:**
84
+ ```
85
+ http://localhost:9292/map?source=Example_Style
86
+ ```
87
+
88
+ ### Standalone Development Server
89
+
90
+ The gem includes a complete Sinatra application for testing and development:
91
+
92
+ ```ruby
93
+ require 'maplibre-preview'
94
+
95
+ # Run standalone development server
96
+ MapLibrePreview::App.run!
97
+ ```
98
+
99
+ This starts a complete web server with:
100
+ - Map interface at `http://localhost:4567/map`
101
+ - JavaScript assets served from `/js/*`
102
+ - All gem functionality available out of the box
103
+
104
+ **How to use with a style:**
105
+ - Pass style URL as parameter: `http://localhost:4567/map?style_url=https://example.com/style.json`
106
+
107
+ **Without a style:**
108
+ - Shows only basemap tiles (OpenStreetMap)
109
+ - Useful for testing basic functionality
110
+ - No custom layers or styling
111
+
112
+ **Use cases:**
113
+ - Quick testing of gem functionality
114
+ - Development and debugging
115
+ - Demonstrating capabilities
116
+
117
+ ## Configuration
118
+
119
+ The gem uses fixed configurations for optimal compatibility:
120
+
121
+ - **Map Center**: `[35.15, 47.41]`
122
+ - **Initial Zoom**: `2`
123
+ - **Basemap**: OpenStreetMap tiles with 0.8 opacity
124
+ - **Library Versions**: MapLibre GL JS 5.7.3, MapLibre Contour 0.1.0, D3.js 7
125
+
126
+ **Style URL**: Pass via URL parameter `?style_url=https://example.com/style.json`
127
+
128
+ ## API Reference
129
+
130
+ ### Sinatra Extension
131
+
132
+ ```ruby
133
+ # Register the extension
134
+ register MapLibrePreview::Extension
135
+ ```
136
+
137
+ ### Helper Methods
138
+
139
+ | Method | Description | Parameters |
140
+ |--------|-------------|------------|
141
+ | `render_maplibre_preview` | Render complete map development interface | None |
142
+ | `render_map_layout` | Render map layout only | None |
143
+ | `style_url` | Get current style URL from params | None |
144
+ | `should_show_map?` | Check if map should be displayed | None |
145
+
146
+ ### Standalone Application
147
+
148
+ ```ruby
149
+ # Available routes
150
+ GET /map # Main map development interface
151
+ GET /js/:file # JavaScript asset serving
152
+ ```
153
+
154
+ ## Style Metadata Support
155
+
156
+ The gem supports advanced filtering through style metadata:
157
+
158
+ ```json
159
+ {
160
+ "metadata": {
161
+ "filters": {
162
+ "buildings": [
163
+ {
164
+ "id": "residential",
165
+ "filter": ["==", ["get", "type"], "residential"]
166
+ },
167
+ {
168
+ "id": "commercial",
169
+ "filter": ["==", ["get", "type"], "commercial"]
170
+ }
171
+ ]
172
+ },
173
+ "locale": {
174
+ "en": {
175
+ "buildings": "Buildings",
176
+ "residential": "Residential",
177
+ "commercial": "Commercial"
178
+ }
179
+ }
180
+ }
181
+ }
182
+ ```
183
+
184
+ ## Terrain Support
185
+
186
+ For terrain visualization, add terrain configuration to your style:
187
+
188
+ ```json
189
+ {
190
+ "terrain": {
191
+ "source": "terrain-source"
192
+ },
193
+ "sources": {
194
+ "terrain-source": {
195
+ "type": "raster-dem",
196
+ "tiles": ["https://your-terrain-tiles/{z}/{x}/{y}.png"],
197
+ "encoding": "terrarium"
198
+ }
199
+ }
200
+ }
201
+ ```
202
+
203
+ ## Performance Monitoring
204
+
205
+ The gem includes real-time performance monitoring:
206
+
207
+ - **FPS and Frame Time**: Real-time rendering performance
208
+ - **Memory Usage**: JavaScript heap memory monitoring
209
+ - **Tile Loading**: Active tile count and loading status
210
+ - **Layer Management**: Active layer count and visibility
211
+ - **Zoom Level**: Current map zoom level
212
+ - **Terrain Status**: Terrain data availability
213
+
214
+ ## File Structure
215
+
216
+ ```
217
+ lib/
218
+ ├── maplibre-preview.rb # Main gem module and Sinatra integration
219
+ └── maplibre-preview/
220
+ ├── version.rb # Gem version
221
+ ├── views/ # Slim templates
222
+ │ ├── map.slim # Main map interface
223
+ │ └── map_layout.slim # HTML layout
224
+ └── public/js/ # JavaScript modules
225
+ ├── filters.js # Layer filtering logic
226
+ └── contour.js # Terrain and contour features
227
+ ```
228
+
229
+ ## Development
230
+
231
+ ### Prerequisites
232
+
233
+ - Ruby 2.7+
234
+ - Sinatra 2.1+
235
+ - Slim 4.1+
236
+ - Rack 2.0+
237
+
238
+ ### Setup
239
+
240
+ ```bash
241
+ # Install dependencies
242
+ bundle install
243
+
244
+ # Run tests
245
+ bundle exec rspec
246
+
247
+ # Run RuboCop
248
+ bundle exec rubocop
249
+
250
+ # Build gem
251
+ gem build maplibre-preview.gemspec
252
+ ```
253
+
254
+ ### Testing
255
+
256
+ ```bash
257
+ # Run all tests
258
+ bundle exec rspec
259
+
260
+ # Run specific test file
261
+ bundle exec rspec spec/maplibre_preview_spec.rb
262
+ ```
263
+
264
+ ## Integration Examples
265
+
266
+ ### Basic Map Integration
267
+
268
+ ```ruby
269
+ class MyApp < Sinatra::Base
270
+ register MapLibrePreview::Extension
271
+
272
+ get '/map' do
273
+ render_maplibre_preview
274
+ end
275
+ end
276
+ ```
277
+
278
+ ### Style URL Integration
279
+
280
+ ```ruby
281
+ class MyApp < Sinatra::Base
282
+ register MapLibrePreview::Extension
283
+
284
+ get '/map' do
285
+ # Style URL passed via params[:style_url]
286
+ render_maplibre_preview
287
+ end
288
+ end
289
+ ```
290
+
291
+ ### Multiple Map Routes
292
+
293
+ ```ruby
294
+ class MyApp < Sinatra::Base
295
+ register MapLibrePreview::Extension
296
+
297
+ get '/map' do
298
+ # Uses params[:style_url] if provided
299
+ render_maplibre_preview
300
+ end
301
+
302
+ get '/terrain' do
303
+ # Set style URL via params
304
+ params[:style_url] = 'https://example.com/terrain-style.json'
305
+ render_maplibre_preview
306
+ end
307
+ end
308
+ ```
309
+
310
+ ## License
311
+
312
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.