Browse Source

manual merge

master
phryk 6 months ago
parent
commit
9ea6562119

+ 23
- 83
poobrains/svg/geo.py View File

@@ -165,12 +165,32 @@ def render_geojson(bbox, data):
165 165
 
166 166
     elif isinstance(data, geojson.geometry.Geometry):
167 167
 
168
-        if isinstance(data, geojson.geometry.Polygon):
168
+        if isinstance(data, geojson.geometry.Point):
169
+            if hasattr(data, 'id'):
170
+                r += '<use id="%s" class="geojson-point" ' % data.id
171
+
172
+            else:
173
+                r += '<use class="geojson-point marker" '
174
+
175
+            x, y = normalize_coords(data.coordinates[0], data.coordinates[1])
176
+            x -= normalized_bbox[0][0]
177
+            x /= span_horizontal
178
+
179
+            y -= normalized_bbox[0][1]
180
+            y /= span_vertical
181
+
182
+            x *= width
183
+            y *= height
184
+
185
+            r += 'href="#marker" x="%f" y="%f" />' % (x, y)
186
+
187
+
188
+        elif isinstance(data, geojson.geometry.Polygon):
169 189
             
170 190
             if hasattr(data, 'id'):
171
-                r += '<path id="{data.id}" '
191
+                r += '<path id="%s" class="geojson-polygon"' % data.id
172 192
             else:
173
-                r += '<path '
193
+                r += '<path class="geojson-polygon" '
174 194
 
175 195
             r += 'd="'
176 196
 
@@ -220,86 +240,6 @@ def render_geojson(bbox, data):
220 240
     return Markup(r)
221 241
 
222 242
 
223
-# mercator calculation shamelessly thieved from the osm wiki
224
-# http://wiki.openstreetmap.org/wiki/Mercator
225
-# NOTE: I *think* this is WGS84?
226
-# NOTE: r_minor seems to have been WGS84 but missed a few decimal places
227
-
228
-def normalize_longitude(longitude):
229
-
230
-    # normalize longitude to linear scale (0-1)
231
-
232
-    normalization_factor = 20037508.3428
233
-
234
-    r_major=6378137.000
235
-    x = r_major*math.radians(longitude)
236
-    #return 50 + 50 * (x / normalization_factor)
237
-    
238
-    return 0.5 + 0.5 * (x / normalization_factor)
239
-
240
-
241
-def normalize_latitude(latitude):
242
-
243
-    #normalization_factor = 19994838.114 # this is the value this function would return for 85.0511° without normalization, which should™ make the map square
244
-    normalization_factor = 12890914.1373 # this is the value this function would return for 75° without normalization, which should™ make the map square
245
-    if latitude>89.5:latitude=89.5
246
-    if latitude<-89.5:latitude=-89.5
247
-    r_major=6378137.000
248
-    r_minor=6356752.3142518
249
-    temp=r_minor/r_major
250
-    eccent=math.sqrt(1-temp**2)
251
-    phi=math.radians(latitude)
252
-    sinphi=math.sin(phi)
253
-    con=eccent*sinphi
254
-    com=eccent/2
255
-    con=((1.0-con)/(1.0+con))**com
256
-    ts=math.tan((math.pi/2-phi)/2)/con
257
-    y=0-r_major*math.log(ts)
258
-
259
-    return 0.5 - 0.5 * (y / normalization_factor)
260
-
261
-
262
-
263
-#class MapDataset(poobrains.commenting.Commentable):
264
-#
265
-#    title = poobrains.storage.fields.CharField()
266
-#    description = poobrains.md.MarkdownField(null=True)
267
-#
268
-#    terrain = poobrains.storage.fields.ForeignKeyField(Terrain, null=True)
269
-#
270
-#
271
-#    @property
272
-#    def authorized_datapoints(self):
273
-#        return GeoData.list('read', g.user).where(GeoData.dataset == self)
274
-#
275
-#
276
-#    @property
277
-#    def geojson(self):
278
-#
279
-#        collection = []
280
-#
281
-#        if self.terrain:
282
-#            terrain = geojson.loads(self.terrain.data)
283
-#            terrain.id = 'terrain-' + self.terrain.name
284
-#
285
-#            collection.append(terrain)
286
-#
287
-#        for datapoint in self.authorized_datapoints:
288
-#
289
-#            data = self.datapoint.geojson
290
-#
291
-#            if isinstance(data, (geojson.Feature, geojson.FeatureCollection)):
292
-#                collection.append(data)
293
-#            else:
294
-#                collection.append(geojson.Feature(geometry=data))
295
-#
296
-#        return geojson.FeatureCollection(collection)
297
-#
298
-#
299
-#    def plot(self):
300
-#
301
-#        return Map(datasets=[self]).render('inline')
302
-
303 243
 class GeoDataForm(poobrains.auth.AutoForm):
