Commit 4da366ad authored by zhangzhaohui's avatar zhangzhaohui

删除多余的文件

parent 46080ab4
Pipeline #334 failed with stages
<template>
<view class="header-bar" :style="{ 'padding-top': statusBarHeight + 'px' , 'height' : navHeight + 'px'}">
<view class="content">
<view class="icon-box" @click="back()">
<image class="icon" src="../static/img/back.png"></image>
<text class="back-text">返回</text>
</view>
<text>{{title}}</text>
</view>
</view>
</template>
<script>
export default {
name:"HeaderBar",
data() {
return {
};
},
props: ['title'],
computed: {
statusBarHeight(){
return this.$store.state.statusBarHeight
},
navHeight(){
return this.$store.state.navHeight
},
},
methods: {
back(){
uni.navigateBack()
},
}
}
</script>
<style lang="scss" scoped>
.header-bar{
width: 100%;
justify-content: center;
align-items: center;
display: flex;
font-size: 36rpx;
box-sizing: border-box;
position: fixed;
top: 0;
z-index: 99;
.content{
flex: 1;
display: flex;
justify-content: center;
position: relative;
align-items: center;
.icon-box{
display: flex;
align-items: center;
position: absolute;
left: 48rpx;
.icon {
height: 40rpx;
width: 40rpx;
margin-right: 15rpx;
}
.back-text{
font-size: 32rpx;
}
}
}
}
</style>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
var L = window.L
L.TileLayer.ChinaProvider = L.TileLayer.extend({
initialize: function(type, options) { // (type, Object)
if (!options) {
options = {}
}
var providers = L.TileLayer.ChinaProvider.providers
var parts = type.split('.')
var providerName = parts[0]
var mapName = parts[1]
var mapType = parts[2]
var url = providers[providerName][mapName][mapType]
options.subdomains = providers[providerName].Subdomains
L.TileLayer.prototype.initialize.call(this, url, options)
}
})
L.TileLayer.ChinaProvider.providers = {
TianDiTu: {
Normal: {
Map: '//t{s}.tianditu.com/DataServer?T=vec_w&X={x}&Y={y}&L={z}&tk={key}',
Annotion: '//t{s}.tianditu.com/DataServer?T=cva_w&X={x}&Y={y}&L={z}&tk={key}'
},
Satellite: {
Map: 'http://t{s}.tianditu.gov.cn/img_w/wmts?tk={key}&SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}',
Annotion: 'http://t{s}.tianditu.gov.cn/img_w/wmts?tk={key}&SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}'
},
Terrain: {
Map: '//t{s}.tianditu.com/DataServer?T=ter_w&X={x}&Y={y}&L={z}&tk={key}',
Annotion: '//t{s}.tianditu.com/DataServer?T=cta_w&X={x}&Y={y}&L={z}&tk={key}'
},
YunNan: {
/* https://maps.ynmap.cn/services/img/map/3857/WMTS?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=tdtYnImg100cm84&STYLE=default&TILEMATRIXSET=default028mm&FORMAT=tiles&TILEMATRIX=18&TILEROW=111233&TILECOL=204031&key= */
Map: 'https://maps.ynmap.cn/services/img/map/3857/WMTS?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=tdtYnImg100cm84&STYLE=default&TILEMATRIXSET=default028mm&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&key={key}',
Annotion: 'http://t{s}.tianditu.com/DataServer?T=cta_w&X={x}&Y={y}&L={z}&tk={key}'
},
Subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
key: '174705aebfe31b79b3587279e211cb9a'
},
MapBox: {
Normal: {
Map: 'https://api.mapbox.com/styles/v1/{user}/{style}/Draft/tiles/256/{z}/{x}/{y}?access_token={token}'
},
Subdomains: []
},
MapABC: {
Normal: {
Map: 'http://emap{s}.mapabc.com/mapabc/maptile?&x={x}&y={y}&z={z}'
},
Subdomains: ['0', '1', '2', '3']
},
GaoDe: {
Normal: {
Map: 'http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'
},
Satellite: {
Map: 'http://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
Annotion: 'http://webst0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}'
},
Subdomains: ['1', '2', '3', '4']
},
GoogleCN: {
Normal: {
Map: 'http://mt{s}.google.cn/vt/lyrs=m&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}'
},
Subdomains: ['1', '2', '3']
},
Geoq: {
Normal: {
Map: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}',
PurplishBlue: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}',
Gray: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}',
Warm: 'http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer/tile/{z}/{y}/{x}'
},
Theme: {
Hydro: 'http://thematic.geoq.cn/arcgis/rest/services/ThematicMaps/WorldHydroMap/MapServer/tile/{z}/{y}/{x}'
},
Subdomains: []
}
}
L.tileLayer.chinaProvider = function(type, options) {
return new L.TileLayer.ChinaProvider(type, options)
}
/* required styles */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
position: absolute;
left: 0;
top: 0;
}
.leaflet-container {
overflow: hidden;
}
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
-webkit-user-drag: none;
}
/* Prevents IE11 from highlighting tiles in blue */
.leaflet-tile::selection {
background: transparent;
}
/* Safari renders non-retina tile on retina better with this, but Chrome is worse */
.leaflet-safari .leaflet-tile {
image-rendering: -webkit-optimize-contrast;
}
/* hack that prevents hw layers "stretching" when loading new tiles */
.leaflet-safari .leaflet-tile-container {
width: 1600px;
height: 1600px;
-webkit-transform-origin: 0 0;
}
.leaflet-marker-icon,
.leaflet-marker-shadow {
display: block;
}
/* .leaflet-container svg: reset svg max-width decleration shipped in Joomla! (joomla.org) 3.x */
/* .leaflet-container img: map is broken in FF if you have max-width: 100% on tiles */
.leaflet-container .leaflet-overlay-pane svg,
.leaflet-container .leaflet-marker-pane img,
.leaflet-container .leaflet-shadow-pane img,
.leaflet-container .leaflet-tile-pane img,
.leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile {
max-width: none !important;
max-height: none !important;
}
.leaflet-container.leaflet-touch-zoom {
-ms-touch-action: pan-x pan-y;
touch-action: pan-x pan-y;
}
.leaflet-container.leaflet-touch-drag {
-ms-touch-action: pinch-zoom;
/* Fallback for FF which doesn't support pinch-zoom */
touch-action: none;
touch-action: pinch-zoom;
}
.leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
-ms-touch-action: none;
touch-action: none;
}
.leaflet-container {
-webkit-tap-highlight-color: transparent;
}
.leaflet-container a {
-webkit-tap-highlight-color: rgba(51, 181, 229, 0.4);
}
.leaflet-tile {
filter: inherit;
visibility: hidden;
}
.leaflet-tile-loaded {
visibility: inherit;
}
.leaflet-zoom-box {
width: 0;
height: 0;
-moz-box-sizing: border-box;
box-sizing: border-box;
z-index: 800;
}
/* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */
.leaflet-overlay-pane svg {
-moz-user-select: none;
}
.leaflet-pane { z-index: 400; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-map-pane canvas { z-index: 100; }
.leaflet-map-pane svg { z-index: 200; }
.leaflet-vml-shape {
width: 1px;
height: 1px;
}
.lvml {
behavior: url(#default#VML);
display: inline-block;
position: absolute;
}
/* control positioning */
.leaflet-control {
position: relative;
z-index: 800;
pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
pointer-events: auto;
}
.leaflet-top,
.leaflet-bottom {
position: absolute;
z-index: 1000;
pointer-events: none;
}
.leaflet-top {
top: 0;
}
.leaflet-right {
right: 0;
}
.leaflet-bottom {
bottom: 0;
}
.leaflet-left {
left: 0;
}
.leaflet-control {
float: left;
clear: both;
}
.leaflet-right .leaflet-control {
float: right;
}
.leaflet-top .leaflet-control {
margin-top: 10px;
}
.leaflet-bottom .leaflet-control {
margin-bottom: 10px;
}
.leaflet-left .leaflet-control {
margin-left: 10px;
}
.leaflet-right .leaflet-control {
margin-right: 10px;
}
/* zoom and fade animations */
.leaflet-fade-anim .leaflet-tile {
will-change: opacity;
}
.leaflet-fade-anim .leaflet-popup {
opacity: 0;
-webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear;
transition: opacity 0.2s linear;
}
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
opacity: 1;
}
.leaflet-zoom-animated {
-webkit-transform-origin: 0 0;
-ms-transform-origin: 0 0;
transform-origin: 0 0;
}
.leaflet-zoom-anim .leaflet-zoom-animated {
will-change: transform;
}
.leaflet-zoom-anim .leaflet-zoom-animated {
-webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
-moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
transition: transform 0.25s cubic-bezier(0,0,0.25,1);
}
.leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile {
-webkit-transition: none;
-moz-transition: none;
transition: none;
}
.leaflet-zoom-anim .leaflet-zoom-hide {
visibility: hidden;
}
/* cursors */
.leaflet-interactive {
cursor: pointer;
}
.leaflet-grab {
cursor: -webkit-grab;
cursor: -moz-grab;
cursor: grab;
}
.leaflet-crosshair,
.leaflet-crosshair .leaflet-interactive {
cursor: crosshair;
}
.leaflet-popup-pane,
.leaflet-control {
cursor: auto;
}
.leaflet-dragging .leaflet-grab,
.leaflet-dragging .leaflet-grab .leaflet-interactive,
.leaflet-dragging .leaflet-marker-draggable {
cursor: move;
cursor: -webkit-grabbing;
cursor: -moz-grabbing;
cursor: grabbing;
}
/* marker & overlays interactivity */
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-image-layer,
.leaflet-pane > svg path,
.leaflet-tile-container {
pointer-events: none;
}
.leaflet-marker-icon.leaflet-interactive,
.leaflet-image-layer.leaflet-interactive,
.leaflet-pane > svg path.leaflet-interactive,
svg.leaflet-image-layer.leaflet-interactive path {
pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
pointer-events: auto;
}
/* visual tweaks */
.leaflet-container {
background: #ddd;
outline: 0;
}
.leaflet-container a {
color: #0078A8;
}
.leaflet-container a.leaflet-active {
outline: 2px solid orange;
}
.leaflet-zoom-box {
border: 2px dotted #38f;
background: rgba(255,255,255,0.5);
}
/* general typography */
.leaflet-container {
font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
}
/* general toolbar styles */
.leaflet-bar {
box-shadow: 0 1px 5px rgba(0,0,0,0.65);
border-radius: 4px;
}
.leaflet-bar a,
.leaflet-bar a:hover {
background-color: #fff;
border-bottom: 1px solid #ccc;
width: 26px;
height: 26px;
line-height: 26px;
display: block;
text-align: center;
text-decoration: none;
color: black;
}
.leaflet-bar a,
.leaflet-control-layers-toggle {
background-position: 50% 50%;
background-repeat: no-repeat;
display: block;
}
.leaflet-bar a:hover {
background-color: #f4f4f4;
}
.leaflet-bar a:first-child {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.leaflet-bar a:last-child {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom: none;
}
.leaflet-bar a.leaflet-disabled {
cursor: default;
background-color: #f4f4f4;
color: #bbb;
}
.leaflet-touch .leaflet-bar a {
width: 30px;
height: 30px;
line-height: 30px;
}
.leaflet-touch .leaflet-bar a:first-child {
border-top-left-radius: 2px;
border-top-right-radius: 2px;
}
.leaflet-touch .leaflet-bar a:last-child {
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
}
/* zoom control */
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
font: bold 18px 'Lucida Console', Monaco, monospace;
text-indent: 1px;
}
.leaflet-touch .leaflet-control-zoom-in, .leaflet-touch .leaflet-control-zoom-out {
font-size: 22px;
}
/* layers control */
.leaflet-control-layers {
box-shadow: 0 1px 5px rgba(0,0,0,0.4);
background: #fff;
border-radius: 5px;
}
.leaflet-control-layers-toggle {
background-image: url(/static/images/layers.png);
width: 36px;
height: 36px;
}
.leaflet-retina .leaflet-control-layers-toggle {
background-image: url(/static/images/layers-2x.png);
background-size: 26px 26px;
}
.leaflet-touch .leaflet-control-layers-toggle {
width: 44px;
height: 44px;
}
.leaflet-control-layers .leaflet-control-layers-list,
.leaflet-control-layers-expanded .leaflet-control-layers-toggle {
display: none;
}
.leaflet-control-layers-expanded .leaflet-control-layers-list {
display: block;
position: relative;
}
.leaflet-control-layers-expanded {
padding: 6px 10px 6px 6px;
color: #333;
background: #fff;
}
.leaflet-control-layers-scrollbar {
overflow-y: scroll;
overflow-x: hidden;
padding-right: 5px;
}
.leaflet-control-layers-selector {
margin-top: 2px;
position: relative;
top: 1px;
}
.leaflet-control-layers label {
display: block;
}
.leaflet-control-layers-separator {
height: 0;
border-top: 1px solid #ddd;
margin: 5px -10px 5px -6px;
}
/* Default icon URLs */
.leaflet-default-icon-path {
background-image: url(/static/images/marker-icon.png);
}
/* attribution and scale controls */
.leaflet-container .leaflet-control-attribution {
background: #fff;
background: rgba(255, 255, 255, 0.7);
margin: 0;
}
.leaflet-control-attribution,
.leaflet-control-scale-line {
padding: 0 5px;
color: #333;
}
.leaflet-control-attribution a {
text-decoration: none;
}
.leaflet-control-attribution a:hover {
text-decoration: underline;
}
.leaflet-container .leaflet-control-attribution,
.leaflet-container .leaflet-control-scale {
font-size: 11px;
}
.leaflet-left .leaflet-control-scale {
margin-left: 5px;
}
.leaflet-bottom .leaflet-control-scale {
margin-bottom: 5px;
}
.leaflet-control-scale-line {
border: 2px solid #777;
border-top: none;
line-height: 1.1;
padding: 2px 5px 1px;
font-size: 11px;
white-space: nowrap;
overflow: hidden;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
background: rgba(255, 255, 255, 0.5);
}
.leaflet-control-scale-line:not(:first-child) {
border-top: 2px solid #777;
border-bottom: none;
margin-top: -2px;
}
.leaflet-control-scale-line:not(:first-child):not(:last-child) {
border-bottom: 2px solid #777;
}
.leaflet-touch .leaflet-control-attribution,
.leaflet-touch .leaflet-control-layers,
.leaflet-touch .leaflet-bar {
box-shadow: none;
}
.leaflet-touch .leaflet-control-layers,
.leaflet-touch .leaflet-bar {
border: 2px solid rgba(0,0,0,0.2);
background-clip: padding-box;
}
/* popup */
.leaflet-popup {
position: absolute;
text-align: center;
margin-bottom: 20px;
}
.leaflet-popup-content-wrapper {
padding: 1px;
text-align: left;
border-radius: 12px;
}
.leaflet-popup-content {
margin: 13px 19px;
line-height: 1.4;
}
.leaflet-popup-content p {
margin: 18px 0;
}
.leaflet-popup-tip-container {
width: 40px;
height: 20px;
position: absolute;
left: 50%;
margin-left: -20px;
overflow: hidden;
pointer-events: none;
}
.leaflet-popup-tip {
width: 17px;
height: 17px;
padding: 1px;
margin: -10px auto 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
background: white;
color: #333;
box-shadow: 0 3px 14px rgba(0,0,0,0.4);
}
.leaflet-container a.leaflet-popup-close-button {
position: absolute;
top: 0;
right: 0;
padding: 4px 4px 0 0;
border: none;
text-align: center;
width: 18px;
height: 14px;
font: 16px/14px Tahoma, Verdana, sans-serif;
color: #c3c3c3;
text-decoration: none;
font-weight: bold;
background: transparent;
}
.leaflet-container a.leaflet-popup-close-button:hover {
color: #999;
}
.leaflet-popup-scrolled {
overflow: auto;
border-bottom: 1px solid #ddd;
border-top: 1px solid #ddd;
}
.leaflet-oldie .leaflet-popup-content-wrapper {
zoom: 1;
}
.leaflet-oldie .leaflet-popup-tip {
width: 24px;
margin: 0 auto;
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678)";
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678);
}
.leaflet-oldie .leaflet-popup-tip-container {
margin-top: -1px;
}
.leaflet-oldie .leaflet-control-zoom,
.leaflet-oldie .leaflet-control-layers,
.leaflet-oldie .leaflet-popup-content-wrapper,
.leaflet-oldie .leaflet-popup-tip {
border: 1px solid #999;
}
/* div icon */
.leaflet-div-icon {
background: #fff;
border: 1px solid #666;
}
/* Tooltip */
/* Base styles for the element that has a tooltip */
.leaflet-tooltip {
position: absolute;
padding: 6px;
background-color: #fff;
border: 1px solid #fff;
border-radius: 3px;
color: #222;
white-space: nowrap;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
pointer-events: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.leaflet-tooltip.leaflet-clickable {
cursor: pointer;
pointer-events: auto;
}
.leaflet-tooltip-top:before,
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
position: absolute;
pointer-events: none;
border: 6px solid transparent;
background: transparent;
content: "";
}
/* Directions */
.leaflet-tooltip-bottom {
margin-top: 6px;
}
.leaflet-tooltip-top {
margin-top: -6px;
}
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-top:before {
left: 50%;
margin-left: -6px;
}
.leaflet-tooltip-top:before {
bottom: 0;
margin-bottom: -12px;
border-top-color: #fff;
}
.leaflet-tooltip-bottom:before {
top: 0;
margin-top: -12px;
margin-left: -6px;
border-bottom-color: #fff;
}
.leaflet-tooltip-left {
margin-left: -6px;
}
.leaflet-tooltip-right {
margin-left: 6px;
}
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
top: 50%;
margin-top: -6px;
}
.leaflet-tooltip-left:before {
right: 0;
margin-right: -12px;
border-left-color: #fff;
}
.leaflet-tooltip-right:before {
left: 0;
margin-left: -12px;
border-right-color: #fff;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
var L = window.L
// 坐标转换
L.CoordConver = function() {
/** 百度转84*/
this.bd09_To_gps84 = function(lng, lat) {
var gcj02 = this.bd09_To_gcj02(lng, lat)
var map84 = this.gcj02_To_gps84(gcj02.lng, gcj02.lat)
return map84
}
/** 84转百度*/
this.gps84_To_bd09 = function(lng, lat) {
var gcj02 = this.gps84_To_gcj02(lng, lat)
var bd09 = this.gcj02_To_bd09(gcj02.lng, gcj02.lat)
return bd09
}
/** 84转火星*/
this.gps84_To_gcj02 = function(lng, lat) {
var dLat = transformLat(lng - 105.0, lat - 35.0)
var dLng = transformLng(lng - 105.0, lat - 35.0)
var radLat = lat / 180.0 * pi
var magic = Math.sin(radLat)
magic = 1 - ee * magic * magic
var sqrtMagic = Math.sqrt(magic)
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi)
dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi)
var mgLat = lat + dLat
var mgLng = lng + dLng
var newCoord = {
lng: mgLng,
lat: mgLat
}
return newCoord
}
/** 火星转84*/
this.gcj02_To_gps84 = function(lng, lat) {
var coord = transform(lng, lat)
var lontitude = lng * 2 - coord.lng
var latitude = lat * 2 - coord.lat
var newCoord = {
lng: lontitude,
lat: latitude
}
return newCoord
}
/** 火星转百度*/
this.gcj02_To_bd09 = function(x, y) {
var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi)
var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi)
var bd_lng = z * Math.cos(theta) + 0.0065
var bd_lat = z * Math.sin(theta) + 0.006
var newCoord = {
lng: bd_lng,
lat: bd_lat
}
return newCoord
}
/** 百度转火星*/
this.bd09_To_gcj02 = function(bd_lng, bd_lat) {
var x = bd_lng - 0.0065
var y = bd_lat - 0.006
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi)
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi)
var gg_lng = z * Math.cos(theta)
var gg_lat = z * Math.sin(theta)
var newCoord = {
lng: gg_lng,
lat: gg_lat
}
return newCoord
}
var pi = 3.1415926535897932384626
var a = 6378245.0
var ee = 0.00669342162296594323
var x_pi = pi * 3000.0 / 180.0
// var R = 6378137
function transform(lng, lat) {
var dLat = transformLat(lng - 105.0, lat - 35.0)
var dLng = transformLng(lng - 105.0, lat - 35.0)
var radLat = lat / 180.0 * pi
var magic = Math.sin(radLat)
magic = 1 - ee * magic * magic
var sqrtMagic = Math.sqrt(magic)
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi)
dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi)
var mgLat = lat + dLat
var mgLng = lng + dLng
var newCoord = {
lng: mgLng,
lat: mgLat
}
return newCoord
}
function transformLat(x, y) {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0
ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0
return ret
}
function transformLng(x, y) {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0
ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0
return ret
}
}
L.coordConver = function() {
return new L.CoordConver()
}
L.tileLayer.chinaProvider = function(type, options) {
options = options || {}
options.corrdType = getCorrdType(type)
return new L.TileLayer.ChinaProvider(type, options)
// 获取坐标类型
function getCorrdType(type) {
var parts = type.split('.')
var providerName = parts[0]
var zbName = 'wgs84'
switch (providerName) {
case 'Geoq':
case 'GaoDe':
case 'Google':
zbName = 'gcj02'
break
case 'Baidu':
zbName = 'bd09'
break
case 'OSM':
case 'TianDiTu':
case 'MapBox':
zbName = 'wgs84'
break
}
return zbName
}
}
L.GridLayer.include({
_setZoomTransform: function(level, _center, zoom) {
var center = _center
if (center !== undefined && this.options) {
if (this.options.corrdType === 'wgs84') {
center = L.coordConver().gcj02_To_gps84(_center.lng, _center.lat)
} else if (this.options.corrdType === 'bd09') {
center = L.coordConver().gcj02_To_bd09(_center.lng, _center.lat)
}
}
var scale = this._map.getZoomScale(zoom, level.zoom)
var translate = level.origin.multiplyBy(scale)
.subtract(this._map._getNewPixelOrigin(center, zoom)).round()
if (L.Browser.any3d) {
L.DomUtil.setTransform(level.el, translate, scale)
} else {
L.DomUtil.setPosition(level.el, translate)
}
},
_getTiledPixelBounds: function(_center) {
var center = _center
if (center !== undefined && this.options) {
if (this.options.corrdType === 'wgs84') {
center = L.coordConver().gcj02_To_gps84(_center.lng, _center.lat)
} else if (this.options.corrdType === 'bd09') {
center = L.coordConver().gcj02_To_bd09(_center.lng, _center.lat)
}
}
var map = this._map
var mapZoom = map._animatingZoom ? Math.max(map._animateToZoom, map.getZoom()) : map.getZoom()
var scale = map.getZoomScale(mapZoom, this._tileZoom)
var pixelCenter = map.project(center, this._tileZoom).floor()
var halfSize = map.getSize().divideBy(scale * 2)
return new L.Bounds(pixelCenter.subtract(halfSize), pixelCenter.add(halfSize))
}
})
(function (root, factory) {
// Node.
if(typeof module === 'object' && typeof module.exports === 'object') {
exports = module.exports = factory(require("./terraformer"));
} else if(typeof navigator === "object") {
// Browser Global.
if (!root.Terraformer){
throw new Error("Terraformer.WKT requires the core Terraformer library. http://github.com/esri/terraformer")
}
root.Terraformer.WKT = factory(root.Terraformer);
}
}(this, function(Terraformer) {
var exports = { };
/* Jison generated parser */
var parser = (function(){
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"expressions":3,"point":4,"EOF":5,"linestring":6,"polygon":7,"multipoint":8,"multilinestring":9,"multipolygon":10,"coordinate":11,"DOUBLE_TOK":12,"ptarray":13,"COMMA":14,"ring_list":15,"ring":16,"(":17,")":18,"POINT":19,"Z":20,"ZM":21,"M":22,"EMPTY":23,"point_untagged":24,"polygon_list":25,"polygon_untagged":26,"point_list":27,"LINESTRING":28,"POLYGON":29,"MULTIPOINT":30,"MULTILINESTRING":31,"MULTIPOLYGON":32,"$accept":0,"$end":1},
terminals_: {2:"error",5:"EOF",12:"DOUBLE_TOK",14:"COMMA",17:"(",18:")",19:"POINT",20:"Z",21:"ZM",22:"M",23:"EMPTY",28:"LINESTRING",29:"POLYGON",30:"MULTIPOINT",31:"MULTILINESTRING",32:"MULTIPOLYGON"},
productions_: [0,[3,2],[3,2],[3,2],[3,2],[3,2],[3,2],[11,2],[11,3],[11,4],[13,3],[13,1],[15,3],[15,1],[16,3],[4,4],[4,5],[4,5],[4,5],[4,2],[24,1],[24,3],[25,3],[25,1],[26,3],[27,3],[27,1],[6,4],[6,5],[6,5],[6,5],[6,2],[7,4],[7,5],[7,5],[7,5],[7,2],[8,4],[8,5],[8,5],[8,5],[8,2],[9,4],[9,5],[9,5],[9,5],[9,2],[10,4],[10,5],[10,5],[10,5],[10,2]],
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$,_$
/**/) {
var $0 = $.length - 1;
switch (yystate) {
case 1: return $[$0-1];
break;
case 2: return $[$0-1];
break;
case 3: return $[$0-1];
break;
case 4: return $[$0-1];
break;
case 5: return $[$0-1];
break;
case 6: return $[$0-1];
break;
case 7: this.$ = new PointArray([ Number($[$0-1]), Number($[$0]) ]);
break;
case 8: this.$ = new PointArray([ Number($[$0-2]), Number($[$0-1]), Number($[$0]) ]);
break;
case 9: this.$ = new PointArray([ Number($[$0-3]), Number($[$0-2]), Number($[$0-1]), Number($[$0]) ]);
break;
case 10: this.$ = $[$0-2].addPoint($[$0]);
break;
case 11: this.$ = $[$0];
break;
case 12: this.$ = $[$0-2].addRing($[$0]);
break;
case 13: this.$ = new RingList($[$0]);
break;
case 14: this.$ = new Ring($[$0-1]);
break;
case 15: this.$ = { "type": "Point", "coordinates": $[$0-1].data[0] };
break;
case 16: this.$ = { "type": "Point", "coordinates": $[$0-1].data[0], "properties": { z: true } };
break;
case 17: this.$ = { "type": "Point", "coordinates": $[$0-1].data[0], "properties": { z: true, m: true } };
break;
case 18: this.$ = { "type": "Point", "coordinates": $[$0-1].data[0], "properties": { m: true } };
break;
case 19: this.$ = { "type": "Point", "coordinates": [ ] };
break;
case 20: this.$ = $[$0];
break;
case 21: this.$ = $[$0-1];
break;
case 22: this.$ = $[$0-2].addPolygon($[$0]);
break;
case 23: this.$ = new PolygonList($[$0]);
break;
case 24: this.$ = $[$0-1];
break;
case 25: this.$ = $[$0-2].addPoint($[$0]);
break;
case 26: this.$ = $[$0];
break;
case 27: this.$ = { "type": "LineString", "coordinates": $[$0-1].data };
break;
case 28: this.$ = { "type": "LineString", "coordinates": $[$0-1].data, "properties": { z: true } };
break;
case 29: this.$ = { "type": "LineString", "coordinates": $[$0-1].data, "properties": { m: true } };
break;
case 30: this.$ = { "type": "LineString", "coordinates": $[$0-1].data, "properties": { z: true, m: true } };
break;
case 31: this.$ = { "type": "LineString", "coordinates": [ ] };
break;
case 32: this.$ = { "type": "Polygon", "coordinates": $[$0-1].toJSON() };
break;
case 33: this.$ = { "type": "Polygon", "coordinates": $[$0-1].toJSON(), "properties": { z: true } };
break;
case 34: this.$ = { "type": "Polygon", "coordinates": $[$0-1].toJSON(), "properties": { m: true } };
break;
case 35: this.$ = { "type": "Polygon", "coordinates": $[$0-1].toJSON(), "properties": { z: true, m: true } };
break;
case 36: this.$ = { "type": "Polygon", "coordinates": [ ] };
break;
case 37: this.$ = { "type": "MultiPoint", "coordinates": $[$0-1].data };
break;
case 38: this.$ = { "type": "MultiPoint", "coordinates": $[$0-1].data, "properties": { z: true } };
break;
case 39: this.$ = { "type": "MultiPoint", "coordinates": $[$0-1].data, "properties": { m: true } };
break;
case 40: this.$ = { "type": "MultiPoint", "coordinates": $[$0-1].data, "properties": { z: true, m: true } };
break;
case 41: this.$ = { "type": "MultiPoint", "coordinates": [ ] }
break;
case 42: this.$ = { "type": "MultiLineString", "coordinates": $[$0-1].toJSON() };
break;
case 43: this.$ = { "type": "MultiLineString", "coordinates": $[$0-1].toJSON(), "properties": { z: true } };
break;
case 44: this.$ = { "type": "MultiLineString", "coordinates": $[$0-1].toJSON(), "properties": { m: true } };
break;
case 45: this.$ = { "type": "MultiLineString", "coordinates": $[$0-1].toJSON(), "properties": { z: true, m: true } };
break;
case 46: this.$ = { "type": "MultiLineString", "coordinates": [ ] };
break;
case 47: this.$ = { "type": "MultiPolygon", "coordinates": $[$0-1].toJSON() };
break;
case 48: this.$ = { "type": "MultiPolygon", "coordinates": $[$0-1].toJSON(), "properties": { z: true } };
break;
case 49: this.$ = { "type": "MultiPolygon", "coordinates": $[$0-1].toJSON(), "properties": { m: true } };
break;
case 50: this.$ = { "type": "MultiPolygon", "coordinates": $[$0-1].toJSON(), "properties": { z: true, m: true } };
break;
case 51: this.$ = { "type": "MultiPolygon", "coordinates": [ ] };
break;
}
},
table: [{3:1,4:2,6:3,7:4,8:5,9:6,10:7,19:[1,8],28:[1,9],29:[1,10],30:[1,11],31:[1,12],32:[1,13]},{1:[3]},{5:[1,14]},{5:[1,15]},{5:[1,16]},{5:[1,17]},{5:[1,18]},{5:[1,19]},{17:[1,20],20:[1,21],21:[1,22],22:[1,23],23:[1,24]},{17:[1,25],20:[1,26],21:[1,28],22:[1,27],23:[1,29]},{17:[1,30],20:[1,31],21:[1,33],22:[1,32],23:[1,34]},{17:[1,35],20:[1,36],21:[1,38],22:[1,37],23:[1,39]},{17:[1,40],20:[1,41],21:[1,43],22:[1,42],23:[1,44]},{17:[1,45],20:[1,46],21:[1,48],22:[1,47],23:[1,49]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4]},{1:[2,5]},{1:[2,6]},{11:51,12:[1,52],13:50},{17:[1,53]},{17:[1,54]},{17:[1,55]},{5:[2,19]},{11:58,12:[1,52],17:[1,59],24:57,27:56},{17:[1,60]},{17:[1,61]},{17:[1,62]},{5:[2,31]},{15:63,16:64,17:[1,65]},{17:[1,66]},{17:[1,67]},{17:[1,68]},{5:[2,36]},{11:58,12:[1,52],17:[1,59],24:57,27:69},{17:[1,70]},{17:[1,71]},{17:[1,72]},{5:[2,41]},{15:73,16:64,17:[1,65]},{17:[1,74]},{17:[1,75]},{17:[1,76]},{5:[2,46]},{17:[1,79],25:77,26:78},{17:[1,80]},{17:[1,81]},{17:[1,82]},{5:[2,51]},{14:[1,84],18:[1,83]},{14:[2,11],18:[2,11]},{12:[1,85]},{11:51,12:[1,52],13:86},{11:51,12:[1,52],13:87},{11:51,12:[1,52],13:88},{14:[1,90],18:[1,89]},{14:[2,26],18:[2,26]},{14:[2,20],18:[2,20]},{11:91,12:[1,52]},{11:58,12:[1,52],17:[1,59],24:57,27:92},{11:58,12:[1,52],17:[1,59],24:57,27:93},{11:58,12:[1,52],17:[1,59],24:57,27:94},{14:[1,96],18:[1,95]},{14:[2,13],18:[2,13]},{11:51,12:[1,52],13:97},{15:98,16:64,17:[1,65]},{15:99,16:64,17:[1,65]},{15:100,16:64,17:[1,65]},{14:[1,90],18:[1,101]},{11:58,12:[1,52],17:[1,59],24:57,27:102},{11:58,12:[1,52],17:[1,59],24:57,27:103},{11:58,12:[1,52],17:[1,59],24:57,27:104},{14:[1,96],18:[1,105]},{15:106,16:64,17:[1,65]},{15:107,16:64,17:[1,65]},{15:108,16:64,17:[1,65]},{14:[1,110],18:[1,109]},{14:[2,23],18:[2,23]},{15:111,16:64,17:[1,65]},{17:[1,79],25:112,26:78},{17:[1,79],25:113,26:78},{17:[1,79],25:114,26:78},{5:[2,15]},{11:115,12:[1,52]},{12:[1,116],14:[2,7],18:[2,7]},{14:[1,84],18:[1,117]},{14:[1,84],18:[1,118]},{14:[1,84],18:[1,119]},{5:[2,27]},{11:58,12:[1,52],17:[1,59],24:120},{18:[1,121]},{14:[1,90],18:[1,122]},{14:[1,90],18:[1,123]},{14:[1,90],18:[1,124]},{5:[2,32]},{16:125,17:[1,65]},{14:[1,84],18:[1,126]},{14:[1,96],18:[1,127]},{14:[1,96],18:[1,128]},{14:[1,96],18:[1,129]},{5:[2,37]},{14:[1,90],18:[1,130]},{14:[1,90],18:[1,131]},{14:[1,90],18:[1,132]},{5:[2,42]},{14:[1,96],18:[1,133]},{14:[1,96],18:[1,134]},{14:[1,96],18:[1,135]},{5:[2,47]},{17:[1,79],26:136},{14:[1,96],18:[1,137]},{14:[1,110],18:[1,138]},{14:[1,110],18:[1,139]},{14:[1,110],18:[1,140]},{14:[2,10],18:[2,10]},{12:[1,141],14:[2,8],18:[2,8]},{5:[2,16]},{5:[2,17]},{5:[2,18]},{14:[2,25],18:[2,25]},{14:[2,21],18:[2,21]},{5:[2,28]},{5:[2,29]},{5:[2,30]},{14:[2,12],18:[2,12]},{14:[2,14],18:[2,14]},{5:[2,33]},{5:[2,34]},{5:[2,35]},{5:[2,38]},{5:[2,39]},{5:[2,40]},{5:[2,43]},{5:[2,44]},{5:[2,45]},{14:[2,22],18:[2,22]},{14:[2,24],18:[2,24]},{5:[2,48]},{5:[2,49]},{5:[2,50]},{14:[2,9],18:[2,9]}],
defaultActions: {14:[2,1],15:[2,2],16:[2,3],17:[2,4],18:[2,5],19:[2,6],24:[2,19],29:[2,31],34:[2,36],39:[2,41],44:[2,46],49:[2,51],83:[2,15],89:[2,27],95:[2,32],101:[2,37],105:[2,42],109:[2,47],117:[2,16],118:[2,17],119:[2,18],122:[2,28],123:[2,29],124:[2,30],127:[2,33],128:[2,34],129:[2,35],130:[2,38],131:[2,39],132:[2,40],133:[2,43],134:[2,44],135:[2,45],138:[2,48],139:[2,49],140:[2,50]},
parseError: function parseError(str, hash) {
throw new Error(str);
},
parse: function parse(input) {
var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
this.lexer.setInput(input);
this.lexer.yy = this.yy;
this.yy.lexer = this.lexer;
this.yy.parser = this;
if (typeof this.lexer.yylloc == "undefined")
this.lexer.yylloc = {};
var yyloc = this.lexer.yylloc;
lstack.push(yyloc);
var ranges = this.lexer.options && this.lexer.options.ranges;
if (typeof this.yy.parseError === "function")
this.parseError = this.yy.parseError;
function popStack(n) {
stack.length = stack.length - 2 * n;
vstack.length = vstack.length - n;
lstack.length = lstack.length - n;
}
function lex() {
var token;
token = self.lexer.lex() || 1;
if (typeof token !== "number") {
token = self.symbols_[token] || token;
}
return token;
}
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
while (true) {
state = stack[stack.length - 1];
if (this.defaultActions[state]) {
action = this.defaultActions[state];
} else {
if (symbol === null || typeof symbol == "undefined") {
symbol = lex();
}
action = table[state] && table[state][symbol];
}
if (typeof action === "undefined" || !action.length || !action[0]) {
var errStr = "";
if (!recovering) {
expected = [];
for (p in table[state])
if (this.terminals_[p] && p > 2) {
expected.push("'" + this.terminals_[p] + "'");
}
if (this.lexer.showPosition) {
errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
} else {
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
}
this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
}
}
if (action[0] instanceof Array && action.length > 1) {
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
}
switch (action[0]) {
case 1:
stack.push(symbol);
vstack.push(this.lexer.yytext);
lstack.push(this.lexer.yylloc);
stack.push(action[1]);
symbol = null;
if (!preErrorSymbol) {
yyleng = this.lexer.yyleng;
yytext = this.lexer.yytext;
yylineno = this.lexer.yylineno;
yyloc = this.lexer.yylloc;
if (recovering > 0)
recovering--;
} else {
symbol = preErrorSymbol;
preErrorSymbol = null;
}
break;
case 2:
len = this.productions_[action[1]][1];
yyval.$ = vstack[vstack.length - len];
yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
if (ranges) {
yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
}
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
if (typeof r !== "undefined") {
return r;
}
if (len) {
stack = stack.slice(0, -1 * len * 2);
vstack = vstack.slice(0, -1 * len);
lstack = lstack.slice(0, -1 * len);
}
stack.push(this.productions_[action[1]][0]);
vstack.push(yyval.$);
lstack.push(yyval._$);
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
stack.push(newState);
break;
case 3:
return true;
}
}
return true;
}
};
undefined/* Jison generated lexer */
var lexer = (function(){
var lexer = ({EOF:1,
parseError:function parseError(str, hash) {
if (this.yy.parser) {
this.yy.parser.parseError(str, hash);
} else {
throw new Error(str);
}
},
setInput:function (input) {
this._input = input;
this._more = this._less = this.done = false;
this.yylineno = this.yyleng = 0;
this.yytext = this.matched = this.match = '';
this.conditionStack = ['INITIAL'];
this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
if (this.options.ranges) this.yylloc.range = [0,0];
this.offset = 0;
return this;
},
input:function () {
var ch = this._input[0];
this.yytext += ch;
this.yyleng++;
this.offset++;
this.match += ch;
this.matched += ch;
var lines = ch.match(/(?:\r\n?|\n).*/g);
if (lines) {
this.yylineno++;
this.yylloc.last_line++;
} else {
this.yylloc.last_column++;
}
if (this.options.ranges) this.yylloc.range[1]++;
this._input = this._input.slice(1);
return ch;
},
unput:function (ch) {
var len = ch.length;
var lines = ch.split(/(?:\r\n?|\n)/g);
this._input = ch + this._input;
this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
//this.yyleng -= len;
this.offset -= len;
var oldLines = this.match.split(/(?:\r\n?|\n)/g);
this.match = this.match.substr(0, this.match.length-1);
this.matched = this.matched.substr(0, this.matched.length-1);
if (lines.length-1) this.yylineno -= lines.length-1;
var r = this.yylloc.range;
this.yylloc = {first_line: this.yylloc.first_line,
last_line: this.yylineno+1,
first_column: this.yylloc.first_column,
last_column: lines ?
(lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
this.yylloc.first_column - len
};
if (this.options.ranges) {
this.yylloc.range = [r[0], r[0] + this.yyleng - len];
}
return this;
},
more:function () {
this._more = true;
return this;
},
less:function (n) {
this.unput(this.match.slice(n));
},
pastInput:function () {
var past = this.matched.substr(0, this.matched.length - this.match.length);
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
},
upcomingInput:function () {
var next = this.match;
if (next.length < 20) {
next += this._input.substr(0, 20-next.length);
}
return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
},
showPosition:function () {
var pre = this.pastInput();
var c = new Array(pre.length + 1).join("-");
return pre + this.upcomingInput() + "\n" + c+"^";
},
next:function () {
if (this.done) {
return this.EOF;
}
if (!this._input) this.done = true;
var token,
match,
tempMatch,
index,
col,
lines;
if (!this._more) {
this.yytext = '';
this.match = '';
}
var rules = this._currentRules();
for (var i=0;i < rules.length; i++) {
tempMatch = this._input.match(this.rules[rules[i]]);
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
match = tempMatch;
index = i;
if (!this.options.flex) break;
}
}
if (match) {
lines = match[0].match(/(?:\r\n?|\n).*/g);
if (lines) this.yylineno += lines.length;
this.yylloc = {first_line: this.yylloc.last_line,
last_line: this.yylineno+1,
first_column: this.yylloc.last_column,
last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
this.yytext += match[0];
this.match += match[0];
this.matches = match;
this.yyleng = this.yytext.length;
if (this.options.ranges) {
this.yylloc.range = [this.offset, this.offset += this.yyleng];
}
this._more = false;
this._input = this._input.slice(match[0].length);
this.matched += match[0];
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
if (this.done && this._input) this.done = false;
if (token) return token;
else return;
}
if (this._input === "") {
return this.EOF;
} else {
return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
{text: "", token: null, line: this.yylineno});
}
},
lex:function lex() {
var r = this.next();
if (typeof r !== 'undefined') {
return r;
} else {
return this.lex();
}
},
begin:function begin(condition) {
this.conditionStack.push(condition);
},
popState:function popState() {
return this.conditionStack.pop();
},
_currentRules:function _currentRules() {
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
},
topState:function () {
return this.conditionStack[this.conditionStack.length-2];
},
pushState:function begin(condition) {
this.begin(condition);
}});
lexer.options = {};
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START
/**/) {
var YYSTATE=YY_START
switch($avoiding_name_collisions) {
case 0:// ignore
break;
case 1:return 17
break;
case 2:return 18
break;
case 3:return 12
break;
case 4:return 19
break;
case 5:return 28
break;
case 6:return 29
break;
case 7:return 30
break;
case 8:return 31
break;
case 9:return 32
break;
case 10:return 14
break;
case 11:return 23
break;
case 12:return 22
break;
case 13:return 20
break;
case 14:return 21
break;
case 15:return 5
break;
case 16:return "INVALID"
break;
}
};
lexer.rules = [/^(?:\s+)/,/^(?:\()/,/^(?:\))/,/^(?:-?[0-9]+(\.[0-9]+)?([eE][\-\+]?[0-9]+)?)/,/^(?:POINT\b)/,/^(?:LINESTRING\b)/,/^(?:POLYGON\b)/,/^(?:MULTIPOINT\b)/,/^(?:MULTILINESTRING\b)/,/^(?:MULTIPOLYGON\b)/,/^(?:,)/,/^(?:EMPTY\b)/,/^(?:M\b)/,/^(?:Z\b)/,/^(?:ZM\b)/,/^(?:$)/,/^(?:.)/];
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"inclusive":true}};
return lexer;})()
parser.lexer = lexer;
function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
return new Parser;
})();
function PointArray (point) {
this.data = [ point ];
this.type = 'PointArray';
}
PointArray.prototype.addPoint = function (point) {
if (point.type === 'PointArray') {
this.data = this.data.concat(point.data);
} else {
this.data.push(point);
}
return this;
};
PointArray.prototype.toJSON = function () {
return this.data;
};
function Ring (point) {
this.data = point;
this.type = 'Ring';
}
Ring.prototype.toJSON = function () {
var data = [ ];
for (var i = 0; i < this.data.data.length; i++) {
data.push(this.data.data[i]);
}
return data;
};
function RingList (ring) {
this.data = [ ring ];
this.type = 'RingList';
}
RingList.prototype.addRing = function (ring) {
this.data.push(ring);
return this;
};
RingList.prototype.toJSON = function () {
var data = [ ];
for (var i = 0; i < this.data.length; i++) {
data.push(this.data[i].toJSON());
}
if (data.length === 1) {
return data;
} else {
return data;
}
};
function PolygonList (polygon) {
this.data = [ polygon ];
this.type = 'PolygonList';
}
PolygonList.prototype.addPolygon = function (polygon) {
this.data.push(polygon);
return this;
};
PolygonList.prototype.toJSON = function () {
var data = [ ];
for (var i = 0; i < this.data.length; i++) {
data = data.concat( [ this.data[i].toJSON() ] );
}
return data;
};
function _parse () {
return parser.parse.apply(parser, arguments);
}
function parse (element) {
var res, primitive;
try {
res = parser.parse(element);
} catch (err) {
throw Error("Unable to parse: " + err);
}
return Terraformer.Primitive(res);
}
function arrayToRing (arr) {
var parts = [ ], ret = '';
for (var i = 0; i < arr.length; i++) {
parts.push(arr[i].join(' '));
}
ret += '(' + parts.join(', ') + ')';
return ret;
}
function pointToWKTPoint (primitive) {
var ret = 'POINT ';
if (primitive.coordinates === undefined || primitive.coordinates.length === 0) {
ret += 'EMPTY';
return ret;
} else if (primitive.coordinates.length === 3) {
// 3d or time? default to 3d
if (primitive.properties && primitive.properties.m === true) {
ret += 'M ';
} else {
ret += 'Z ';
}
} else if (primitive.coordinates.length === 4) {
// 3d and time
ret += 'ZM ';
}
// include coordinates
ret += '(' + primitive.coordinates.join(' ') + ')';
return ret;
}
function lineStringToWKTLineString (primitive) {
var ret = 'LINESTRING ';
if (primitive.coordinates === undefined || primitive.coordinates.length === 0 || primitive.coordinates[0].length === 0) {
ret += 'EMPTY';
return ret;
} else if (primitive.coordinates[0].length === 3) {
if (primitive.properties && primitive.properties.m === true) {
ret += 'M ';
} else {
ret += 'Z ';
}
} else if (primitive.coordinates[0].length === 4) {
ret += 'ZM ';
}
ret += arrayToRing(primitive.coordinates);
return ret;
}
function polygonToWKTPolygon (primitive) {
var ret = 'POLYGON ';
if (primitive.coordinates === undefined || primitive.coordinates.length === 0 || primitive.coordinates[0].length === 0) {
ret += 'EMPTY';
return ret;
} else if (primitive.coordinates[0][0].length === 3) {
if (primitive.properties && primitive.properties.m === true) {
ret += 'M ';
} else {
ret += 'Z ';
}
} else if (primitive.coordinates[0][0].length === 4) {
ret += 'ZM ';
}
ret += '(';
var parts = [ ];
for (var i = 0; i < primitive.coordinates.length; i++) {
parts.push(arrayToRing(primitive.coordinates[i]));
}
ret += parts.join(', ');
ret += ')';
return ret;
}
function multiPointToWKTMultiPoint (primitive) {
var ret = 'MULTIPOINT ';
if (primitive.coordinates === undefined || primitive.coordinates.length === 0 || primitive.coordinates[0].length === 0) {
ret += 'EMPTY';
return ret;
} else if (primitive.coordinates[0].length === 3) {
if (primitive.properties && primitive.properties.m === true) {
ret += 'M ';
} else {
ret += 'Z ';
}
} else if (primitive.coordinates[0].length === 4) {
ret += 'ZM ';
}
ret += arrayToRing(primitive.coordinates);
return ret;
}
function multiLineStringToWKTMultiLineString (primitive) {
var ret = 'MULTILINESTRING ';
if (primitive.coordinates === undefined || primitive.coordinates.length === 0 || primitive.coordinates[0].length === 0) {
ret += 'EMPTY';
return ret;
} else if (primitive.coordinates[0][0].length === 3) {
if (primitive.properties && primitive.properties.m === true) {
ret += 'M ';
} else {
ret += 'Z ';
}
} else if (primitive.coordinates[0][0].length === 4) {
ret += 'ZM ';
}
ret += '(';
var parts = [ ];
for (var i = 0; i < primitive.coordinates.length; i++) {
parts.push(arrayToRing(primitive.coordinates[i]));
}
ret += parts.join(', ');
ret += ')';
return ret;
}
function multiPolygonToWKTMultiPolygon (primitive) {
var ret = 'MULTIPOLYGON ';
if (primitive.coordinates === undefined || primitive.coordinates.length === 0 || primitive.coordinates[0].length === 0) {
ret += 'EMPTY';
return ret;
} else if (primitive.coordinates[0][0][0].length === 3) {
if (primitive.properties && primitive.properties.m === true) {
ret += 'M ';
} else {
ret += 'Z ';
}
} else if (primitive.coordinates[0][0][0].length === 4) {
ret += 'ZM ';
}
ret += '(';
var inner = [ ];
for (var c = 0; c < primitive.coordinates.length; c++) {
var it = '(';
var parts = [ ];
for (var i = 0; i < primitive.coordinates[c].length; i++) {
parts.push(arrayToRing(primitive.coordinates[c][i]));
}
it += parts.join(', ');
it += ')';
inner.push(it);
}
ret += inner.join(', ');
ret += ')';
return ret;
}
function convert (primitive) {
switch (primitive.type) {
case 'Point':
return pointToWKTPoint(primitive);
case 'LineString':
return lineStringToWKTLineString(primitive);
case 'Polygon':
return polygonToWKTPolygon(primitive);
case 'MultiPoint':
return multiPointToWKTMultiPoint(primitive);
case 'MultiLineString':
return multiLineStringToWKTMultiLineString(primitive);
case 'MultiPolygon':
return multiPolygonToWKTMultiPolygon(primitive);
case 'GeometryCollection':
var ret = 'GEOMETRYCOLLECTION';
var parts = [ ];
for (i = 0; i < primitive.geometries.length; i++){
parts.push(convert(primitive.geometries[i]));
}
return ret + '(' + parts.join(', ') + ')';
default:
throw Error ("Unknown Type: " + primitive.type);
}
}
exports.parser = parser;
exports.Parser = parser.Parser;
exports.parse = parse;
exports.convert = convert;
return exports;
}));
(function (root, factory) {
// Node.
if(typeof module === 'object' && typeof module.exports === 'object') {
exports = module.exports = factory();
}
// Browser Global.
if(typeof window === "object") {
root.Terraformer = factory();
}
}(this, function(){
var exports = {},
EarthRadius = 6378137,
DegreesPerRadian = 57.295779513082320,
RadiansPerDegree = 0.017453292519943,
MercatorCRS = {
"type": "link",
"properties": {
"href": "http://spatialreference.org/ref/sr-org/6928/ogcwkt/",
"type": "ogcwkt"
}
},
GeographicCRS = {
"type": "link",
"properties": {
"href": "http://spatialreference.org/ref/epsg/4326/ogcwkt/",
"type": "ogcwkt"
}
};
/*
Internal: isArray function
*/
function isArray(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
}
/*
Internal: safe warning
*/
function warn() {
var args = Array.prototype.slice.apply(arguments);
if (typeof console !== undefined && console.warn) {
console.warn.apply(console, args);
}
}
/*
Internal: Extend one object with another.
*/
function extend(destination, source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
destination[k] = source[k];
}
}
return destination;
}
/*
Public: Calculate an bounding box for a geojson object
*/
function calculateBounds (geojson) {
if(geojson.type){
switch (geojson.type) {
case 'Point':
return [ geojson.coordinates[0], geojson.coordinates[1], geojson.coordinates[0], geojson.coordinates[1]];
case 'MultiPoint':
return calculateBoundsFromArray(geojson.coordinates);
case 'LineString':
return calculateBoundsFromArray(geojson.coordinates);
case 'MultiLineString':
return calculateBoundsFromNestedArrays(geojson.coordinates);
case 'Polygon':
return calculateBoundsFromNestedArrays(geojson.coordinates);
case 'MultiPolygon':
return calculateBoundsFromNestedArrayOfArrays(geojson.coordinates);
case 'Feature':
return geojson.geometry? calculateBounds(geojson.geometry) : null;
case 'FeatureCollection':
return calculateBoundsForFeatureCollection(geojson);
case 'GeometryCollection':
return calculateBoundsForGeometryCollection(geojson);
default:
throw new Error("Unknown type: " + geojson.type);
}
}
return null;
}
/*
Internal: Calculate an bounding box from an nested array of positions
[
[
[ [lng, lat],[lng, lat],[lng, lat] ]
]
[
[lng, lat],[lng, lat],[lng, lat]
]
[
[lng, lat],[lng, lat],[lng, lat]
]
]
*/
function calculateBoundsFromNestedArrays (array) {
var x1 = null, x2 = null, y1 = null, y2 = null;
for (var i = 0; i < array.length; i++) {
var inner = array[i];
for (var j = 0; j < inner.length; j++) {
var lonlat = inner[j];
var lon = lonlat[0];
var lat = lonlat[1];
if (x1 === null) {
x1 = lon;
} else if (lon < x1) {
x1 = lon;
}
if (x2 === null) {
x2 = lon;
} else if (lon > x2) {
x2 = lon;
}
if (y1 === null) {
y1 = lat;
} else if (lat < y1) {
y1 = lat;
}
if (y2 === null) {
y2 = lat;
} else if (lat > y2) {
y2 = lat;
}
}
}
return [x1, y1, x2, y2 ];
}
/*
Internal: Calculate a bounding box from an array of arrays of arrays
[
[ [lng, lat],[lng, lat],[lng, lat] ]
[ [lng, lat],[lng, lat],[lng, lat] ]
[ [lng, lat],[lng, lat],[lng, lat] ]
]
*/
function calculateBoundsFromNestedArrayOfArrays (array) {
var x1 = null, x2 = null, y1 = null, y2 = null;
for (var i = 0; i < array.length; i++) {
var inner = array[i];
for (var j = 0; j < inner.length; j++) {
var innerinner = inner[j];
for (var k = 0; k < innerinner.length; k++) {
var lonlat = innerinner[k];
var lon = lonlat[0];
var lat = lonlat[1];
if (x1 === null) {
x1 = lon;
} else if (lon < x1) {
x1 = lon;
}
if (x2 === null) {
x2 = lon;
} else if (lon > x2) {
x2 = lon;
}
if (y1 === null) {
y1 = lat;
} else if (lat < y1) {
y1 = lat;
}
if (y2 === null) {
y2 = lat;
} else if (lat > y2) {
y2 = lat;
}
}
}
}
return [x1, y1, x2, y2];
}
/*
Internal: Calculate a bounding box from an array of positions
[
[lng, lat],[lng, lat],[lng, lat]
]
*/
function calculateBoundsFromArray (array) {
var x1 = null, x2 = null, y1 = null, y2 = null;
for (var i = 0; i < array.length; i++) {
var lonlat = array[i];
var lon = lonlat[0];
var lat = lonlat[1];
if (x1 === null) {
x1 = lon;
} else if (lon < x1) {
x1 = lon;
}
if (x2 === null) {
x2 = lon;
} else if (lon > x2) {
x2 = lon;
}
if (y1 === null) {
y1 = lat;
} else if (lat < y1) {
y1 = lat;
}
if (y2 === null) {
y2 = lat;
} else if (lat > y2) {
y2 = lat;
}
}
return [x1, y1, x2, y2 ];
}
/*
Internal: Calculate an bounding box for a feature collection
*/
function calculateBoundsForFeatureCollection(featureCollection){
var extents = [], extent;
for (var i = featureCollection.features.length - 1; i >= 0; i--) {
extent = calculateBounds(featureCollection.features[i].geometry);
extents.push([extent[0],extent[1]]);
extents.push([extent[2],extent[3]]);
}
return calculateBoundsFromArray(extents);
}
/*
Internal: Calculate an bounding box for a geometry collection
*/
function calculateBoundsForGeometryCollection(geometryCollection){
var extents = [], extent;
for (var i = geometryCollection.geometries.length - 1; i >= 0; i--) {
extent = calculateBounds(geometryCollection.geometries[i]);
extents.push([extent[0],extent[1]]);
extents.push([extent[2],extent[3]]);
}
return calculateBoundsFromArray(extents);
}
function calculateEnvelope(geojson){
var bounds = calculateBounds(geojson);
return {
x: bounds[0],
y: bounds[1],
w: Math.abs(bounds[0] - bounds[2]),
h: Math.abs(bounds[1] - bounds[3])
};
}
/*
Internal: Convert radians to degrees. Used by spatial reference converters.
*/
function radToDeg(rad) {
return rad * DegreesPerRadian;
}
/*
Internal: Convert degrees to radians. Used by spatial reference converters.
*/
function degToRad(deg) {
return deg * RadiansPerDegree;
}
/*
Internal: Loop over each array in a geojson object and apply a function to it. Used by spatial reference converters.
*/
function eachPosition(coordinates, func) {
for (var i = 0; i < coordinates.length; i++) {
// we found a number so lets convert this pair
if(typeof coordinates[i][0] === "number"){
coordinates[i] = func(coordinates[i]);
}
// we found an coordinates array it again and run THIS function against it
if(typeof coordinates[i] === "object"){
coordinates[i] = eachPosition(coordinates[i], func);
}
}
return coordinates;
}
/*
Public: Convert a GeoJSON Position object to Geographic (4326)
*/
function positionToGeographic(position) {
var x = position[0];
var y = position[1];
return [radToDeg(x / EarthRadius) - (Math.floor((radToDeg(x / EarthRadius) + 180) / 360) * 360), radToDeg((Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * y / EarthRadius))))];
}
/*
Public: Convert a GeoJSON Position object to Web Mercator (102100)
*/
function positionToMercator(position) {
var lng = position[0];
var lat = Math.max(Math.min(position[1], 89.99999), -89.99999);
return [degToRad(lng) * EarthRadius, EarthRadius/2.0 * Math.log( (1.0 + Math.sin(degToRad(lat))) / (1.0 - Math.sin(degToRad(lat))) )];
}
/*
Public: Apply a function agaist all positions in a geojson object. Used by spatial reference converters.
*/
function applyConverter(geojson, converter, noCrs){
if(geojson.type === "Point") {
geojson.coordinates = converter(geojson.coordinates);
} else if(geojson.type === "Feature") {
geojson.geometry = applyConverter(geojson.geometry, converter, true);
} else if(geojson.type === "FeatureCollection") {
for (var f = 0; f < geojson.features.length; f++) {
geojson.features[f] = applyConverter(geojson.features[f], converter, true);
}
} else if(geojson.type === "GeometryCollection") {
for (var g = 0; g < geojson.geometries.length; g++) {
geojson.geometries[g] = applyConverter(geojson.geometries[g], converter, true);
}
} else {
geojson.coordinates = eachPosition(geojson.coordinates, converter);
}
if(!noCrs){
if(converter === positionToMercator){
geojson.crs = MercatorCRS;
}
}
if(converter === positionToGeographic){
delete geojson.crs;
}
return geojson;
}
/*
Public: Convert a GeoJSON object to ESRI Web Mercator (102100)
*/
function toMercator(geojson) {
return applyConverter(geojson, positionToMercator);
}
/*
Convert a GeoJSON object to Geographic coordinates (WSG84, 4326)
*/
function toGeographic(geojson) {
return applyConverter(geojson, positionToGeographic);
}
/*
Internal: -1,0,1 comparison function
*/
function cmp(a, b) {
if(a < b) {
return -1;
} else if(a > b) {
return 1;
} else {
return 0;
}
}
/*
Internal: used for sorting
*/
function compSort(p1, p2) {
if (p1[0] > p2[0]) {
return -1;
} else if (p1[0] < p2[0]) {
return 1;
} else if (p1[1] > p2[1]) {
return -1;
} else if (p1[1] < p2[1]) {
return 1;
} else {
return 0;
}
}
/*
Internal: used to determine turn
*/
function turn(p, q, r) {
// Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn.
return cmp((q[0] - p[0]) * (r[1] - p[1]) - (r[0] - p[0]) * (q[1] - p[1]), 0);
}
/*
Internal: used to determine euclidean distance between two points
*/
function euclideanDistance(p, q) {
// Returns the squared Euclidean distance between p and q.
var dx = q[0] - p[0];
var dy = q[1] - p[1];
return dx * dx + dy * dy;
}
function nextHullPoint(points, p) {
// Returns the next point on the convex hull in CCW from p.
var q = p;
for(var r in points) {
var t = turn(p, q, points[r]);
if(t === -1 || t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q)) {
q = points[r];
}
}
return q;
}
function convexHull(points) {
// implementation of the Jarvis March algorithm
// adapted from http://tixxit.wordpress.com/2009/12/09/jarvis-march/
if(points.length === 0) {
return [];
} else if(points.length === 1) {
return points;
}
// Returns the points on the convex hull of points in CCW order.
var hull = [points.sort(compSort)[0]];
for(var p = 0; p < hull.length; p++) {
var q = nextHullPoint(points, hull[p]);
if(q !== hull[0]) {
hull.push(q);
}
}
return hull;
}
function isConvex(points) {
var ltz;
for (var i = 0; i < points.length - 3; i++) {
var p1 = points[i];
var p2 = points[i + 1];
var p3 = points[i + 2];
var v = [p2[0] - p1[0], p2[1] - p1[1]];
// p3.x * v.y - p3.y * v.x + v.x * p1.y - v.y * p1.x
var res = p3[0] * v[1] - p3[1] * v[0] + v[0] * p1[1] - v[1] * p1[0];
if (i === 0) {
if (res < 0) {
ltz = true;
} else {
ltz = false;
}
} else {
if (ltz && (res > 0) || !ltz && (res < 0)) {
return false;
}
}
}
return true;
}
function coordinatesContainPoint(coordinates, point) {
var contains = false;
for(var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {
if (((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1]) ||
(coordinates[j][1] <= point[1] && point[1] < coordinates[i][1])) &&
(point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0])) {
contains = !contains;
}
}
return contains;
}
function polygonContainsPoint(polygon, point) {
if (polygon && polygon.length) {
if (polygon.length === 1) { // polygon with no holes
return coordinatesContainPoint(polygon[0], point);
} else { // polygon with holes
if (coordinatesContainPoint(polygon[0], point)) {
for (var i = 1; i < polygon.length; i++) {
if (coordinatesContainPoint(polygon[i], point)) {
return false; // found in hole
}
}
return true;
} else {
return false;
}
}
} else {
return false;
}
}
function edgeIntersectsEdge(a1, a2, b1, b2) {
var ua_t = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);
var ub_t = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);
var u_b = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);
if ( u_b !== 0 ) {
var ua = ua_t / u_b;
var ub = ub_t / u_b;
if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 ) {
return true;
}
}
return false;
}
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function arraysIntersectArrays(a, b) {
if (isNumber(a[0][0])) {
if (isNumber(b[0][0])) {
for (var i = 0; i < a.length - 1; i++) {
for (var j = 0; j < b.length - 1; j++) {
if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {
return true;
}
}
}
} else {
for (var k = 0; k < b.length; k++) {
if (arraysIntersectArrays(a, b[k])) {
return true;
}
}
}
} else {
for (var l = 0; l < a.length; l++) {
if (arraysIntersectArrays(a[l], b)) {
return true;
}
}
}
return false;
}
/*
Internal: Returns a copy of coordinates for s closed polygon
*/
function closedPolygon(coordinates) {
var outer = [ ];
for (var i = 0; i < coordinates.length; i++) {
var inner = coordinates[i].slice();
if (pointsEqual(inner[0], inner[inner.length - 1]) === false) {
inner.push(inner[0]);
}
outer.push(inner);
}
return outer;
}
function pointsEqual(a, b) {
for (var i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
function coordinatesEqual(a, b) {
if (a.length !== b.length) {
return false;
}
var na = a.slice().sort(compSort);
var nb = b.slice().sort(compSort);
for (var i = 0; i < na.length; i++) {
if (na[i].length !== nb[i].length) {
return false;
}
for (var j = 0; j < na.length; j++) {
if (na[i][j] !== nb[i][j]) {
return false;
}
}
}
return true;
}
/*
Internal: An array of variables that will be excluded form JSON objects.
*/
var excludeFromJSON = ["length"];
/*
Internal: Base GeoJSON Primitive
*/
function Primitive(geojson){
if(geojson){
switch (geojson.type) {
case 'Point':
return new Point(geojson);
case 'MultiPoint':
return new MultiPoint(geojson);
case 'LineString':
return new LineString(geojson);
case 'MultiLineString':
return new MultiLineString(geojson);
case 'Polygon':
return new Polygon(geojson);
case 'MultiPolygon':
return new MultiPolygon(geojson);
case 'Feature':
return new Feature(geojson);
case 'FeatureCollection':
return new FeatureCollection(geojson);
case 'GeometryCollection':
return new GeometryCollection(geojson);
default:
throw new Error("Unknown type: " + geojson.type);
}
}
}
Primitive.prototype.toMercator = function(){
return toMercator(this);
};
Primitive.prototype.toGeographic = function(){
return toGeographic(this);
};
Primitive.prototype.envelope = function(){
return calculateEnvelope(this);
};
Primitive.prototype.bbox = function(){
return calculateBounds(this);
};
Primitive.prototype.convexHull = function(){
var coordinates = [ ], i, j;
if (this.type === 'Point') {
return null;
} else if (this.type === 'LineString' || this.type === 'MultiPoint') {
if (this.coordinates && this.coordinates.length >= 3) {
coordinates = this.coordinates;
} else {
return null;
}
} else if (this.type === 'Polygon' || this.type === 'MultiLineString') {
if (this.coordinates && this.coordinates.length > 0) {
for (i = 0; i < this.coordinates.length; i++) {
coordinates = coordinates.concat(this.coordinates[i]);
}
if(coordinates.length < 3){
return null;
}
} else {
return null;
}
} else if (this.type === 'MultiPolygon') {
if (this.coordinates && this.coordinates.length > 0) {
for (i = 0; i < this.coordinates.length; i++) {
for (j = 0; j < this.coordinates[i].length; j++) {
coordinates = coordinates.concat(this.coordinates[i][j]);
}
}
if(coordinates.length < 3){
return null;
}
} else {
return null;
}
} else if(this.type === "Feature"){
var primitive = new Primitive(this.geometry);
return primitive.convexHull();
}
return new Polygon({
type: 'Polygon',
coordinates: closedPolygon([convexHull(coordinates)])
});
};
Primitive.prototype.toJSON = function(){
var obj = {};
for (var key in this) {
if (this.hasOwnProperty(key) && excludeFromJSON.indexOf(key) === -1) {
obj[key] = this[key];
}
}
obj.bbox = calculateBounds(this);
return obj;
};
Primitive.prototype.contains = function(primitive){
return new Primitive(primitive).within(this);
};
Primitive.prototype.within = function(primitive) {
var coordinates, i, contains;
// if we are passed a feature, use the polygon inside instead
if (primitive.type === 'Feature') {
primitive = primitive.geometry;
}
// point.within(point) :: equality
if (primitive.type === "Point") {
if (this.type === "Point") {
return pointsEqual(this.coordinates, primitive.coordinates);
}
}
// point.within(multilinestring)
if (primitive.type === "MultiLineString") {
if (this.type === "Point") {
for (i = 0; i < primitive.coordinates.length; i++) {
var linestring = { type: "LineString", coordinates: primitive.coordinates[i] };
if (this.within(linestring)) {
return true;
}
}
}
}
// point.within(linestring), point.within(multipoint)
if (primitive.type === "LineString" || primitive.type === "MultiPoint") {
if (this.type === "Point") {
for (i = 0; i < primitive.coordinates.length; i++) {
if (this.coordinates.length !== primitive.coordinates[i].length) {
return false;
}
if (pointsEqual(this.coordinates, primitive.coordinates[i])) {
return true;
}
}
}
}
if (primitive.type === "Polygon") {
// polygon.within(polygon)
if (this.type === "Polygon") {
// check for equal polygons
if (primitive.coordinates.length === this.coordinates.length) {
for (i = 0; i < this.coordinates.length; i++) {
if (coordinatesEqual(this.coordinates[i], primitive.coordinates[i])) {
return true;
}
}
}
if (this.coordinates.length && polygonContainsPoint(primitive.coordinates, this.coordinates[0][0])) {
return !arraysIntersectArrays(closedPolygon(this.coordinates), closedPolygon(primitive.coordinates));
} else {
return false;
}
// point.within(polygon)
} else if (this.type === "Point") {
return polygonContainsPoint(primitive.coordinates, this.coordinates);
// linestring/multipoint withing polygon
} else if (this.type === "LineString" || this.type === "MultiPoint") {
if (!this.coordinates || this.coordinates.length === 0) {
return false;
}
for (i = 0; i < this.coordinates.length; i++) {
if (polygonContainsPoint(primitive.coordinates, this.coordinates[i]) === false) {
return false;
}
}
return true;
// multilinestring.within(polygon)
} else if (this.type === "MultiLineString") {
for (i = 0; i < this.coordinates.length; i++) {
var ls = new LineString(this.coordinates[i]);
if (ls.within(primitive) === false) {
contains++;
return false;
}
}
return true;
// multipolygon.within(polygon)
} else if (this.type === "MultiPolygon") {
for (i = 0; i < this.coordinates.length; i++) {
var p1 = new Primitive({ type: "Polygon", coordinates: this.coordinates[i] });
if (p1.within(primitive) === false) {
return false;
}
}
return true;
}
}
if (primitive.type === "MultiPolygon") {
// point.within(multipolygon)
if (this.type === "Point") {
if (primitive.coordinates.length) {
for (i = 0; i < primitive.coordinates.length; i++) {
coordinates = primitive.coordinates[i];
if (polygonContainsPoint(coordinates, this.coordinates) && arraysIntersectArrays([this.coordinates], primitive.coordinates) === false) {
return true;
}
}
}
return false;
// polygon.within(multipolygon)
} else if (this.type === "Polygon") {
for (i = 0; i < this.coordinates.length; i++) {
if (primitive.coordinates[i].length === this.coordinates.length) {
for (j = 0; j < this.coordinates.length; j++) {
if (coordinatesEqual(this.coordinates[j], primitive.coordinates[i][j])) {
return true;
}
}
}
}
if (arraysIntersectArrays(this.coordinates, primitive.coordinates) === false) {
if (primitive.coordinates.length) {
for (i = 0; i < primitive.coordinates.length; i++) {
coordinates = primitive.coordinates[i];
if (polygonContainsPoint(coordinates, this.coordinates[0][0]) === false) {
contains = false;
} else {
contains = true;
}
}
return contains;
}
}
// linestring.within(multipolygon), multipoint.within(multipolygon)
} else if (this.type === "LineString" || this.type === "MultiPoint") {
for (i = 0; i < primitive.coordinates.length; i++) {
var p = { type: "Polygon", coordinates: primitive.coordinates[i] };
if (this.within(p)) {
return true;
}
return false;
}
// multilinestring.within(multipolygon)
} else if (this.type === "MultiLineString") {
for (i = 0; i < this.coordinates.length; i++) {
var lines = new LineString(this.coordinates[i]);
if (lines.within(primitive) === false) {
return false;
}
}
return true;
// multipolygon.within(multipolygon)
} else if (this.type === "MultiPolygon") {
for (i = 0; i < primitive.coordinates.length; i++) {
var mpoly = { type: "Polygon", coordinates: primitive.coordinates[i] };
if (this.within(mpoly) === false) {
return false;
}
}
return true;
}
}
// default to false
return false;
};
Primitive.prototype.intersects = function(primitive) {
// if we are passed a feature, use the polygon inside instead
if (primitive.type === 'Feature') {
primitive = primitive.geometry;
}
var p = new Primitive(primitive);
if (this.within(primitive) || p.within(this)) {
return true;
}
if (this.type !== 'Point' && this.type !== 'MultiPoint' &&
primitive.type !== 'Point' && primitive.type !== 'MultiPoint') {
return arraysIntersectArrays(this.coordinates, primitive.coordinates);
} else if (this.type === 'Feature') {
// in the case of a Feature, use the internal primitive for intersection
var inner = new Primitive(this.geometry);
return inner.intersects(primitive);
}
warn("Type " + this.type + " to " + primitive.type + " intersection is not supported by intersects");
return false;
};
/*
GeoJSON Point Class
new Point();
new Point(x,y,z,wtf);
new Point([x,y,z,wtf]);
new Point([x,y]);
new Point({
type: "Point",
coordinates: [x,y]
});
*/
function Point(input){
var args = Array.prototype.slice.call(arguments);
if(input && input.type === "Point" && input.coordinates){
extend(this, input);
} else if(input && isArray(input)) {
this.coordinates = input;
} else if(args.length >= 2) {
this.coordinates = args;
} else {
throw "Terraformer: invalid input for Terraformer.Point";
}
this.type = "Point";
}
Point.prototype = new Primitive();
Point.prototype.constructor = Point;
/*
GeoJSON MultiPoint Class
new MultiPoint();
new MultiPoint([[x,y], [x1,y1]]);
new MultiPoint({
type: "MultiPoint",
coordinates: [x,y]
});
*/
function MultiPoint(input){
if(input && input.type === "MultiPoint" && input.coordinates){
extend(this, input);
} else if(isArray(input)) {
this.coordinates = input;
} else {
throw "Terraformer: invalid input for Terraformer.MultiPoint";
}
this.type = "MultiPoint";
}
MultiPoint.prototype = new Primitive();
MultiPoint.prototype.constructor = MultiPoint;
MultiPoint.prototype.forEach = function(func){
for (var i = 0; i < this.coordinates.length; i++) {
func.apply(this, [this.coordinates[i], i, this.coordinates]);
}
return this;
};
MultiPoint.prototype.addPoint = function(point){
this.coordinates.push(point);
return this;
};
MultiPoint.prototype.insertPoint = function(point, index){
this.coordinates.splice(index, 0, point);
return this;
};
MultiPoint.prototype.removePoint = function(remove){
if(typeof remove === "number"){
this.coordinates.splice(remove, 1);
} else {
this.coordinates.splice(this.coordinates.indexOf(remove), 1);
}
return this;
};
MultiPoint.prototype.get = function(i){
return new Point(this.coordinates[i]);
};
/*
GeoJSON LineString Class
new LineString();
new LineString([[x,y], [x1,y1]]);
new LineString({
type: "LineString",
coordinates: [x,y]
});
*/
function LineString(input){
if(input && input.type === "LineString" && input.coordinates){
extend(this, input);
} else if(isArray(input)) {
this.coordinates = input;
} else {
throw "Terraformer: invalid input for Terraformer.LineString";
}
this.type = "LineString";
}
LineString.prototype = new Primitive();
LineString.prototype.constructor = LineString;
LineString.prototype.addVertex = function(point){
this.coordinates.push(point);
return this;
};
LineString.prototype.insertVertex = function(point, index){
this.coordinates.splice(index, 0, point);
return this;
};
LineString.prototype.removeVertex = function(remove){
this.coordinates.splice(remove, 1);
return this;
};
/*
GeoJSON MultiLineString Class
new MultiLineString();
new MultiLineString([ [[x,y], [x1,y1]], [[x2,y2], [x3,y3]] ]);
new MultiLineString({
type: "MultiLineString",
coordinates: [ [[x,y], [x1,y1]], [[x2,y2], [x3,y3]] ]
});
*/
function MultiLineString(input){
if(input && input.type === "MultiLineString" && input.coordinates){
extend(this, input);
} else if(isArray(input)) {
this.coordinates = input;
} else {
throw "Terraformer: invalid input for Terraformer.MultiLineString";
}
this.type = "MultiLineString";
}
MultiLineString.prototype = new Primitive();
MultiLineString.prototype.constructor = MultiLineString;
MultiLineString.prototype.forEach = function(func){
for (var i = 0; i < this.coordinates.length; i++) {
func.apply(this, [this.coordinates[i], i, this.coordinates ]);
}
};
MultiLineString.prototype.get = function(i){
return new LineString(this.coordinates[i]);
};
/*
GeoJSON Polygon Class
new Polygon();
new Polygon([ [[x,y], [x1,y1], [x2,y2]] ]);
new Polygon({
type: "Polygon",
coordinates: [ [[x,y], [x1,y1], [x2,y2]] ]
});
*/
function Polygon(input){
if(input && input.type === "Polygon" && input.coordinates){
extend(this, input);
} else if(isArray(input)) {
this.coordinates = input;
} else {
throw "Terraformer: invalid input for Terraformer.Polygon";
}
this.type = "Polygon";
}
Polygon.prototype = new Primitive();
Polygon.prototype.constructor = Polygon;
Polygon.prototype.addVertex = function(point){
this.insertVertex(point, this.coordinates[0].length - 1);
return this;
};
Polygon.prototype.insertVertex = function(point, index){
this.coordinates[0].splice(index, 0, point);
return this;
};
Polygon.prototype.removeVertex = function(remove){
this.coordinates[0].splice(remove, 1);
return this;
};
Polygon.prototype.close = function() {
this.coordinates = closedPolygon(this.coordinates);
};
Polygon.prototype.hasHoles = function() {
return this.coordinates.length > 1;
};
Polygon.prototype.holes = function() {
holes = [];
if (this.hasHoles()) {
for (var i = 1; i < this.coordinates.length; i++) {
holes.push(new Polygon([this.coordinates[i]]));
}
}
return holes;
};
/*
GeoJSON MultiPolygon Class
new MultiPolygon();
new MultiPolygon([ [ [[x,y], [x1,y1]], [[x2,y2], [x3,y3]] ] ]);
new MultiPolygon({
type: "MultiPolygon",
coordinates: [ [ [[x,y], [x1,y1]], [[x2,y2], [x3,y3]] ] ]
});
*/
function MultiPolygon(input){
if(input && input.type === "MultiPolygon" && input.coordinates){
extend(this, input);
} else if(isArray(input)) {
this.coordinates = input;
} else {
throw "Terraformer: invalid input for Terraformer.MultiPolygon";
}
this.type = "MultiPolygon";
}
MultiPolygon.prototype = new Primitive();
MultiPolygon.prototype.constructor = MultiPolygon;
MultiPolygon.prototype.forEach = function(func){
for (var i = 0; i < this.coordinates.length; i++) {
func.apply(this, [this.coordinates[i], i, this.coordinates ]);
}
};
MultiPolygon.prototype.get = function(i){
return new Polygon(this.coordinates[i]);
};
MultiPolygon.prototype.close = function(){
var outer = [];
this.forEach(function(polygon){
outer.push(closedPolygon(polygon));
});
this.coordinates = outer;
return this;
};
/*
GeoJSON Feature Class
new Feature();
new Feature({
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [ [ [[x,y], [x1,y1]], [[x2,y2], [x3,y3]] ] ]
}
});
new Feature({
type: "Polygon",
coordinates: [ [ [[x,y], [x1,y1]], [[x2,y2], [x3,y3]] ] ]
});
*/
function Feature(input){
if(input && input.type === "Feature"){
extend(this, input);
} else if(input && input.type && input.coordinates) {
this.geometry = input;
} else {
throw "Terraformer: invalid input for Terraformer.Feature";
}
this.type = "Feature";
}
Feature.prototype = new Primitive();
Feature.prototype.constructor = Feature;
/*
GeoJSON FeatureCollection Class
new FeatureCollection();
new FeatureCollection([feature, feature1]);
new FeatureCollection({
type: "FeatureCollection",
coordinates: [feature, feature1]
});
*/
function FeatureCollection(input){
if(input && input.type === "FeatureCollection" && input.features){
extend(this, input);
} else if(isArray(input)) {
this.features = input;
} else {
throw "Terraformer: invalid input for Terraformer.FeatureCollection";
}
this.type = "FeatureCollection";
}
FeatureCollection.prototype = new Primitive();
FeatureCollection.prototype.constructor = FeatureCollection;
FeatureCollection.prototype.forEach = function(func){
for (var i = 0; i < this.features.length; i++) {
func.apply(this, [this.features[i], i, this.features]);
}
};
FeatureCollection.prototype.get = function(id){
var found;
this.forEach(function(feature){
if(feature.id === id){
found = feature;
}
});
return new Feature(found);
};
/*
GeoJSON GeometryCollection Class
new GeometryCollection();
new GeometryCollection([geometry, geometry1]);
new GeometryCollection({
type: "GeometryCollection",
coordinates: [geometry, geometry1]
});
*/
function GeometryCollection(input){
if(input && input.type === "GeometryCollection" && input.geometries){
extend(this, input);
} else if(isArray(input)) {
this.geometries = input;
} else if(input.coordinates && input.type){
this.type = "GeometryCollection";
this.geometries = [input];
} else {
throw "Terraformer: invalid input for Terraformer.GeometryCollection";
}
this.type = "GeometryCollection";
}
GeometryCollection.prototype = new Primitive();
GeometryCollection.prototype.constructor = GeometryCollection;
GeometryCollection.prototype.forEach = function(func){
for (var i = 0; i < this.geometries.length; i++) {
func.apply(this, [this.geometries[i], i, this.geometries]);
}
};
GeometryCollection.prototype.get = function(i){
return new Primitive(this.geometries[i]);
};
function createCircle(center, radius, interpolate){
var mercatorPosition = positionToMercator(center);
var steps = interpolate || 64;
var polygon = {
type: "Polygon",
coordinates: [[]]
};
for(var i=1; i<=steps; i++) {
var radians = i * (360/steps) * Math.PI / 180;
polygon.coordinates[0].push([mercatorPosition[0] + radius * Math.cos(radians), mercatorPosition[1] + radius * Math.sin(radians)]);
}
polygon.coordinates = closedPolygon(polygon.coordinates);
return toGeographic(polygon);
}
function Circle (center, radius, interpolate) {
var steps = interpolate || 64;
var rad = radius || 250;
if(!center || center.length < 2 || !rad || !steps) {
throw new Error("Terraformer: missing parameter for Terraformer.Circle");
}
extend(this, new Feature({
type: "Feature",
geometry: createCircle(center, rad, steps),
properties: {
radius: rad,
center: center,
steps: steps
}
}));
}
Circle.prototype = new Primitive();
Circle.prototype.constructor = Circle;
Circle.prototype.recalculate = function(){
this.geometry = createCircle(this.properties.center, this.properties.radius, this.properties.steps);
return this;
};
Circle.prototype.center = function(coordinates){
if(coordinates){
this.properties.center = coordinates;
this.recalculate();
}
return this.properties.center;
};
Circle.prototype.radius = function(radius){
if(radius){
this.properties.radius = radius;
this.recalculate();
}
return this.properties.radius;
};
Circle.prototype.steps = function(steps){
if(steps){
this.properties.steps = steps;
this.recalculate();
}
return this.properties.steps;
};
Circle.prototype.toJSON = function() {
var output = Primitive.prototype.toJSON.call(this);
return output;
};
exports.Primitive = Primitive;
exports.Point = Point;
exports.MultiPoint = MultiPoint;
exports.LineString = LineString;
exports.MultiLineString = MultiLineString;
exports.Polygon = Polygon;
exports.MultiPolygon = MultiPolygon;
exports.Feature = Feature;
exports.FeatureCollection = FeatureCollection;
exports.GeometryCollection = GeometryCollection;
exports.Circle = Circle;
exports.toMercator = toMercator;
exports.toGeographic = toGeographic;
exports.Tools = {};
exports.Tools.positionToMercator = positionToMercator;
exports.Tools.positionToGeographic = positionToGeographic;
exports.Tools.applyConverter = applyConverter;
exports.Tools.toMercator = toMercator;
exports.Tools.toGeographic = toGeographic;
exports.Tools.createCircle = createCircle;
exports.Tools.calculateBounds = calculateBounds;
exports.Tools.calculateEnvelope = calculateEnvelope;
exports.Tools.coordinatesContainPoint = coordinatesContainPoint;
exports.Tools.polygonContainsPoint = polygonContainsPoint;
exports.Tools.arraysIntersectArrays = arraysIntersectArrays;
exports.Tools.coordinatesContainPoint = coordinatesContainPoint;
exports.Tools.coordinatesEqual = coordinatesEqual;
exports.Tools.convexHull = convexHull;
exports.Tools.isConvex = isConvex;
exports.MercatorCRS = MercatorCRS;
exports.GeographicCRS = GeographicCRS;
return exports;
}));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment