maplibre-preview 0.0.2 → 1.1.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 +4 -4
- data/.github/workflows/release.yml +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +260 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +51 -0
- data/LICENSE +21 -0
- data/README.md +312 -0
- data/Rakefile +50 -0
- data/docs/README_RU.md +312 -0
- data/lib/maplibre-preview/public/js/contour.js +85 -0
- data/lib/maplibre-preview/public/js/filters.js +323 -0
- data/lib/maplibre-preview/version.rb +1 -1
- data/lib/maplibre-preview/views/maplibre_layout.slim +329 -0
- data/lib/maplibre-preview/views/maplibre_map.slim +829 -0
- data/lib/maplibre-preview.rb +77 -2
- data/spec/maplibre_preview_spec.rb +52 -0
- data/spec/spec_helper.rb +11 -0
- metadata +88 -35
- data/lib/maplibre-preview/sinatra_ext.rb +0 -27
- data/lib/maplibre-preview/views/maplibre_preview.slim +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eb134207de2f2a8569ae8cfed678aa2fff2bf1830445b1fcfbc91aa7425a31b
|
4
|
+
data.tar.gz: fe069e3cee94b2be2ccbca438b900829feb1e1bdbfa0f3223dacafde8f7d813f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff02d878106be03c989ceff9851832c2d42a3745b338ffc8491b47b7694a81f48632eb87211bb82d73306d8d5ba959b10b61ed0abd982c8d70307544aff98995
|
7
|
+
data.tar.gz: aca536c781206ce0d75234aa924e663429db495c84478b5742aa1074699bc2618aab48f34236006eb694c9599f3f52bf5b299e17751eb83ba2575bd266f738a9
|
@@ -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
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,51 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [1.1.0] - 2025-10-01
|
4
|
+
|
5
|
+
### Refactored
|
6
|
+
- **Simplified architecture** with streamlined Sinatra extension pattern
|
7
|
+
- **Consolidated code** into single `lib/maplibre-preview.rb` file
|
8
|
+
- **Removed helper methods** in favor of direct Slim template calls
|
9
|
+
- **Updated template names** to `maplibre_map` and `maplibre_layout` to avoid conflicts
|
10
|
+
- **Streamlined Sinatra extension** with prepend modules for static assets and templates
|
11
|
+
|
12
|
+
### Technical Changes
|
13
|
+
- **Removed StaticMiddleware** in favor of prepend-based static asset serving
|
14
|
+
- **Removed Helpers module** with helper methods
|
15
|
+
- **Direct route integration** using `slim :maplibre_map, layout: :maplibre_layout`
|
16
|
+
- **Simplified file structure** with all core functionality in main file
|
17
|
+
- **Improved template resolution** using `__dir__` context for gem paths
|
18
|
+
|
19
|
+
## [1.0.0] - 2025-09-29
|
20
|
+
|
21
|
+
### Added
|
22
|
+
- **Extracted MapLibre development tools** from existing tiles-proxy-cache project
|
23
|
+
- **Sinatra extension** for easy integration into existing applications
|
24
|
+
- **StaticMiddleware** for serving gem assets (JS files) without conflicts
|
25
|
+
- **Helper methods** for rendering map development interface
|
26
|
+
- **Standalone application** for testing and development purposes
|
27
|
+
|
28
|
+
### Extracted Features
|
29
|
+
- **Advanced layer filtering** with metadata support (from `filters.js`)
|
30
|
+
- **Terrain visualization** and elevation profiles (from `contour.js`)
|
31
|
+
- **Performance monitoring** and metrics display
|
32
|
+
- **Interactive style debugging** tools
|
33
|
+
- **Contour line generation** for terrain data using MapLibre Contour
|
34
|
+
- **Hover and click modes** for feature inspection
|
35
|
+
- **MapLibre GL JS integration** with version 5.7.3
|
36
|
+
|
37
|
+
### Refactored Components
|
38
|
+
- **Slim templates** (`map.slim`, `map_layout.slim`) adapted for gem structure
|
39
|
+
- **JavaScript modules** (`filters.js`, `contour.js`) preserved with original functionality
|
40
|
+
- **View rendering** with dynamic path resolution for gem integration
|
41
|
+
- **Configuration system** with sensible defaults for MapLibre development
|
42
|
+
|
43
|
+
### Technical Implementation
|
44
|
+
- **Ruby >= 2.7.0** support with modern gem structure
|
45
|
+
- **Sinatra 2.1+** compatibility and extension system
|
46
|
+
- **Rack middleware** for asset serving without path conflicts
|
47
|
+
- **Comprehensive test suite** with RSpec for all components
|
48
|
+
- **Clean gem structure** optimized for integration use cases
|
49
|
+
|
50
|
+
### Migration Notes
|
51
|
+
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
|
+
[](https://ruby-lang.org)
|
6
|
+
[](http://sinatrarb.com/)
|
7
|
+
[](https://maplibre.org/)
|
8
|
+
[](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
|
+
slim :maplibre_map, layout: :maplibre_layout
|
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
|
+
slim :maplibre_map, layout: :maplibre_layout
|
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
|
+
### Template Integration
|
138
|
+
|
139
|
+
The gem provides Slim templates that can be used directly in your routes:
|
140
|
+
|
141
|
+
| Template | Description | Usage |
|
142
|
+
|----------|-------------|-------|
|
143
|
+
| `maplibre_map` | Main map interface template | `slim :maplibre_map, layout: :maplibre_layout` |
|
144
|
+
| `maplibre_layout` | HTML layout with external dependencies | Used as layout for map template |
|
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
|
+
slim :maplibre_map, layout: :maplibre_layout
|
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
|
+
slim :maplibre_map, layout: :maplibre_layout
|
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
|
+
slim :maplibre_map, layout: :maplibre_layout
|
300
|
+
end
|
301
|
+
|
302
|
+
get '/terrain' do
|
303
|
+
# Set style URL via params
|
304
|
+
params[:style_url] = 'https://example.com/terrain-style.json'
|
305
|
+
slim :maplibre_map, layout: :maplibre_layout
|
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.
|