UNPKG

famous-map

Version:

Map integration for Famo.us (google-maps, leaflet, open-layers & mapboxgl)

14 lines 18.8 kB
/** * This Source Code is licensed under the MIT license. If a copy of the * MIT-license was not distributed with this file, You can obtain one at: * http://opensource.org/licenses/mit-license.html. * * @author: Hein Rutjes (IjzerenHein) * @license MIT * @copyright Gloey Apps, 2014/2015 * * @library famous-map * @version 0.3.2 * @generated 08-05-2015 */ !function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c){"use strict";function d(a){this.mapView=a.mapView,this._output={transform:e.identity,opacity:1,origin:null,align:null,size:null,target:null},this._cache={},this._positionGetter=null,this._rotateTowardsGetter=null,this._offset=a.offset,this._zoomScale=a.zoomScale,this._zoomBase=a.zoomBase,a.position&&this.positionFrom(a.position),a.rotateTowards&&this.rotateTowardsFrom(a.rotateTowards)}var e="undefined"!=typeof window?window.famous.core.Transform:"undefined"!=typeof c?c.famous.core.Transform:null,f=a("./MapUtility");d.prototype.positionFrom=function(a){return a?a instanceof Function?this._positionGetter=a:a instanceof Object&&a.getPosition?this._positionGetter=a.getPosition.bind(a):(this._positionGetter=null,this._position=a):(this._positionGetter=null,this._position=null),this},d.prototype.rotateTowardsFrom=function(a){return a?a instanceof Function?this._rotateTowardsGetter=a:a instanceof Object&&a.getPosition?this._rotateTowardsGetter=a.getPosition.bind(a):(this._rotateTowardsGetter=null,this._rotateTowards=a):(this._rotateTowardsGetter=null,this._rotateTowards=null),this},d.prototype.zoomBaseFrom=function(a){return this._zoomBase=a,this},d.prototype.zoomScaleFrom=function(a){return this._zoomScale=a,this},d.prototype.offsetFrom=function(a){return this._offset=a,this},d.prototype.getPosition=function(){return this._positionGetter||this._position},d.prototype.getRotateTowards=function(){return this._rotateTowardsGetter||this._rotateTowards},d.prototype.getZoomBase=function(){return this._zoomBase},d.prototype.getZoomScale=function(){return this._zoomScale},d.prototype.getOffset=function(){return this._offset},d.prototype.modify=function(a){if(!this.mapView.isInitialized())return this._output.target=a,this._output;var b=!1;if(void 0!==this._zoomBase){var c;if(this._zoomScale)if(this._zoomScale instanceof Function)c=this._zoomScale(this._zoomBase,this.mapView.getZoom());else{var d=this.mapView.getZoom()-this._zoomBase+1;c=0>d?1/(Math.abs(d)+1)*this._zoomScale:(1+d)*this._zoomScale}else c=Math.pow(2,this.mapView.getZoom()-this._zoomBase);this._cache.scaling!==c&&(this._cache.scaling=c,this._cache.scale=e.scale(c,c,1),b=!0)}else this._cache.scale&&(this._cache.scale=null,this._cache.scaling=null,b=!0);var g=this._positionGetter?this._positionGetter():this._position;if(g){this._offset&&(g={lat:f.lat(g)+f.lat(this._offset),lng:f.lng(g)+f.lng(this._offset)});var h=this._rotateTowardsGetter?this._rotateTowardsGetter():this._rotateTowards;if(h){var i=f.rotationFromPositions(g,h);i+=this.mapView.getRotation(),this._cache.rotation!==i&&(this._cache.rotation=i,this._cache.rotate=e.rotateZ(i),b=!0)}else this._cache.rotate&&(this._cache.rotate=null,this._cache.rotation=null,b=!0);var j=this.mapView.pointFromPosition(g);this._cache.point&&j.x===this._cache.point.x&&j.y===this._cache.point.y||(this._cache.point=j,this._cache.translate=e.translate(j.x,j.y,0),b=!0)}else this._cache.translate&&(this._cache.point=null,this._cache.translate=null,b=!0);if(b){var k=this._cache.scale;this._cache.rotate&&(k=k?e.multiply(this._cache.rotate,k):this._cache.rotate),this._cache.translate&&(k=k?e.multiply(this._cache.translate,k):this._cache.translate),this._output.transform=k}return this._output.target=a,this._output},b.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./MapUtility":5}],2:[function(a,b,c){(function(c){"use strict";function d(a){this.position=new e([0,0]),a&&this.set(a)}var e="undefined"!=typeof window?window.famous.transitions.Transitionable:"undefined"!=typeof c?c.famous.transitions.Transitionable:null,f=a("./MapUtility");d.prototype.setDefaultTransition=function(a){this.position.setDefault(a)},d.prototype.reset=function(a){var b=[f.lat(a),f.lng(a)];this.position.reset(b),this._final=a},d.prototype.set=function(a,b,c){var d=[f.lat(a),f.lng(a)];return this.position.set(d,b,c),this._final=a,this},d.prototype.get=function(){if(this.isActive()){var a=this.position.get();return{lat:a[0],lng:a[1]}}return this._final},d.prototype.getFinal=function(){return this._final},d.prototype.isActive=function(){return this.position.isActive()},d.prototype.halt=function(){this._final=this.get(),this.position.halt()},b.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./MapUtility":5}],3:[function(a,b,c){"use strict";function d(a){this.mapView=a.mapView,this._positionState=new f(a.position),this._rotateTowardsState=new f(a.rotateTowards),this._modifier=new e({mapView:this.mapView}),a.position&&this.setPosition(a.position),a.rotateTowards&&this.rotateTowards(a.rotateTowards),a.offset&&this.setOffset(a.offset),void 0!==a.zoomBase&&this.setZoomBase(a.zoomBase),a.zoomScale&&this.setZoomScale(a.zoomScale)}var e=a("./MapModifier"),f=a("./MapPositionTransitionable");d.prototype.setPosition=function(a,b,c){return this._positionState.set(a,b,c),this},d.prototype.rotateTowards=function(a,b,c){this._rotateTowardsState.set(a,b,c)},d.prototype.setZoomBase=function(a){return this._modifier.zoomBaseFrom(a),this},d.prototype.setZoomScale=function(a){return this._modifier.zoomScaleFrom(a),this},d.prototype.setOffset=function(a){return this._modifier.offsetFrom(a),this},d.prototype.getPosition=function(){return this._positionState.get()},d.prototype.getRotateTowards=function(){return this._rotateTowardsState.get()},d.prototype.getFinalPosition=function(){return this._positionState.getFinal()},d.prototype.getFinalRotateTowards=function(){return this._rotateTowardsState.getFinal()},d.prototype.getZoomBase=function(){return this._modifier.getZoomBase()},d.prototype.getZoomScale=function(){return this._modifier.getZoomScale()},d.prototype.getOffset=function(){return this._modifier.getOffset()},d.prototype.halt=function(){this._positionState.halt(),this._rotateTowardsState.halt()},d.prototype.isActive=function(){return this._positionState.isActive()||this._rotateTowardsState.isActive()},d.prototype.modify=function(a){return this._modifier.positionFrom(this._positionState.get()),this._modifier.rotateTowardsFrom(this._rotateTowardsState.getFinal()),this._modifier.modify(a)},b.exports=d},{"./MapModifier":1,"./MapPositionTransitionable":2}],4:[function(a,b,c){"use strict";function d(){this.state=void 0,this._startTime=0,this._startState=0,this._updateTime=0,this._endState=0,this._active=!1,this._duration=0,this._distance=0,this._callback=void 0}function e(a,b,c){return(1-c)*a+c*b}function f(a){return a.slice(0)}var g=a("./MapUtility");d.SUPPORTS_MULTIPLE=2,d.DEFAULT_OPTIONS={speed:1e3},d.prototype.reset=function(a){if(this._callback){var b=this._callback;this._callback=void 0,b()}this.state=f(a),this._startTime=0,this._updateTime=0,this._startState=this.state,this._endState=this.state,this._duration=0,this._distance=0,this._active=!1},d.prototype.set=function(a,b,c){return b?(this._speed=d.DEFAULT_OPTIONS.speed,b&&b.speed&&(this._speed=b.speed),this._startState=this.get(),this._startTime=Date.now(),this._endState=f(a),this._active=!0,this._callback=c,this._distance=g.distanceBetweenPositions(this._startState,this._endState),void(this._duration=this._distance/this._speed*36e5)):(this.reset(a),void(c&&c()))},d.prototype.get=function(a){if(!this._active){if(this._callback){var b=this._callback;this._callback=void 0,b()}return this.state}if(a||(a=Date.now()),this._updateTime>=a)return this.state;this._updateTime=a;var c=a-this._startTime;if(c>=this._duration)this.state=this._endState,this._active=!1;else if(0>c)this.state=this._startState;else{var d=c/this._duration,f=e(this._startState[0],this._endState[0],d),g=e(this._startState[1],this._endState[1],d);this.state=[f,g]}return this.state},d.prototype.isActive=function(){return this._active},d.prototype.halt=function(){this.set(this.get())},b.exports=d},{"./MapUtility":5}],5:[function(a,b,c){"use strict";var d={};d.lat=function(a){return a instanceof Array?a[0]:a.lat instanceof Function?a.lat():a.lat},d.lng=function(a){return a instanceof Array?a[1]:a.lng instanceof Function?a.lng():a.lng},d.equals=function(a,b){return d.lat(a)===d.lat(b)&&d.lng(a)===d.lng(b)},d.radiansFromDegrees=function(a){return a*(Math.PI/180)},d.rotationFromPositions=function(a,b){return Math.atan2(d.lng(a)-d.lng(b),d.lat(a)-d.lat(b))+Math.PI/2},d.distanceBetweenPositions=function(a,b){var c=6371,e=d.radiansFromDegrees(d.lat(a)),f=d.radiansFromDegrees(d.lat(b)),g=d.radiansFromDegrees(d.lat(b)-d.lat(a)),h=d.radiansFromDegrees(d.lng(b)-d.lng(a)),i=Math.sin(g/2)*Math.sin(g/2)+Math.cos(e)*Math.cos(f)*Math.sin(h/2)*Math.sin(h/2),j=2*Math.atan2(Math.sqrt(i),Math.sqrt(1-i)),k=c*j;return k},b.exports=d},{}],6:[function(a,b,c){(function(c){"use strict";function d(){if(g.apply(this,arguments),this.map=null,this.mapType=this.options.type,this._position=new j(this.options.mapOptions.center),this._zoom={center:new j(this.options.mapOptions.center),northEast:new j(this.options.mapOptions.center),southWest:new j(this.options.mapOptions.center)},this._cache={},this.mapType===m.LEAFLET&&(this.options.zoomTransition={duration:0}),this.options.mapOptions&&this.options.id)this.mapId=this.options.id;else{this.mapId="MapView"+l,l++;var a=new f({classes:["mapview","fm-mapview"],content:'<div id="'+this.mapId+'" style="width: 100%; height: 100%;"></div>',size:[void 0,void 0]});this.add(a),this._surface=a}}function e(a){return a.className.indexOf("fm-mapview")>=0?!0:a.parentElement?e(a.parentElement):!1}var f="undefined"!=typeof window?window.famous.core.Surface:"undefined"!=typeof c?c.famous.core.Surface:null,g="undefined"!=typeof window?window.famous.views.SizeAwareView:"undefined"!=typeof c?c.famous.views.SizeAwareView:null,h="undefined"!=typeof window?window.famous.transitions.Transitionable:"undefined"!=typeof c?c.famous.transitions.Transitionable:null,i=a("./MapUtility"),j=a("./MapPositionTransitionable"),k=a("./MapTransition");h.registerMethod("map-speed",k);var l=1,m={GOOGLEMAPS:1,LEAFLET:2,OPENLAYERS3:3,MAPBOXGL:4};d.prototype=Object.create(g.prototype),d.prototype.constructor=d,d.MapType=m,d.DEFAULT_OPTIONS={type:m.GOOGLEMAPS,mapOptions:{zoom:10,center:{lat:51.4400867,lng:5.4782571}},id:null,zoomTransition:{duration:100}},d.prototype._initMap=function(){var a=document.getElementById(this.mapId);if(a){var b;switch(this.mapType){case m.GOOGLEMAPS:this.map=new google.maps.Map(a,this.options.mapOptions);var c=this.map.addListener("projection_changed",function(){google.maps.event.removeListener(c),this._initComplete=!0}.bind(this));break;case m.LEAFLET:this.map=L.map(a,this.options.mapOptions),this._initComplete=!0;break;case m.OPENLAYERS3:b=this.options.mapOptions;var d=b.center;this.map=new ol.Map({target:a,controls:ol.control.defaults({attributionOptions:{collapsible:!1}}),view:new ol.View({center:ol.proj.transform([i.lng(d),i.lat(d)],"EPSG:4326","EPSG:3857"),zoom:b.zoom})}),this._surface.on("resize",function(){this.map.updateSize()}.bind(this)),this._surface.on("deploy",function(){this._initComplete&&this.map.updateSize()}.bind(this)),this.map.once("postrender",function(){this._initComplete=!0}.bind(this));break;case m.MAPBOXGL:b={};for(var e in this.options.mapOptions)b[e]=this.options.mapOptions[e];b.container=a,this.map=new mapboxgl.Map(b),this._initComplete=!0}}},d.prototype.getMap=function(){return this.map},d.prototype.isInitialized=function(){return this._initComplete&&this._loadEventEmitted},d.prototype.setPosition=function(a,b,c){return this._position.set(a,b,c),this._positionInvalidated=!0,this},d.prototype.getPosition=function(){return this._zoom.center.get()},d.prototype.getFinalPosition=function(){return this._position.getFinal()},d.prototype.getZoom=function(){return this._cache.zoom},d.prototype.getRotation=function(){switch(this.mapType){case m.GOOGLEMAPS:case m.LEAFLET:return 0;case m.OPENLAYERS3:return this.map.getView().getRotation();case m.MAPBOXGL:return this.map.getBearing()*Math.PI/-180}},d.prototype.pointFromPosition=function(a){var b;switch(this.mapType){case m.GOOGLEMAPS:a instanceof google.maps.LatLng||(a=new google.maps.LatLng(i.lat(a),i.lng(a),!0));var c=this.map.getProjection().fromLatLngToPoint(a);return{x:(c.x-this._cache.bottomLeft.x)*this._cache.scale,y:(c.y-this._cache.topRight.y)*this._cache.scale};case m.LEAFLET:return b=this.map.latLngToContainerPoint(a);case m.OPENLAYERS3:return b=this.map.getPixelFromCoordinate(ol.proj.transform([i.lng(a),i.lat(a)],"EPSG:4326","EPSG:3857")),{x:b[0],y:b[1]};case m.MAPBOXGL:return this.map.project([i.lat(a),i.lng(a)])}},d.prototype.positionFromPoint=function(a){switch(this.mapType){case m.GOOGLEMAPS:var b=new google.maps.Point(a.x/this._cache.scale+this._cache.bottomLeft.x,a.y/this._cache.scale+this._cache.topRight.y);return this.map.getProjection().fromPointToLatLng(b);case m.LEAFLET:return this.map.containerPointToLatLng(a);case m.OPENLAYERS3:var c=ol.proj.transform(this.map.getCoordinateFromPixel([a.x,a.y]),"EPSG:3857","EPSG:4326");return{lat:c[1],lng:c[0]};case m.MAPBOXGL:return this.map.unproject(a)}},d.prototype.getSize=function(){return this._cache.size},d.prototype.halt=function(){this._position.halt(),this._positionInvalidated=!0},d.prototype.isActive=function(){return this._position.isActive()},d.prototype._updateCache=function(a,b,c){switch(this._cache.finalZoom=a,this._cache.finalScale=Math.pow(2,this._cache.finalZoom),this._cache.finalNorthEast=b,this._cache.finalSouthWest=c,this.mapType){case m.GOOGLEMAPS:b instanceof google.maps.LatLng||(b=new google.maps.LatLng(i.lat(b),i.lng(b),!0)),c instanceof google.maps.LatLng||(c=new google.maps.LatLng(i.lat(c),i.lng(c),!0));var d=this.map.getProjection().fromLatLngToPoint(b),e=this.map.getProjection().fromLatLngToPoint(c);this._cache.size=[(d.x-e.x)*this._cache.finalScale,(e.y-d.y)*this._cache.finalScale];break;case m.LEAFLET:var f=this.map.getSize();this._cache.size=[f.x,f.y];break;case m.OPENLAYERS3:this._cache.size=this.map.getSize();break;case m.MAPBOXGL:this._cache.size=this.getParentSize()}switch(this.mapType){case m.GOOGLEMAPS:b=this._zoom.northEast.get(),c=this._zoom.southWest.get(),b instanceof google.maps.LatLng||(b=new google.maps.LatLng(i.lat(b),i.lng(b),!0)),c instanceof google.maps.LatLng||(c=new google.maps.LatLng(i.lat(c),i.lng(c),!0)),this._cache.topRight=this.map.getProjection().fromLatLngToPoint(b),this._cache.bottomLeft=this.map.getProjection().fromLatLngToPoint(c),this._cache.scale=this._cache.size[0]/(this._cache.topRight.x-this._cache.bottomLeft.x),this._cache.zoom=Math.log(this._cache.scale)/Math.log(2);break;case m.LEAFLET:case m.OPENLAYERS3:case m.MAPBOXGL:this._cache.zoom=a}},d.prototype._getMapInfo=function(){var a,b,c,d,e;switch(this.mapType){case m.GOOGLEMAPS:a=this.map.getBounds(),d=this.map.getCenter(),e=this.map.getZoom();var f=i.lng(d);b=a.getNorthEast();for(var g=b.lng();f>g;)g+=360;for(;g>f+360;)g-=360;c=a.getSouthWest();for(var h=c.lng();f-360>h;)h+=360;for(;h>f;)h-=360;return{zoom:e,center:{lat:d.lat(),lng:d.lng()},southWest:{lat:c.lat(),lng:h},northEast:{lat:b.lat(),lng:g}};case m.LEAFLET:return a=this.map.getBounds(),c=a.getSouthWest(),b=a.getNorthEast(),d=this.map.getCenter(),e=this.map.getZoom(),{zoom:e,center:{lat:d.lat,lng:d.lng},southWest:{lat:c.lat,lng:c.lng},northEast:{lat:b.lat,lng:b.lng}};case m.OPENLAYERS3:var j=this.map.getView();return a=ol.proj.transformExtent(j.calculateExtent(this.map.getSize()),"EPSG:3857","EPSG:4326"),d=ol.proj.transform(j.getCenter(),"EPSG:3857","EPSG:4326"),e=j.getZoom(),{zoom:e,center:{lat:d[1],lng:d[0]},southWest:{lat:a[1],lng:a[0]},northEast:{lat:a[3],lng:a[2]},rotation:j.getRotation()};case m.MAPBOXGL:return a=this.map.getBounds(),{zoom:this.map.getZoom(),center:this.map.getCenter(),southWest:a.getSouthWest(),northEast:a.getNorthEast(),rotation:this.map.getBearing()*Math.PI/-180}}},d.prototype.render=function(){if(this.map||this._initMap(),this._initComplete){var a,b=this._getMapInfo(),c=!1;if(b.zoom!==this._cache.finalZoom?(this._zoom.northEast.halt(),this._zoom.southWest.halt(),this._zoom.center.halt(),this._zoom.northEast.set(b.northEast,this.options.zoomTransition),this._zoom.southWest.set(b.southWest,this.options.zoomTransition),this._zoom.center.set(b.center,this.options.zoomTransition),c=!0):this._zoom.northEast.isActive()?(this._zoom.northEast.get(),c=!0):(this._zoom.northEast.reset(b.northEast),this._zoom.southWest.reset(b.southWest),this._zoom.center.reset(b.center)),!c&&b.zoom===this._cache.finalZoom&&i.equals(b.northEast,this._cache.finalNorthEast)&&i.equals(b.southWest,this._cache.finalSouthWest)||this._updateCache(b.zoom,b.northEast,b.southWest),this._position.isActive()||this._positionInvalidated?(a={center:this._position.get()},this._positionInvalidated=!1):this._position.reset(b.center),a)switch(this.mapType){case m.GOOGLEMAPS:this.map.setOptions(a);break;case m.LEAFLET:this.map.panTo(a.center,{animate:!1});break;case m.OPENLAYERS3:this.map.getView().setCenter(ol.proj.transform([i.lng(a.center),i.lat(a.center)],"EPSG:4326","EPSG:3857"));break;case m.MAPBOXGL:this.map.setCenter([i.lat(a.center),i.lng(a.center)])}this._loadEventEmitted||(this._loadEventEmitted=!0,this._eventOutput.emit("load",this))}return this._node.render()},d.installSelectiveTouchMoveHandler=function(){window.addEventListener("touchmove",function(a){e(a.target)||a.preventDefault()})},b.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./MapPositionTransitionable":2,"./MapTransition":4,"./MapUtility":5}],7:[function(a,b,c){"undefined"==typeof famousmap&&(famousmap={}),famousmap.MapView=a("./MapView"),famousmap.MapModifier=a("./MapModifier"),famousmap.MapStateModifier=a("./MapStateModifier"),famousmap.MapTransition=a("./MapTransition"),famousmap.MapPositionTransitionable=a("./MapPositionTransitionable"),famousmap.MapUtility=a("./MapUtility")},{"./MapModifier":1,"./MapPositionTransitionable":2,"./MapStateModifier":3,"./MapTransition":4,"./MapUtility":5,"./MapView":6}]},{},[7]);