MCPcopy Create free account
hub / github.com/Maps4HTML/MapML.js / _query

Function _query

src/mapml/handlers/QueryHandler.js:93–475  ·  view source on GitHub ↗
(e, layer)

Source from the content-addressed store, hash-verified

91 }
92 },
93 _query(e, layer) {
94 var zoom = e.target.getZoom(),
95 map = this._map,
96 crs = M[layer.options.projection], // the crs for each extent would be the same
97 tileSize = map.options.crs.options.crs.tile.bounds.max.x,
98 container = layer._container,
99 popupOptions = {
100 autoClose: false,
101 autoPan: true,
102 maxHeight: map.getSize().y * 0.5 - 50,
103 maxWidth: map.getSize().x * 0.7
104 },
105 tcrs2pcrs = function (c) {
106 return crs.transformation.untransform(c, crs.scale(zoom));
107 },
108 tcrs2gcrs = function (c) {
109 return crs.unproject(
110 crs.transformation.untransform(c, crs.scale(zoom)),
111 zoom
112 );
113 };
114 var tcrsClickLoc = crs.latLngToPoint(e.latlng, zoom),
115 tileMatrixClickLoc = tcrsClickLoc.divideBy(tileSize).floor(),
116 tileBounds = new Bounds(
117 tcrsClickLoc.divideBy(tileSize).floor().multiplyBy(tileSize),
118 tcrsClickLoc.divideBy(tileSize).ceil().multiplyBy(tileSize)
119 );
120
121 let point = this._map.project(e.latlng),
122 scale = this._map.options.crs.scale(this._map.getZoom()),
123 pcrsClick = this._map.options.crs.transformation.untransform(
124 point,
125 scale
126 );
127 let templates = layer.getQueryTemplates(pcrsClick, zoom);
128
129 let fetches = [];
130
131 var fetchFeatures = function (template, obj) {
132 const parser = new DOMParser();
133 return fetch(LeafletUtil.template(template.template, obj), {
134 redirect: 'follow'
135 })
136 .then((response) => {
137 if (response.status >= 200 && response.status < 300) {
138 return response.text().then((text) => {
139 return {
140 contenttype: response.headers.get('Content-Type'),
141 text: text
142 };
143 });
144 } else {
145 throw new Error(response.status);
146 }
147 })
148 .then((response) => {
149 let features = [];
150 let queryMetas = [];

Callers

nothing calls this directly

Calls 5

tcrs2pcrsFunction · 0.85
tcrs2gcrsFunction · 0.85
fetchFeaturesFunction · 0.85
displayFeaturesPopupFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected