ekylibre-cartography 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/Rakefile +10 -0
- data/app/assets/javascripts/cartography.coffee +535 -0
- data/app/assets/javascripts/cartography/base.coffee +11 -0
- data/app/assets/javascripts/cartography/controls.coffee +463 -0
- data/app/assets/javascripts/cartography/events.coffee +36 -0
- data/app/assets/javascripts/cartography/layers.coffee +127 -0
- data/app/assets/javascripts/cartography/layers/simple.coffee +37 -0
- data/app/assets/javascripts/cartography/leaflet/controls.coffee +420 -0
- data/app/assets/javascripts/cartography/leaflet/handlers.coffee +461 -0
- data/app/assets/javascripts/cartography/leaflet/i18n.coffee +31 -0
- data/app/assets/javascripts/cartography/leaflet/layers.coffee +60 -0
- data/app/assets/javascripts/cartography/leaflet/toolbars.coffee +450 -0
- data/app/assets/javascripts/cartography/patches.js +8 -0
- data/app/assets/javascripts/cartography/util.coffee +18 -0
- data/app/assets/javascripts/main.js +18 -0
- data/app/assets/stylesheets/cartography.css +86 -0
- data/app/helpers/cartography_helper.rb +55 -0
- data/lib/cartography.rb +1 -0
- data/lib/cartography/engine.rb +11 -0
- data/lib/cartography/version.rb +3 -0
- data/vendor/assets/components/d3-array/dist/d3-array.js +590 -0
- data/vendor/assets/components/d3-array/dist/d3-array.min.js +2 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.js +295 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.js.map +21 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.min.js +1 -0
- data/vendor/assets/components/leaflet-controlpanel/dist/leaflet.controlpanel.css +29 -0
- data/vendor/assets/components/leaflet-controlpanel/dist/leaflet.controlpanel.js +269 -0
- data/vendor/assets/components/leaflet-draw-cut/dist/leaflet.draw.cut.css +1 -0
- data/vendor/assets/components/leaflet-draw-cut/dist/leaflet.draw.cut.js +8 -0
- data/vendor/assets/components/leaflet-draw-merge/dist/leaflet.draw.merge.css +0 -0
- data/vendor/assets/components/leaflet-draw-merge/dist/leaflet.draw.merge.js +48026 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.css +326 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.js +4653 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.map +1 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw.css +10 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw.js +10 -0
- data/vendor/assets/components/leaflet-geographicutil/dist/leaflet.geographicutil.js +3220 -0
- data/vendor/assets/components/leaflet-reactive_measure/dist/reactive_measure.css +30 -0
- data/vendor/assets/components/leaflet-reactive_measure/dist/reactive_measure.js +3764 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.js +13609 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.js.map +1 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.map +1 -0
- data/vendor/assets/components/leaflet/dist/leaflet.css +632 -0
- data/vendor/assets/components/leaflet/dist/leaflet.js +5 -0
- data/vendor/assets/components/leaflet/dist/leaflet.js.map +1 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.min.js +9 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.umd.js +1716 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.umd.js.map +1 -0
- data/vendor/assets/components/polygon-clipping/dist/polygon-clipping.js +279 -0
- data/vendor/assets/components/polygon-clipping/dist/polygon-clipping.min.js +1 -0
- data/vendor/assets/components/rtree/dist/rtree.js +911 -0
- data/vendor/assets/components/rtree/dist/rtree.min.js +1 -0
- data/vendor/assets/components/splaytree/dist/splay.es6.js +765 -0
- data/vendor/assets/components/splaytree/dist/splay.es6.js.map +1 -0
- data/vendor/assets/components/splaytree/dist/splay.js +797 -0
- data/vendor/assets/components/splaytree/dist/splay.js.map +1 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78e2caf3b8e30c5efa269f552f49ac1c1e255701cee461a657237255ed42f7a5
|
4
|
+
data.tar.gz: 3013a1ef5bea6a49c35f57f71b09ebdd50d75a47a38d21e384e275da40205988
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79f304cb9082de0c96e039ecacb74a3bf55f8bbeea52802119e6d70e8924e2aa6f395f22783cae14f62d44552b3c31e7526e847f6502360459cf7b3a4433d33c
|
7
|
+
data.tar.gz: 65a544cc1d3a91421149062eae776bf85faf0cf0a4edf54ec4956c35ed60ed7f69cb816d177f4808a65683f0bc7f3a07cb9fc13d06c783afb0d43089e6890df1
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,535 @@
|
|
1
|
+
#= require cartography/events
|
2
|
+
#= require cartography/util
|
3
|
+
#= require cartography/base
|
4
|
+
#= require cartography/controls
|
5
|
+
#= require cartography/layers
|
6
|
+
#= require cartography/layers/simple
|
7
|
+
|
8
|
+
((C) ->
|
9
|
+
"use strict"
|
10
|
+
|
11
|
+
class C.Map extends C.BaseClass
|
12
|
+
@IDS: 0
|
13
|
+
options:
|
14
|
+
box:
|
15
|
+
height: '85vh'
|
16
|
+
width: undefined
|
17
|
+
map:
|
18
|
+
scrollWheelZoom: true
|
19
|
+
zoomControl: false
|
20
|
+
attributionControl: true
|
21
|
+
setDefaultBackground: false
|
22
|
+
setDefaultOverlay: false
|
23
|
+
dragging: true
|
24
|
+
touchZoom: true
|
25
|
+
doubleClickZoom: true
|
26
|
+
boxZoom: true
|
27
|
+
tap: true
|
28
|
+
controls:
|
29
|
+
draw: false
|
30
|
+
cut: false
|
31
|
+
layers: true
|
32
|
+
backgrounds: true
|
33
|
+
overlays: true
|
34
|
+
edit: true
|
35
|
+
snap: true
|
36
|
+
reactiveMeasure: true
|
37
|
+
selection: false
|
38
|
+
locking: false
|
39
|
+
zoom: true
|
40
|
+
home: true
|
41
|
+
scale: true
|
42
|
+
snap:
|
43
|
+
panel:
|
44
|
+
surfaceProperty: 'Surface'
|
45
|
+
polygon:
|
46
|
+
snapDistance: 15
|
47
|
+
snapOriginDistance: 15
|
48
|
+
cut:
|
49
|
+
cycling: 2
|
50
|
+
panel:
|
51
|
+
title: 'Splitter tool'
|
52
|
+
animatedHelper: undefined
|
53
|
+
surfacesProperty: 'Surfaces'
|
54
|
+
merge:
|
55
|
+
panel:
|
56
|
+
title: 'Merger tool'
|
57
|
+
animatedHelper: undefined
|
58
|
+
draw:
|
59
|
+
panel:
|
60
|
+
title: 'Create plot'
|
61
|
+
coordinatesProperty: 'Coordinates'
|
62
|
+
animatedHelper: undefined
|
63
|
+
ignoreActions: true
|
64
|
+
edit:
|
65
|
+
selectedPathOptions:
|
66
|
+
dashArray: null
|
67
|
+
fill: true
|
68
|
+
color: '#1195F5'
|
69
|
+
fillColor: '#1195F5'
|
70
|
+
opacity: 1
|
71
|
+
fillOpacity: 0.35
|
72
|
+
maintainColor: false
|
73
|
+
panel:
|
74
|
+
title: 'Edit plot'
|
75
|
+
animatedHelper: undefined
|
76
|
+
remove: false
|
77
|
+
controlLayers:
|
78
|
+
position: 'topleft'
|
79
|
+
zoom:
|
80
|
+
zoomInTitle: 'Zoom in'
|
81
|
+
zoomOutTitle: 'Zoom out'
|
82
|
+
|
83
|
+
constructor: (id, options = {}) ->
|
84
|
+
C.Util.setOptions @, options
|
85
|
+
|
86
|
+
# Merge drawLocal to forward translations through options.
|
87
|
+
_.merge @options, L.drawLocal
|
88
|
+
|
89
|
+
@baseElement = L.DomUtil.get(id)
|
90
|
+
@baseElement.setAttribute "data-map-id", @constructor.IDS
|
91
|
+
@constructor.IDS++
|
92
|
+
|
93
|
+
@mapElement = L.DomUtil.create('div', 'map', @baseElement)
|
94
|
+
|
95
|
+
@map = L.map(@mapElement, @options.map)
|
96
|
+
|
97
|
+
@setMode @options.mode
|
98
|
+
|
99
|
+
@resize()
|
100
|
+
|
101
|
+
@controls()
|
102
|
+
|
103
|
+
@initHooks()
|
104
|
+
|
105
|
+
resize: ->
|
106
|
+
if @options.box? and @options.box.height?
|
107
|
+
@mapElement.style.height = @options.box.height
|
108
|
+
if @options.box? and @options.box.width?
|
109
|
+
@mapElement.style.width = @options.box.width
|
110
|
+
|
111
|
+
initHooks: ->
|
112
|
+
|
113
|
+
@getMap().on L.Draw.Event.CREATED, (e) =>
|
114
|
+
return unless e.layerType == "polygon" or e.layerType is undefined
|
115
|
+
|
116
|
+
feature = if e.layer instanceof L.Layer
|
117
|
+
then e.layer.toGeoJSON(17)
|
118
|
+
else e.layer
|
119
|
+
|
120
|
+
@getFeatureGroup(name: "edition").addData(feature)
|
121
|
+
|
122
|
+
uuid = feature.properties.uuid
|
123
|
+
type = feature.properties.type = @getMode()
|
124
|
+
|
125
|
+
layer = @getFeatureGroup(name: "edition").getLayers()[..].pop()
|
126
|
+
centroid = layer.getCenter()
|
127
|
+
area = L.GeometryUtil.geodesicArea(layer.getLatLngs()[0])
|
128
|
+
|
129
|
+
@getMap().fire C.Events.new.complete, data: { uuid: uuid, type: type, shape: feature, area: area, centroid: centroid }
|
130
|
+
|
131
|
+
@getMap().on L.Selectable.Event.SELECT, (e) =>
|
132
|
+
@getMap().fire C.Events.select.select, data: { uuid: e.layer.feature.properties.uuid }
|
133
|
+
|
134
|
+
@getMap().on L.Selectable.Event.UNSELECT, (e) =>
|
135
|
+
@getMap().fire C.Events.select.unselect, data: { uuid: e.layer.feature.properties.uuid }
|
136
|
+
|
137
|
+
@getMap().on L.Selectable.Event.SELECTED, (e) ->
|
138
|
+
console.error 'selected layers', e
|
139
|
+
|
140
|
+
@getMap().on L.Selectable.Event.START, (e) ->
|
141
|
+
console.error "Starting selection mode"
|
142
|
+
|
143
|
+
@getMap().on L.Selectable.Event.STOP, (e) ->
|
144
|
+
console.error "Stopping selection mode"
|
145
|
+
|
146
|
+
@getMap().on L.Cutting.Polyline.Event.START, =>
|
147
|
+
@getMap().fire C.Events.split.start
|
148
|
+
|
149
|
+
@getMap().on L.Cutting.Polyline.Event.STOP, =>
|
150
|
+
@getMap().fire C.Events.split.cancel
|
151
|
+
|
152
|
+
@getMap().on L.Cutting.Polyline.Event.SELECT, (e) =>
|
153
|
+
uuid = e.layer.feature.properties.uuid
|
154
|
+
type = e.layer.feature.properties.type || @getMode()
|
155
|
+
@getMap().fire C.Events.split.select, data: { uuid: uuid, type: type }
|
156
|
+
|
157
|
+
onSplitChange = (e) =>
|
158
|
+
data = {}
|
159
|
+
data['splitter'] = e.splitter
|
160
|
+
data['old'] = {uuid: e.parent.feature.properties.uuid, name: e.parent.feature.properties.name}
|
161
|
+
data['new'] = e.layers.map (layer) ->
|
162
|
+
p = layer.feature.properties
|
163
|
+
measure = layer.getMeasure()
|
164
|
+
|
165
|
+
{ num: p.num, area: measure.extrapolatedArea, perimeter: measure.extrapolatedPerimeter, color: p.color, shape: layer.toGeoJSON(17) }
|
166
|
+
|
167
|
+
@getMap().fire C.Events.split.change, data: data
|
168
|
+
|
169
|
+
@getMap().on L.Cutting.Polyline.Event.CREATED, onSplitChange, @
|
170
|
+
@getMap().on L.Cutting.Polyline.Event.UPDATED, onSplitChange, @
|
171
|
+
|
172
|
+
@getMap().on L.Cutting.Polyline.Event.CUTTING, (e) =>
|
173
|
+
@getMap().fire C.Events.split.cutting, data: perimeter: e.perimeter
|
174
|
+
|
175
|
+
@getMap().on L.SnapEditing.Event.CHANGE, (e) =>
|
176
|
+
if e.layer.getLatLngs().constructor.name is 'Array'
|
177
|
+
latlngs = e.layer.getLatLngs()[0]
|
178
|
+
else
|
179
|
+
latlngs = e.layer.getLatLngs()
|
180
|
+
|
181
|
+
area = L.GeometryUtil.geodesicArea(latlngs)
|
182
|
+
feature = e.layer.toGeoJSON(17)
|
183
|
+
|
184
|
+
uuid = feature.properties.uuid
|
185
|
+
type = feature.properties.type = @getMode()
|
186
|
+
|
187
|
+
centroid = e.layer.getCenter()
|
188
|
+
|
189
|
+
@getMap().fire C.Events.edit.change, data: { uuid: uuid, type: type, shape: feature, area: area, centroid: centroid }
|
190
|
+
|
191
|
+
|
192
|
+
controls: ->
|
193
|
+
@controls = new C.Controls(@getMap(), @options)
|
194
|
+
|
195
|
+
@controls.register 'layers', false, =>
|
196
|
+
new C.Controls.Layers(undefined, @getMap(), @options)
|
197
|
+
, =>
|
198
|
+
@controls.register 'backgrounds', false, =>
|
199
|
+
new C.Controls.BaseLayers(@controls.get('layers').getControl(), @getMap(), @options)
|
200
|
+
|
201
|
+
@controls.register 'overlays', false, =>
|
202
|
+
new C.Controls.OverlayLayers(@controls.get('layers').getControl(), @getMap(), @options)
|
203
|
+
, =>
|
204
|
+
return unless @options.controls.snap?
|
205
|
+
layers = @controls.get('overlays').getLayers()
|
206
|
+
@options.snap.polygon.guideLayers = Object.values(layers)
|
207
|
+
|
208
|
+
if @options.controls.backgrounds
|
209
|
+
@controls.add 'backgrounds'
|
210
|
+
|
211
|
+
if @options.controls.overlays
|
212
|
+
@controls.add 'overlays'
|
213
|
+
|
214
|
+
@controls.register 'zoom', true, =>
|
215
|
+
new C.Controls.Zoom(@getMap(), @options.zoom)
|
216
|
+
|
217
|
+
@controls.register 'home', true, =>
|
218
|
+
new C.Controls.Home(@getMap(), home: { featureGroup: @getFeatureGroup() } )
|
219
|
+
|
220
|
+
@controls.register 'draw', true, =>
|
221
|
+
new C.Controls.Draw(@getMap(), @options)
|
222
|
+
|
223
|
+
@controls.register 'edit', true, =>
|
224
|
+
C.Util.setOptions @, edit: {featureGroup: @getFeatureGroup()}
|
225
|
+
new C.Controls.Edit(@getMap(), @options)
|
226
|
+
, =>
|
227
|
+
return unless @options.controls.reactiveMeasure?
|
228
|
+
@controls.register 'measure', true, =>
|
229
|
+
new C.Controls.Edit.ReactiveMeasure(@getMap(), @controls.get('edit'), @options)
|
230
|
+
@controls.add 'measure'
|
231
|
+
@removeControl 'edit'
|
232
|
+
|
233
|
+
@controls.register 'scale', true, =>
|
234
|
+
new C.Controls.Scale(@getMap(), @options)
|
235
|
+
|
236
|
+
@controls.register 'selection', false, =>
|
237
|
+
new C.Controls.LayerSelection(@getMap(), {layerSelection: {featureGroup: @getFeatureGroup()}})
|
238
|
+
, =>
|
239
|
+
@controls.get('selection').getControl().enable()
|
240
|
+
|
241
|
+
@controls.register 'locking', false, =>
|
242
|
+
new C.Controls.LayerLocking(@getMap(), {layerLocking: {featureGroup: @getFeatureGroup(name: 'crops')}})
|
243
|
+
, =>
|
244
|
+
@controls.get('locking').getControl().enable()
|
245
|
+
|
246
|
+
@controls.register 'shape_draw', false, =>
|
247
|
+
unless @options.draw.allowOverlap
|
248
|
+
layers = @controls.get('overlays').getLayers()
|
249
|
+
@options.draw.overlapLayers = Object.values(layers)
|
250
|
+
new C.Controls.ShapeDraw(@getMap(), @options)
|
251
|
+
, =>
|
252
|
+
@controls.get('shape_draw').getControl().enable()
|
253
|
+
|
254
|
+
@controls.register 'cut', true, =>
|
255
|
+
C.Util.setOptions @, cut: {featureGroup: @getFeatureGroup()}
|
256
|
+
new C.Controls.Cut(@getMap(), @options)
|
257
|
+
|
258
|
+
@controls.register 'shape_cut', false, =>
|
259
|
+
C.Util.setOptions @, cut: {featureGroup: @getFeatureGroup()}
|
260
|
+
new C.Controls.ShapeCut(@getMap(), @options)
|
261
|
+
, =>
|
262
|
+
@controls.get('shape_cut').getControl().enable()
|
263
|
+
|
264
|
+
if @options.controls.layers
|
265
|
+
@controls.add 'layers'
|
266
|
+
|
267
|
+
if @options.controls.zoom
|
268
|
+
@controls.add 'zoom'
|
269
|
+
|
270
|
+
if @options.controls.home
|
271
|
+
@controls.add 'home'
|
272
|
+
|
273
|
+
if @options.controls.edit
|
274
|
+
@controls.add 'edit'
|
275
|
+
|
276
|
+
if @options.controls.scale
|
277
|
+
@controls.add 'scale'
|
278
|
+
|
279
|
+
if @options.controls.selection
|
280
|
+
@controls.add 'selection'
|
281
|
+
|
282
|
+
if @options.controls.locking
|
283
|
+
@controls.add 'locking'
|
284
|
+
|
285
|
+
if @options.controls.draw
|
286
|
+
@controls.add 'draw'
|
287
|
+
|
288
|
+
if @options.controls.cut
|
289
|
+
@controls.add 'cut'
|
290
|
+
|
291
|
+
style = (feature) ->
|
292
|
+
feature.properties.style ||= {}
|
293
|
+
color: feature.properties.style.color || "#1195F5", fillOpacity: feature.properties.style.opacity || 0.35, opacity: 1, fill: true
|
294
|
+
|
295
|
+
serie = [{edition: []}, [name: 'edition', type: 'simple', index: true, serie: 'edition', style: style]]
|
296
|
+
@addOverlay(serie)
|
297
|
+
@setView()
|
298
|
+
|
299
|
+
##### PUBLIC API ######
|
300
|
+
setView: ->
|
301
|
+
if @options.bounds
|
302
|
+
bounds = @options.bounds.split(',')
|
303
|
+
@getMap().fitBounds([[bounds[1], bounds[0]], [bounds[3], bounds[2]]],{ maxZoom: 21 })
|
304
|
+
return
|
305
|
+
|
306
|
+
if @getFeatureGroup().getLayers().length
|
307
|
+
@getMap().fitBounds(@getFeatureGroup().getBounds(),{ maxZoom: 21 })
|
308
|
+
else
|
309
|
+
@center @defaultCenter(), 6
|
310
|
+
|
311
|
+
setMode: (mode) ->
|
312
|
+
@_mode = mode
|
313
|
+
|
314
|
+
getMode: ->
|
315
|
+
@_mode
|
316
|
+
|
317
|
+
setOffset: (obj) ->
|
318
|
+
@_offset = L.point obj
|
319
|
+
|
320
|
+
resetOffset: ->
|
321
|
+
delete @_offset
|
322
|
+
|
323
|
+
center: (obj, zoom = 18) ->
|
324
|
+
return unless obj.lat && obj.lng
|
325
|
+
|
326
|
+
@getMap().setView L.latLng(obj), zoom
|
327
|
+
|
328
|
+
_findLayerByUUID: (featureGroup, uuid) ->
|
329
|
+
containerLayer = undefined
|
330
|
+
featureGroup.eachLayer (layer) ->
|
331
|
+
if layer.feature and layer.feature.properties.uuid == uuid
|
332
|
+
containerLayer = layer
|
333
|
+
return
|
334
|
+
containerLayer
|
335
|
+
|
336
|
+
select: (uuid, center = false, featureGroup = undefined, trigger = true) ->
|
337
|
+
name = featureGroup if featureGroup
|
338
|
+
featureGroup = @getFeatureGroup(name: name)
|
339
|
+
layer = @_findLayerByUUID(featureGroup, uuid)
|
340
|
+
if layer && !layer.selected
|
341
|
+
if trigger
|
342
|
+
layer.fire 'click'
|
343
|
+
layer.fire 'select'
|
344
|
+
if center
|
345
|
+
@getMap().fitBounds layer.getBounds()
|
346
|
+
|
347
|
+
layer
|
348
|
+
|
349
|
+
selectMany: (uuids, center = false) ->
|
350
|
+
layers = []
|
351
|
+
for uuid in uuids
|
352
|
+
featureGroup = @getFeatureGroup()
|
353
|
+
layer = @_findLayerByUUID(featureGroup, uuid)
|
354
|
+
if layer
|
355
|
+
layers.push layer
|
356
|
+
unless layer.selected
|
357
|
+
layer.fire 'click'
|
358
|
+
group = L.featureGroup layers
|
359
|
+
if center && group
|
360
|
+
@getMap().fitBounds group.getBounds()
|
361
|
+
group
|
362
|
+
|
363
|
+
unselectMany: (uuids) ->
|
364
|
+
for uuid in uuids
|
365
|
+
featureGroup = @getFeatureGroup()
|
366
|
+
layer = @_findLayerByUUID(featureGroup, uuid)
|
367
|
+
if layer && layer.selected
|
368
|
+
layer.fire 'click'
|
369
|
+
|
370
|
+
centerCollection: (uuids, center = true) ->
|
371
|
+
layers = []
|
372
|
+
for uuid in uuids
|
373
|
+
featureGroup = @getFeatureGroup()
|
374
|
+
layer = @_findLayerByUUID(featureGroup, uuid)
|
375
|
+
if layer
|
376
|
+
layers.push layer
|
377
|
+
group = L.featureGroup layers
|
378
|
+
if center && group
|
379
|
+
@getMap().fitBounds group.getBounds()
|
380
|
+
group
|
381
|
+
|
382
|
+
centerLayer: (uuid, center = true, featureGroup = undefined) ->
|
383
|
+
featureGroup = @getFeatureGroup(name: featureGroup)
|
384
|
+
layer = @_findLayerByUUID(featureGroup, uuid)
|
385
|
+
|
386
|
+
if center && layer
|
387
|
+
@getMap().fitBounds layer.getBounds()
|
388
|
+
|
389
|
+
layer
|
390
|
+
|
391
|
+
unselect: (uuid) ->
|
392
|
+
featureGroup = @getFeatureGroup()
|
393
|
+
layer = @_findLayerByUUID(featureGroup, uuid)
|
394
|
+
if layer && layer.selected
|
395
|
+
@unhighlight(uuid)
|
396
|
+
layer.fire 'select'
|
397
|
+
|
398
|
+
highlight: (uuid, featureGroup = undefined) ->
|
399
|
+
layer = @select uuid, false, featureGroup, false
|
400
|
+
if layer
|
401
|
+
layer.options.highlightOriginal = L.extend({}, layer.options)
|
402
|
+
layer.setStyle color: "#D84315", fillOpacity: 0.5
|
403
|
+
|
404
|
+
unhighlight: (uuid, featureGroup = undefined) ->
|
405
|
+
layer = @select uuid, false, featureGroup, false
|
406
|
+
if layer
|
407
|
+
layer.setStyle layer.options.highlightOriginal
|
408
|
+
delete layer.options.highlightOriginal
|
409
|
+
|
410
|
+
destroy: (uuid, featureGroup = undefined) ->
|
411
|
+
layer = @select uuid, false, featureGroup, false
|
412
|
+
name = featureGroup if featureGroup
|
413
|
+
if layer
|
414
|
+
@getFeatureGroup(name: name).removeLayer layer
|
415
|
+
|
416
|
+
buildControls: (name = undefined) ->
|
417
|
+
featureGroup = @getFeatureGroup(name: name)
|
418
|
+
return unless featureGroup && featureGroup.getLayers()
|
419
|
+
featureGroup.eachLayer (layer) ->
|
420
|
+
layer.onBuild.call @ if layer.onBuild and layer.onBuild.constructor.name == 'Function'
|
421
|
+
|
422
|
+
edit: (uuid, featureGroup = undefined, options = {}) ->
|
423
|
+
@unhighlight uuid
|
424
|
+
layer = @select uuid, false, featureGroup, false
|
425
|
+
if layer
|
426
|
+
if options.cancel && layer._editToolbar
|
427
|
+
layer._editToolbar.disable()
|
428
|
+
@unselect layer.feature.properties.uuid
|
429
|
+
return
|
430
|
+
|
431
|
+
snapOptions = {polygon: guideLayers: @getFeatureGroup()}
|
432
|
+
|
433
|
+
options = C.Util.extend @options, snap: snapOptions
|
434
|
+
|
435
|
+
layer._editToolbar = new L.EditToolbar.SelectableSnapEdit @getMap(),
|
436
|
+
snapOptions: options.snap
|
437
|
+
featureGroup: @getFeatureGroup(name: featureGroup)
|
438
|
+
selectedPathOptions: options.edit.selectedPathOptions
|
439
|
+
disabledPathOptions: options.edit.disabledPathOptions
|
440
|
+
poly: options.poly
|
441
|
+
layer._editToolbar.enable layer
|
442
|
+
layer._editToolbar._activate layer
|
443
|
+
|
444
|
+
union: (polygons) ->
|
445
|
+
L.Calculation.union(polygons)
|
446
|
+
|
447
|
+
difference: (feature1, feature2) ->
|
448
|
+
L.Calculation.difference(feature1, feature2)
|
449
|
+
|
450
|
+
contains: (feature1, feature2) ->
|
451
|
+
L.Calculation.contains feature1, feature2
|
452
|
+
|
453
|
+
intersect: (feature1, feature2) ->
|
454
|
+
L.Calculation.intersect feature1, feature2
|
455
|
+
|
456
|
+
sync: (data, layerName, options = {}) =>
|
457
|
+
|
458
|
+
layerGroup = @controls.get('overlays').getLayers()[layerName]
|
459
|
+
|
460
|
+
newLayers = new L.geoJSON()
|
461
|
+
|
462
|
+
onAdd = (e) =>
|
463
|
+
layerGroup.bindInit 'layeradd', onLayerAdd
|
464
|
+
e.target.eachLayer (layer) =>
|
465
|
+
if options.onEachFeature && options.onEachFeature.constructor.name is 'Function'
|
466
|
+
options.onEachFeature.call @, layer
|
467
|
+
|
468
|
+
onLayerAdd = (e) =>
|
469
|
+
if options.onEachFeature && options.onEachFeature.constructor.name is 'Function'
|
470
|
+
options.onEachFeature.call @, e.layer
|
471
|
+
|
472
|
+
layerGroup.bindInit 'layeradd', onLayerAdd
|
473
|
+
layerGroup.bindInit 'add', onAdd
|
474
|
+
|
475
|
+
layerGroup.on 'remove', =>
|
476
|
+
layerGroup.unbind 'layeradd', onLayerAdd
|
477
|
+
|
478
|
+
for el in data
|
479
|
+
if el.shape
|
480
|
+
geojson = el.shape
|
481
|
+
feature = L.GeoJSON.asFeature(el.shape)
|
482
|
+
feature.properties = el
|
483
|
+
delete feature.properties.shape
|
484
|
+
newLayers.addData(feature)
|
485
|
+
|
486
|
+
if layerGroup.getLayers().length
|
487
|
+
removeList = layerGroup.getLayers().filter (layer) ->
|
488
|
+
!newLayers.hasUUIDLayer layer
|
489
|
+
|
490
|
+
if removeList.length
|
491
|
+
for l in removeList
|
492
|
+
@getMap().fire L.Selectable.Event.UNSELECT, { layer: l }
|
493
|
+
layerGroup.removeLayer l
|
494
|
+
|
495
|
+
addList = newLayers.getLayers().filter (layer) ->
|
496
|
+
!layerGroup.hasUUIDLayer layer
|
497
|
+
|
498
|
+
else
|
499
|
+
addList = newLayers.getLayers()
|
500
|
+
|
501
|
+
for layer in addList
|
502
|
+
geojson = layer.toGeoJSON(17)
|
503
|
+
layerGroup.addData(geojson)
|
504
|
+
# newLayer = @_findLayerByUUID(layerGroup, geojson.properties.uuid)
|
505
|
+
|
506
|
+
|
507
|
+
defaultCenter: =>
|
508
|
+
@options.defaultCenter
|
509
|
+
|
510
|
+
addOverlay: (serie, type = "series") =>
|
511
|
+
@controls.get('overlays').add(serie, type)
|
512
|
+
|
513
|
+
removeOverlay: (name) =>
|
514
|
+
@controls.get('overlays').remove(name)
|
515
|
+
|
516
|
+
getOverlay: (name) =>
|
517
|
+
@controls.get('overlays').getLayer(name)
|
518
|
+
|
519
|
+
addControl: (name) =>
|
520
|
+
@controls.add(name)
|
521
|
+
|
522
|
+
removeControl: (name) =>
|
523
|
+
@controls.remove(name)
|
524
|
+
|
525
|
+
getFeatureGroup: (options = {}) =>
|
526
|
+
options.main ||= true
|
527
|
+
|
528
|
+
return @controls.get('overlays').getLayers()[options.name] if options.name
|
529
|
+
|
530
|
+
@controls.get('overlays').getMainLayer()
|
531
|
+
|
532
|
+
clean: =>
|
533
|
+
@getFeatureGroup(name: "edition").clearLayers()
|
534
|
+
|
535
|
+
)(window.Cartography = window.Cartography || {})
|