Widget:Karte v2/script-babel

Aus Guild Wars 2 Wiki
Zur Navigation springen Zur Suche springen

/* */ /** * widget-map-floors * https://github.com/GW2Wiki/widget-map-floors * * Created by Smiley on 11.06.2016. * https://github.com/codemasher * https://wiki.guildwars2.com/wiki/User:Smiley-1 * * scripts & libraries used: * * https://leafletjs.com/ * http://vanilla-js.com/ */ "use strict"; function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf  ? Object.getPrototypeOf  : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError( "this hasn't been initialised - super() hasn't been called" ); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var GW2MapOptions = { // errorTile  : 'https://wiki.guildwars2.com/images/a/af/Widget_Map_floors_blank_tile.png', initLayers: [ "region_label", "map_label", "task_icon", "heropoint_icon", "waypoint_icon", "landmark_icon", "vista_icon", "unlock_icon", "masterypoint_icon", "adventure_icon", "jumpingpuzzle_icon", "sector_label" ] }; /** * Class GW2Map */ var GW2Map = /*#__PURE__*/ (function() { // common settings for all maps // per-map options parsed from the container's dataset /** * GW2Map constructor. * * @param {HTMLElement} container * @param {string} id * @param {Object} options * @returns {GW2Map} */ function GW2Map(container, id, options) { _classCallCheck(this, GW2Map); _defineProperty(this, "options", { containerClassName: "gw2map", linkboxClassName: "gw2map-linkbox", // additional to containerClassName navClassName: "gw2map-nav", lang: "en", initLayers: null, mapAttribution: true, errorTile: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAADHUlEQVR4nO3UMQEAIAzAsIF/zyBjRxMFvXpm5g2QdLcDgD0GAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEGAGEfdCIC/5NkVo8AAAAASUVORK5CYII=", padding: 0.5, defaultZoom: 4, minZoom: 0, maxZoom: 7, fullscreenControl: true, coordView: true, apiBase: "https://api.guildwars2.com", tileBase: "https://tiles.guildwars2.com/", tileExt: ".jpg", colors: { map_poly: "rgba(255, 255, 255, 0.5)", region_poly: "rgba(255, 155, 255, 0.5)", sector_poly: "rgba(40, 140, 25, 0.5)", task_poly: "rgba(250, 250, 30, 0.5)", event_poly: "rgba(210, 125, 40, 0.5)" } }); _defineProperty(this, "iconZoomLayers", [ "waypoint_icon", "landmark_icon", "vista_icon", "heropoint_icon", "task_icon", "unlock_icon", "masterypoint_icon", "adventure_icon", "jumpingpuzzle_icon", "region_label", "map_label", "sector_label", "event_icon", "extra" ]); _defineProperty(this, "linkboxExclude", [ "region_label", "region_poly", "map_poly", "sector_poly", "task_poly", "event_poly", "extra" ]); _defineProperty(this, "dataset", {}); _defineProperty(this, "layers", {}); this.container = container; this.id = id; this.options = GW2MapUtil.extend(this.options, options); this.dataset = new GW2MapDataset( this.container.dataset, this.options ).getData(); } /** * @returns {GW2Map} * @public */ _createClass(GW2Map, [ { key: "init", value: function init() { if (this.dataset.linkbox) { this.linkbox = document.createElement("div"); this.linkbox.className = this.options.navClassName; // this.linkbox.style = // "max-height:" + this.container.clientHeight + "px;"; // this.container.className += " " + this.options.linkboxClassName; this.container.parentNode.insertBefore( this.linkbox, this.container.nextSibling ); } this._setBaseMap(); // build the request path @todo var url = this.options.apiBase + "/v2/continents/" + this.dataset.continentId + "/floors/" + this.dataset.floorId; url += this.dataset.regionId  ? "/regions/" + this.dataset.regionId  : ""; url += this.dataset.regionId && this.dataset.mapId  ? "/maps/" + this.dataset.mapId  : ""; url += "?wiki=1&lang=" + this.dataset.language; // xhr > fetch. DON'T @ ME /* fetch(url) .then(response => { if(response.status === 200){ return response.json(); } throw new Error(response.statusText); }) .then(json => this._renderFloor(json)) .catch(error => console.log('(╯°□°)╯彡┻━┻ /v2/continents fetch error:', error)); */ this._request(url, "_renderFloor"); /* if(this.dataset.events){ this._renderEvents(); } */ return this; } /** * @param {string} url * @param {string} callback * @private */ }, { key: "_request", value: function _request(url, callback) { var _this = this; // xhr > fetch. DON'T @ ME var request = new XMLHttpRequest(); request.open("GET", url, true); request.addEventListener("load", function(ev) { if (request.readyState === 4 && request.status === 200) { return _this[callback](JSON.parse(request.responseText)); } console.log("(╯°□°)╯彡┻━┻ ", request.status); }); request.send(); } /** * sets the base tiles and adds an optional copyright info * * @returns {GW2Map} * @private */ }, { key: "_setBaseMap", value: function _setBaseMap() { var _this2 = this; // the map object this.map = L.map(this.container, { crs: L.CRS.Simple, minZoom: this.options.minZoom, maxZoom: this.options.maxZoom, attributionControl: this.options.mapAttribution, zoomControl: this.dataset.mapControls, fullscreenControl: this.options.fullscreenControl, coordView: this.options.coordView }); // the main tile layer L.tileLayer(null, { // use the custom tile getter tileGetter: function tileGetter(coords, zoom) { return _this2._tileGetter(coords, zoom); }, continuousWorld: true, minZoom: this.options.minZoom, maxZoom: this.options.maxZoom, attribution: this.options.mapAttribution === true  ? GW2MAP_I18N.attribution + ' © <a href="http://www.arena.net/" target="_blank">ArenaNet</a>'  : false }).addTo(this.map); // add the layer controls if (this.dataset.mapControls) { this.controls = L.control.layers().addTo(this.map); } return this; } /** * @todo https://github.com/arenanet/api-cdi/pull/61 * @todo https://github.com/arenanet/api-cdi/pull/62 * @todo https://github.com/arenanet/api-cdi/issues/308 * * @param {*} json * @private */ }, { key: "_renderFloor", value: function _renderFloor(json) { var _this3 = this; // transform the response to GeoJSON - polyfill for https://github.com/arenanet/api-cdi/pull/62 this.floorGeoJSON = new GW2FloorGeoJSON( json, this.dataset.customRect, this.dataset.extraLayers, this.dataset.includeMaps ); var geojson = this.floorGeoJSON.getData(); this.viewRect = geojson.viewRect; // set viewRect for the tile getter var rect = new GW2ContinentRect(this.viewRect).getBounds(); var bounds = new L.LatLngBounds( this._p2ll(rect[0]), this._p2ll(rect[1]) ).pad(this.options.padding); var center = bounds.getCenter(); var coords = this.dataset.centerCoords || []; if (coords.length === 2) { console.log(coords, center, this.viewRect); if ( coords[0] > 0 && coords[0] <= 49152 && coords[1] > 0 && coords[1] <= 49152 ) { center = this._p2ll(coords); console.log(coords, center); } } this.map.setMaxBounds(bounds).setView(center, this.dataset.zoom); var panes = Object.keys(geojson.featureCollections); panes.forEach(function(pane) { return _this3._createPane( geojson.featureCollections[pane].getJSON(), pane, _this3.dataset.initLayers || _this3.options.initLayers || panes ); }); this.map.on("zoomend", function(ev) { return _this3._zoomEndEvent(); }); this._zoomEndEvent(); // invoke once to set the icon zoom on the newly created map } /** * @private */ }, { key: "_zoomEndEvent", value: function _zoomEndEvent() { var _this4 = this; var zoom = this.map.getZoom(); this.iconZoomLayers.forEach(function(layer) { if (!_this4.layers[layer]) { return; } var element = _this4.layers[layer].options.pane; if (zoom >= 5) { PrototypeElement.removeClassName(element, "half"); } else if (zoom < 5 && zoom >= 3) { PrototypeElement.removeClassName(element, "quarter"); PrototypeElement.addClassName(element, "half"); } else if (zoom < 3 && zoom >= 1) { PrototypeElement.removeClassName(element, "half"); PrototypeElement.removeClassName(element, "invis"); PrototypeElement.addClassName(element, "quarter"); } else if (zoom < 1) { PrototypeElement.removeClassName(element, "quarter"); PrototypeElement.addClassName(element, "invis"); } }); } /** * */ /* _renderEvents(){ // i hate this so much Promise.all(['event_details', 'maps'].map(path => fetch(this.options.apiBase + '/v1/' + path + '.json?lang=' + this.dataset.language) .then(response => { if(response.status === 200){ return Promise.resolve(response); } return Promise.reject(new Error(response.statusText)); }) .then(response => { return response.json(); }) .catch(error => console.log('(╯°□°)╯彡┻━┻ /v1/events fetch error', error)) )) .then(responses => { let eventGeoJSON = new GW2EventGeoJSON(responses[0].events, responses[1].maps, this.floorGeoJSON.maps).getData(); let panes = Object.keys(eventGeoJSON.featureCollections); panes.forEach(pane => {this._createPane(eventGeoJSON.featureCollections[pane].getJSON(), pane, (this.dataset.initLayers || this.options.initLayers || panes))}); }); } */ /** * @param {GW2FloorGeoJSON[]} geojson * @param {string} pane * @param {string[]}initLayers * @private */ }, { key: "_createPane", value: function _createPane(geojson, pane, initLayers) { var _this5 = this; var name = '<span class="gw2map-layer-control ' + pane + '"> </span> ' + GW2MAP_I18N.layers[pane]; if (!this.layers[pane]) { this.layers[pane] = L.geoJson(geojson, { pane: this.map.createPane(pane), coordsToLatLng: function coordsToLatLng(coords) { return _this5._p2ll(coords); }, pointToLayer: function pointToLayer(feature, coords) { return _this5._pointToLayer(feature, coords, pane); }, onEachFeature: function onEachFeature(feature, layer) { return _this5._onEachFeature(feature, layer, pane); }, style: function style(feature) { return _this5._layerStyle(feature, pane); } }); this.controls.addOverlay(this.layers[pane], name); } else { this.layers[pane].addData(geojson); } if (GW2MapUtil.in_array(pane, initLayers)) { this.layers[pane].addTo(this.map); } } /** * @link http://leafletjs.com/reference-1.5.0.html#geojson-oneachfeature * @param {*} feature * @param {L.Layer} layer * @param {string} pane * @private */ }, { key: "_onEachFeature", value: function _onEachFeature(feature, layer, pane) { var p = feature.properties; var content = ""; // no popup for event circles // if(p.layertype === 'poly' && p.type === 'event'){ // return; // } if (p.layertype === "icon") { content += p.icon  ? '<img class="gw2map-popup-icon gw2map-layer-control" src="' + p.icon + '" alt="' + p.name + '"/>'  : '<span class="gw2map-layer-control ' + pane + '" ></span>'; } if (p.name) { if (!GW2MapUtil.in_array(p.type, ["vista"])) { //noinspection RegExpRedundantEscape var wikiname = p.name .toString() .replace(/\.$/, "") .replace(/\s/g, "_") .replace(/(Mount\:_|Raid—)/, ""); content += '<a class="gw2map-wikilink" href="' + GW2MAP_I18N.wiki + encodeURIComponent(wikiname) + '" target="_blank">' + p.name + "</a>"; } else { content += p.name; } } if (p.level) { content += " (" + p.level + ")"; } else if (p.min_level && p.max_level) { content += " (" + (p.min_level === p.max_level  ? p.max_level  : p.min_level + "-" + p.max_level) + ")"; } if (p.chat_link) { if (content) { content += "<br>"; } content += '<input class="gw2map-chatlink" type="text" value="' + p.chat_link + '" readonly="readonly" onclick="this.select();return false;" />'; } if (p.description) { if (content) { content += "<br>"; } content += '<div class="gw2map-description">' + this._parseWikilinks(p.description) + "</div>"; } if (content) { layer.bindPopup(content); } if (this.dataset.linkbox) { this._linkboxItem(feature, layer, pane); } } /** * * @param {string} str * @returns {string} * @private */ }, { key: "_parseWikilinks", value: function _parseWikilinks(str) { return str .replace( /\[\[([^\]\|]+)\]\]/gi, '<a href="' + GW2MAP_I18N.wiki + '$1" target="_blank">$1</a>' ) .replace( /\[\[([^\|]+)(\|)([^\]]+)\]\]/gi, '<a href="' + GW2MAP_I18N.wiki + '$1" target="_blank">$3</a>' ); } /** * @param {*} feature * @param {L.Layer} layer * @param {string} pane * @private */ }, { key: "_linkboxItem", value: function _linkboxItem(feature, layer, pane) { var _this6 = this; var p = feature.properties; if ( GW2MapUtil.in_array(pane, this.linkboxExclude) || p.mapID === -1 ) { return; } var navid = "gw2map-navbox-map-" + p.mapID; var nav = document.getElementById(navid); if (!nav) { nav = document.createElement("div"); nav.id = navid; nav.className = "gw2map-navbox"; this.linkbox.appendChild(nav); } var paneContentID = "gw2map-navbox-" + p.mapID + "-" + pane; var paneContent = document.getElementById(paneContentID); if (!paneContent && pane !== "map_label") { paneContent = document.createElement("div"); paneContent.id = paneContentID; nav.appendChild(paneContent); } var item = document.createElement("span"); if (pane !== "map_label") { item.innerHTML = '<span class="gw2map-layer-control ' + pane + '"></span>'; } item.innerHTML += p.name || p.id || "-"; if (typeof layer.getLatLng === "function") { item.addEventListener("click", function(ev) { var latlng = layer.getLatLng(); _this6.map.panTo(latlng).openPopup(layer.getPopup(), latlng); }); // insert the map label as first item pane === "map_label"  ? nav.insertBefore(item, nav.firstChild)  : paneContent.appendChild(item); } } /** * @link http://leafletjs.com/reference-1.5.0.html#geojson-pointtolayer * @param {*} feature * @param {LatLng} coords * @param {string} pane * @private */ }, { key: "_pointToLayer", value: function _pointToLayer(feature, coords, pane) { var icon; var p = feature.properties; if (p.layertype === "poly" && p.type === "event") { return new L.Circle(coords, feature.properties.radius); } var iconParams = { pane: pane, iconSize: null, popupAnchor: "auto", className: "gw2map-" + p.layertype + " gw2map-" + p.type + "-" + p.layertype }; if (p.icon) { iconParams.iconUrl = p.icon; if (p.className) { iconParams.className += " " + p.className; } icon = L.icon(iconParams); } else { if (p.layertype === "label") { iconParams.html = p.name; iconParams.iconAnchor = "auto"; } if (p.type === "masterypoint") { iconParams.className += " " + p.region.toLowerCase(); } else if (p.type === "heropoint") { iconParams.className += p.id.split("-")[0] === "0" ? " core" : " expac"; } icon = L.divIcon(iconParams); } return L.marker(coords, { pane: pane, title: p.layertype === "icon" ? p.name : null, icon: icon }); } /** * @link http://leafletjs.com/reference-1.5.0.html#geojson-style * @param {*} feature * @param {string} pane * @private */ }, { key: "_layerStyle", value: function _layerStyle(feature, pane) { if ( GW2MapUtil.in_array(pane, [ "region_poly", "map_poly", "sector_poly", "task_poly", "event_poly" ]) ) { return { pane: pane, stroke: true, opacity: 0.8, color: this.options.colors[pane] || "rgba(255, 255, 255, 0.3)", weight: 2, interactive: false }; } return {}; } /** * @param {[*,*]} coords * @returns {LatLng} * @private */ }, { key: "_p2ll", value: function _p2ll(coords) { return this.map.unproject(coords, this.options.maxZoom); } /** * @param {[*,*]} coords * @param {number} zoom * @returns {[*,*]} * @private */ }, { key: "_project", value: function _project(coords, zoom) { var _this7 = this; return coords.map(function(c) { return Math.floor(c / (1 << (_this7.options.maxZoom - zoom)) / 256); }); } /** * @param {[*,*]} coords * @param {number} zoom * @returns {string} * @private */ }, { key: "_tileGetter", value: function _tileGetter(coords, zoom) { var _this8 = this; var clamp = this.viewRect.map(function(c) { return _this8._project(c, zoom); }); if ( coords.x < clamp[0][0] || coords.x > clamp[1][0] || coords.y < clamp[0][1] || coords.y > clamp[1][1] ) { return this.options.errorTile; } return ( this.options.tileBase + this.dataset.continentId + "/" + (this.dataset.customFloor || this.dataset.floorId) + "/" + zoom + "/" + coords.x + "/" + coords.y + this.options.tileExt ); } } ]); return GW2Map; })(); /** * Class GW2MapDataset * * reads the dataset from the container element, validates and stores the values in this.dataset * * i hate all of this. */ var GW2MapDataset = /*#__PURE__*/ (function() { //noinspection RegExpRedundantEscape /** * @param {Object} dataset * @param {Object} options */ function GW2MapDataset(dataset, options) { _classCallCheck(this, GW2MapDataset); _defineProperty(this, "metadata", { continentId: { type: "int", default: 1 }, floorId: { type: "int", default: 1 }, regionId: { type: "int", default: null }, mapId: { type: "int", default: null }, customFloor: { type: "int", default: null }, language: { type: "int", default: null }, zoom: { type: "int", default: -1 }, mapControls: { type: "bool", default: true }, linkbox: { type: "bool", default: false }, events: { type: "bool", default: false }, initLayers: { type: "array", default: null, regex: /^([a-z_,\s]+)$/i }, extraLayers: { type: "array", default: [], regex: /^([a-z_,\s]+)$/i }, centerCoords: { type: "array", default: null, regex: /^([\[\]\s\d\.,]+)$/ }, customRect: { type: "array", default: null, regex: /^([\[\]\s\d\.,]+)$/ }, includeMaps: { type: "array", default: [], regex: /^([\s\d,]+)$/ } }); _defineProperty(this, "dataset", {}); this.options = options; this._parse(dataset); } /** * @returns {Object} */ _createClass(GW2MapDataset, [ { key: "getData", value: function getData() { return this.dataset; } /** * @param {Object} dataset * @private */ }, { key: "_parse", value: function _parse(dataset) { var _this9 = this; Object.keys(this.metadata).forEach(function(k) { if (typeof dataset[k] === "undefined" || dataset[k] === "") { _this9.dataset[k] = _this9.metadata[k]["default"]; } else { ["int", "bool", "array", "string"].forEach(function(t) { if (_this9.metadata[k].type === t) { _this9.dataset[k] = _this9["_parse_" + t]( dataset[k], _this9.metadata[k] ); } }); } if (typeof _this9["_parse_" + k] === "function") { _this9.dataset[k] = _this9["_parse_" + k]( _this9.dataset[k], _this9.metadata[k] ); } }); } /** * @param {Object} data * @returns {number} * @private */ }, { key: "_parse_int", value: function _parse_int(data) { return GW2MapUtil.intval(data); } /** * @param {Object} data * @returns {boolean} * @private */ }, { key: "_parse_bool", value: function _parse_bool(data) { return GW2MapUtil.in_array(data.toLowerCase(), [ "1", "true", "t", "yes", "y" ]); } /** * @param {Object} data * @param {Object} meta * @returns {*} * @private */ }, { key: "_parse_array", value: function _parse_array(data, meta) { var match = data.match(meta.regex); if (match) { return match; } return meta["default"]; } /** * @param {Object} data * @param {Object} meta * @returns {*} * @private */ }, { key: "_parse_string", value: function _parse_string(data, meta) { return this._parse_array(data, meta); } /** * @param {Object} data * @param {Object} meta * @returns {number} * @private */ }, { key: "_parse_continentId", value: function _parse_continentId(data, meta) { return GW2MapUtil.in_array(data, [1, 2]) ? data : meta["default"]; } /** * @param {Object} data * @param {Object} meta * @returns {number} * @private */ }, { key: "_parse_regionId", value: function _parse_regionId(data, meta) { return data > 0 ? data : meta["default"]; } /** * @param {Object} data * @param {Object} meta * @returns {number} * @private */ }, { key: "_parse_mapId", value: function _parse_mapId(data, meta) { return data > 0 ? data : meta["default"]; } /** * @param {Object} data * @param {Object} meta * @returns {string} * @private */ }, { key: "_parse_language", value: function _parse_language(data, meta) { return ["de", "en", "es", "fr", "zh"][data] || this.options.lang; } }, { key: "_parse_zoom", /** * @param {Object} data * @returns {number} * @private */ value: function _parse_zoom(data) { return data < this.options.minZoom || data > this.options.maxZoom  ? this.options.defaultZoom  : data; } /** * @param {Object} data * @param {Object} meta * @returns {[]} * @private */ }, { key: "_parse_includeMaps", value: function _parse_includeMaps(data, meta) { if (data === meta["default"]) { return data; } var ret = []; data[0] .replace(/[^\d,]/g, "") .split(",") .forEach(function(v) { if (v) { ret.push(GW2MapUtil.intval(v)); } }); return ret; } /** * @param {Object} data * @param {Object} meta * @returns {number[][]} * @private */ }, { key: "_parse_customRect", value: function _parse_customRect(data, meta) { if (data === meta["default"]) { return data; } data = JSON.parse(data[0]); if (data.length < 2 || data[0].length < 2 || data[1].length < 2) { return meta["default"]; } return data; } /** * @param {Object} data * @param {Object} meta * @returns {number[]} * @private */ }, { key: "_parse_centerCoords", value: function _parse_centerCoords(data, meta) { if (data === meta["default"]) { return data; } data = JSON.parse(data[0]); if ( data.length < 2 || typeof data[0] !== "number" || typeof data[1] !== "number" ) { return meta["default"]; } return data; } /** * @param {Object} data * @param {Object} meta * @returns {string[]} * @private */ }, { key: "_parse_extraLayers", value: function _parse_extraLayers(data, meta) { if (data === meta["default"]) { return data; } var ret = []; data[0] .replace(/\s/g, "") .split(",") .forEach(function(v) { if (v) { ret.push(v.toLowerCase()); } }); return ret; } /** * @param {Object} data * @param {Object} meta * @returns {string[]} * @private */ }, { key: "_parse_initLayers", value: function _parse_initLayers(data, meta) { return this._parse_extraLayers(data, meta); } } ]); return GW2MapDataset; })(); /** * Class GW2MapUtil */ var GW2MapUtil = /*#__PURE__*/ (function() { function GW2MapUtil() { _classCallCheck(this, GW2MapUtil); } _createClass(GW2MapUtil, null, [ { key: "extend", /** * @param {Object} target * @param {Object} source * @returns {Object} */ value: function extend(target, source) { for (var property in source) { if (source.hasOwnProperty(property)) { target[property] = source[property]; } } return target; } /** * @link http://locutus.io/php/var/intval/ * * @param {*} mixed_var * @param {number} base * @returns {*} */ }, { key: "intval", value: function intval(mixed_var, base) { var tmp; var type = typeof mixed_var; if (type === "boolean") { return +mixed_var; } else if (type === "string") { tmp = parseInt(mixed_var, base || 10); return isNaN(tmp) || !isFinite(tmp) ? 0 : tmp; } else if (type === "number" && isFinite(mixed_var)) { return mixed_var | 0; } else { return 0; } } /** * @param {*} needle * @param {*} haystack * @returns {boolean} */ }, { key: "in_array", value: function in_array(needle, haystack) { for (var key in haystack) { if (haystack.hasOwnProperty(key)) { if (haystack[key] === needle) { return true; } } } return false; } } ]); return GW2MapUtil; })(); /** * Class GW2GeoJSONAbstract */ var GW2GeoJSONAbstract = /*#__PURE__*/ (function() { function GW2GeoJSONAbstract(includeMaps) { _classCallCheck(this, GW2GeoJSONAbstract); _defineProperty(this, "featureCollections", {}); _defineProperty(this, "includeMaps", []); this.includeMaps = includeMaps; } /** * @param {string} layer * @param {string|number} id * @param {number} mapID * @param {string} name * @param {*} properties * @param {*} geometry * @param {string} [geometryType] * @returns {GW2FloorGeoJSON} * @protected */ _createClass(GW2GeoJSONAbstract, [ { key: "_addFeature", value: function _addFeature( layer, id, mapID, name, properties, geometry, geometryType ) { if (!this.featureCollections[layer]) { this.featureCollections[layer] = new GeoJSONFeatureCollection(); } this.featureCollections[layer] .addFeature( GW2MapUtil.extend( { name: name, mapID: mapID, layertype: "icon" }, properties ) ) .setID(id) .setGeometry(geometry, geometryType); return this; } } ]); return GW2GeoJSONAbstract; })(); /** * Class GW2FloorGeoJSON * * polyfill for https://github.com/arenanet/api-cdi/pull/62 */ var GW2FloorGeoJSON = /*#__PURE__*/ (function(_GW2GeoJSONAbstract) { _inherits(GW2FloorGeoJSON, _GW2GeoJSONAbstract); /** * GW2FloorGeoJSON constructor * * @param {*} floordata * @param {[[],[]]} customRect * @param {string[]} extraMarkers * @param {number[]} includeMaps */ function GW2FloorGeoJSON(floordata, customRect, extraMarkers, includeMaps) { var _this10; _classCallCheck(this, GW2FloorGeoJSON); _this10 = _possibleConstructorReturn( this, _getPrototypeOf(GW2FloorGeoJSON).call(this, includeMaps) ); _defineProperty(_assertThisInitialized(_this10), "floordata", {}); _defineProperty(_assertThisInitialized(_this10), "maps", []); _this10.floordata = floordata; _this10.extraMarkers = [ "adventure_icon", "jumpingpuzzle_icon", "polylines" ].concat(extraMarkers); _this10.setView(customRect); return _this10; } /** * @returns {GW2FloorGeoJSON} */ _createClass(GW2FloorGeoJSON, [ { key: "setView", value: function setView(customRect) { if (customRect) { this.viewRect = customRect; // @todo } else if (this.floordata.continent_rect) { this.viewRect = this.floordata.continent_rect; } else if (this.floordata.clamped_view) { this.viewRect = this.floordata.clamped_view; } else if (this.floordata.texture_dims) { this.viewRect = [[0, 0], this.floordata.texture_dims]; } else { this.viewRect = [[0, 0], [49152, 49152]]; } return this; } /** * @returns {*} */ }, { key: "getData", value: function getData() { // a response to floors if (this.floordata.regions) { this.continent(this.floordata.regions); } // a regions response else if (this.floordata.maps) { this.region(this.floordata); } // an actual map response else if (this.floordata.points_of_interest) { this.map(this.floordata); } return { viewRect: this.viewRect, featureCollections: this.featureCollections }; } /** * @param {*} continent * @returns {GW2FloorGeoJSON} */ }, { key: "continent", value: function continent(_continent) { var _this11 = this; Object.keys(_continent).forEach(function(regionID) { return _this11.region(_continent[regionID]); }); return this; } /** * @param {*} region * @returns {GW2FloorGeoJSON} */ }, { key: "region", value: function region(_region) { var _this12 = this; this._addFeature( "region_label", _region.id, -1, _region.name, { type: "region", layertype: "label" }, _region.label_coord ); /* this._addFeature('region_poly', region.id, -1, region.name, { type  : 'region', layertype: 'poly', }, new GW2ContinentRect(region.continent_rect).getPoly(), 'Polygon'); */ Object.keys(_region.maps).forEach(function(mapID) { var map = _region.maps[mapID]; map.id = GW2MapUtil.intval(mapID); // console.log('map', map.id, map.name); // @todo if (_this12.includeMaps.length > 0) { if (!GW2MapUtil.in_array(map.id, _this12.includeMaps)) { return _this12; } } _this12.map(map); }); return this; } /** * @param {*} map * @returns {GW2FloorGeoJSON} */ }, { key: "map", value: function map(_map) { var _this13 = this; this.maps.push(_map.id); var rect = new GW2ContinentRect(_map.continent_rect); // https://github.com/arenanet/api-cdi/issues/334 this._addFeature( "map_label", _map.id, _map.id, _map.name, { min_level: _map.min_level, max_level: _map.max_level, type: "map", layertype: "label" }, _map.label_coord || rect.getCenter() ); /* this._addFeature('map_poly', map.id, map.id, map.name, { type  : 'map', layertype: 'poly', }, rect.getPoly(), 'Polygon'); */ this.sectors(_map.sectors, _map.id) .poi(_map.points_of_interest, _map.id) .task(_map.tasks, _map.id) .heropoint(_map.skill_challenges, _map.id) .masteryPoint(_map.mastery_points, _map.id) .adventure(_map.adventures || [], _map.id); if (this.extraMarkers.length) { this.extraMarkers.forEach(function(layer) { if ( !GW2W_EXTRA_DATA[layer] || !GW2W_EXTRA_DATA[layer].data[_map.id] ) { return; } _this13.extra(GW2W_EXTRA_DATA[layer], layer, _map.id); }); } return this; } /** * @param {*} extra * @param {string} layer * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "extra", value: function extra(_extra, layer, mapID) { var _this14 = this; _extra.data[mapID].forEach(function(e) { _this14._addFeature( layer, e.id, mapID, e.name || _extra.name, { icon: e.icon || _extra.icon || null, className: _extra.className, type: _extra.type, layertype: _extra.layertype || "icon", description: e.description || _extra.description || null }, e.coord, e.featureType || _extra.featureType || "Point" ); }); } /** * @param {*} sectors * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "sectors", value: function sectors(_sectors, mapID) { var _this15 = this; Object.keys(_sectors).forEach(function(sectorId) { var sector = _sectors[sectorId]; if (GW2W_SECTOR_NAMES[sectorId]) { sector = GW2MapUtil.extend(sector, GW2W_SECTOR_NAMES[sectorId]); } _this15._addFeature( "sector_label", sector.id, mapID, sector.name, { chat_link: sector.chat_link, level: sector.level, type: "sector", layertype: "label" }, sector.coord ); _this15._addFeature( "sector_poly", sector.id, mapID, sector.name, { type: "sector", layertype: "poly" }, [sector.bounds], "Polygon" ); }); return this; } /** * @param {*} pois * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "poi", value: function poi(pois, mapID) { var _this16 = this; Object.keys(pois).forEach(function(poiID) { var poi = pois[poiID]; if (GW2W_POIDATA[poi.type] && GW2W_POIDATA[poi.type][poiID]) { poi = GW2MapUtil.extend(poi, GW2W_POIDATA[poi.type][poiID]); } _this16._addFeature( poi.type + "_icon", poi.id || null, mapID, null, { name: poi.name || poi.id || "", type: poi.type, chat_link: poi.chat_link || false, // floor  : poi.floor, // ??? icon: poi.icon }, poi.coord ); }); return this; } /** * @param {*} tasks * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "task", value: function task(tasks, mapID) { var _this17 = this; Object.keys(tasks).forEach(function(taskID) { var task = tasks[taskID]; _this17._addFeature( "task_icon", task.id, mapID, task.objective, { chat_link: task.chat_link, level: task.level, type: "task" }, task.coord ); _this17._addFeature( "task_poly", task.id, mapID, task.objective, { type: "task", layertype: "poly" }, [task.bounds], "Polygon" ); }); return this; } /** * @param {*} heropoints * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "heropoint", value: function heropoint(heropoints, mapID) { var _this18 = this; if (!heropoints.length) { return this; } heropoints.forEach(function(heropoint) { // https://github.com/arenanet/api-cdi/issues/329 _this18._addFeature( "heropoint_icon", heropoint.id, mapID, null, { name: GW2W_HEROPOINT_NAMES[heropoint.id] || "", type: "heropoint" }, heropoint.coord ); }); return this; } /** * @param {*} masterypoints * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "masteryPoint", value: function masteryPoint(masterypoints, mapID) { var _this19 = this; if (!masterypoints.length) { return this; } masterypoints.forEach(function(masterypoint) { _this19._addFeature( "masterypoint_icon", masterypoint.id, mapID, null, { name: GW2W_MASTERYPOINT_NAMES[masterypoint.id] || "", region: masterypoint.region, type: "masterypoint" }, masterypoint.coord ); }); return this; } /** * @param {*} adventures * @param {number} mapID * @returns {GW2FloorGeoJSON} */ }, { key: "adventure", value: function adventure(adventures, mapID) { var _this20 = this; if (!adventures.length) { return this; } adventures.forEach(function(adventure) { _this20._addFeature( "adventure_icon", null, mapID, adventure.name, { description: adventure.description || "", type: "adventure" }, adventure.coord ); }); return this; } } ]); return GW2FloorGeoJSON; })(GW2GeoJSONAbstract); /** * Class GW2EventGeoJSON */ var GW2EventGeoJSON = /*#__PURE__*/ (function(_GW2GeoJSONAbstract2) { _inherits(GW2EventGeoJSON, _GW2GeoJSONAbstract2); function GW2EventGeoJSON(event_details, map_details, includeMaps) { var _this21; _classCallCheck(this, GW2EventGeoJSON); _this21 = _possibleConstructorReturn( this, _getPrototypeOf(GW2EventGeoJSON).call(this, includeMaps) ); _defineProperty(_assertThisInitialized(_this21), "event_details", {}); _defineProperty(_assertThisInitialized(_this21), "map_details", {}); _defineProperty(_assertThisInitialized(_this21), "map", {}); _this21.event_details = event_details; _this21.map_details = map_details; return _this21; } _createClass(GW2EventGeoJSON, [ { key: "getData", value: function getData() { var _this22 = this; Object.keys(this.event_details).forEach(function(id) { var event = _this22.event_details[id]; if (!GW2MapUtil.in_array(event.map_id, _this22.includeMaps)) { delete _this22.event_details[id]; delete _this22.map_details[event.map_id]; return; } var map = _this22.map_details[event.map_id]; if (!_this22.map[event.map_id]) { _this22.map[event.map_id] = map; _this22.map[event.map_id].rect = new GW2ContinentRect( map.continent_rect, map.map_rect ); } map = _this22.map[event.map_id]; _this22._addFeature( "event_icon", id, event.map_id, event.name, { icon: event.icon  ? "https://render.guildwars2.com/file/" + event.icon.signature + "/" + event.icon.file_id + ".png"  : null, flags: event.flags, type: "event", layertype: "icon" }, map.rect.scaleCoords(event.location.center) ); if (event.location.type === "poly") { _this22._addFeature( "event_poly", id, event.map_id, event.name, { type: "event", layertype: "poly" }, [ event.location.points.map(function(point) { return map.rect.scaleCoords(point); }) ], "Polygon" ); } else { _this22._addFeature( "event_poly", id, event.map_id, event.name, { type: "event", layertype: "poly", radius: map.rect.scaleLength(event.location.radius) }, map.rect.scaleCoords(event.location.center), "Point" ); } }); return { featureCollections: this.featureCollections }; } } ]); return GW2EventGeoJSON; })(GW2GeoJSONAbstract); /** * Class GW2ContinentRect */ var GW2ContinentRect = /*#__PURE__*/ (function() { /** * GW2ContinentRect constructor * * @param continent_rect * @param map_rect */ function GW2ContinentRect(continent_rect, map_rect) { _classCallCheck(this, GW2ContinentRect); this.rect = continent_rect; this.map_rect = map_rect; } /** * returns bounds for L.LatLngBounds() * * @returns {*[]} */ _createClass(GW2ContinentRect, [ { key: "getBounds", value: function getBounds() { return [ [this.rect[0][0], this.rect[1][1]], [this.rect[1][0], this.rect[0][1]] ]; } /** * returns the center of the rectangle * * @returns {*[]} */ }, { key: "getCenter", value: function getCenter() { return [ (this.rect[0][0] + this.rect[1][0]) / 2, (this.rect[0][1] + this.rect[1][1]) / 2 ]; } /** * returns a polygon made of the rectangles corners * * @returns {*[]} */ }, { key: "getPoly", value: function getPoly() { return [ [ [this.rect[0][0], this.rect[0][1]], [this.rect[1][0], this.rect[0][1]], [this.rect[1][0], this.rect[1][1]], [this.rect[0][0], this.rect[1][1]] ] ]; } /** * @param {[]} coords from event_details.json or Mumble Link data. * @param {[]} [map_rect] taken from maps.json or map_floor.json * @returns {*[]} */ }, { key: "scaleCoords", value: function scaleCoords(coords, map_rect) { map_rect = this.map_rect || map_rect; return [ Math.round( this.rect[0][0] + ((this.rect[1][0] - this.rect[0][0]) * (coords[0] - map_rect[0][0])) / (map_rect[1][0] - map_rect[0][0]) ), Math.round( this.rect[0][1] + (this.rect[1][1] - this.rect[0][1]) * (1 - (coords[1] - map_rect[0][1]) / (map_rect[1][1] - map_rect[0][1])) ) ]; } /** * @param {number} length from event_details.json or Mumble Link data * @param {[]} [map_rect] taken from maps.json or map_floor.json * @returns {number} */ }, { key: "scaleLength", value: function scaleLength(length, map_rect) { map_rect = this.map_rect || map_rect; var scalex = (length - map_rect[0][0]) / (map_rect[1][0] - map_rect[0][0]); var scaley = (length - map_rect[0][1]) / (map_rect[1][1] - map_rect[0][1]); return Math.sqrt(scalex * scalex + scaley * scaley); } } ]); return GW2ContinentRect; })(); /** * Class GeoJSONFeatureCollection */ var GeoJSONFeatureCollection = /*#__PURE__*/ (function() { /** * GeoJSONFeatureCollection constructor */ function GeoJSONFeatureCollection() { _classCallCheck(this, GeoJSONFeatureCollection); this.json = { type: "FeatureCollection", features: [] }; } /** * @returns {{type: string, features: Array}|*} */ _createClass(GeoJSONFeatureCollection, [ { key: "getJSON", value: function getJSON() { var _this23 = this; this.json.features.forEach(function(feature, i) { return (_this23.json.features[i] = feature.getJSON()); }); return this.json; } /** * @param type * @param properties * @returns {GeoJSONFeatureCollection} */ }, { key: "setCRS", value: function setCRS(type, properties) { this.json.crs = { type: type, properties: properties }; return this; } /** * @param properties * @returns {GeoJSONFeature} */ }, { key: "addFeature", value: function addFeature(properties) { var feature = new GeoJSONFeature(properties); this.json.features.push(feature); return feature; } } ]); return GeoJSONFeatureCollection; })(); /** * Class GeoJSONFeature */ var GeoJSONFeature = /*#__PURE__*/ (function() { /** * GeoJSONFeature constructor * * @param properties */ function GeoJSONFeature(properties) { _classCallCheck(this, GeoJSONFeature); this.json = { type: "Feature", geometry: { type: "", coordinates: [] }, properties: properties || {} }; } /** * @returns {{type: string, geometry: {type: string, coordinates: Array}, properties: (*|{})}|*} */ _createClass(GeoJSONFeature, [ { key: "getJSON", value: function getJSON() { return this.json; } /** * @param id * @returns {GeoJSONFeature} */ }, { key: "setID", value: function setID(id) { if (id) { this.json.id = id; // gmaps this.json.properties.id = id; // leaflet } return this; } /** * @param coords * @param type * @returns {GeoJSONFeature} */ }, { key: "setGeometry", value: function setGeometry(coords, type) { this.json.geometry.coordinates = coords; this.json.geometry.type = GW2MapUtil.in_array(type, [ "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection" ])  ? type  : "Point"; return this; } } ]); return GeoJSONFeature; })(); /** * prototype DOM rewrite inc * @link https://github.com/prototypejs/prototype/blob/master/src/prototype/dom/dom.js */ var PrototypeElement = /*#__PURE__*/ (function() { function PrototypeElement() { _classCallCheck(this, PrototypeElement); } _createClass(PrototypeElement, null, [ { key: "addClassName", value: function addClassName(element, className) { if (!this.hasClassName(element, className)) { element.className += (element.className ? " " : "") + className; } return element; } }, { key: "removeClassName", value: function removeClassName(element, className) { element.className = element.className .replace(this.getRegExpForClassName(className), " ") .replace(/^\s+/, "") .replace(/\s+$/, ""); return element; } }, { key: "toggleClassName", value: function toggleClassName(element, className, bool) { if (typeof bool === "undefined") { bool = !this.hasClassName(element, className); } return this[bool ? "addClassName" : "removeClassName"]( element, className ); } }, { key: "hasClassName", value: function hasClassName(element, className) { var elementClassName = element.className; if (elementClassName.length === 0) { return false; } if (elementClassName === className) { return true; } return this.getRegExpForClassName(className).test(elementClassName); } }, { key: "getRegExpForClassName", value: function getRegExpForClassName(className) { return new RegExp("(^|\\s+)" + className + "(\\s+|$)"); } } ]); return PrototypeElement; })(); // invoke the maps (function($options, $containers) { $containers = $containers || document.getElementsByClassName($options.containerClassName); // no map, no scripts. if (!$containers.length) { return; } $options = GW2MapUtil.extend( { containerClassName: "gw2map", linkboxClassName: "gw2map-linkbox", navClassName: "gw2map-nav", scriptContainerId: "gw2map-script", scripts: [ "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0/leaflet-src.js", // 'https://unpkg.com/leaflet-ant-path@1.3.0/dist/leaflet-ant-path.js', "https://wiki.guildwars2.com/index.php?title=Widget:Map_floors/data&action=raw&ctype=text/javascript" ], stylesheets: [ "https://wiki.guildwars2.com/index.php?title=Widget:Map_floors/style&action=raw&ctype=text/css" ] }, $options ); // scripts to <body> $options.scripts.forEach(function(script) { var s = document.getElementById($options.scriptContainerId); var node = document.createElement("script"); node.src = script; s.parentNode.insertBefore(node, s); }); // stylesheets to the <head> $options.stylesheets.forEach(function(stylesheet) { var node = document.createElement("link"); node.rel = "stylesheet"; node.href = stylesheet; document.getElementsByTagName("head")[0].appendChild(node); }); // ogogog window.addEventListener("load", function() { // check if leaflet is loaded (paranoid) if (typeof L === "undefined" || !L.version) { console.log("GW2Map error: leaflet not loaded!"); return; } // https://github.com/Leaflet/Leaflet.fullscreen L.Control.Fullscreen = L.Control.extend({ options: { position: "topleft", title: { false: "View Fullscreen", true: "Exit Fullscreen" } }, onAdd: function onAdd(map) { var container = L.DomUtil.create( "div", "leaflet-control-fullscreen leaflet-bar leaflet-control" ); this.link = L.DomUtil.create( "a", "leaflet-control-fullscreen-button leaflet-bar-part", container ); this.link.href = "#"; this._map = map; this._map.on("fullscreenchange", this._toggleTitle, this); this._toggleTitle(); L.DomEvent.on(this.link, "click", this._click, this); return container; }, _click: function _click(e) { L.DomEvent.stopPropagation(e); L.DomEvent.preventDefault(e); this._map.toggleFullscreen(this.options); }, _toggleTitle: function _toggleTitle() { this.link.title = this.options.title[this._map.isFullscreen()]; } }); L.Map.include({ isFullscreen: function isFullscreen() { return this._isFullscreen || false; }, toggleFullscreen: function toggleFullscreen(options) { var container = this.getContainer(); if (this.isFullscreen()) { if (options && options.pseudoFullscreen) { this._disablePseudoFullscreen(container); } else if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else { this._disablePseudoFullscreen(container); } } else { if (options && options.pseudoFullscreen) { this._enablePseudoFullscreen(container); } else if (container.requestFullscreen) { container.requestFullscreen(); } else if (container.mozRequestFullScreen) { container.mozRequestFullScreen(); } else if (container.webkitRequestFullscreen) { container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); } else if (container.msRequestFullscreen) { container.msRequestFullscreen(); } else { this._enablePseudoFullscreen(container); } } }, _enablePseudoFullscreen: function _enablePseudoFullscreen(container) { L.DomUtil.addClass(container, "leaflet-pseudo-fullscreen"); this._setFullscreen(true); this.fire("fullscreenchange"); }, _disablePseudoFullscreen: function _disablePseudoFullscreen(container) { L.DomUtil.removeClass(container, "leaflet-pseudo-fullscreen"); this._setFullscreen(false); this.fire("fullscreenchange"); }, _setFullscreen: function _setFullscreen(fullscreen) { this._isFullscreen = fullscreen; var container = this.getContainer(); if (fullscreen) { L.DomUtil.addClass(container, "leaflet-fullscreen-on"); } else { L.DomUtil.removeClass(container, "leaflet-fullscreen-on"); } this.invalidateSize(); }, _onFullscreenChange: function _onFullscreenChange(e) { var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement; if (fullscreenElement === this.getContainer() && !this._isFullscreen) { this._setFullscreen(true); this.fire("fullscreenchange"); } else if ( fullscreenElement !== this.getContainer() && this._isFullscreen ) { this._setFullscreen(false); this.fire("fullscreenchange"); } } }); L.Map.mergeOptions({ fullscreenControl: false }); L.Map.addInitHook(function() { if (this.options.fullscreenControl) { this.fullscreenControl = new L.Control.Fullscreen( this.options.fullscreenControl ); this.addControl(this.fullscreenControl); } var fullscreenchange; if ("onfullscreenchange" in document) { fullscreenchange = "fullscreenchange"; } else if ("onmozfullscreenchange" in document) { fullscreenchange = "mozfullscreenchange"; } else if ("onwebkitfullscreenchange" in document) { fullscreenchange = "webkitfullscreenchange"; } else if ("onmsfullscreenchange" in document) { fullscreenchange = "MSFullscreenChange"; } if (fullscreenchange) { var onFullscreenChange = L.bind(this._onFullscreenChange, this); this.whenReady(function() { L.DomEvent.on(document, fullscreenchange, onFullscreenChange); }); this.on("unload", function() { L.DomEvent.off(document, fullscreenchange, onFullscreenChange); }); } }); L.control.fullscreen = function(options) { return new L.Control.Fullscreen(options); }; // coordinate view with selectable input (eases gw2wiki use) L.Control.Coordview = L.Control.extend({ options: { position: "bottomleft" }, onAdd: function onAdd(map) { var container = L.DomUtil.create( "div", "leaflet-control-coordview leaflet-control" ); var input = L.DomUtil.create("input"); input.type = "text"; input.placeholder = "<coords>"; input.readOnly = true; container.appendChild(input); L.DomEvent.disableClickPropagation(container); L.DomEvent.on(input, "click", function(ev) { return ev.target.select(); }); map.on("click", function(ev) { var point = map.project(ev.latlng, map.options.maxZoom); input.value = "[" + Math.round(point.x) + ", " + Math.round(point.y) + "]"; // ckeckbox: copy to clipboard // navigator.clipboard.writeText(input.value); }); return container; } }); L.Map.mergeOptions({ coordView: true }); L.Map.addInitHook(function() { if (this.options.coordView) { new L.Control.Coordview().addTo(this); } }); L.control.coordview = function(options) { return new L.Control.Coordview(options); }; // override L.TileLayer.getTileUrl() and add a custom tile getter L.TileLayer.include({ getTileUrl: function getTileUrl(coords) { var tileGetter = this.options.tileGetter; if (typeof tileGetter === "function") { return tileGetter(coords, this._getZoomForUrl()); } return false; } }); // auto center popups and align div/html icons L.Popup.include({ _getAnchor: function _getAnchor() { var anchor = this._source && this._source._getPopupAnchor  ? this._source._getPopupAnchor()  : [0, 0]; if (typeof anchor === "string" && anchor.toLowerCase() === "auto") { var style = { left: 0, top: 0, width: 0 }; // is the layer active? if (this._source._icon) { style = window.getComputedStyle(this._source._icon); } anchor = [ GW2MapUtil.intval(style.left) + Math.round(GW2MapUtil.intval(style.width) / 2), GW2MapUtil.intval(style.top) ]; } return L.point(anchor); } }); L.Marker.include({ _initIcon: function _initIcon() { var options = this.options; var classToAdd = "leaflet-zoom-" + (this._zoomAnimated ? "animated" : "hide"); var icon = options.icon.createIcon(this._icon); var addIcon = false; // if we're not reusing the icon, remove the old one and init new one if (icon !== this._icon) { if (this._icon) { this._removeIcon(); } addIcon = true; if (options.title) { icon.title = options.title; } if (icon.tagName === "IMG") { icon.alt = options.alt || ""; } } L.DomUtil.addClass(icon, classToAdd); if (options.keyboard) { icon.tabIndex = "0"; } this._icon = icon; if (options.riseOnHover) { this.on({ mouseover: this._bringToFront, mouseout: this._resetZIndex }); } if (options.opacity < 1) { this._updateOpacity(); } if (addIcon) { this.getPane().appendChild(this._icon); // set icon styles after the node is appended to properly get the computed dimensions options.icon._setIconStyles(this._icon, "icon", addIcon); } this._initInteraction(); } }); L.Icon.include({ _setIconStyles: function _setIconStyles(img, name, addIcon) { if (addIcon !== true) { return; } img.className = "leaflet-marker-icon " + (this.options.className || ""); var sizeOption = this.options.iconSize; var anchor = this.options.iconAnchor; if (typeof sizeOption === "number") { sizeOption = [sizeOption, sizeOption]; } var size = L.point(sizeOption); if (anchor && anchor.toString().toLowerCase() === "auto") { var origin = window .getComputedStyle(img) .perspectiveOrigin.split(" "); img.style.left = "-" + origin[0]; img.style.top = "-" + origin[1]; } else { anchor = L.point(anchor || (size && size.divideBy(2, true))); if (anchor) { img.style.marginLeft = -anchor.x + "px"; img.style.marginTop = -anchor.y + "px"; } } if (size) { img.style.width = size.x + "px"; img.style.height = size.y + "px"; } } }); // save the GW2Map objects for later usage // noinspection JSMismatchedCollectionQueryUpdate var maps = []; var mapOptions = GW2MapUtil.extend(GW2MapOptions, $options); Object.keys($containers).forEach(function(id) { maps[id] = new GW2Map($containers[id], id, mapOptions).init(); }); // console.log(maps); }); })(GW2MapInvokerOptions, GW2MapContainers); /* */