304 244
 
305 245
     def process(self, submit, exceptions=False):

+ 17
- 49
poobrains/themes/default/svg.scss View File

@@ -449,11 +449,6 @@ svg.map {
449 449
             fill: opacify($color_background_dark, -20%);
450 450
             transition: fill 0.3s linear, stroke 0.3s linear;
451 451
 
452
-            &:hover {
453
-                stroke: $color_highlight;
454
-                fill: mix($color_highlight, $color_background_dark, 25%);
455
-            }
456
-
457 452
             g,
458 453
             path {
459 454
                 stroke-width: 0.1rem;
@@ -463,62 +458,30 @@ svg.map {
463 458
 
464 459
     g.datapoints {
465 460
 
466
-        path {
467
-            fill: opacify($color_highlight, -65%);
468
-            stroke: opacify($color_font_light, -50%)
469
-        }
470 461
 
471 462
         g.datapoint {
472 463
 
473
-            g.infobox {
474
-
475
-                display: none;
476
-                opacity: 0;
477
-                fill: $color_font_light;
478
-                font-size: 1rem;
479
-                /*transform: translateY(1rem);*/
480
-                transition: opacity 0.3s linear;
481
-
464
+            .marker,
465
+            g.feature path {
466
+                transition: fill 0.3s, stroke 0.3s;
482 467
             }
483 468
 
484
-            &:hover,
485
-            &:focus,
486
-            &:target {
487
-
488
-                .marker {
489
-                    opacity: 1;
490
-                    fill: $color_highlight;
491
-                    stroke: $color_background_light;
492
-                }
469
+            /* palettize data */
470
+            @for $i from 1 through $palette_size {
493 471
 
494
-                g.infobox {
472
+                $color: nth($palette, $i);
495 473
 
496
-                    display: block;
497
-                    opacity: 1;
498
-                    background: $color_background_dark;
474
+                &:nth-child(#{$i}n+#{$i}) {
499 475
 
500
-                    .html body {
501
-                        background: $color_background_dark;
476
+                    .marker {
477
+                        fill: desaturate($color, 20%);
502 478
                     }
503 479
 
504
-                    .fallback .background {
505
-                        fill: $color_background_dark;
480
+                    g.feature path {
481
+                        fill: opacify($color, -65%);
482
+                        stroke: opacify($color_background_light, -50%);
506 483
                     }
507
-                }
508
-            }
509
-        }
510
-
511
-        /* palettize datasets */
512
-        @for $i from 1 through $palette_size {
513 484
 
514
-            $color: nth($palette, $i);
515
-
516
-            g.dataset:nth-child(#{$i}n+#{$i}) {
517
-                g.datapoint {
518
-
519
-                    .marker {
520
-                        fill: desaturate($color, 20%);
521
-                    }
522 485
 
523 486
                     &:hover,
524 487
                     &:focus,
@@ -526,6 +489,11 @@ svg.map {
526 489
 
527 490
                         .marker {
528 491
                             fill: $color;
492
+                            stroke: $color_background_light;
493
+                        }
494
+                        g.feature path {
495
+                            fill: opacify($color, -55%);
496
+                            stroke: opacify($color_background_light, -40%);
529 497
                         }
530 498
                     }
531 499
                 }

+ 5
- 5
poobrains/themes/default/svg/map-raw.jinja View File

@@ -19,12 +19,12 @@
19 19
 
20 20
     {% include "svg/defs.jinja" %}
21 21
 
22
-    <svg class="terrain">
23
-        <a href="#">
24
-            <rect class="ocean" x="0" y="0" width="100%" height="{{ content.height }}px" />
22
+    <a href="#terrain"> <!-- / click to deselect datapoint[s] -->
23
+        <svg id="terrain" class="terrain">
24
+            <rect class="ocean" x="0" y="0" width="100%" height="100%" />
25 25
             {{ content.render_geojson(content.terrain.geojson) }}
26
-        </a>
27
-    </svg> <!-- / .terrain -->
26
+        </svg> <!-- / .terrain -->
27
+    </a>
28 28
 
29 29
     {{ content.grid() }}
30 30
 

+ 0
- 232
poobrains/themes/default/svg/world.jinja
File diff suppressed because it is too large
View File


Loading…
Cancel
Save