Skip to content

Commit 813af9c

Browse files
Merge pull request #126 from ThalesGroup/dev-pla
Add interaction example with a measuring ruler, two cases: without or…
2 parents bb26f73 + bfa2fd1 commit 813af9c

24 files changed

Lines changed: 571 additions & 86 deletions

src/GeoView-Examples/GeoViewExamples.class.st

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,6 @@ GeoViewExamples class >> exampleGeoCircles [
300300
objects := self createGeoCircles: 1000.
301301
element addObjects: objects.
302302

303-
"Example of event handler behavior on geoView domain event"
304-
element addEventHandlerOn: GeoViewCursorCoordinatesChangedEvent do: [ :event |
305-
event absoluteCoordinates printString traceCr.
306-
].
307-
308-
"Example of custom EventHandler, here a logger"
309-
element addEventHandler: (GeoViewEventLogger new).
310-
311303
^ self openViewInWindow: element
312304
]
313305

@@ -333,6 +325,22 @@ GeoViewExamples class >> exampleGeoCirclesAddedOneByOne [
333325
^ self openViewInWindow: element
334326
]
335327

328+
{ #category : #'examples - GeoObjects' }
329+
GeoViewExamples class >> exampleGeoCirclesProjected [
330+
"Same example as exampleGeoCircles but with projected circles (due to projection deformation)"
331+
332+
| element objects |
333+
element := GeoViewUtils createGeoViewForGeoObjects.
334+
335+
(element getLayer: #GeoObjectsLayer) setProcessData: (GeoCircleProjectedProcessData new) forClass: GeoCircle.
336+
337+
"create sample datas"
338+
objects := self createGeoCircles: 100 do: [ :e | e radiusInMeters: 1000000 ].
339+
element addObjects: objects.
340+
341+
^ self openViewInWindow: element
342+
]
343+
336344
{ #category : #'examples - GeoObjects' }
337345
GeoViewExamples class >> exampleGeoEllipse [
338346

@@ -678,6 +686,51 @@ GeoViewExamples class >> exampleLargestCountriesOfTheWorld [
678686
^ self openViewInWindow: geoView
679687
]
680688

689+
{ #category : #'examples - interactions' }
690+
GeoViewExamples class >> exampleMeasuringRuler [
691+
"This example show how to use a MeasuringRuler with a custom process data"
692+
693+
| element layer instructionsText |
694+
element := GeoViewElement new id: #geoView.
695+
element addLayer: (GeoViewMapTilesLayer newWithOpenStreetMap).
696+
697+
"Create a new layer to display the measure tool"
698+
layer := GeoViewDomainObjectsLayer new name: #tools.
699+
layer setProcessData: (GeoMeasuringRulerProcessData new) forClass: GeoMeasuringRuler.
700+
element addLayer: layer.
701+
702+
"Create a text to display instructions"
703+
instructionsText := BlTextElement new
704+
background: Color white;
705+
effect: (BlGaussianShadowEffect color: (Color gray alpha: 0.5) width: 10 offset: 0@0);
706+
constraintsDo: [ :constraints |
707+
constraints horizontal fitContent.
708+
constraints vertical exact: 15.
709+
constraints padding: (BlInsets all: 10.0) ];
710+
id: #instructionsText; text: 'Double click on a position to start a measurement, move the mouse and click another time to stay the ruler.' asRopedText;
711+
yourself.
712+
element addChild: instructionsText.
713+
714+
"create a controller to manager the ruler"
715+
element addEventHandler: GeoViewMeasuringRulerController new.
716+
717+
^ self openViewInWindow: element
718+
]
719+
720+
{ #category : #'examples - interactions' }
721+
GeoViewExamples class >> exampleMeasuringRulerWithCircle [
722+
"This example show how to use a MeasuringRuler but with a process data which is display a circle in addition to the ruler"
723+
724+
| space geoView layer |
725+
space := self exampleMeasuringRuler.
726+
727+
geoView := space root childWithId: #geoView.
728+
729+
"change process data"
730+
layer := geoView getLayer: #tools.
731+
layer setProcessData: (GeoMeasuringRulerWithCircleProcessData new) forClass: GeoMeasuringRuler.
732+
]
733+
681734
{ #category : #'examples - filters' }
682735
GeoViewExamples class >> exampleObjectsFilterChanged [
683736

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
Class {
2+
#name : #GeoViewMeasuringRulerController,
3+
#superclass : #BlEventListener,
4+
#instVars : [
5+
'geoView',
6+
'measuringRuler',
7+
'isMeasuring'
8+
],
9+
#category : #'GeoView-Examples-Utils'
10+
}
11+
12+
{ #category : #'mouse handlers' }
13+
GeoViewMeasuringRulerController >> clickEvent: anEvent [
14+
15+
self isMeasuring: false
16+
17+
18+
]
19+
20+
{ #category : #'mouse handlers' }
21+
GeoViewMeasuringRulerController >> doubleClickEvent: anEvent [
22+
23+
| coordinates |
24+
25+
"remove previous measure"
26+
measuringRuler ifNotNil: [
27+
geoView removeObject: measuringRuler.
28+
measuringRuler := nil ].
29+
30+
coordinates := geoView absoluteCoordinatesFromGlobalPoint: anEvent position.
31+
coordinates ifNil: [ ^ self ].
32+
33+
"start a measure"
34+
self isMeasuring: true.
35+
measuringRuler := GeoMeasuringRuler key: #measuringRuler.
36+
measuringRuler fromAbsoluteCoordinates: coordinates.
37+
geoView addObject: measuringRuler
38+
]
39+
40+
{ #category : #accessing }
41+
GeoViewMeasuringRulerController >> isMeasuring [
42+
43+
^ isMeasuring ifNil: [ isMeasuring := false ]
44+
]
45+
46+
{ #category : #accessing }
47+
GeoViewMeasuringRulerController >> isMeasuring: aBoolean [
48+
49+
isMeasuring := aBoolean
50+
]
51+
52+
{ #category : #'mouse handlers' }
53+
GeoViewMeasuringRulerController >> mouseMoveEvent: anEvent [
54+
55+
| coordinates |
56+
self isMeasuring ifFalse:[ ^ self ].
57+
58+
coordinates := geoView absoluteCoordinatesFromGlobalPoint: anEvent position.
59+
coordinates ifNil:[ ^ self ].
60+
61+
measuringRuler toAbsoluteCoordinates: coordinates.
62+
geoView updateObject: measuringRuler.
63+
]
64+
65+
{ #category : #'api - hooks' }
66+
GeoViewMeasuringRulerController >> onInstalledIn: aGeoView [
67+
68+
super onInstalledIn: aGeoView.
69+
geoView := aGeoView
70+
]
71+
72+
{ #category : #'api - hooks' }
73+
GeoViewMeasuringRulerController >> onUninstalledIn: aGeoView [
74+
75+
measuringRuler ifNotNil: [ geoView removeObject: measuringRuler ].
76+
measuringRuler := nil.
77+
geoView := nil.
78+
79+
super onUninstalledIn: aGeoView
80+
]

src/GeoView-Tests/GeoArcBandTest.class.st

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Class {
77
#category : #'GeoView-Tests-GeoObjects'
88
}
99

10-
{ #category : #'tests-updating' }
10+
{ #category : #'tests - instance' }
1111
GeoArcBandTest >> geoObject1 [
1212

1313
| object |
@@ -21,7 +21,7 @@ GeoArcBandTest >> geoObject1 [
2121
yourself.
2222
]
2323

24-
{ #category : #'tests-updating' }
24+
{ #category : #'tests - instance' }
2525
GeoArcBandTest >> geoObject2 [
2626

2727
| object |
@@ -41,7 +41,7 @@ GeoArcBandTest >> geoObjectClass [
4141
^ GeoArcBand
4242
]
4343

44-
{ #category : #'tests-updating' }
44+
{ #category : #tests }
4545
GeoArcBandTest >> testCopy [
4646

4747
| copy |
@@ -54,7 +54,7 @@ GeoArcBandTest >> testCopy [
5454
self assert: geoObject radiusInMeters2 equals: copy radiusInMeters2.
5555
]
5656

57-
{ #category : #'tests-updating' }
57+
{ #category : #tests }
5858
GeoArcBandTest >> testUpdateWith [
5959

6060
| object1 object2 |

src/GeoView-Tests/GeoEllipseTest.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GeoEllipseTest >> geoObjectClass [
3737
^ GeoEllipse
3838
]
3939

40-
{ #category : #'tests-updating' }
40+
{ #category : #tests }
4141
GeoEllipseTest >> testCopy [
4242

4343
| copy |
@@ -48,7 +48,7 @@ GeoEllipseTest >> testCopy [
4848
self assert: geoObject radiusInMeters2 equals: copy radiusInMeters2.
4949
]
5050

51-
{ #category : #'tests-updating' }
51+
{ #category : #tests }
5252
GeoEllipseTest >> testUpdateWith [
5353
| object1 object2 |
5454

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Class {
2+
#name : #GeoMeasuringRulerTest,
3+
#superclass : #GeoToolTest,
4+
#category : #'GeoView-Tests-GeoObjects'
5+
}
6+
7+
{ #category : #accessing }
8+
GeoMeasuringRulerTest >> geoObjectClass [
9+
10+
^ GeoMeasuringRuler
11+
]

src/GeoView-Tests/GeoObjectTest.class.st

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ GeoObjectTest >> setUp [
4949
geoObject := self geoObjectClass new
5050
]
5151

52+
{ #category : #tests }
53+
GeoObjectTest >> testAbsoluteCoordinates [
54+
55+
self assert: geoObject absoluteCoordinates isNil.
56+
57+
geoObject absoluteCoordinates: AbsoluteCoordinates zero.
58+
self assert: geoObject absoluteCoordinates equals: AbsoluteCoordinates zero.
59+
60+
geoObject absoluteCoordinates: nil.
61+
self assert: geoObject absoluteCoordinates isNil.
62+
]
63+
5264
{ #category : #tests }
5365
GeoObjectTest >> testCopy [
5466

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Class {
2+
#name : #GeoToolTest,
3+
#superclass : #GeoObjectTest,
4+
#category : #'GeoView-Tests-GeoObjects'
5+
}
6+
7+
{ #category : #testing }
8+
GeoToolTest class >> isAbstract [
9+
10+
^ self == GeoToolTest
11+
]

src/GeoView/DLeafShapeGeoViewProcessData.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Class {
77
{ #category : #accessing }
88
DLeafShapeGeoViewProcessData class >> isAbstract [
99

10-
^ self = DLeafShapeGeoViewProcessData
10+
^ self == DLeafShapeGeoViewProcessData
1111
]
1212

1313
{ #category : #private }

src/GeoView/DMultiShapesGeoViewProcessData.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Class {
77
{ #category : #accessing }
88
DMultiShapesGeoViewProcessData class >> isAbstract [
99

10-
^ self = DMultiShapesGeoViewProcessData
10+
^ self == DMultiShapesGeoViewProcessData
1111
]

src/GeoView/DShapeGeoViewProcessData.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Class {
99
{ #category : #accessing }
1010
DShapeGeoViewProcessData class >> isAbstract [
1111

12-
^ self = DShapeGeoViewProcessData
12+
^ self == DShapeGeoViewProcessData
1313
]
1414

1515
{ #category : #computing }

0 commit comments

Comments
 (0)