geojs 1.10.8 → 1.10.9
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/.github/workflows/commitlint.yml +11 -0
- package/commitlint.config.js +24 -0
- package/geo.js +116 -14
- package/geo.lean.js +116 -14
- package/geo.lean.min.js +5 -5
- package/geo.min.js +1 -1
- package/package.json +1 -1
- package/src/event.js +1 -1
- package/src/index.js +6 -0
- package/src/map.js +2 -0
- package/src/mapInteractor.js +22 -0
- package/src/util/polyops.js +50 -1
package/package.json
CHANGED
package/src/event.js
CHANGED
package/src/index.js
CHANGED
|
@@ -108,3 +108,9 @@ if (window && !window.$) {
|
|
|
108
108
|
if (window && !window.jQuery) {
|
|
109
109
|
window.jQuery = $;
|
|
110
110
|
}
|
|
111
|
+
if (window && !window.geojsMap) {
|
|
112
|
+
window.geojsMap = () => {
|
|
113
|
+
const maps = $('.geojs-map').map((idx, m) => $(m).data('data-geojs-map'));
|
|
114
|
+
return maps.length === 0 ? undefined : maps.length === 1 ? maps[0] : maps;
|
|
115
|
+
};
|
|
116
|
+
}
|
package/src/map.js
CHANGED
|
@@ -1966,6 +1966,8 @@ var map = function (arg) {
|
|
|
1966
1966
|
|
|
1967
1967
|
/* Report the current version on the map object. */
|
|
1968
1968
|
this._version = require('./version');
|
|
1969
|
+
/* Link to the main library */
|
|
1970
|
+
this._geo = require('./index');
|
|
1969
1971
|
|
|
1970
1972
|
/**
|
|
1971
1973
|
* Draw a layer image to a canvas context. The layer's opacity and transform
|
package/src/mapInteractor.js
CHANGED
|
@@ -100,6 +100,28 @@ var Mousetrap = require('mousetrap');
|
|
|
100
100
|
* The default is `(2 - t) * t`.
|
|
101
101
|
*/
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* The state of the mouse.
|
|
105
|
+
*
|
|
106
|
+
* @typedef {object} geo.mouseState
|
|
107
|
+
* @property {geo.screenPosition} page Mouse position relative to the page.
|
|
108
|
+
* @property {geo.geoPosition} map Mouse position relative to the map.
|
|
109
|
+
* @property {geo.geoPosition} geo Mouse position in map interface gcs.
|
|
110
|
+
* @property {geo.geoPosition} mapgcs Mouse position in map gcs
|
|
111
|
+
* @property {object} buttons Which mouse buttons are down.
|
|
112
|
+
* @property {boolean} buttons.left State of the left mouse button.
|
|
113
|
+
* @property {boolean} buttons.right State of the right mouse button.
|
|
114
|
+
* @property {boolean} buttons.middle State of the middle mouse button.
|
|
115
|
+
* @property {object} modifiers Which modifier keys are down.
|
|
116
|
+
* @property {boolean} modifiers.alt State of the alt key.
|
|
117
|
+
* @property {boolean} modifiers.ctrl State of the ctrl key.
|
|
118
|
+
* @property {boolean} modifiers.shift State of the shift key.
|
|
119
|
+
* @property {boolean} modifiers.meta State of the meta key.
|
|
120
|
+
* @property {number} time Time (epoch ms) the event was captured.
|
|
121
|
+
* @property {number} deltaTime Time elapsed (ms) since the last mouse event.
|
|
122
|
+
* @property {geo.screenPosition} velocity Mouse speed in pixels/ms.
|
|
123
|
+
*/
|
|
124
|
+
|
|
103
125
|
/**
|
|
104
126
|
* The mapInteractor class is responsible for handling raw events from the
|
|
105
127
|
* browser and interpreting them as map navigation interactions. This class
|
package/src/util/polyops.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var PolyBool = require('polybooljs');
|
|
2
2
|
var geo_map = require('../map');
|
|
3
|
+
var util = require('../util/common');
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A list of flat polygon lists.
|
|
@@ -80,11 +81,13 @@ const AlternateOpNames = {
|
|
|
80
81
|
* Convert a segment list to a polygon list.
|
|
81
82
|
*
|
|
82
83
|
* @param {object[]} seglist A PolyBool segment list.
|
|
83
|
-
* @returns {geo.polygonList} A polygon list.
|
|
84
|
+
* @returns {geo.polygonList|undefined} A polygon list.
|
|
84
85
|
*/
|
|
85
86
|
function seglistToPolygonList(seglist) {
|
|
86
87
|
// This single line doesn't arrange holes correctly
|
|
87
88
|
// return seglist.map((s) => PolyBool.polygon(s).regions);
|
|
89
|
+
/* This uses PolyBools' operations (mostly), but is much slower than needed
|
|
90
|
+
* since it goes through geojson.
|
|
88
91
|
const polys = [];
|
|
89
92
|
seglist.forEach((s) => {
|
|
90
93
|
const geojson = PolyBool.polygonToGeoJSON(PolyBool.polygon(s));
|
|
@@ -97,6 +100,52 @@ function seglistToPolygonList(seglist) {
|
|
|
97
100
|
}
|
|
98
101
|
});
|
|
99
102
|
return polys;
|
|
103
|
+
*/
|
|
104
|
+
const polys = []; // end result
|
|
105
|
+
const borders = []; // polygons in format needed for util.pointInPolygon
|
|
106
|
+
const regions = []; // polygons in end result format
|
|
107
|
+
const parents = []; // list of parents of each polygon
|
|
108
|
+
seglist.forEach((s) => PolyBool.polygon(s).regions.forEach((r) => {
|
|
109
|
+
const border = r.map((pt) => ({x: pt[0], y: pt[1]}));
|
|
110
|
+
if (border.length < 3) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
parents.push([]);
|
|
114
|
+
borders.forEach((b, i) => {
|
|
115
|
+
if (util.pointInPolygon(border[0], b)) {
|
|
116
|
+
parents[borders.length].push(i);
|
|
117
|
+
} else if (util.pointInPolygon(b[0], border)) {
|
|
118
|
+
parents[i].push(borders.length);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
regions.push(r);
|
|
122
|
+
borders.push(border);
|
|
123
|
+
}));
|
|
124
|
+
/* find nested polygons */
|
|
125
|
+
const dest = Array(regions.length);
|
|
126
|
+
let used = 0;
|
|
127
|
+
while (used < regions.length) {
|
|
128
|
+
for (let i = 0; i < regions.length; i += 1) {
|
|
129
|
+
if (dest[i] === undefined && !parents[i].length) {
|
|
130
|
+
dest[i] = polys.length;
|
|
131
|
+
/* reverse the outer polygons for consistency with how PolyBool
|
|
132
|
+
* generates geojson */
|
|
133
|
+
polys.push([regions[i].reverse()]);
|
|
134
|
+
used += 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (let i = 0; i < regions.length; i += 1) {
|
|
138
|
+
if (dest[i] === undefined && parents[i].length === 1 && dest[parents[i][0]] !== undefined) {
|
|
139
|
+
polys[dest[parents[i][0]]].push(regions[i]);
|
|
140
|
+
dest[i] = dest[parents[i][0]];
|
|
141
|
+
used += 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < regions.length; i += 1) {
|
|
145
|
+
parents[i] = parents[i].filter((d) => dest[d] === undefined);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return polys.length ? polys : [[]];
|
|
100
149
|
}
|
|
101
150
|
|
|
102
151
|
/**
|