draw-libre 0.2.1 → 0.2.3
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.
- package/README.md +165 -165
- package/dist/index.d.ts +2 -16
- package/dist/index.global.js +1 -1
- package/dist/index.js +2 -4
- package/package.json +9 -4
- package/dist/index.d.mts +0 -260
- package/dist/index.mjs +0 -3
package/README.md
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
<section >
|
|
2
|
-
<h1>DrawLibre</h1>
|
|
3
|
-
<img width=600 alt="GIF" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExaDZscnowMHNndmtiZzcwb3Bvc2Y2b29qbHdndndndGE3Mzk5Z2Q0cSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/m6lig0ZCfL45FZQo7b/giphy.gif" />
|
|
4
|
-
</section>
|
|
5
|
-
|
|
6
|
-
## Features
|
|
7
|
-
|
|
8
|
-
- Draw linestrings (including closed ones) and polygons
|
|
9
|
-
- Compatible with maplibre-gl.js and mapbox-gl.js (currently supports Mercator projection only)
|
|
10
|
-
- Customizable UI and controls
|
|
11
|
-
- Event-driven architecture for easy integration
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install draw-libre
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Quick Start
|
|
20
|
-
|
|
21
|
-
```javascript
|
|
22
|
-
import maplibregl from "maplibre-gl";
|
|
23
|
-
import DrawLibre from "draw-libre";
|
|
24
|
-
import "draw-libre/dist/index.css";
|
|
25
|
-
|
|
26
|
-
const map = new maplibregl.Map({
|
|
27
|
-
container: ...,
|
|
28
|
-
style: ...,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const draw = DrawLibre.getInstance();
|
|
32
|
-
|
|
33
|
-
map.on("load", (event) => {
|
|
34
|
-
event.target.addControl(draw, "top-left");
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## API
|
|
39
|
-
|
|
40
|
-
### Configuration
|
|
41
|
-
|
|
42
|
-
```javascript
|
|
43
|
-
const draw = DrawLibre.getInstance({
|
|
44
|
-
modes: {
|
|
45
|
-
initial: null, // default value; can be "line" or "polygon". Initial mode for drawing
|
|
46
|
-
breakGeometry: { visible: true }, // Controls visibility of the break geometry button
|
|
47
|
-
line: {
|
|
48
|
-
closeGeometry: true, // Enables/disables ability to close a LineString
|
|
49
|
-
visible: true, // Controls visibility of the line drawing button
|
|
50
|
-
},
|
|
51
|
-
polygon: { visible: true }, // Controls visibility of the polygon drawing button
|
|
52
|
-
},
|
|
53
|
-
panel: {
|
|
54
|
-
size: "medium", // "large" || "small" - Controls size of the panel that appears after pressing a button
|
|
55
|
-
buttons: {
|
|
56
|
-
delete: { visible: true }, // Controls visibility of the delete all points button
|
|
57
|
-
save: {
|
|
58
|
-
clearOnSave: true, // Whether to clear all points after saving
|
|
59
|
-
visible: true, // Controls visibility of the save button
|
|
60
|
-
},
|
|
61
|
-
undo: { visible: true }, // Controls visibility of the undo button
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
locale: {
|
|
65
|
-
// Customize button labels and tooltips
|
|
66
|
-
break: "Break",
|
|
67
|
-
closeLine: "Close",
|
|
68
|
-
createPolygon: "Create",
|
|
69
|
-
delete: "Delete",
|
|
70
|
-
line: "Line",
|
|
71
|
-
polygon: "Polygon",
|
|
72
|
-
save: "Save",
|
|
73
|
-
undo: "Undo",
|
|
74
|
-
},
|
|
75
|
-
layersPaint: {
|
|
76
|
-
// Customize layer styles here. Refer to MapLibre's layer specifications for options.
|
|
77
|
-
onLinePoint: {}, // CircleLayerSpecification["paint"]
|
|
78
|
-
firstPoint: {}, // CircleLayerSpecification["paint"]
|
|
79
|
-
points: {}, // CircleLayerSpecification["paint"]
|
|
80
|
-
line: {}, // LineLayerSpecification["paint"]
|
|
81
|
-
polygon: {}, // FillLayerSpecification["paint"]
|
|
82
|
-
breakLine: {}, // LineLayerSpecification["paint"]
|
|
83
|
-
},
|
|
84
|
-
dynamicLine: true, // Whether to draw a dynamic line following the cursor after placing the first point
|
|
85
|
-
initial: {
|
|
86
|
-
// Initialize with pre-existing GeoJSON data
|
|
87
|
-
closeGeometry: false, // Specify if the geometry is closed. Must be true if the geometry type is polygon.
|
|
88
|
-
generateId: true, // Whether to generate unique IDs for your geometries. Should be true if there are no IDs for each point in `steps`.
|
|
89
|
-
geometry: "line", // "line" | "polygon" - Specifies the type of geometry to initialize
|
|
90
|
-
steps: [
|
|
91
|
-
// Array of {id?: string | number, lat: number, lng: number}
|
|
92
|
-
// The first and the last point should be the same if the geometry is closed.
|
|
93
|
-
// The closeGeometry also should be true in this case.
|
|
94
|
-
{ lat: 40, lng: 30 },
|
|
95
|
-
{ lat: 31, lng: 21 },
|
|
96
|
-
{ lat: 31, lng: 21 },
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Events
|
|
103
|
-
|
|
104
|
-
Import events from the library:
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
import DrawLibre, {
|
|
108
|
-
|
|
109
|
-
map.on(
|
|
110
|
-
console.log("Add event", event);
|
|
111
|
-
});
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Available events:
|
|
115
|
-
|
|
116
|
-
- `mdl:doubleclick` (PointDoubleClickEvent)
|
|
117
|
-
- `mdl:pointenter` (PointEnterEvent)
|
|
118
|
-
- `mdl:pointleave` (PointLeaveEvent)
|
|
119
|
-
- `mdl:moveend` (PointMoveEvent)
|
|
120
|
-
- `mdl:add` (PointAddEvent)
|
|
121
|
-
- `mdl:undo` (UndoEvent)
|
|
122
|
-
- `mdl:removeall` (RemoveAllEvent)
|
|
123
|
-
- `mdl:save` (SaveEvent)
|
|
124
|
-
- `mdl:mdl:modechanged` (ModeChangeEvent)
|
|
125
|
-
|
|
126
|
-
### Methods
|
|
127
|
-
|
|
128
|
-
```javascript
|
|
129
|
-
const draw = DrawLibre.getInstance();
|
|
130
|
-
|
|
131
|
-
// Find a step by its ID
|
|
132
|
-
draw.findStepById(id: string)
|
|
133
|
-
|
|
134
|
-
// Get all steps, optionally specifying the return type
|
|
135
|
-
draw.getAllSteps(type?: "array" | "linkedlist")
|
|
136
|
-
|
|
137
|
-
// Set new steps. If ID is not provided, it will be generated automatically
|
|
138
|
-
draw.setSteps(steps: {lat: number; lng: number; id?: string}[])
|
|
139
|
-
|
|
140
|
-
// Remove all steps
|
|
141
|
-
draw.removeAllSteps()
|
|
142
|
-
|
|
143
|
-
// Update options. Note that options are immutable, so return a new object with spread values.
|
|
144
|
-
draw.setOptions((options: RequiredDrawOptions) => {
|
|
145
|
-
return {
|
|
146
|
-
...options,
|
|
147
|
-
locale: {
|
|
148
|
-
...options.locale,
|
|
149
|
-
save: "Save update",
|
|
150
|
-
},
|
|
151
|
-
modes: {
|
|
152
|
-
...options.modes,
|
|
153
|
-
line: {
|
|
154
|
-
...options.modes.line,
|
|
155
|
-
closeGeometry: false,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
dynamicLine: false,
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## License
|
|
164
|
-
|
|
165
|
-
This project is licensed under the [MIT License](LICENSE).
|
|
1
|
+
<section >
|
|
2
|
+
<h1>DrawLibre</h1>
|
|
3
|
+
<img width=600 alt="GIF" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExaDZscnowMHNndmtiZzcwb3Bvc2Y2b29qbHdndndndGE3Mzk5Z2Q0cSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/m6lig0ZCfL45FZQo7b/giphy.gif" />
|
|
4
|
+
</section>
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Draw linestrings (including closed ones) and polygons
|
|
9
|
+
- Compatible with maplibre-gl.js and mapbox-gl.js (currently supports Mercator projection only)
|
|
10
|
+
- Customizable UI and controls
|
|
11
|
+
- Event-driven architecture for easy integration
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install draw-libre
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import maplibregl from "maplibre-gl";
|
|
23
|
+
import DrawLibre from "draw-libre";
|
|
24
|
+
import "draw-libre/dist/index.css";
|
|
25
|
+
|
|
26
|
+
const map = new maplibregl.Map({
|
|
27
|
+
container: ...,
|
|
28
|
+
style: ...,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const draw = DrawLibre.getInstance();
|
|
32
|
+
|
|
33
|
+
map.on("load", (event) => {
|
|
34
|
+
event.target.addControl(draw, "top-left");
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### Configuration
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
const draw = DrawLibre.getInstance({
|
|
44
|
+
modes: {
|
|
45
|
+
initial: null, // default value; can be "line" or "polygon". Initial mode for drawing
|
|
46
|
+
breakGeometry: { visible: true }, // Controls visibility of the break geometry button
|
|
47
|
+
line: {
|
|
48
|
+
closeGeometry: true, // Enables/disables ability to close a LineString
|
|
49
|
+
visible: true, // Controls visibility of the line drawing button
|
|
50
|
+
},
|
|
51
|
+
polygon: { visible: true }, // Controls visibility of the polygon drawing button
|
|
52
|
+
},
|
|
53
|
+
panel: {
|
|
54
|
+
size: "medium", // "large" || "small" - Controls size of the panel that appears after pressing a button
|
|
55
|
+
buttons: {
|
|
56
|
+
delete: { visible: true }, // Controls visibility of the delete all points button
|
|
57
|
+
save: {
|
|
58
|
+
clearOnSave: true, // Whether to clear all points after saving
|
|
59
|
+
visible: true, // Controls visibility of the save button
|
|
60
|
+
},
|
|
61
|
+
undo: { visible: true }, // Controls visibility of the undo button
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
locale: {
|
|
65
|
+
// Customize button labels and tooltips
|
|
66
|
+
break: "Break",
|
|
67
|
+
closeLine: "Close",
|
|
68
|
+
createPolygon: "Create",
|
|
69
|
+
delete: "Delete",
|
|
70
|
+
line: "Line",
|
|
71
|
+
polygon: "Polygon",
|
|
72
|
+
save: "Save",
|
|
73
|
+
undo: "Undo",
|
|
74
|
+
},
|
|
75
|
+
layersPaint: {
|
|
76
|
+
// Customize layer styles here. Refer to MapLibre's layer specifications for options.
|
|
77
|
+
onLinePoint: {}, // CircleLayerSpecification["paint"]
|
|
78
|
+
firstPoint: {}, // CircleLayerSpecification["paint"]
|
|
79
|
+
points: {}, // CircleLayerSpecification["paint"]
|
|
80
|
+
line: {}, // LineLayerSpecification["paint"]
|
|
81
|
+
polygon: {}, // FillLayerSpecification["paint"]
|
|
82
|
+
breakLine: {}, // LineLayerSpecification["paint"]
|
|
83
|
+
},
|
|
84
|
+
dynamicLine: true, // Whether to draw a dynamic line following the cursor after placing the first point
|
|
85
|
+
initial: {
|
|
86
|
+
// Initialize with pre-existing GeoJSON data
|
|
87
|
+
closeGeometry: false, // Specify if the geometry is closed. Must be true if the geometry type is polygon.
|
|
88
|
+
generateId: true, // Whether to generate unique IDs for your geometries. Should be true if there are no IDs for each point in `steps`.
|
|
89
|
+
geometry: "line", // "line" | "polygon" - Specifies the type of geometry to initialize
|
|
90
|
+
steps: [
|
|
91
|
+
// Array of {id?: string | number, lat: number, lng: number}
|
|
92
|
+
// The first and the last point should be the same if the geometry is closed.
|
|
93
|
+
// The closeGeometry also should be true in this case.
|
|
94
|
+
{ lat: 40, lng: 30 },
|
|
95
|
+
{ lat: 31, lng: 21 },
|
|
96
|
+
{ lat: 31, lng: 21 },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Events
|
|
103
|
+
|
|
104
|
+
Import events from the library:
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
import DrawLibre, { type PointAddEvent } from "draw-libre";
|
|
108
|
+
|
|
109
|
+
map.on(mdl:add, (event: PointAddEvent) => {
|
|
110
|
+
console.log("Add event", event);
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Available events:
|
|
115
|
+
|
|
116
|
+
- `mdl:doubleclick` (PointDoubleClickEvent)
|
|
117
|
+
- `mdl:pointenter` (PointEnterEvent)
|
|
118
|
+
- `mdl:pointleave` (PointLeaveEvent)
|
|
119
|
+
- `mdl:moveend` (PointMoveEvent)
|
|
120
|
+
- `mdl:add` (PointAddEvent)
|
|
121
|
+
- `mdl:undo` (UndoEvent)
|
|
122
|
+
- `mdl:removeall` (RemoveAllEvent)
|
|
123
|
+
- `mdl:save` (SaveEvent)
|
|
124
|
+
- `mdl:mdl:modechanged` (ModeChangeEvent)
|
|
125
|
+
|
|
126
|
+
### Methods
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const draw = DrawLibre.getInstance();
|
|
130
|
+
|
|
131
|
+
// Find a step by its ID
|
|
132
|
+
draw.findStepById(id: string)
|
|
133
|
+
|
|
134
|
+
// Get all steps, optionally specifying the return type
|
|
135
|
+
draw.getAllSteps(type?: "array" | "linkedlist")
|
|
136
|
+
|
|
137
|
+
// Set new steps. If ID is not provided, it will be generated automatically
|
|
138
|
+
draw.setSteps(steps: {lat: number; lng: number; id?: string}[])
|
|
139
|
+
|
|
140
|
+
// Remove all steps
|
|
141
|
+
draw.removeAllSteps()
|
|
142
|
+
|
|
143
|
+
// Update options. Note that options are immutable, so return a new object with spread values.
|
|
144
|
+
draw.setOptions((options: RequiredDrawOptions) => {
|
|
145
|
+
return {
|
|
146
|
+
...options,
|
|
147
|
+
locale: {
|
|
148
|
+
...options.locale,
|
|
149
|
+
save: "Save update",
|
|
150
|
+
},
|
|
151
|
+
modes: {
|
|
152
|
+
...options.modes,
|
|
153
|
+
line: {
|
|
154
|
+
...options.modes.line,
|
|
155
|
+
closeGeometry: false,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
dynamicLine: false,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
This project is licensed under the [MIT License](LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -133,19 +133,6 @@ type RequiredDrawOptions = DeepRequired<Omit<DrawOptions, "layersPaint">> & {
|
|
|
133
133
|
layersPaint: LayersPaint;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
declare const EVENTS: {
|
|
137
|
-
readonly DOUBLECLICK: "mdl:doubleclick";
|
|
138
|
-
readonly POINTENTER: "mdl:pointenter";
|
|
139
|
-
readonly POINTLEAVE: "mdl:pointleave";
|
|
140
|
-
readonly MOVEEND: "mdl:moveend";
|
|
141
|
-
readonly ADD: "mdl:add";
|
|
142
|
-
readonly UNDO: "mdl:undo";
|
|
143
|
-
readonly REMOVEALL: "mdl:removeall";
|
|
144
|
-
readonly SAVE: "mdl:save";
|
|
145
|
-
readonly BREAK: "mdl:break";
|
|
146
|
-
readonly MODECHANGED: "mdl:mode_changed";
|
|
147
|
-
};
|
|
148
|
-
|
|
149
136
|
interface BaseEvent {
|
|
150
137
|
id: Uuid;
|
|
151
138
|
total: number;
|
|
@@ -187,8 +174,7 @@ interface PointLeaveEvent extends BaseEvent {
|
|
|
187
174
|
coordinates: LatLng;
|
|
188
175
|
}
|
|
189
176
|
interface ModeChangeEvent {
|
|
190
|
-
|
|
191
|
-
mode: ModeEvent;
|
|
177
|
+
mode: Mode | "break";
|
|
192
178
|
}
|
|
193
179
|
|
|
194
180
|
declare class DrawLibre implements IControl {
|
|
@@ -257,4 +243,4 @@ declare class DrawLibre implements IControl {
|
|
|
257
243
|
removeAllSteps: () => void;
|
|
258
244
|
}
|
|
259
245
|
|
|
260
|
-
export {
|
|
246
|
+
export { type ModeChangeEvent, type PointAddEvent, type PointDoubleClickEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type UndoEvent, DrawLibre as default };
|