diff --git a/dist/openlayers-indoorequal.cjs.js b/dist/openlayers-indoorequal.cjs.js index 2c8aea1..cb264e7 100644 --- a/dist/openlayers-indoorequal.cjs.js +++ b/dist/openlayers-indoorequal.cjs.js @@ -158,7 +158,7 @@ function areaLayer(feature, resolution) { color = '#fefee2'; } let stroke; - if (['area', 'corridor', 'plaform'].includes(properties.class)) { + if (['area', 'corridor', 'platform'].includes(properties.class)) { stroke = new style.Stroke({ color: '#bfbfbf', width: 1 diff --git a/dist/openlayers-indoorequal.esm.js b/dist/openlayers-indoorequal.esm.js index 12a9faf..e08f24e 100644 --- a/dist/openlayers-indoorequal.esm.js +++ b/dist/openlayers-indoorequal.esm.js @@ -154,7 +154,7 @@ function areaLayer(feature, resolution) { color = '#fefee2'; } let stroke; - if (['area', 'corridor', 'plaform'].includes(properties.class)) { + if (['area', 'corridor', 'platform'].includes(properties.class)) { stroke = new Stroke({ color: '#bfbfbf', width: 1 diff --git a/dist/openlayers-indoorequal.umd.min.js b/dist/openlayers-indoorequal.umd.min.js index ba54cfa..6e08284 100644 --- a/dist/openlayers-indoorequal.umd.min.js +++ b/dist/openlayers-indoorequal.umd.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ol/Feature"),require("ol/layer/Heatmap"),require("ol/format/MVT"),require("ol/tilegrid/TileGrid"),require("ol/source/TileJSON"),require("ol/source/Vector"),require("ol/layer/VectorTile"),require("ol/source/VectorTile"),require("ol/proj"),require("ol/loadingstrategy"),require("ol/control"),require("ol/style"),require("ol/Object")):"function"==typeof define&&define.amd?define(["exports","ol/Feature","ol/layer/Heatmap","ol/format/MVT","ol/tilegrid/TileGrid","ol/source/TileJSON","ol/source/Vector","ol/layer/VectorTile","ol/source/VectorTile","ol/proj","ol/loadingstrategy","ol/control","ol/style","ol/Object"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IndoorEqual={},e.ol.Feature,e.ol.layer.Heatmap,e.ol.format.MVT,e.ol.tilegrid.TileGrid,e.ol.source.TileJSON,e.ol.source.Vector,e.ol.layer.VectorTile,e.ol.source.VectorTile,e.ol.proj,e.ol.loadingstrategy,e.ol.control,e.ol.style,e.ol.Object)}(this,(function(e,t,o,r,l,n,i,s,a,c,u,d,h,f){"use strict";const g=function(){const e=[];for(let t=78271.51696402048;e.length<=24;t/=2)e.push(t);return e}();function y(e){const o=e.getTileJSON(),n=Array.isArray(o.tiles)?o.tiles:[o.tiles],i=e.getTileGrid(),s=function(e){const t=e.bounds;if(t){const e=c.fromLonLat([t[0],t[1]]),o=c.fromLonLat([t[2],t[3]]);return[e[0],e[1],o[0],o[1]]}}(o),u=o.minzoom,d=o.maxzoom;return new a({attributions:e.getAttributions(),format:new r({featureClass:t}),tileGrid:new l({origin:i.getOrigin(0),extent:s||i.getExtent(),minZoom:u,resolutions:g.slice(0,d+1),tileSize:512}),urls:n})}async function p(e){const t=await function(e){return new Promise(((t,o)=>{const r=new n({url:e});r.on("change",(function(){"ready"===r.getState()&&t(r)})),"ready"===r.getState()&&r.changed()}))}(e);return y(t)}function m(e){return new s({declutter:!0,...e})}function w(e){return new o({maxZoom:17,gradient:["rgba(102, 103, 173, 0)","rgba(102, 103, 173, 0.2)","rgba(102, 103, 173, 0.7)"],...e})}class v extends d.Control{constructor(e,t={}){const o=document.createElement("div");o.className="level-control ol-unselectable ol-control",super({element:o,target:t.target}),this.indoorEqual=e,this._renderNewLevels(),this.indoorEqual.on("change:levels",this._renderNewLevels.bind(this)),this.indoorEqual.on("change:level",this._renderNewLevels.bind(this))}_renderNewLevels(){this.element.innerHTML="";const e=this.indoorEqual.get("level");this.indoorEqual.get("levels").forEach((t=>{const o=document.createElement("button");e===t&&o.classList.add("level-control-active"),o.textContent=t,o.addEventListener("click",(()=>{this.indoorEqual.set("level",t)})),this.element.appendChild(o)}))}}async function L(e){const t=.5==(window.devicePixelRatio>=1.5?.5:1)?"@2x":"";let o=e+t+".json";var r;return{json:await(await fetch(o,{credentials:"same-origin"})).json(),png:await(r=e+t+".png",new Promise(((e,t)=>{const o=new Image;o.crossOrigin="anonymous",o.onload=function(){o.onload=null,e(o)},o.onerror=t,o.src=r})))}}function S(e,t,o){let r=null;return o&&L(o).then((e=>{t.changed(),r=e})),function(t,o){const l=t.getProperties();return"area"===l.layer?function(e,t){const o=e.getProperties();if("level"===o.class)return;let r,l="#fdfcfa";return o.access&&["no","private"].includes(o.access)?l="#F2F1F0":o.is_poi&&"corridor"!==o.class?l="#D4EDFF":"room"===o.class&&(l="#fefee2"),["area","corridor","plaform"].includes(o.class)&&(r=new h.Stroke({color:"#bfbfbf",width:1})),"column"===o.class&&(l="#bfbfbf"),["room","wall"].includes(o.class)&&(r=new h.Stroke({color:"gray",width:2})),new h.Style({fill:new h.Fill({color:l}),stroke:r})}(t):"transportation"===l.layer?new h.Style({stroke:new h.Stroke({color:"gray",width:2,lineDash:[4,7]})}):"area_name"===l.layer?function(e,t){return new h.Style({text:new h.Text({font:"13px Noto Sans Regular, sans-serif",text:e.getProperties().name,fill:new h.Fill({color:"#666"}),stroke:new h.Stroke({color:"white",width:1})})})}(t):"poi"===l.layer?function(e,t,o,r){const l=e.getProperties();if(o.getView().getZoomForResolution(t)<19&&["waste_basket","information","vending_machine"].includes(l.class))return;let n;if(r){const e=r.json["indoorequal-"+l.subclass]||r.json["indoorequal-"+l.class];e&&(n=new h.Icon({img:r.png,size:[e.width,e.height],offset:[e.x,e.y]}))}return new h.Style({text:new h.Text({font:"11px Noto Sans Regular, sans-serif",text:l.name,fill:new h.Fill({color:"#666"}),offsetY:18,stroke:new h.Stroke({color:"white",width:1})}),image:n})}(t,o,e,r):void 0}}function b(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function T(e,t,o){var r,l,n,i,s;function a(){var c=Date.now()-i;c=0?r=setTimeout(a,t-c):(r=null,o||(s=e.apply(n,l),n=l=null))}null==t&&(t=100);var c=function(){n=this,l=arguments,i=Date.now();var c=o&&!r;return r||(r=setTimeout(a,t)),c&&(s=e.apply(n,l),n=l=null),s};return c.clear=function(){r&&(clearTimeout(r),r=null)},c.flush=function(){r&&(s=e.apply(n,l),n=l=null,clearTimeout(r),r=null)},c}T.debounce=T;var q=b(T);e.LevelControl=v,e.default=class extends f{constructor(e,t={}){const o={url:"https://tiles.indoorequal.org/",defaultStyle:!0,spriteBaseUrl:null,heatmap:!0},r={...o,...t};if(r.url===o.url&&!r.apiKey)throw"You must register your apiKey at https://indoorequal.com before and set it as apiKey param.";super({levels:[],level:"0"}),this.map=e,this.url=r.url,this.apiKey=r.apiKey,this._createLayers(r.heatmap),this._loadSource(),this.styleFunction=r.defaultStyle?S(this.map,this.indoorLayer,r.spriteBaseUrl):null,this._changeLayerOnLevelChange(),this._setLayerStyle(),this._resetLevelOnLevelsChange()}setStyle(e){this.styleFunction=e}setHeatmapVisible(e){this.heatmapLayer.setVisible(e)}async _loadSource(){const e=this.apiKey?`?key=${this.apiKey}`:"";this.source=await p(`${this.url}${e}`),this.indoorLayer.setSource(this.source),this.heatmapLayer.setSource(function(e){const t=e.getTileGrid(),o=new i({loader(t,r,l,n,i){const s=()=>{const r=e.getFeaturesInExtent(t);o.clear(!0),o.addFeatures(r),n(r)};e.on("tileloadend",s),s()},loadingstrategy:u.tile(t)});return o}(this.source)),this._listenForLevels()}_createLayers(e){this.indoorLayer=m(),this.heatmapLayer=w({visible:e}),[this.indoorLayer,this.heatmapLayer].forEach((e=>{this.map.addLayer(e)}))}_listenForLevels(){const e=this.source,t=q((()=>{const t=this.map.getView().calculateExtent(this.map.getSize()),o=e.getFeaturesInExtent(t);this.set("levels",function(e){const t=[];for(let o=0;oe-t)).reverse()}(o))}),1e3);e.on("tileloadend",t),this.map.getView().on("change:center",t)}_changeLayerOnLevelChange(){this.on("change:level",(()=>{this.indoorLayer.changed()}))}_setLayerStyle(){this.indoorLayer.setStyle(((e,t)=>{if(e.getProperties().level===this.get("level"))return this.styleFunction&&this.styleFunction(e,t)}))}_resetLevelOnLevelsChange(){this.on("change:levels",(()=>{this.get("levels").includes(this.get("level"))||this.set("level","0")}))}},e.defaultStyle=S,e.getHeatmapLayer=w,e.getLayer=m,e.loadSourceFromTileJSON=p,Object.defineProperty(e,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ol/Feature"),require("ol/layer/Heatmap"),require("ol/format/MVT"),require("ol/tilegrid/TileGrid"),require("ol/source/TileJSON"),require("ol/source/Vector"),require("ol/layer/VectorTile"),require("ol/source/VectorTile"),require("ol/proj"),require("ol/loadingstrategy"),require("ol/control"),require("ol/style"),require("ol/Object")):"function"==typeof define&&define.amd?define(["exports","ol/Feature","ol/layer/Heatmap","ol/format/MVT","ol/tilegrid/TileGrid","ol/source/TileJSON","ol/source/Vector","ol/layer/VectorTile","ol/source/VectorTile","ol/proj","ol/loadingstrategy","ol/control","ol/style","ol/Object"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IndoorEqual={},e.ol.Feature,e.ol.layer.Heatmap,e.ol.format.MVT,e.ol.tilegrid.TileGrid,e.ol.source.TileJSON,e.ol.source.Vector,e.ol.layer.VectorTile,e.ol.source.VectorTile,e.ol.proj,e.ol.loadingstrategy,e.ol.control,e.ol.style,e.ol.Object)}(this,(function(e,t,o,r,l,n,i,s,a,c,u,d,h,f){"use strict";const g=function(){const e=[];for(let t=78271.51696402048;e.length<=24;t/=2)e.push(t);return e}();function y(e){const o=e.getTileJSON(),n=Array.isArray(o.tiles)?o.tiles:[o.tiles],i=e.getTileGrid(),s=function(e){const t=e.bounds;if(t){const e=c.fromLonLat([t[0],t[1]]),o=c.fromLonLat([t[2],t[3]]);return[e[0],e[1],o[0],o[1]]}}(o),u=o.minzoom,d=o.maxzoom;return new a({attributions:e.getAttributions(),format:new r({featureClass:t}),tileGrid:new l({origin:i.getOrigin(0),extent:s||i.getExtent(),minZoom:u,resolutions:g.slice(0,d+1),tileSize:512}),urls:n})}async function p(e){const t=await function(e){return new Promise(((t,o)=>{const r=new n({url:e});r.on("change",(function(){"ready"===r.getState()&&t(r)})),"ready"===r.getState()&&r.changed()}))}(e);return y(t)}function m(e){return new s({declutter:!0,...e})}function w(e){return new o({maxZoom:17,gradient:["rgba(102, 103, 173, 0)","rgba(102, 103, 173, 0.2)","rgba(102, 103, 173, 0.7)"],...e})}class v extends d.Control{constructor(e,t={}){const o=document.createElement("div");o.className="level-control ol-unselectable ol-control",super({element:o,target:t.target}),this.indoorEqual=e,this._renderNewLevels(),this.indoorEqual.on("change:levels",this._renderNewLevels.bind(this)),this.indoorEqual.on("change:level",this._renderNewLevels.bind(this))}_renderNewLevels(){this.element.innerHTML="";const e=this.indoorEqual.get("level");this.indoorEqual.get("levels").forEach((t=>{const o=document.createElement("button");e===t&&o.classList.add("level-control-active"),o.textContent=t,o.addEventListener("click",(()=>{this.indoorEqual.set("level",t)})),this.element.appendChild(o)}))}}async function L(e){const t=.5==(window.devicePixelRatio>=1.5?.5:1)?"@2x":"";let o=e+t+".json";var r;return{json:await(await fetch(o,{credentials:"same-origin"})).json(),png:await(r=e+t+".png",new Promise(((e,t)=>{const o=new Image;o.crossOrigin="anonymous",o.onload=function(){o.onload=null,e(o)},o.onerror=t,o.src=r})))}}function S(e,t,o){let r=null;return o&&L(o).then((e=>{t.changed(),r=e})),function(t,o){const l=t.getProperties();return"area"===l.layer?function(e,t){const o=e.getProperties();if("level"===o.class)return;let r,l="#fdfcfa";return o.access&&["no","private"].includes(o.access)?l="#F2F1F0":o.is_poi&&"corridor"!==o.class?l="#D4EDFF":"room"===o.class&&(l="#fefee2"),["area","corridor","platform"].includes(o.class)&&(r=new h.Stroke({color:"#bfbfbf",width:1})),"column"===o.class&&(l="#bfbfbf"),["room","wall"].includes(o.class)&&(r=new h.Stroke({color:"gray",width:2})),new h.Style({fill:new h.Fill({color:l}),stroke:r})}(t):"transportation"===l.layer?new h.Style({stroke:new h.Stroke({color:"gray",width:2,lineDash:[4,7]})}):"area_name"===l.layer?function(e,t){return new h.Style({text:new h.Text({font:"13px Noto Sans Regular, sans-serif",text:e.getProperties().name,fill:new h.Fill({color:"#666"}),stroke:new h.Stroke({color:"white",width:1})})})}(t):"poi"===l.layer?function(e,t,o,r){const l=e.getProperties();if(o.getView().getZoomForResolution(t)<19&&["waste_basket","information","vending_machine"].includes(l.class))return;let n;if(r){const e=r.json["indoorequal-"+l.subclass]||r.json["indoorequal-"+l.class];e&&(n=new h.Icon({img:r.png,size:[e.width,e.height],offset:[e.x,e.y]}))}return new h.Style({text:new h.Text({font:"11px Noto Sans Regular, sans-serif",text:l.name,fill:new h.Fill({color:"#666"}),offsetY:18,stroke:new h.Stroke({color:"white",width:1})}),image:n})}(t,o,e,r):void 0}}function b(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function T(e,t,o){var r,l,n,i,s;function a(){var c=Date.now()-i;c=0?r=setTimeout(a,t-c):(r=null,o||(s=e.apply(n,l),n=l=null))}null==t&&(t=100);var c=function(){n=this,l=arguments,i=Date.now();var c=o&&!r;return r||(r=setTimeout(a,t)),c&&(s=e.apply(n,l),n=l=null),s};return c.clear=function(){r&&(clearTimeout(r),r=null)},c.flush=function(){r&&(s=e.apply(n,l),n=l=null,clearTimeout(r),r=null)},c}T.debounce=T;var q=b(T);e.LevelControl=v,e.default=class extends f{constructor(e,t={}){const o={url:"https://tiles.indoorequal.org/",defaultStyle:!0,spriteBaseUrl:null,heatmap:!0},r={...o,...t};if(r.url===o.url&&!r.apiKey)throw"You must register your apiKey at https://indoorequal.com before and set it as apiKey param.";super({levels:[],level:"0"}),this.map=e,this.url=r.url,this.apiKey=r.apiKey,this._createLayers(r.heatmap),this._loadSource(),this.styleFunction=r.defaultStyle?S(this.map,this.indoorLayer,r.spriteBaseUrl):null,this._changeLayerOnLevelChange(),this._setLayerStyle(),this._resetLevelOnLevelsChange()}setStyle(e){this.styleFunction=e}setHeatmapVisible(e){this.heatmapLayer.setVisible(e)}async _loadSource(){const e=this.apiKey?`?key=${this.apiKey}`:"";this.source=await p(`${this.url}${e}`),this.indoorLayer.setSource(this.source),this.heatmapLayer.setSource(function(e){const t=e.getTileGrid(),o=new i({loader(t,r,l,n,i){const s=()=>{const r=e.getFeaturesInExtent(t);o.clear(!0),o.addFeatures(r),n(r)};e.on("tileloadend",s),s()},loadingstrategy:u.tile(t)});return o}(this.source)),this._listenForLevels()}_createLayers(e){this.indoorLayer=m(),this.heatmapLayer=w({visible:e}),[this.indoorLayer,this.heatmapLayer].forEach((e=>{this.map.addLayer(e)}))}_listenForLevels(){const e=this.source,t=q((()=>{const t=this.map.getView().calculateExtent(this.map.getSize()),o=e.getFeaturesInExtent(t);this.set("levels",function(e){const t=[];for(let o=0;oe-t)).reverse()}(o))}),1e3);e.on("tileloadend",t),this.map.getView().on("change:center",t)}_changeLayerOnLevelChange(){this.on("change:level",(()=>{this.indoorLayer.changed()}))}_setLayerStyle(){this.indoorLayer.setStyle(((e,t)=>{if(e.getProperties().level===this.get("level"))return this.styleFunction&&this.styleFunction(e,t)}))}_resetLevelOnLevelsChange(){this.on("change:levels",(()=>{this.get("levels").includes(this.get("level"))||this.set("level","0")}))}},e.defaultStyle=S,e.getHeatmapLayer=w,e.getLayer=m,e.loadSourceFromTileJSON=p,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/package.json b/package.json index c3ffcbf..f300d7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openlayers-indoorequal", - "version": "0.1.0", + "version": "0.1.1", "description": "Integrate indoor= into your OpenLayers map.", "repository": "https://github.com/indoorequal/openlayers-indoorequal", "author": "François de Metz",