/************************************************************************ 設定 ************************************************************************/ var GSI = { ClientMode: {} , Modal: {} , Draw: {} , Edit: {} , Control: {} , Utils: { Browser: {} } , GLOBALS: {} , TEXT: {} , FILEURL: {} }; GSI.TEXT = GSITEXT; /************************************************************************ モバイル判定 ************************************************************************/ if (location.pathname.indexOf(CONFIG.MOBILE_FILENAME) < 0) { if ( navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0 ) { var hash = location.hash; if (!hash || hash.indexOf("&frommobile") < 0) { location.href = CONFIG.MOBILEURL + hash; } } } /************************************************************************ jQuery メソッド補完、追加 ************************************************************************/ jQuery.extend({ stringify: function stringify(obj) { var t = typeof (obj); if (t != "object" || obj === null) { // simple data type if (t == "string") obj = '"' + obj + '"'; return String(obj); } else { // recurse array or object var json = [], arr = (obj && obj.constructor == Array); for (var n in obj) { var v = obj[n]; t = typeof (v); if (obj.hasOwnProperty(n)) { if (t == "string") v = '"' + v + '"'; else if (t == "object" && v !== null) v = jQuery.stringify(v); json.push((arr ? "" : '"' + n + '":') + String(v)); } } return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); } } }); try { window.console = window.console || { log: function () { } }; } catch (e) { } try { window.JSON || (window.JSON = { parse: function (src) { return $.parseJSON(src); }, stringify: function (obj) { return $.stringify(obj); } }); } catch (e) { } // ie8 array のmap, filterメソッド追加 try { (function (fn) { if (!fn.map) fn.map = function (f) { var r = []; for (var i = 0; i < this.length; i++)if (this[i] !== undefined) r[i] = f(this[i]); return r; } if (!fn.filter) fn.filter = function (f) { var r = []; for (var i = 0; i < this.length; i++)if (this[i] !== undefined && f(this[i])) r[i] = this[i]; return r; } })(Array.prototype); } catch (e) { } // leafletのsetOpacityがIE8で利かないためjQueryに任せる L.DomUtil.setOpacity = function (el, opacity) { $(el).css({ opacity: opacity }); }; // JQuery.ajax IE11の場合XMLHttpRequestを使用させるため if (window.ActiveXObject !== undefined && !window.XDomainRequest) { jQuery.ajaxSettings.xhr = function () { try { return new window.XMLHttpRequest(); } catch (e) { } }; } /************************************************************************ Proj4js ************************************************************************/ Proj4js.defs["EPSG:3097"] = "+proj=utm +zone=51 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; //UTM Zone51 Proj4js.defs["EPSG:3098"] = "+proj=utm +zone=52 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; //UTM Zone52 Proj4js.defs["EPSG:3099"] = "+proj=utm +zone=53 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; //UTM Zone53 Proj4js.defs["EPSG:3100"] = "+proj=utm +zone=54 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; //UTM Zone54 Proj4js.defs["EPSG:3101"] = "+proj=utm +zone=55 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; //UTM Zone55 Proj4js.defs["SR-ORG:1235"] = "+proj=utm +zone=56 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; //UTM Zone56 Proj4js.defs['EPSG:4301'] = "+proj=longlat +ellps=bessel +towgs84=-146.336,506.832,680.254,0,0,0,0 +no_defs"; //日本測地系(経緯度座標) Proj4js.defs["EPSG:4612"] = "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"; Proj4js.defs["EPSG:4019"] = "+proj=longlat +ellps=GRS80 +no_defs"; Proj4js.defs["EPSG:3857"] = "+title= Google Mercator EPSG:3857 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"; Proj4js.defs["EPSG:32651"] = "+proj=utm +zone=51 +datum=WGS84 +units=m +no_defs"; Proj4js.defs["EPSG:32652"] = "+proj=utm +zone=52 +datum=WGS84 +units=m +no_defs"; Proj4js.defs["EPSG:32653"] = "+proj=utm +zone=53 +datum=WGS84 +units=m +no_defs"; Proj4js.defs["EPSG:32654"] = "+proj=utm +zone=54 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"; Proj4js.defs["EPSG:32655"] = "+proj=utm +zone=55 +datum=WGS84 +units=m +no_defs"; Proj4js.defs["EPSG:32656"] = "+proj=utm +zone=56 +datum=WGS84 +units=m +no_defs"; Proj4js.defs["EPSG:6668"] = "+proj=longlat +ellps=GRS80 +no_defs"; Proj4js.defs["EPSG:6669"] = "+proj=tmerc +lat_0=33 +lon_0=129.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6670"] = "+proj=tmerc +lat_0=33 +lon_0=131 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6671"] = "+proj=tmerc +lat_0=36 +lon_0=132.1666666666667 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6672"] = "+proj=tmerc +lat_0=33 +lon_0=133.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6673"] = "+proj=tmerc +lat_0=36 +lon_0=134.3333333333333 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6674"] = "+proj=tmerc +lat_0=36 +lon_0=136 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6675"] = "+proj=tmerc +lat_0=36 +lon_0=137.1666666666667 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6676"] = "+proj=tmerc +lat_0=36 +lon_0=138.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6677"] = "+proj=tmerc +lat_0=36 +lon_0=139.8333333333333 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6678"] = "+proj=tmerc +lat_0=40 +lon_0=140.8333333333333 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6679"] = "+proj=tmerc +lat_0=44 +lon_0=140.25 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6680"] = "+proj=tmerc +lat_0=44 +lon_0=142.25 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6681"] = "+proj=tmerc +lat_0=44 +lon_0=144.25 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6682"] = "+proj=tmerc +lat_0=26 +lon_0=142 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6683"] = "+proj=tmerc +lat_0=26 +lon_0=127.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6684"] = "+proj=tmerc +lat_0=26 +lon_0=124 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6685"] = "+proj=tmerc +lat_0=26 +lon_0=131 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6686"] = "+proj=tmerc +lat_0=20 +lon_0=136 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs"; Proj4js.defs["EPSG:6688"] = "+proj=utm +zone=51 +ellps=GRS80 +datum=WGS80 +units=m +no_defs"; Proj4js.defs["EPSG:6689"] = "+proj=utm +zone=52 +ellps=GRS80 +datum=WGS80 +units=m +no_defs"; Proj4js.defs["EPSG:6690"] = "+proj=utm +zone=53 +ellps=GRS80 +datum=WGS80 +units=m +no_defs"; Proj4js.defs["EPSG:6691"] = "+proj=utm +zone=54 +ellps=GRS80 +datum=WGS80 +units=m +no_defs"; Proj4js.defs["EPSG:6692"] = "+proj=utm +zone=55 +ellps=GRS80 +datum=WGS80 +units=m +no_defs"; Proj4js.defs["EPSG:2443"] = "+proj=tmerc +lat_0=33 +lon_0=129.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2444"] = "+proj=tmerc +lat_0=33 +lon_0=131 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2445"] = "+proj=tmerc +lat_0=36 +lon_0=132.1666666666667 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2446"] = "+proj=tmerc +lat_0=33 +lon_0=133.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2447"] = "+proj=tmerc +lat_0=36 +lon_0=134.3333333333333 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2448"] = "+proj=tmerc +lat_0=36 +lon_0=136 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2449"] = "+proj=tmerc +lat_0=36 +lon_0=137.1666666666667 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2450"] = "+proj=tmerc +lat_0=36 +lon_0=138.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2451"] = "+proj=tmerc +lat_0=36 +lon_0=139.8333333333333 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2452"] = "+proj=tmerc +lat_0=40 +lon_0=140.8333333333333 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2453"] = "+proj=tmerc +lat_0=44 +lon_0=140.25 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2454"] = "+proj=tmerc +lat_0=44 +lon_0=142.25 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2455"] = "+proj=tmerc +lat_0=44 +lon_0=144.25 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2456"] = "+proj=tmerc +lat_0=26 +lon_0=142 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2457"] = "+proj=tmerc +lat_0=26 +lon_0=127.5 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2458"] = "+proj=tmerc +lat_0=26 +lon_0=124 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2459"] = "+proj=tmerc +lat_0=26 +lon_0=131 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2460"] = "+proj=tmerc +lat_0=20 +lon_0=136 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Proj4js.defs["EPSG:2461"] = "+proj=tmerc +lat_0=26 +lon_0=154 +k=0.9999 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" dslorethumbnail_click = function (elements) { var x = new GSI.Modal.dsloreDialog(elements); x.show(); //return false; }; /************************************************************************ GSI.Draw L.FeatureGroup L.Polygon L.Draw.Circle L.Draw.Polyline L.Draw.Polygon L.Draw.SimpleShape ************************************************************************/ L.Draw.SimpleShape.prototype._onMouseUp = function () { if (this._shape) { this._fireCreatedEvent(); this.disable(); } else { this.disable(); if (this.options.repeatMode) { this.enable(); } } }; L.FeatureGroup.include({ closePopup: function () { for (var id in this._layers) { this._layers[id].closePopup(); } return this; }, unbindPopup: function () { for (var id in this._layers) { this._layers[id].unbindPopup(); } return this; } }); GSI.Circle = L.Circle.extend({ initialize: function (latlng, radius, options) { this._bounds = new L.LatLngBounds(); L.Circle.prototype.initialize.call(this, latlng, radius, options); this._circleToLatLngs(); }, _circleToLatLngs: function () { var idx = 0; var latlngs = []; latlngs[idx] = [] var numSides = CONFIG.CIRCLETOPOLYGONNUMSIDES; var center = this.getLatLng(); var radius = this._mRadius; var wrap = false; var direct = GSI.Utils.Geodesic.vincentyDirect(center, 0, radius, wrap); var prev = L.latLng(direct.lat, direct.lng); latlngs[idx].push(prev); var isOver = false; if (prev.lat > 85.0511287798 || prev.lat < -85.0511287798) isOver = true; for (step = 1; step <= numSides;) { direct = GSI.Utils.Geodesic.vincentyDirect(center, 360 / numSides * step, radius, wrap); var gp = L.latLng(direct.lat, direct.lng); if (Math.abs(gp.lng - prev.lng) > 180) { var inverse = GSI.Utils.Geodesic.vincentyInverse(prev, gp); var sec = GSI.Utils.Geodesic.intersection(prev, inverse.initialBearing, { lat: -89, lng: ((gp.lng - prev.lng) > 0) ? -GSI.Utils.Geodesic.INTERSECT_LNG : GSI.Utils.Geodesic.INTERSECT_LNG }, 0); if (sec) { latlngs[idx].push(L.latLng(sec.lat, sec.lng)); idx++; latlngs[idx] = []; prev = L.latLng(sec.lat, -sec.lng); latlngs[idx].push(prev); if (sec.lat > 85.0511287798 || sec.lat < -85.0511287798) isOver = true; if (prev.lat > 85.0511287798 || prev.lat < -85.0511287798) isOver = true; } else { idx++; latlngs[idx] = []; latlngs[idx].push(gp); prev = gp; step++; if (gp.lat > 85.0511287798 || gp.lat < -85.0511287798) isOver = true; } } else { latlngs[idx].push(gp); prev = gp; step++; if (gp.lat > 85.0511287798 || gp.lat < -85.0511287798) isOver = true; } } this._latlngs = this._convertLatLngs(latlngs); if (isOver) { try { if (this._strokeLine) this._strokeLine.remove(); this._strokeLine = null; } catch (ex) { } this._lineLatLngs = this._makeStrokeLine(latlngs); if (this._map) { this._strokeLine = L.polyline(this._lineLatLngs, { color: this.options.color, stroke: this.options.stroke, fill: false, opacity: this.options.opacity, weight: this.options.weight, lineCap: this.options.lineCap, lineJoin: this.options.lineJoin, dashArray: this.options.dashArray }).addTo(this._map); } } else { this._lineLatLngs = null; try { if (this._strokeLine) this._strokeLine.remove(); this._strokeLine = null; } catch (ex) { } } }, onAdd: function () { this._renderer._initPath(this); this._reset(); this._renderer._addPath(this); try { if (this._strokeLine) this._strokeLine.remove(); this._strokeLine = null; } catch (ex) { } if (this._lineLatLngs) this._strokeLine = L.polyline(this._lineLatLngs, { color: this.options.color, stroke: this.options.stroke, fill: false, opacity: this.options.opacity, weight: this.options.weight, lineCap: this.options.lineCap, lineJoin: this.options.lineJoin, dashArray: this.options.dashArray }).addTo(this._map); }, onRemove: function () { this._renderer._removePath(this); if (this._strokeLine) this._strokeLine.remove(); this._strokeLine = null; }, _makeStrokeLine: function (latlngs) { var result = []; var prevLatLng = null; var MAX_LAT = 85.0511287798; var MIN_LAT = -85.0511287798; for (var i = 0; i < latlngs.length; i++) { var arr = []; for (var j = 0; j < latlngs[i].length; j++) { var latlng = L.latLng(latlngs[i][j]); if (latlng.lat > MAX_LAT) { if (prevLatLng && prevLatLng.lat < MAX_LAT) arr.push(L.latLng(MAX_LAT, latlng.lng)); result.push(arr); arr = []; } else if (latlng.lat < MIN_LAT) { if (prevLatLng && prevLatLng.lat > MIN_LAT) arr.push(L.latLng(MIN_LAT, latlng.lng)); result.push(arr); arr = []; } else { if (prevLatLng) { if (prevLatLng.lat > MAX_LAT) arr.push(L.latLng(MAX_LAT, prevLatLng.lng)); else if (prevLatLng.lat < MIN_LAT) arr.push(L.latLng(MIN_LAT, prevLatLng.lng)); } arr.push(latlng); } prevLatLng = latlng; } if (arr.length > 0) result.push(arr); } return result; }, _simplifyPoints: function () { var parts = this._parts, tolerance = this.options.smoothFactor; for (var i = 0, len = parts.length; i < len; i++) { parts[i] = L.LineUtil.simplify(parts[i], tolerance); } }, _update: function () { if (!this._map) { return; } this._circleToLatLngs(); this._clipPoints(); this._simplifyPoints(); this._updatePath(); }, _clipPoints: function () { // polygons need a different clipping algorithm so we redefine that var bounds = this._renderer._bounds, w = this.options.weight, p = new L.Point(w, w); // increase clip padding by stroke width to avoid stroke on clip edges bounds = new L.Bounds(bounds.min.subtract(p), bounds.max.add(p)); this._parts = []; if (!this._pxBounds || !this._pxBounds.intersects(bounds)) { return; } if (this.options.noClip) { this._parts = this._rings; return; } for (var i = 0, len = this._rings.length, clipped; i < len; i++) { clipped = L.PolyUtil.clipPolygon(this._rings[i], bounds, true); if (clipped.length) { this._parts.push(clipped); } } }, _project: function () { L.Circle.prototype._project.call(this); var pxBounds = new L.Bounds(); this._rings = []; this._projectLatlngs(this._latlngs, this._rings, pxBounds); var w = this._clickTolerance(), p = new L.Point(w, w); if (this._bounds.isValid() && pxBounds.isValid()) { pxBounds.min._subtract(p); pxBounds.max._add(p); this._pxBounds = pxBounds; } }, _projectLatlngs: function (latlngs, result, projectedBounds) { var flat = latlngs[0] instanceof L.LatLng, len = latlngs.length, i, ring; if (flat) { ring = []; for (i = 0; i < len; i++) { ring[i] = this._map.latLngToLayerPoint(latlngs[i]); projectedBounds.extend(ring[i]); } result.push(ring); } else { for (i = 0; i < len; i++) { this._projectLatlngs(latlngs[i], result, projectedBounds); } } }, _convertLatLngs: function (latlngs) { var result = [], flat = L.LineUtil.isFlat(latlngs); for (var i = 0, len = latlngs.length; i < len; i++) { if (flat) { result[i] = L.latLng(latlngs[i]); this._bounds.extend(result[i]); } else { result[i] = this._convertLatLngs(latlngs[i]); } } return result; }, _updatePath: function () { var stroke = this.options.stroke; if (this._lineLatLngs && stroke) { this.options.stroke = false; this._renderer._updateStyle(this); } this._renderer._updatePoly(this, true); this.options.stroke = stroke; } }); // マーカー移動中にマップにイベントを渡さない GSI.MarkerDrag = L.Handler.extend({ initialize: function (marker) { this._marker = marker; }, addHooks: function () { var icon = this._marker._icon; if (!this._draggable) { this._draggable = new GSI.Draggable(icon, icon, true); } this._draggable.on({ dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, this).enable(); L.DomUtil.addClass(icon, 'leaflet-marker-draggable'); }, removeHooks: function () { this._draggable.off({ dragstart: this._onDragStart, drag: this._onDrag, dragend: this._onDragEnd }, this).disable(); if (this._marker._icon) { L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-draggable'); } }, moved: function () { return this._draggable && this._draggable._moved; }, _onDragStart: function () { // @section Dragging events // @event dragstart: Event // Fired when the user starts dragging the marker. // @event movestart: Event // Fired when the marker starts moving (because of dragging). this._oldLatLng = this._marker.getLatLng(); this._marker .closePopup() .fire('movestart') .fire('dragstart'); }, _onDrag: function (e) { var marker = this._marker, shadow = marker._shadow, iconPos = L.DomUtil.getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos); // update shadow position if (shadow) { L.DomUtil.setPosition(shadow, iconPos); } if (this._oldLatLng) latlng.alt = this._oldLatLng.alt; marker._latlng = latlng; e.latlng = latlng; e.oldLatLng = this._oldLatLng; // @event drag: Event // Fired repeatedly while the user drags the marker. marker .fire('move', e) .fire('drag', e); }, _onDragEnd: function (e) { // @event dragend: DragEndEvent // Fired when the user stops dragging the marker. // @event moveend: Event // Fired when the marker stops moving (because of dragging). delete this._oldLatLng; this._marker .fire('moveend') .fire('dragend', e); } }); GSI.Draggable = L.Draggable.extend({ _onDown: function (e) { L.Draggable.prototype._onDown.call(this, e); L.DomEvent.stop(e); } }); GSI.Circle.addInitHook(function () { if (L.Edit.Circle) { this.editing = new L.Edit.Circle(this); if (this.options.editable) { this.editing.enable(); } } this.on('add', function () { if (this.editing && this.editing.enabled()) { this.editing.addHooks(); } }); this.on('remove', function () { if (this.editing && this.editing.enabled()) { this.editing.removeHooks(); } }); }); L.circle = function (latlng, radius, options) { return new GSI.Circle(latlng, radius, options); }; GSI.Draw.convertRadius = function (radius, latlng, unit) { var result = { radius: radius.toFixed(1), latlng: latlng, unit: unit }; if (unit == "m") { if (result.radius > 1000) { result.radius = (radius / 1000).toFixed(4); result.unit = 'km'; } } if (unit == "px") { result.radius = Math.floor(result.radius); } return result; }; GSI.PixelRectangle = L.Polygon.extend({ initialize: function (center, width, height, anchorX, anchorY, options) { this._center = center; this._width = width; this._height = height; this._anchorX = anchorX; this._anchorY = anchorY; options.noGeodesic = true; L.Polygon.prototype.initialize.call(this, [this._center, this._center, this._center], options); }, onZoomEnd: function () { this.setLatLngs(this._boundsToLatLngs(this._center, this._width, this._height, this._anchorX, this._anchorY)); }, onAdd: function (map) { L.Polygon.prototype.onAdd.call(this, map); this.setLatLngs(this._boundsToLatLngs(this._center, this._width, this._height, this._anchorX, this._anchorY)); this._onZoomEnd = L.bind(this.onZoomEnd, this); map.on('zoomend', this._onZoomEnd); }, onRemove: function (map) { map.off('zoomend', this._onZoomEnd); L.Polygon.prototype.onRemove.call(this, map); }, _boundsToLatLngs: function (center, width, height, anchorX, anchorY) { var centerPoint = this._map.latLngToContainerPoint(center); var left = centerPoint.x - anchorX; var top = centerPoint.y - anchorY; var right = centerPoint.x + (width - anchorX); var bottom = centerPoint.y + (height - anchorY); var southWest = this._map.containerPointToLatLng(L.point(left, bottom)); var northEast = this._map.containerPointToLatLng(L.point(right, top)); latLngBounds = L.latLngBounds(southWest, northEast); return [ latLngBounds.getSouthWest(), latLngBounds.getNorthWest(), latLngBounds.getNorthEast(), latLngBounds.getSouthEast() ]; } }); GSI.Draw.Circle = L.Draw.Circle.extend({ _onMouseDown: function (e) { if (!$(e.originalEvent.target).hasClass("gsi_centercross") && $(e.originalEvent.target).hasClass("leaflet-marker-icon")) { return; } if (this._shape) { this._map.getContainer().focus(); this.fire("start"); this._startLatLng = e.latlng; L.DomEvent .on(document, 'mouseup', this._onMouseUp, this) .on(document, 'touchend', this._onMouseUp, this) .preventDefault(e.originalEvent); } else { this.fire("start"); L.Draw.Circle.prototype._onMouseDown.call(this, e); } }, setRadius: function (radius) { if (!this._shape) { this._shape = new GSI.Circle(this._map.getCenter(), radius, this.options.shapeOptions); this._map.addLayer(this._shape); } else { this._shape.setRadius(radius); this._shape.redraw(); } }, _onMouseMove: function (e) { var latlng = e.latlng, showRadius = this.options.showRadius, useMetric = this.options.metric, radius; this._tooltip.updatePosition(latlng); if (this._isDrawing) { this._drawShape(latlng); // Get the new radius (rounded to 1 dp) radius = this._shape.getRadius().toFixed(1); this._tooltip.updateContent({ text: this._endLabelText, subtext: showRadius ? '半径: ' + L.GeometryUtil.readableDistance(radius, useMetric) : '' }); } else { if (this._shape) this._shape.setLatLng(latlng); } if (this._isDrawing) { this.fire("change", GSI.Draw.convertRadius(this._shape.getRadius(), latlng, "m")); } }, _drawShape: function (latlng) { if (!this._shape) { this._shape = new GSI.Circle(this._startLatLng, this._startLatLng.distanceTo(latlng), this.options.shapeOptions); this._map.addLayer(this._shape); } else { this._shape.setRadius(this._startLatLng.distanceTo(latlng)); } }, _fireCreatedEvent: function () { var circle = new GSI.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions); L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle); } }); GSI.Draw.CircleMarker = L.Draw.Circle.extend({ _getPixelDistance: function (latlng1, latlng2) { var p1 = this._map.latLngToContainerPoint(latlng1); var p2 = this._map.latLngToContainerPoint(latlng2); var a = p1.x - p2.x; var b = p1.y - p2.y; return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); }, _drawShape: function (latlng) { var distance = this._getPixelDistance(this._startLatLng, latlng); if (!this._shape) { var options = $.extend(true, { radius: distance }, this.options.shapeOptions); this._shape = new L.CircleMarker(this._startLatLng, options); this._map.addLayer(this._shape); } else { this._shape.setRadius(distance); } }, _fireCreatedEvent: function () { var options = $.extend(true, { radius: this._shape.getRadius() }, this.options.shapeOptions); var circle = new L.CircleMarker(this._startLatLng, options); L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle); }, _onMouseDown: function (e) { if (!$(e.originalEvent.target).hasClass("gsi_centercross") && $(e.originalEvent.target).hasClass("leaflet-marker-icon")) { return; } if (this._shape) { this._map.getContainer().focus(); this.fire("start"); this._startLatLng = e.latlng; L.DomEvent .on(document, 'mouseup', this._onMouseUp, this) .on(document, 'touchend', this._onMouseUp, this) .preventDefault(e.originalEvent); } else { this.fire("start"); L.Draw.Circle.prototype._onMouseDown.call(this, e); } }, setRadius: function (radius) { if (!this._shape) { var options = $.extend(true, { radius: radius }, this.options.shapeOptions); this._shape = new L.CircleMarker(this._map.getCenter(), options); this._map.addLayer(this._shape); } else { this._shape.setRadius(radius); } }, _onMouseMove: function (e) { var latlng = e.latlng, showRadius = this.options.showRadius, useMetric = this.options.metric, radius; this._tooltip.updatePosition(latlng); if (this._isDrawing) { this._drawShape(latlng); // Get the new radius (rounded to 1 dp) radius = this._shape.getRadius().toFixed(0); this._tooltip.updateContent({ text: this._endLabelText, subtext: showRadius ? '半径: ' + radius + 'px' : '' }); } else { if (this._shape) this._shape.setLatLng(latlng); } if (this._isDrawing) { this.fire("change", { radius: this._shape.getRadius().toFixed(0) }); } } }); L.Polyline.prototype.spliceLatLngs = function () { // (Number index, Number howMany) var removed = [].splice.apply(this._latlngs, arguments); this._convertLatLngs(this._latlngs, true); this.redraw(); return removed; }; L.Polyline.prototype._projectOrig = L.Polyline.prototype._project; L.Polyline.prototype._project = function (e) { if (!this.options.geodesic) { L.Polyline.prototype._projectOrig.call(this); return; } this.options.noClip = true; var pxBounds = new L.Bounds(); this._rings = []; var origLatlngs = $.extend(true, [], this._latlngs); if (L.LineUtil.isFlat(origLatlngs)) origLatlngs = [origLatlngs]; if (this instanceof L.Polygon) { var isMultiPolygon = false; if (L.LineUtil.isFlat(origLatlngs)) { if (!origLatlngs[0].equals(origLatlngs[origLatlngs.length - 1])) { origLatlngs.push(L.latLng(origLatlngs[0].lat, origLatlngs[0].lng, origLatlngs[0].alt)); } } else { for (var i = 0; i < origLatlngs.length; i++) { if (L.LineUtil.isFlat(origLatlngs[i])) { if (!origLatlngs[i][0].equals(origLatlngs[i][origLatlngs[i].length - 1])) { origLatlngs[i].push(L.latLng(origLatlngs[i][0].lat, origLatlngs[i][0].lng, origLatlngs[i][0].alt)); } } else { isMultiPolygon = true; for (var j = 0; j < origLatlngs[i].length; j++) { if (!origLatlngs[i][j][0].equals(origLatlngs[i][j][origLatlngs[i][j].length - 1])) { origLatlngs[i][j].push(L.latLng(origLatlngs[i][j][0].lat, origLatlngs[i][j][0].lng, origLatlngs[i][j][0].alt)); } } } } } } var latlngs = null; if (isMultiPolygon) { latlngs = []; for (var i = 0; i < origLatlngs.length; i++) { latlngs.push(GSI.Utils.Geodesic.createLine(origLatlngs[i], GSI.Utils.Geodesic.LINESTEPS)); } } else { latlngs = GSI.Utils.Geodesic.createLine(origLatlngs, GSI.Utils.Geodesic.LINESTEPS); } this._projectLatlngs(latlngs, this._rings, pxBounds); var w = this._clickTolerance(), p = new L.Point(w, w); if (this._bounds.isValid() && pxBounds.isValid()) { pxBounds.min._subtract(p); pxBounds.max._add(p); this._pxBounds = pxBounds; } }; L.Polygon.prototype.spliceLatLngs = function () { // (Number index, Number howMany) var latlngs = this._latlngs; var flat = L.LineUtil.isFlat(latlngs); if (!flat) latlngs = latlngs[0]; var removed = [].splice.apply(latlngs, arguments); this._convertLatLngs(latlngs, true); this.redraw(); return removed; }; L.Draw.Polyline.prototype._onTouch = function (e) { // #TODO: use touchstart and touchend vs using click(touch start & end). if (GSI.Utils.Browser.touch) { // #TODO: get rid of this once leaflet fixes their click/touch. this._onMouseMove(e); this._onMouseDown(e); this._onMouseUp(e); } }; L.Draw.Polyline.prototype._onContextMenu = function (e) { L.DomEvent.preventDefault(e); if (this._map && e.originalEvent.button == 2 && this._markers.length > 1) { this._map.fire("drawcancel"); } this.deleteLastVertex(); }, L.Draw.Polyline.prototype._onMouseUp = function (e) { if (this._mouseDownOrigin) { if (e.originalEvent.button == 2) { } else { // We detect clicks within a certain tolerance, otherwise let it // be interpreted as a drag by the map var distance = L.point(e.originalEvent.clientX, e.originalEvent.clientY) .distanceTo(this._mouseDownOrigin); if (Math.abs(distance) < 9 * (window.devicePixelRatio || 1)) { this.addVertex(e.latlng); } } } this._mouseDownOrigin = null; }; GSI.Draw.Polyline = L.Draw.Polyline.extend({ options: { allowIntersection: true, repeatMode: false, drawError: { color: '#b00b00', timeout: 2500 }, icon: new L.DivIcon({ iconSize: new L.Point(8, 8), className: 'leaflet-div-icon leaflet-editing-icon' }), touchIcon: new L.DivIcon({ iconSize: new L.Point(24, 24), className: 'leaflet-div-icon leaflet-editing-icon gsi_draw_icon' }), guidelineDistance: 20, maxGuideLineLength: 4000, shapeOptions: { stroke: true, color: '#f06eaa', weight: 4, opacity: 0.5, fill: false, clickable: true }, metric: true, // Whether to use the metric meaurement system or imperial showLength: true, // Whether to display distance in the tooltip zIndexOffset: 2000 // This should be > than the highest z-index any map layers }, initialize: function (map, options) { if (GSI.Utils.Browser.touch) { this.options.icon = this.options.touchIcon; } // Need to set this here to ensure the correct message is used. this.options.drawError.message = L.drawLocal.draw.handlers.polyline.error; // Merge default drawError options with custom options if (options && options.drawError) { options.drawError = L.Util.extend({}, this.options.drawError, options.drawError); } // Save the type so super can fire, need to do this as cannot do this.TYPE :( this.type = L.Draw.Polyline.TYPE; L.Draw.Feature.prototype.initialize.call(this, map, options); }, _updateFinishHandler: function () { var markerCount = this._markers.length; // The last marker should have a click handler to close the polyline if (markerCount > 1) { this._markers[markerCount - 1].on('click', this._finishShape, this); } // Remove the old marker click handler (as only the last point should close the polyline) if (markerCount > 2) { this._markers[markerCount - 2].off('click', this._finishShape, this); } }, _getTooltipText: function () { var labelText = L.Draw.Polyline.prototype._getTooltipText.call(this); if (this._currentLatLng) { var dms = GSI.Utils.latLngToDMS(this._currentLatLng); labelText.text += "
" + dms.lat.d + "度" + dms.lat.m + "分" + dms.lat.s.toFixed(2) + "秒," + dms.lng.d + "度" + dms.lng.m + "分" + dms.lng.s.toFixed(2) + "秒" ; } return labelText; }, _vertexChanged: function (latlng, added) { this._currentLatLng = latlng; L.Draw.Polyline.prototype._vertexChanged.call(this, latlng, added); var currentLatLng = this._currentLatLng, previousLatLng = this._markers[this._markers.length - 1].getLatLng(), distance; distance = this._measurementRunningTotal + currentLatLng.distanceTo(previousLatLng); var distanceStr = '0 m'; if (distance > 1000) { distanceStr = (distance / 1000).toFixed(3) + ' km'; } else { distanceStr = Math.ceil(distance) + ' m'; } this.fire('measurechange', { distance: distanceStr }); } }); L.drawLocal.draw.handlers.polyline.inner_error = 'エラー: 対象のポリゴン内を指定して下さい'; L.drawLocal.draw.handlers.polyline.inner_error2 = 'エラー: 中抜きポリゴン同士が交差しています'; L.drawLocal.draw.handlers.polyline.inner_error3 = 'エラー: 対象のポリゴン外を通過しています'; GSI.Draw.Polygon = L.Draw.Polygon.extend({ options: { allowIntersection: false, repeatMode: false, drawError: { color: '#b00b00', timeout: 2500 }, icon: new L.DivIcon({ iconSize: new L.Point(8, 8), className: 'leaflet-div-icon leaflet-editing-icon' }), touchIcon: new L.DivIcon({ iconSize: new L.Point(24, 24), className: 'leaflet-div-icon leaflet-editing-icon gsi_draw_icon' }), guidelineDistance: 20, maxGuideLineLength: 4000, metric: true, // Whether to use the metric meaurement system or imperial showLength: true, // Whether to display distance in the tooltip zIndexOffset: 2000, // This should be > than the highest z-index any map layers showArea: false, shapeOptions: { stroke: true, color: '#f06eaa', weight: 4, opacity: 0.5, fill: true, fillColor: null, //same as color by default fillOpacity: 0.2, clickable: true } }, initialize: function (map, options) { if (GSI.Utils.Browser.touch) { this.options.icon = this.options.touchIcon; } // Need to set this here to ensure the correct message is used. this.options.drawError.message = L.drawLocal.draw.handlers.polyline.error; // Merge default drawError options with custom options if (options && options.drawError) { options.drawError = L.Util.extend({}, this.options.drawError, options.drawError); } this.type = L.Draw.Polygon.TYPE; L.Draw.Feature.prototype.initialize.call(this, map, options); }, _pointInPolygon: function (poly, p) { var p1, p2; var inside = false; var oldPoint = poly[poly.length - 1]; for (var i = 0; i < poly.length; i++) { var newPoint = poly[i]; if (newPoint.lng > oldPoint.lng) { p1 = oldPoint; p2 = newPoint; } else { p1 = newPoint; p2 = oldPoint; } if ((p1.lng < p.lng) == (p.lng <= p2.lng) && (p.lat - p1.lat) * (p2.lng - p1.lng) < (p2.lat - p1.lat) * (p.lng - p1.lng)) { inside = !inside; } oldPoint = newPoint; } return inside; }, _lineIentersectedPolygon: function (poly, line) { //_lineIentersected if (!line || line.length < 2) return false; for (var i = 0; i < poly.length; i++) { var p1 = poly[i]; var p2 = poly[(poly.length - 1 > i ? i + 1 : 0)]; if (this._lineIentersected(p1, p2, line[0], line[1])) { return true; } } return false; }, addVertex: function (latlng) { if (this.options.ownerPolygon) { // 中抜きが外のポリゴン内か、他の中抜きと交差していないか this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error; var isMulti = false; var latlngs = this.options.ownerPolygon.getLatLngs(); var err = false; if (L.LineUtil.isFlat(latlngs)) { err = !this._pointInPolygon(latlngs, latlng); } else { if (L.LineUtil.isFlat(latlngs[0])) { err = !this._pointInPolygon(latlngs[0], latlng); } else { isMulti = true; var newLatLngs = this._poly.getLatLngs(); if (newLatLngs.length <= 0) { err = true; for (var i = 0; i < latlngs.length; i++) { if (this._pointInPolygon(latlngs[i][0], latlng)) { err = false; this._ownerIndex = i; break; } } } else { err = !this._pointInPolygon(latlngs[this._ownerIndex][0], latlng); } } if (!err) { if (!isMulti) { var newLatLngs = this._poly.getLatLngs(); if (newLatLngs.length > 0) { newLatLngs = [newLatLngs[newLatLngs.length - 1], latlng]; } else newLatLngs = undefined; if (newLatLngs && this._lineIentersectedPolygon(latlngs[0], newLatLngs)) { err = true; this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error3; } else { for (var i = 1; i < latlngs.length; i++) { err = this._pointInPolygon(latlngs[i], latlng); if (err) { this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error2; break; } else if (newLatLngs) { if (this._polyIntersected(latlngs[i], newLatLngs)) { err = true; this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error2; break; } } } } } else { // マルチポリゴン var newLatLngs = this._poly.getLatLngs(); if (newLatLngs.length > 0) { newLatLngs = [newLatLngs[newLatLngs.length - 1], latlng]; } else newLatLngs = undefined; if (newLatLngs && this._lineIentersectedPolygon(latlngs[this._ownerIndex][0], newLatLngs)) { err = true; this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error3; } else { for (var i = 1; i < latlngs[this._ownerIndex].length; i++) { err = this._pointInPolygon(latlngs[this._ownerIndex][i], latlng); if (err) { this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error2; break; } else if (newLatLngs) { if (this._polyIntersected(latlngs[this._ownerIndex][i], newLatLngs)) { err = true; this.options.drawError.message = L.drawLocal.draw.handlers.polyline.inner_error2; break; } } } } } } } if (err) { this._showErrorTooltip(); return; } } this.options.drawError.message = L.drawLocal.draw.handlers.polyline.error; this._poly._originalPoints = []; for (var i = 0; i < this._poly._latlngs.length; i++) { this._poly._originalPoints.push(this._map.latLngToLayerPoint(this._poly._latlngs[i])); } var markersLength = this._markers.length; if (markersLength > 0 && !this.options.allowIntersection && this._poly.newLatLngIntersects(latlng)) { this._showErrorTooltip(); return; } else if (this._errorShown) { this._hideErrorTooltip(); } this._markers.push(this._createMarker(latlng)); this._poly.addLatLng(latlng); if (!this.options.shapeOptions) this.options.shapeOptions = {}; this.options.shapeOptions._ownerIndex = this._ownerIndex; if (this._poly.getLatLngs().length === 2) { this._map.addLayer(this._poly); } this._vertexChanged(latlng, true); //L.Draw.Polygon.prototype.addVertex.call(this, latlng); }, _polyIntersected: function (poly1, poly2) { for (var i = 0; i < poly1.length; i++) { var from1 = poly1[i]; var to1 = (i < poly1.length - 1 ? poly1[i + 1] : poly1[0]); for (var j = 0; j < poly2.length; j++) { var from2 = poly2[j]; var to2 = (j < poly2.length - 1 ? poly2[j + 1] : poly2[0]); if (this._lineIentersected(from1, to1, from2, to2)) { return true; } } } return false; }, _lineIentersected: function (from1, to1, from2, to2) { //ax, ay, bx, by, cx, cy, dx, dy) { var ax = from1.lng; var ay = from1.lat; var bx = to1.lng; var by = to1.lat; var cx = from2.lng; var cy = from2.lat; var dx = to2.lng; var dy = to2.lat; var ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax); var tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx); var tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx); var td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx); return tc * td <= 0 && ta * tb <= 0; // 端点を含む場合 }, _finishShape: function () { this._poly._originalPoints = []; for (var i = 0; i < this._poly._latlngs.length; i++) { this._poly._originalPoints.push(this._map.latLngToLayerPoint(this._poly._latlngs[i])); } L.Draw.Polygon.prototype._finishShape.call(this); }, _getTooltipText: function () { var labelText = L.Draw.Polygon.prototype._getTooltipText.call(this); if (this._currentLatLng) { var dms = GSI.Utils.latLngToDMS(this._currentLatLng); labelText.text += "
" + dms.lat.d + "度" + dms.lat.m + "分" + dms.lat.s.toFixed(2) + "秒," + dms.lng.d + "度" + dms.lng.m + "分" + dms.lng.s.toFixed(2) + "秒" ; } return labelText; }, _vertexChanged: function (latlng, added) { L.Draw.Polygon.prototype._vertexChanged.call(this, latlng, added); var latlngs = this._poly.getLatLngs(); if (!L.LineUtil.isFlat(latlngs)) latlngs = latlngs[0]; this.fire('measurechange', { distance: this._area2MeasurementString(this._area) }); }, _area2MeasurementString: function (area) { var result = '0 m²'; if (area) { if (area < 1000000) { result = Math.ceil(area) + ' m²'; } else { result = (area / 1000000).toFixed(3) + ' km²'; } } return result; }, _getMeasurementString: function () { var area = this._area; if (!area) { return null; } return this._area2MeasurementString(area); }, _updateFinishHandler: function () { var markerCount = this._markers.length; // The first marker should have a click handler to close the polygon if (markerCount === 1) { this._markers[0].on('click', this._finishShape, this); } // Add and update the double click handler if (markerCount > 2) { this._markers[markerCount - 1].on('click', this._finishShape, this); // Only need to remove handler if has been added before if (markerCount > 3) { this._markers[markerCount - 2].off('click', this._finishShape, this); } } } }); GSI.Draw.FreehandPolyline = L.Draw.SimpleShape.extend({ initialize: function (map, options) { this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end; this._initialLabelText = "マウスダウンで線の描画開始"; L.Draw.SimpleShape.prototype.initialize.call(this, map, options); }, _onMouseDown: function (e) { if (!$(e.originalEvent.target).hasClass("gsi_centercross") && $(e.originalEvent.target).hasClass("leaflet-marker-icon")) { return; } this.fire("start"); L.Draw.SimpleShape.prototype._onMouseDown.call(this, e); }, _onTouch: function (e) { // #TODO: use touchstart and touchend vs using click(touch start & end). if (GSI.Utils.Browser.touch) { // #TODO: get rid of this once leaflet fixes their click/touch. this._onMouseMove(e); this._onMouseDown(e); this._onMouseUp(e); } }, _drawShape: function (latlng) { if (!this._shape) { this._shape = new L.Polyline([], this.options.shapeOptions); this._map.addLayer(this._shape); } else { var latlngs = this._shape.getLatLngs(); if (latlngs.length > 0) { var prevLatLng = latlngs[latlngs.length - 1]; if (prevLatLng.lat != latlng.lat || prevLatLng.lng != latlng.lng) { this._shape.addLatLng(latlng); } } else { this._shape.addLatLng(latlng); } } }, _fireCreatedEvent: function () { var plyline = new L.Polyline(this._shape.getLatLngs(), this.options.shapeOptions); L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, plyline); } }); /************************************************************************ GSI.Links ************************************************************************/ GSI.Links = {}; GSI.Links.getURL = function (pageStateManager, id, center, z, bounds) { if (id == "gsi3d_l") { if (GSI.Utils.Browser.ie && (GSI.Utils.Browser.version <= 10)) { alert('お使いのWebブラウザは地理院地図3Dに対応していません。\nChrome、Firefox、IE11 をご使用ください。'); return null; } var args = ""; args += "?z=" + z; args += "&lat=" + center.lat; args += "&lon=" + center.lng; args += "&pxsize=2048"; args += "&" + pageStateManager.getLayersQueryString({ visibleOnly: true, withRelief: true }) return "./index_3d.html" + args; } else if (id == "gsi3d_s") { if (GSI.Utils.Browser.ie && (GSI.Utils.Browser.version <= 10)) { alert('お使いのWebブラウザは地理院地図3Dに対応していません。\nChrome、Firefox、IE11 をご使用ください。'); return null; } var args = ""; args += "?z=" + z; args += "&lat=" + center.lat; args += "&lon=" + center.lng; args += "&pxsize=1024"; args += "&" + pageStateManager.getLayersQueryString({ visibleOnly: true, withRelief: true }) return "./index_3d.html" + args; } else if (id == "gsi3d_view") { if (GSI.Utils.Browser.ie && (GSI.Utils.Browser.version <= 10)) { alert('お使いのWebブラウザは地理院地図3Dに対応していません。\nChrome、Firefox、IE11 をご使用ください。'); return null; } var size = GSI.GLOBALS.gsimaps._mainMap._map.getSize(); if (size.x > 2048) size.x = 2048; if (size.y > 2048) size.y = 2048; if (size.x % 2 == 1) size.x -= 1; if (size.y % 2 == 1) size.y -= 1; var args = ""; args += "?z=" + z; args += "&lat=" + center.lat; args += "&lon=" + center.lng; args += "&w=" + size.x; args += "&h=" + size.y; args += "&" + pageStateManager.getLayersQueryString({ visibleOnly: true, withRelief: true }) return "./index_3d.html" + args; } else if (id == 'gsiglobe') { if (GSI.Utils.Browser.ie && (GSI.Utils.Browser.version <= 10)) { alert('お使いのWebブラウザは地理院地図Globeに対応していません。\nChrome、Firefox、IE11 をご使用ください。'); return null; } var url = CONFIG.GLOBEURL; // GlobeのURL生成 var queryString = pageStateManager.getPositionQueryString(); if (queryString != "") queryString += "/1/"; var base = pageStateManager.getBaseLayerQueryString(); var hasBase = (base != ''); if (base != '') queryString += (queryString != '' ? '&' : '#') + base; var ls = pageStateManager.getLayersQueryString(); var disp = pageStateManager.getTileViewSetting(); if (ls != '') queryString += (queryString != '' ? '&' : '#') + ls; if (disp != '') queryString += (queryString != '' ? '&' : '#') + disp; url += queryString; return url; //'https://maps.gsi.go.jp/globe/index_globe.html'; } else if (id == 'mapion') { var zoomLevel = z; if (z <= 6) { zoomLevel = 6; } return "./link.html?site=mapion&lat=" + center.lat + "&lng=" + center.lng + "&z=" + zoomLevel; } else if (id == 'itsumonavi') { var zoomLevel = 18; var japanP = GSI.Utils.world2Japan(center); var y = Math.round(japanP.y * 3600 * 1000); var x = Math.round(japanP.x * 3600 * 1000); if (z <= 5) { zoomLevel = 1; } else if (z <= 6) { zoomLevel = 2; } else if (z <= 7) { zoomLevel = 3; } else if (z <= 8) { zoomLevel = 4; } else if (z <= 9) { zoomLevel = 6; } else if (z <= 10) { zoomLevel = 7; } else if (z <= 11) { zoomLevel = 8; } else if (z <= 12) { zoomLevel = 9; } else if (z <= 13) { zoomLevel = 10; } else if (z <= 14) { zoomLevel = 11; } else if (z <= 15) { zoomLevel = 13; } else if (z <= 16) { zoomLevel = 14; } else if (z <= 17) { zoomLevel = 16; } else { zoomLevel = 18; } return "./link.html?site=itsumonavi&lat=" + y + "&lng=" + x + "&z=" + zoomLevel; } else if (id == 'ucodehref') { return 'http://ucopendb.gsi.go.jp/ucode_app/logical_code/ucode_disp.php?lat=' + center.lat + '&lng=' + center.lng + '&zoom=' + z; } else if (id == 'gsivector') { var zoomlevel = z - 1; return 'https://maps.gsi.go.jp/vector/#' + zoomlevel + '/' + center.lat + '/' + center.lng + '/&ls=vstd&disp=1&d=l'; } else { return id; } }; /************************************************************************ GSI.showTopMassage ************************************************************************/ GSI.showTopMassage = function () { var message = (CONFIG.TOPMESSAGE && CONFIG.TOPMESSAGE.DETAILS ? CONFIG.TOPMESSAGE.DETAILS : '現在情報はありません'); GSI.Modal.Message.show(message, { className: "gsi_modal_topmessage", width: 500, closeBtnVisible: true }); }; /************************************************************************ GSI.Utils ************************************************************************/ GSI.Utils.encodeHTML = function (src) { src = src.replace(/&/g, '&'); src = src.replace(//g, '>'); return src; }; GSI.Utils.getInternetExplorerVersion = function () { var rv = -1; if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat(RegExp.$1); } else if (navigator.appName == 'Netscape') { var ua = navigator.userAgent; var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat(RegExp.$1); } return rv; }; GSI.Utils.Browser = {}; GSI.Utils.Browser.userAgent = window.navigator.userAgent.toLowerCase(); if (typeof document.documentElement.style.maxHeight != "undefined") { var ieVersion = GSI.Utils.getInternetExplorerVersion(); if (ieVersion < 1) { // IE 以外 } else { // IE8 以降 GSI.Utils.Browser.ie = true; GSI.Utils.Browser.version = ieVersion; } } else { // IE 6.0 以下 GSI.Utils.Browser.ie = true; GSI.Utils.Browser.version = 6; } GSI.Utils.Browser.isiPhone = GSI.Utils.Browser.userAgent.indexOf('iphone') >= 0; GSI.Utils.Browser.isiPod = GSI.Utils.Browser.userAgent.indexOf('ipod') >= 0; GSI.Utils.Browser.isiPad = GSI.Utils.Browser.userAgent.indexOf('ipad') >= 0; GSI.Utils.Browser.isiOS = (GSI.Utils.Browser.isiPhone || GSI.Utils.Browser.isiPod || GSI.Utils.Browser.isiPad); GSI.Utils.Browser.isAndroid = GSI.Utils.Browser.userAgent.indexOf('android') >= 0; GSI.Utils.Browser.isSmartMobile = (GSI.Utils.Browser.isiOS || GSI.Utils.Browser.isAndroid); GSI.Utils.Browser.isChrome = GSI.Utils.Browser.userAgent.indexOf('chrome') != -1; GSI.Utils.Browser.isMac = !!GSI.Utils.Browser.userAgent.match(/mac|ppc/); GSI.Utils.hasFileAPI = (window.File && window.FileReader && window.FileList && window.Blob); GSI.Utils.Browser.msPointer = window.navigator && window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints && !window.PointerEvent; GSI.Utils.Browser.pointer = (window.PointerEvent && window.navigator.pointerEnabled && window.navigator.maxTouchPoints) || GSI.Utils.Browser.msPointer; GSI.Utils.Browser.TouchDevice = function () { var f = false; if (GSI.Utils.Browser.isiPhone || GSI.Utils.Browser.isiPod || GSI.Utils.Browser.isiPad || GSI.Utils.Browser.isiOS || GSI.Utils.Browser.isAndroid || GSI.Utils.Browser.isSmartMobile ) { f = true; } return f; }; var phantomjs = GSI.Utils.Browser.userAgent.indexOf('phantom') !== -1; GSI.Utils.Browser.touch = !window.L_NO_TOUCH && !phantomjs && (function () { var msPointer = window.navigator && window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints && !window.PointerEvent; var pointer = (window.PointerEvent && window.navigator.pointerEnabled && window.navigator.maxTouchPoints) || msPointer; var startName = 'ontouchstart'; // IE10+ (We simulate these into touch* events in L.DomEvent and L.DomEvent.Pointer) or WebKit, etc. if (pointer || (startName in document.documentElement)) { return true; } // Firefox/Gecko var div = document.createElement('div'), supported = false; if (!div.setAttribute) { return false; } div.setAttribute(startName, 'return;'); if (typeof div[startName] === 'function') { supported = true; } div.removeAttribute(startName); div = null; return supported; }()); GSI.Utils.getCurrentID = function () { var id = 1; if (!GSI.Utils._currentID) { GSI.Utils._currentID = 1; } id = GSI.Utils._currentID; GSI.Utils._currentID++; return id; }; GSI.Utils.isLocalUrl = function (url) { if ((GSI.ClientMode.baseUrl && GSI.ClientMode.baseUrl != '') || url.match(/(http|https):\/\/.+/)) { return false; } else { return true; } }; GSI.Utils.flashPlayerVersion = null; GSI.Utils.canUseWebGL = function () { try { var canvas = document.createElement('canvas'); var webGLContext = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!(!!(window.WebGLRenderingContext && webGLContext && webGLContext.getShaderPrecisionFormat))) { return false; } var gl = canvas.getContext("experimental-webgl"); var extensions = gl.getSupportedExtensions(); var supportedExtensions = {}; for (var i = 0; i < extensions.length; i++) { supportedExtensions[extensions[i]] = true; } if ( supportedExtensions["WEBGL_depth_texture"] && // 深度テクスチャ supportedExtensions["WEBGL_color_buffer_float"] // 浮動小数点テクスチャ ) { return true; } else { return false; } } catch (ex) { return false; } }; GSI.Utils.canUseFlashPlayer = function () { if (GSI.Utils.flashPlayerVersion == null) { GSI.Utils.flashPlayerVersion = GSI.Utils.getFlashPlayerVersion(); } return (GSI.Utils.flashPlayerVersion > 0); }; GSI.Utils.getFlashPlayerVersion = function () { var result = 0; if (navigator.plugins && navigator.mimeTypes['application/x-shockwave-flash']) { var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; if (plugin) { result = parseInt(plugin.description.match(/\d+\.\d+/)); } } else { try { var flashOCX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").match(/([0-9]+)/); if (flashOCX) { result = parseInt(flashOCX[0]); } } catch (e) { } } if (result <= 6) { result = 0; } return result; }; GSI.Utils.getCurrentPath = function () { var _location = (GSI.ClientMode.location ? GSI.ClientMode.location : location); var port = _location.port; var pathName = _location.pathname; if (pathName.length <= 0 || pathName.charAt(0) != '/') pathName = '/' + pathName; return _location.protocol + '//' + (_location.host ? _location.host : _location.hostname) + pathName; }; GSI.Utils.getTimeStampString = function () { var now = new Date(); var year = now.getFullYear(); // 年 var month = now.getMonth() + 1; // 月 var day = now.getDate(); // 日 var hour = now.getHours(); // 時 var min = now.getMinutes(); // 分 var sec = now.getSeconds(); // 秒 var msec = now.getMilliseconds(); // ミリ秒 var result = year + '' + ('00' + month).slice(-2) + ('00' + day).slice(-2) + ('00' + hour).slice(-2) + ('00' + min).slice(-2) + ('00' + sec).slice(-2) + msec; return result; }; GSI.Utils.getScreenSize = function () { return { w: window.innerWidth ? window.innerWidth : $(window).width(), h: window.innerHeight ? window.innerHeight : $(window).height() }; }; GSI.Utils.world2Japan = function (latLng) { var worldLonLat = new Proj4js.Proj('EPSG:4326'); var japanLonLat = new Proj4js.Proj('EPSG:4301'); var worldP = new Proj4js.Point(latLng.lng, latLng.lat); var japanP = Proj4js.transform(worldLonLat, japanLonLat, worldP); return { x: japanP.x, y: japanP.y } }; GSI.Utils.latLngToDMS = function (latLng) { var latLng = { lat: latLng.lat, lng: latLng.lng }; var latMinus = (latLng.lat < 0 ? -1 : 1); var lngMinus = (latLng.lng < 0 ? -1 : 1); latLng.lat = Math.abs(latLng.lat); latLng.lng = Math.abs(latLng.lng); var latD = Math.floor(latLng.lat); var latM = Math.floor((latLng.lat - latD) * 60); var latS = (latLng.lat - latD - (latM / 60)) * 3600; if (latS == 60) { latS = 0; latM = latM + 1; }; if (latM == 60) { latM = 0; latD = latD + 1; }; var lngD = Math.floor(latLng.lng); var lngM = Math.floor((latLng.lng - lngD) * 60); var lngS = (latLng.lng - lngD - (lngM / 60)) * 3600; if (lngS == 60) { lngS = 0; lngM = lngM + 1; }; if (lngM == 60) { lngM = 0; lngD = lngD + 1; }; return { lat: { d: latD, m: latM, s: latS }, lng: { d: lngD, m: lngM, s: lngS } }; }; GSI.Utils.dotLineTo = function (texture, p1x, p1y, p2x, p2y, dashArray) { if (texture.setLineDash !== undefined) { texture.setLineDash(dashArray); texture.lineTo(p2x, p2y); } else if (texture.mozDash !== undefined) { texture.mozDash = dashArray; texture.lineTo(p2x, p2y); } else { var d = Math.sqrt(Math.pow(p2x - p1x, 2) + Math.pow(p2y - p1y, 2)); var rad = Math.atan2(p2y - p1y, p2x - p1x); var space = (dashArray && dashArray.length >= 2 && dashArray[0] > 0 ? dashArray[0] : 5); var dotted = Math.round(d / space / 2); for (var i = 0; i < dotted; i++) { var p3x = Math.cos(rad) * space * (i * 2) + p1x; var p3y = Math.sin(rad) * space * (i * 2) + p1y; var p4x = Math.cos(rad) * space * (i * 2 + 1) + p1x; var p4y = Math.sin(rad) * space * (i * 2 + 1) + p1y; texture.moveTo(p3x, p3y); texture.lineTo(p4x, p4y); } } } // 磁北線を表示できる範囲内かどうかを返す GSI.Utils.isVaridVariation = function (latLng) { //経度:122度~154度 //緯度:20度~46度 return !(latLng.lat < 20 || latLng.lat > 46 || latLng.lng < 122 || latLng.lng > 154); } // 指定緯度経度の偏角を算出し、角度を返す GSI.Utils.getVariation = function (latLng) { var px = latLng.lng; var py = latLng.lat; //経緯度座標(10進数)を小数点以下6桁に丸める px = px * 1000000; px = parseInt(px); px = px / 1000000; py = py * 1000000; py = parseInt(py); py = py / 1000000; //西偏角計算 var KEE = px - 138; var KNN = py - 37; var KKK = (7 + 40.585 / 60) + (19.003 / 60) * KNN - (6.265 / 60) * KEE + (0.009 / 60) * KNN * KNN + (0.024 / 60) * KNN * KEE - (0.591 / 60) * KEE * KEE; return KKK; }; GSI.Utils.ConverUnit = function (map, shape, radius, unit_src, unit_to) { if (unit_src == "px" && unit_to == "m") { var r_radius = radius; var r_latlng = shape.getLatLng(); var p = map.latLngToContainerPoint(r_latlng); var p_to_x = p.x; var p_to_y = p.y; p_to_x += r_radius; var r_latlng_to = map.containerPointToLatLng(L.point(p_to_x, p_to_y)); var r = r_latlng.distanceTo(r_latlng_to); radius = r; } if (unit_src == "m" && unit_to == "px") { var r_latlng = shape.getBounds(); var n_p = map.latLngToContainerPoint(r_latlng._northEast); var s_p = map.latLngToContainerPoint(r_latlng._southWest); var r = Math.floor((n_p.x - s_p.x) * 0.5); radius = r; } return radius; }; GSI.Utils.Cookie = L.Class.extend({ _config: { defaults: {} }, initialize: function () { }, _encode: function (s) { return this._config.raw ? s : encodeURIComponent(s); }, _decode: function (s) { return this._config.raw ? s : decodeURIComponent(s); }, _stringifyCookieValue: function (value) { return this._encode(this._config.json ? JSON.stringify(value) : String(value)); }, _parseCookieValue: function (s) { if (s.indexOf('"') === 0) { s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); } try { var pluses = /\+/g; s = decodeURIComponent(s.replace(pluses, ' ')); return this._config.json ? JSON.parse(s) : s; } catch (e) { } }, _read: function (s, converter) { return this._config.raw ? s : this._parseCookieValue(s); }, get: function (key) { var result = key ? undefined : {}; var cookies = document.cookie ? document.cookie.split('; ') : []; for (var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); var name = this._decode(parts.shift()); var cookie = parts.join('='); if (key && key === name) { result = this._read(cookie); break; } if (!key && (cookie = this._read(cookie)) !== undefined) { result[name] = cookie; } } return result; }, set: function (key, value, options) { options = $.extend({}, this._config.defaults, options); if (typeof options.expires === 'number') { var hours = options.expires, t = options.expires = new Date(); t.setTime(+t + hours * 1000 * 60 * 60);// } return (document.cookie = [ this._encode(key), '=', this._stringifyCookieValue(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : '' ].join('')); }, remove: function (key, options) { if (this.get(key) === undefined) { return false; } this.set(key, '', $.extend({}, options, { expires: -1 })); return !this.get(key); } }); GSI.Utils.sendSelectedLayer = function (id) { $.ajax({ type: "GET", data: id, url: "./layers_txt/anchor.txt", datatype: "text", cache: false, }); }; GSI.Utils.sendSelectedFunction = function (function_id) { // 202303 convetersを追加 $.ajax({ type: "GET", data: function_id, url: "./js/anchor_func.js", datatype: "text", converters: {'text script': window.String}, cache: false, }); }; GSI.Utils.get2ndMesh = function (lat, lon) { //1st mesh code var lat1 = Math.floor((lat * 60) / 40); var lat2 = (lat * 60) % 40; var lon1 = Math.floor(lon - 100); var lon2 = lon - 100 - lon1; //2nd mesh code var m2lat = Math.floor(lat2 / 5); var m2lon = Math.floor((lon2 * 60) / 7.5); return "" + lat1 + lon1 + m2lat + m2lon; }; GSI.Utils.rpad = function (src, letter, num) { var dst = src; var len = num - src.length; if (dst) dst = ""; for (var i = 0; i < len; i++) { dst += letter; } return dst; }; GSI.Utils.lpad = function (src, letter, num) { var dst = ""; var len = num - src.length; for (var i = 0; i < len; i++) { dst += letter; } return dst + src; }; L.LatLng.prototype._originalDistanceTo = L.LatLng.prototype.distanceTo; L.LatLng.prototype.distanceTo = function (other) { other = L.latLng(other); var ret = null; if (CONFIG.USEGSIDISTANCE) return GSI.Utils.DistanceCalculator.calc(this, other); else return L.LatLng.prototype._originalDistanceTo.call(this, other); }; GSI.Utils.setMixBlendMode = function (item, flg) { if ((flg != true) && (flg != "1")) { flg = false; } if (flg == "1") { flg = true; } if (item._visibleInfo.layer.setBlendEnable) { item._visibleInfo.layer.setBlendEnable(flg); return; } if (item._visibleInfo.layer._container == null) { return; } if (GSI.Utils.Browser.ie || L.Browser.edge) { return; } if ((flg === undefined) || (flg == null)) { //flg = false; return; } var el = item._visibleInfo.layer._container.getAttribute('style'); if (el) { el = el.replace("mix-blend-mode: multiply; ", ""); } else { el = ""; } if (flg == true) { el = "mix-blend-mode: multiply; " + el; } item._visibleInfo.layer._container.setAttribute('style', el); }; GSI.Utils.objAssign = function(tt, src){ var dest; if (Array.isArray(src) == true){ dest = $.extend([], src); } else{ dest = $.extend({}, src); } return dest; }; GSI.Utils.getNextOutsideTileNo = function(){ if ( !GSI.Utils._outsideTileNo ){ GSI.Utils._outsideTileNo = 0; } return GSI.Utils._outsideTileNo++; }; /************************************************************************ GSI.UTM ************************************************************************/ GSI.UTM = {}; GSI.UTM.Utils = { PROJ_WORLD: new Proj4js.Proj('EPSG:4326'), lng2Zone: function (lng) { return Math.floor(lng / 6) + 31; }, zone2Lng: function (zone) { return (zone - 31) * 6; }, getUTMDefName: function (zone) { var defName = ''; if (!zone) return defName; switch (zone + '') { case '51': defName = 'EPSG:3097'; break; case '52': defName = 'EPSG:3098'; break; case '53': defName = 'EPSG:3099'; break; case '54': defName = 'EPSG:3100'; break; case '55': defName = 'EPSG:3101'; break; case '56': defName = 'SR-ORG:1235'; break; } return defName; }, getUTMMark: function (lat) { var mark = ''; if (lat >= 16 && lat < 24) { mark = "Q"; } else if (lat >= 24 && lat < 32) { mark = "R"; } else if (lat >= 32 && lat < 40) { mark = "S"; } else if (lat >= 40 && lat < 48) { mark = "T"; } else if (lat >= 48 && lat < 56) { mark = "U"; } return mark; }, _parseUSNGText: function (s) { var result = {}; var j = 0; var k; var usngStr = []; var usngStr_temp = [] usngStr_temp = s.toUpperCase() var regexp = /%20/g usngStr = usngStr_temp.replace(regexp, "") regexp = / /g usngStr = usngStr_temp.replace(regexp, "") if (usngStr.length < 7) { return null; } result.zone = usngStr.charAt(j++) * 10 + usngStr.charAt(j++) * 1; result.mylet = usngStr.charAt(j++) result.sq1 = usngStr.charAt(j++) result.sq2 = usngStr.charAt(j++) result.precision = (usngStr.length - j) / 2; result.east = ''; result.north = ''; for (var k = 0; k < result.precision; k++) { result.east += usngStr.charAt(j++) } if (usngStr[j] == " ") { j++ } for (var k = 0; k < result.precision; k++) { result.north += usngStr.charAt(j++) } return result; }, _USNGtoUTM: function (zone, mylet, sq1, sq2, east, north) { var result = {}; //Starts (southern edge) of N-S zones in millons of meters var zoneBase = [1.1, 2.0, 2.9, 3.8, 4.7, 5.6, 6.5, 7.3, 8.2, 9.1, 0, 0.8, 1.7, 2.6, 3.5, 4.4, 5.3, 6.2, 7.0, 7.9]; var segBase = [0, 2, 2, 2, 4, 4, 6, 6, 8, 8, 0, 0, 0, 2, 2, 4, 4, 6, 6, 6]; //Starts of 2 million meter segments, indexed by zone // convert easting to UTM var eSqrs = "ABCDEFGHJKLMNPQRSTUVWXYZ".indexOf(sq1); var appxEast = 1 + eSqrs % 8; // convert northing to UTM var letNorth = "CDEFGHJKLMNPQRSTUVWX".indexOf(mylet); if (zone % 2) //odd number zone var nSqrs = "ABCDEFGHJKLMNPQRSTUV".indexOf(sq2) else // even number zone var nSqrs = "FGHJKLMNPQRSTUVABCDE".indexOf(sq2); var zoneStart = zoneBase[letNorth]; var appxNorth = Number(segBase[letNorth]) + nSqrs / 10; if (appxNorth < zoneStart) appxNorth += 2; result.N = appxNorth * 1000000 + Number(north) * Math.pow(10, 5 - north.length); result.E = appxEast * 100000 + Number(east) * Math.pow(10, 5 - east.length) result.zone = zone; result.letter = mylet; return result; }, _UTMtoLL: function (UTMNorthing, UTMEasting, UTMZoneNumber, ret) { var EASTING_OFFSET = 500000.0; // (meters) var NORTHING_OFFSET = 10000000.0; // (meters) var k0 = 0.9996; var EQUATORIAL_RADIUS = 6378137.0; // GRS80 ellipsoid (meters) var ECC_SQUARED = 0.006694380023; var ECC_PRIME_SQUARED = ECC_SQUARED / (1 - ECC_SQUARED); var E1 = (1 - Math.sqrt(1 - ECC_SQUARED)) / (1 + Math.sqrt(1 - ECC_SQUARED)); var RAD_2_DEG = 180.0 / Math.PI; // remove 500,000 meter offset for longitude var xUTM = parseFloat(UTMEasting) - EASTING_OFFSET; var yUTM = parseFloat(UTMNorthing); var zoneNumber = parseInt(UTMZoneNumber); // origin longitude for the zone (+3 puts origin in zone center) var lonOrigin = (zoneNumber - 1) * 6 - 180 + 3; // M is the "true distance along the central meridian from the Equator to phi // (latitude) var M = yUTM / k0; var mu = M / (EQUATORIAL_RADIUS * (1 - ECC_SQUARED / 4 - 3 * ECC_SQUARED * ECC_SQUARED / 64 - 5 * ECC_SQUARED * ECC_SQUARED * ECC_SQUARED / 256)); // phi1 is the "footprint latitude" or the latitude at the central meridian which // has the same y coordinate as that of the point (phi (lat), lambda (lon) ). var phi1Rad = mu + (3 * E1 / 2 - 27 * E1 * E1 * E1 / 32) * Math.sin(2 * mu) + (21 * E1 * E1 / 16 - 55 * E1 * E1 * E1 * E1 / 32) * Math.sin(4 * mu) + (151 * E1 * E1 * E1 / 96) * Math.sin(6 * mu); var phi1 = phi1Rad * RAD_2_DEG; // Terms used in the conversion equations var N1 = EQUATORIAL_RADIUS / Math.sqrt(1 - ECC_SQUARED * Math.sin(phi1Rad) * Math.sin(phi1Rad)); var T1 = Math.tan(phi1Rad) * Math.tan(phi1Rad); var C1 = ECC_PRIME_SQUARED * Math.cos(phi1Rad) * Math.cos(phi1Rad); var R1 = EQUATORIAL_RADIUS * (1 - ECC_SQUARED) / Math.pow(1 - ECC_SQUARED * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5); var D = xUTM / (N1 * k0); // Calculate latitude, in decimal degrees var lat = phi1Rad - (N1 * Math.tan(phi1Rad) / R1) * (D * D / 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * ECC_PRIME_SQUARED) * D * D * D * D / 24 + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * ECC_PRIME_SQUARED - 3 * C1 * C1) * D * D * D * D * D * D / 720); lat = lat * RAD_2_DEG; // Calculate longitude, in decimal degrees var lng = (D - (1 + 2 * T1 + C1) * D * D * D / 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * ECC_PRIME_SQUARED + 24 * T1 * T1) * D * D * D * D * D / 120) / Math.cos(phi1Rad); lng = lonOrigin + lng * RAD_2_DEG; return L.latLng(lat, lng); }, point2LatLng: function (s) { var latLng = null; try { var usngp = this._parseUSNGText(s, usngp); if (!usngp) return null; var coords = this._USNGtoUTM(usngp.zone, usngp.mylet, usngp.sq1, usngp.sq2, usngp.east, usngp.north) if (usngp.mylet < 'N') { coords.N -= NORTHING_OFFSET } latLng = this._UTMtoLL(coords.N, coords.E, usngp.zone) } catch (e) { latLng = null; } return latLng; }, latlng2PointName: function (lat, lng) { var zone = GSI.UTM.Utils.lng2Zone(lng); var defName = GSI.UTM.Utils.getUTMDefName(zone); if (defName == '') return ''; var projUTM = new Proj4js.Proj(defName); var latLngPoint = new Proj4js.Point(lng, lat); var utmPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, latLngPoint); return GSI.UTM.Utils.getUTMPointName( zone, GSI.UTM.Utils.getUTMMark(lat), utmPoint.x, utmPoint.y, 4 ); }, getUTMPointName: function (zone, mark, x, y, num, hideNumber) { var x10mNumber = ''; var y10mNumber = ''; if (!hideNumber && x && y) { var zero = ''; for (var i = 0; i < num; i++) { zero += '0'; } x10mNumber = zero + Math.floor(x / 10); x10mNumber = x10mNumber.substr(x10mNumber.length - num, num); y10mNumber = zero + Math.floor(y / 10); y10mNumber = y10mNumber.substr(y10mNumber.length - num, num); } var letters = GSI.UTM.Utils.findGridLetters(zone, Math.floor(y / 10) * 10, Math.floor(x / 10) * 10); return zone + mark + letters + x10mNumber + y10mNumber; }, findSet: function (zoneNum) { zoneNum = parseInt(zoneNum); zoneNum = zoneNum % 6; switch (zoneNum) { case 0: return 6; case 1: return 1; case 2: return 2; case 3: return 3; case 4: return 4; case 5: return 5; default: return -1; } }, BLOCK_SIZE: 100000, GRIDSQUARE_SET_ROW_SIZE: 20, GRIDSQUARE_SET_COL_SIZE: 8, findGridLetters: function (zoneNum, northing, easting) { zoneNum = parseInt(zoneNum); northing = parseFloat(northing); easting = parseFloat(easting); row = 1; // northing coordinate to single-meter precision north_1m = Math.round(northing); // Get the row position for the square identifier that contains the point while (north_1m >= GSI.UTM.Utils.BLOCK_SIZE) { north_1m = north_1m - GSI.UTM.Utils.BLOCK_SIZE; row++; } // cycle repeats (wraps) after 20 rows row = row % GSI.UTM.Utils.GRIDSQUARE_SET_ROW_SIZE; col = 0; // easting coordinate to single-meter precision east_1m = Math.round(easting); // Get the column position for the square identifier that contains the point while (east_1m >= GSI.UTM.Utils.BLOCK_SIZE) { east_1m = east_1m - GSI.UTM.Utils.BLOCK_SIZE; col++; } // cycle repeats (wraps) after 8 columns col = col % GSI.UTM.Utils.GRIDSQUARE_SET_COL_SIZE; return GSI.UTM.Utils.lettersHelper(GSI.UTM.Utils.findSet(zoneNum), row, col); }, lettersHelper: function (set, row, col) { // handle case of last row if (row == 0) { row = GSI.UTM.Utils.GRIDSQUARE_SET_ROW_SIZE - 1; } else { row--; } if (col == 0) { col = GSI.UTM.Utils.GRIDSQUARE_SET_COL_SIZE - 1; } else { col--; } switch (set) { case 1: l1 = "ABCDEFGH"; // column ids l2 = "ABCDEFGHJKLMNPQRSTUV"; // row ids return l1.charAt(col) + l2.charAt(row); case 2: l1 = "JKLMNPQR"; l2 = "FGHJKLMNPQRSTUVABCDE"; return l1.charAt(col) + l2.charAt(row); case 3: l1 = "STUVWXYZ"; l2 = "ABCDEFGHJKLMNPQRSTUV"; return l1.charAt(col) + l2.charAt(row); case 4: l1 = "ABCDEFGH"; l2 = "FGHJKLMNPQRSTUVABCDE"; return l1.charAt(col) + l2.charAt(row); case 5: l1 = "JKLMNPQR"; l2 = "ABCDEFGHJKLMNPQRSTUV"; return l1.charAt(col) + l2.charAt(row); case 6: l1 = "STUVWXYZ"; l2 = "FGHJKLMNPQRSTUVABCDE"; return l1.charAt(col) + l2.charAt(row); } } }; GSI.UTM.Grid = L.Evented.extend({ options: { lineStyle: { color: "#FF0000", weight: 2, color2: "#FF0000", opacity: 1, fillOpacity: 1, dashArray: [3, 3], visible: false, clickable: false, noGeodesic: true }, zoneLineStyle: { color: "#FF0000", weight: 2, color2: "#FF0000", opacity: 1, fillOpacity: 1, dashArray: null, visible: false, clickable: false, noGeodesic: true }, labelClassName: 'utmgrid_label', visible: false }, _lines: [], _labels: [], _zoneLines: [], _zoneLabels: [], initialize: function (map, options) { this._lines = []; this._labels = []; this._zoneLines = []; this._zoneLabels = []; this._map = map; this._onMoveEnd = L.bind(this.onMoveEnd, this); options = L.setOptions(this, options); options.lineStyle.clickable = false; options.lineStyle.noGeodesic = true; options.zoneLineStyle.noGeodesic = true; if (this.options.visible) { this.options.visible = false; this.setVisible(true);//this.refresh(); } }, onMoveEnd: function () { this.refresh(); }, refresh: function () { if (!this.options.visible) { this.clear(); return; } if (GSI.Utils.Browser.ie && GSI.Utils.Browser.version <= 8) { this.clear(); } var bounds = this._map.getBounds(); var zoom = this._map.getZoom(); for (var i = 0; i < this.options.condition.length; i++) { var c = this.options.condition[i]; if (zoom <= c.zoom) { if (c.grid == 'a') { this._clearLayerArr(this._lines, 0); this._clearLayerArr(this._labels, 0); this.drawZoneGrid(bounds); } else { this.drawGrid(bounds, zoom, c.grid); this.drawZoneGrid(bounds, true, this.options.zoneLineStyle); } try { if (this._layer) this._layer.bringToBack(); } catch (ex) { } break; } } }, drawPath: function (texture, latLngBounds, pixelBounds) { var bounds = (latLngBounds ? latLngBounds : this._map.getBounds()); pixelBounds = (pixelBounds ? pixelBounds : this._map.getPixelBounds()); var zoom = this._map.getZoom(); for (var i = 0; i < this.options.condition.length; i++) { var c = this.options.condition[i]; if (zoom <= c.zoom) { if (c.grid == 'a') { this.drawZoneGridPath(texture, pixelBounds, bounds); } else { this.drawGridPath(texture, pixelBounds, bounds, zoom, c.grid); this.drawZoneGridPath(texture, pixelBounds, bounds, true, this.options.zoneLineStyle); } break; } } }, _drawTextToTexture: function (texture, latlng, text, pixelBounds) { var zoom = this._map.getZoom(); var p = this._map.project(latlng, zoom); p.x -= pixelBounds.min.x; p.y -= pixelBounds.min.y; texture.globalAlpha = 1.0; texture.fillStyle = this.options.lineStyle.color; texture.textBaseline = 'bottom'; texture.textAlign = 'left'; texture.font = "bold 12pt 'Lucida Grande','Hiragino Kaku Gothic ProN', 'ヒラギノ角ゴ ProN W3', Meiryo, メイリオ, sans-serif"; texture.fillText(text, p.x + 8, p.y - 6); }, _drawGridLineToTexture: function (texture, latlngs, pixelBounds, lineStyle) { var zoom = this._map.getZoom(); latlngs = (L.LineUtil.isFlat(latlngs) ? latlngs : latlngs[0]); texture.beginPath(); texture.lineWidth = lineStyle.weight; texture.strokeStyle = lineStyle.color; if (latlngs.length > 0) { var p = this._map.project(latlngs[0], zoom); p.x -= pixelBounds.min.x; p.y -= pixelBounds.min.y; texture.moveTo(p.x, p.y); } for (var i = 1; i < latlngs.length; i++) { var p1 = this._map.project(latlngs[i - 1], zoom); var p2 = this._map.project(latlngs[i], zoom); p1.x -= pixelBounds.min.x; p1.y -= pixelBounds.min.y; p2.x -= pixelBounds.min.x; p2.y -= pixelBounds.min.y; if (lineStyle.dashArray && lineStyle.dashArray.length > 0) this._lineToDot(texture, p1.x, p1.y, p2.x, p2.y); else texture.lineTo(p2.x, p2.y); } texture.stroke(); }, drawGridPath: function (texture, pixelBounds, bounds, zoom, meter) { // グリッド var startZone = GSI.UTM.Utils.lng2Zone(bounds.getWest()); var projUTM = new Proj4js.Proj(GSI.UTM.Utils.getUTMDefName(startZone)); var startLatLngPoint = new Proj4js.Point(bounds.getWest(), bounds.getSouth()); var startUTMPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, startLatLngPoint); startUTMPoint.x = Math.floor(startUTMPoint.x / meter) * meter; startUTMPoint.x -= meter; startUTMPoint.y = Math.floor(startUTMPoint.y / meter) * meter; startUTMPoint.y -= meter; // x軸ループ var utmX = startUTMPoint.x; var zone = startZone; var lineStyle = $.extend(true, {}, this.options.lineStyle); var xExit = false; var gridPoints = []; var gridPoints2 = []; var lineIndex = 0; var labelIndex = 0; while (true) { var currentZoneLng = GSI.UTM.Utils.zone2Lng(zone); var nextZoneLng = GSI.UTM.Utils.zone2Lng(zone + 1); var isNextZone = true; var xExit2 = true; // y軸ループ var latlngs = []; var labelLatlngs = []; var utmYs = []; var utmY = startUTMPoint.y; var yIndex = 0; var yIndex2 = 0; var x10mNumber = ''; if (meter < 100 * 1000) { x10mNumber = utmX; } var lastMark = ''; while (true) { var utmPoint = new Proj4js.Point(utmX, utmY); var latLngPoint = Proj4js.transform(projUTM, GSI.UTM.Utils.PROJ_WORLD, utmPoint); var mark = GSI.UTM.Utils.getUTMMark(latLngPoint.y); if (lastMark != '' && lastMark != mark) { var latLng = L.latLng(24 + Math.floor((latLngPoint.y - 24) / 8) * 8, latLngPoint.x); var changeUTMPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, new Proj4js.Point(latLng.lng, latLng.lat)); utmYs.push(changeUTMPoint.y); if (CONFIG.UTMGRIDBOUNDARYLABEL_HIDEMETER) latLng._hideMeter = true labelLatlngs.push(latLng); if (!gridPoints2[yIndex2]) gridPoints2[yIndex2] = []; gridPoints2[yIndex2].push(latLng); yIndex2++; } lastMark = mark; var latLng = L.latLng(latLngPoint.y, latLngPoint.x); utmYs.push(utmY); latlngs.push(latLng); labelLatlngs.push(latLng); if (!gridPoints[yIndex]) gridPoints[yIndex] = []; gridPoints[yIndex].push(latLng); if (latLngPoint.x < nextZoneLng) isNextZone = false; if (latLngPoint.x <= bounds.getEast()) xExit2 = false; yIndex++; utmY += meter; if (latLngPoint.y > bounds.getNorth()) break; } if (latlngs.length > 0) { this._drawGridLineToTexture(texture, latlngs, pixelBounds, lineStyle); lineIndex++; } if (isNextZone) { // 横線 for (var i = 0; i < gridPoints.length; i++) { if (!gridPoints[i]) continue; this._drawGridLineToTexture(texture, gridPoints[i], pixelBounds, lineStyle); lineIndex++; } for (var i = 0; i < gridPoints2.length; i++) { if (!gridPoints2[i]) continue; this._drawGridLineToTexture(texture, gridPoints2[i], pixelBounds, lineStyle); lineIndex++; } gridPoints = []; gridPoints2 = []; zone++; projUTM = new Proj4js.Proj(GSI.UTM.Utils.getUTMDefName(zone)); startLatLngPoint = new Proj4js.Point(GSI.UTM.Utils.zone2Lng(zone), bounds.getSouth()); startUTMPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, startLatLngPoint); startUTMPoint.x = Math.floor(startUTMPoint.x / meter) * meter; startUTMPoint.x -= meter; startUTMPoint.y = Math.floor(startUTMPoint.y / meter) * meter; startUTMPoint.y -= meter; utmX = startUTMPoint.x; } else { // ラベル表示 for (var i = 0; i < labelLatlngs.length; i++) { var latlng = labelLatlngs[i]; var utmY = utmYs[i]; var mark = GSI.UTM.Utils.getUTMMark(latlng.lat); // 2015-07-19 this._drawTextToTexture(texture, latlng, GSI.UTM.Utils.getUTMPointName(zone, mark, utmX, utmY, 4, (latlng._hideMeter || meter >= 100000)), pixelBounds); labelIndex++; } } if (xExit) { // 横線 for (var i = 0; i < gridPoints.length; i++) { if (!gridPoints[i]) continue; this._drawGridLineToTexture(texture, gridPoints[i], pixelBounds, lineStyle); lineIndex++; } for (var i = 0; i < gridPoints2.length; i++) { if (!gridPoints2[i]) continue; this._drawGridLineToTexture(texture, gridPoints2[i], pixelBounds, lineStyle); lineIndex++; } gridPoints = []; gridPoints2 = []; break; } utmX += meter; xExit = xExit2; } }, drawZoneGridPath: function (texture, pixelBounds, bounds, nolabel, style) { // 小縮尺用グリッド var startX = Math.floor(bounds.getWest() / 6) * 6; var startY = Math.floor(bounds.getSouth() / 8) * 8; var endX = (Math.floor(bounds.getEast() / 6) + 1) * 6; var endY = (Math.floor(bounds.getNorth() / 8) + 1) * 8; var lineStyle = $.extend(true, {}, (style ? style : this.options.lineStyle)); var lineIndex = 0; var labelIndex = 0; for (var y = startY; y <= endY; y += 8) { var mark = GSI.UTM.Utils.getUTMMark(y); if (y < 16) continue; if (y >= 57) break; var latlngs = []; for (var x = startX; x <= endX; x += 6) { if (!nolabel) { var zone = Math.floor(x / 6) + 31; var nextZone = Math.floor((x + 6) / 6) + 31; if (zone < 51) continue; if (zone > 57) break; if (y + 8 <= endY && y + 8 < 57 && x + 6 <= endX && nextZone <= 57) { this._drawTextToTexture(texture, L.latLng([y, x]), //{ 'lng' : x, 'lat' : y} , zone + mark, pixelBounds); labelIndex++; } } latlngs.push(L.latLng(y, x)); } this._drawGridLineToTexture(texture, latlngs, pixelBounds, lineStyle); lineIndex++; } for (var x = startX; x <= endX; x += 6) { var zone = Math.floor(x / 6) + 31; if (zone < 51 || zone > 57) continue; var latlngs = []; for (var y = startY; y <= endY; y += 8) { if (y < 16 || y >= 57) continue; latlngs.push(L.latLng(y, x)); } this._drawGridLineToTexture(texture, latlngs, pixelBounds, lineStyle); lineIndex++; } }, _lineToDot: function (texture, p1x, p1y, p2x, p2y) { var d = Math.sqrt(Math.pow(p2x - p1x, 2) + Math.pow(p2y - p1y, 2)); var rad = Math.atan2(p2y - p1y, p2x - p1x); var space = 3; var dotted = Math.round(d / space / 2); for (var i = 0; i < dotted; i++) { var p3x = Math.cos(rad) * space * (i * 2) + p1x; var p3y = Math.sin(rad) * space * (i * 2) + p1y; var p4x = Math.cos(rad) * space * (i * 2 + 1) + p1x; var p4y = Math.sin(rad) * space * (i * 2 + 1) + p1y; texture.moveTo(p3x, p3y); texture.lineTo(p4x, p4y); } }, _updateStyle: function (texture, layer) { if (!layer._parts) return; var options = layer.options; if (options.stroke) { texture.lineWidth = options.weight; texture.strokeStyle = options.color; } if (options.fill) { texture.fillStyle = options.fillColor || options.color; } }, _drawPath: function (texture, layer) { if (!layer._parts) return; var i, j, len, len2, point, drawMethod; var vp = this._map._pathViewport; var origin = this._map.getPixelOrigin(); var pixelBounds = this._map.getPixelBounds(); texture.beginPath(); var parts = layer._parts; for (i = 0, len = parts.length; i < len; i++) { for (j = 0, len2 = parts[i].length; j < len2; j++) { point = parts[i][j]; drawMethod = (j === 0 ? 'move' : 'line') + 'To'; texture[drawMethod](point.x + (origin.x - pixelBounds.min.x), point.y + (origin.y - pixelBounds.min.y)); } // TODO refactor ugly hack if (layer instanceof L.Polygon || layer instanceof L.Circle) { texture.closePath(); } } texture.save(); this._updateStyle(texture, layer); var opacity = 1; if (layer.options.fill) { texture.globalAlpha = (layer.options.fillOpacity ? layer.options.fillOpacity : 1) * opacity; texture.fill(); } if (layer.options.stroke) { texture.globalAlpha = opacity; texture.stroke(); } texture.restore(); }, drawGrid: function (bounds, zoom, meter) { // グリッド var startZone = GSI.UTM.Utils.lng2Zone(bounds.getWest()); var projUTM = new Proj4js.Proj(GSI.UTM.Utils.getUTMDefName(startZone)); var startLatLngPoint = new Proj4js.Point(bounds.getWest(), bounds.getSouth()); var startUTMPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, startLatLngPoint); startUTMPoint.x = Math.floor(startUTMPoint.x / meter) * meter; startUTMPoint.x -= meter; startUTMPoint.y = Math.floor(startUTMPoint.y / meter) * meter; startUTMPoint.y -= meter; // x軸ループ var utmX = startUTMPoint.x; var zone = startZone; var lineStyle = $.extend(true, {}, this.options.lineStyle); var xExit = false; var gridPoints = []; var gridPoints2 = []; var lineIndex = 0; var labelIndex = 0; var layer = (this._layer ? this._layer : L.featureGroup()); layer._noMeasure = true; while (true) { var currentZoneLng = GSI.UTM.Utils.zone2Lng(zone); var nextZoneLng = GSI.UTM.Utils.zone2Lng(zone + 1); var isNextZone = true; var xExit2 = true; // y軸ループ var latlngs = []; var labelLatlngs = []; var utmYs = []; var utmY = startUTMPoint.y; var yIndex = 0; var yIndex2 = 0; var x10mNumber = ''; if (meter < 100 * 1000) { x10mNumber = utmX; } var lastMark = ''; while (true) { var utmPoint = new Proj4js.Point(utmX, utmY); var latLngPoint = Proj4js.transform(projUTM, GSI.UTM.Utils.PROJ_WORLD, utmPoint); var mark = GSI.UTM.Utils.getUTMMark(latLngPoint.y); if (lastMark != '' && lastMark != mark) { var latLng = L.latLng(24 + Math.floor((latLngPoint.y - 24) / 8) * 8, latLngPoint.x); var changeUTMPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, new Proj4js.Point(latLng.lng, latLng.lat)); utmYs.push(changeUTMPoint.y); if (CONFIG.UTMGRIDBOUNDARYLABEL_HIDEMETER) latLng._hideMeter = true labelLatlngs.push(latLng); if (!gridPoints2[yIndex2]) gridPoints2[yIndex2] = []; gridPoints2[yIndex2].push(latLng); yIndex2++; } lastMark = mark; var latLng = L.latLng(latLngPoint.y, latLngPoint.x); utmYs.push(utmY); latlngs.push(latLng); labelLatlngs.push(latLng); if (!gridPoints[yIndex]) gridPoints[yIndex] = []; gridPoints[yIndex].push(latLng); if (latLngPoint.x < nextZoneLng) isNextZone = false; if (latLngPoint.x <= bounds.getEast()) xExit2 = false; yIndex++; utmY += meter; if (latLngPoint.y > bounds.getNorth()) break; } if (latlngs.length > 0) { if (this._lines.length <= lineIndex) { var polyline = L.polyline(latlngs, lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._lines.push(polyline); } else { var polyline = this._lines[lineIndex]; polyline.setLatLngs(latlngs); } lineIndex++; } if (isNextZone) { // 横線 for (var i = 0; i < gridPoints.length; i++) { if (!gridPoints[i]) continue; if (this._lines.length <= lineIndex) { var polyline = L.polyline(gridPoints[i], lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._lines.push(polyline); } else { var polyline = this._lines[lineIndex]; polyline.setLatLngs(gridPoints[i]); } lineIndex++; } for (var i = 0; i < gridPoints2.length; i++) { if (!gridPoints2[i]) continue; if (this._lines.length <= lineIndex) { var polyline = L.polyline(gridPoints2[i], lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._lines.push(polyline); } else { var polyline = this._lines[lineIndex]; polyline.setLatLngs(gridPoints2[i]); } lineIndex++; } gridPoints = []; gridPoints2 = []; zone++; projUTM = new Proj4js.Proj(GSI.UTM.Utils.getUTMDefName(zone)); startLatLngPoint = new Proj4js.Point(GSI.UTM.Utils.zone2Lng(zone), bounds.getSouth()); startUTMPoint = Proj4js.transform(GSI.UTM.Utils.PROJ_WORLD, projUTM, startLatLngPoint); startUTMPoint.x = Math.floor(startUTMPoint.x / meter) * meter; startUTMPoint.x -= meter; startUTMPoint.y = Math.floor(startUTMPoint.y / meter) * meter; startUTMPoint.y -= meter; utmX = startUTMPoint.x; } else { // ラベル表示 for (var i = 0; i < labelLatlngs.length; i++) { var latlng = labelLatlngs[i]; var utmY = utmYs[i]; var mark = GSI.UTM.Utils.getUTMMark(latlng.lat); // 2015-07-19 if (this._labels.length <= labelIndex) { var label = new L.Label({ zoomAnimation: true, noHide: true, offset: [8, -24], className: this.options.labelClassName + " nomaptoimage", clickable: false }); label.setContent(GSI.UTM.Utils.getUTMPointName(zone, mark, utmX, utmY, 4, (latlng._hideMeter || meter >= 100000))); label.setLatLng(latlng); layer.addLayer(label); this._labels.push(label); } else { var label = this._labels[labelIndex]; label.setContent(GSI.UTM.Utils.getUTMPointName(zone, mark, utmX, utmY, 4, (latlng._hideMeter || meter >= 100000))); label.setLatLng(latlng); } labelIndex++; } } if (xExit) { // 横線 for (var i = 0; i < gridPoints.length; i++) { if (!gridPoints[i]) continue; if (this._lines.length <= lineIndex) { var polyline = L.polyline(gridPoints[i], lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._lines.push(polyline); } else { var polyline = this._lines[lineIndex]; polyline.setLatLngs(gridPoints[i]); } lineIndex++; } for (var i = 0; i < gridPoints2.length; i++) { if (!gridPoints2[i]) continue; if (this._lines.length <= lineIndex) { var polyline = L.polyline(gridPoints2[i], lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._lines.push(polyline); } else { var polyline = this._lines[lineIndex]; polyline.setLatLngs(gridPoints2[i]); } lineIndex++; } gridPoints = []; gridPoints2 = []; break; } utmX += meter; xExit = xExit2; } if (!this._layer) { this._layer = layer; this._map.addLayer(this._layer); } this._clearLayerArr(this._lines, lineIndex); this._clearLayerArr(this._labels, labelIndex); }, drawZoneGrid: function (bounds, nolabel, style) { // 小縮尺用グリッド var startX = Math.floor(bounds.getWest() / 6) * 6; var startY = Math.floor(bounds.getSouth() / 8) * 8; var endX = (Math.floor(bounds.getEast() / 6) + 1) * 6; var endY = (Math.floor(bounds.getNorth() / 8) + 1) * 8; var lineStyle = $.extend(true, {}, (style ? style : this.options.lineStyle)); var lineIndex = 0; var labelIndex = 0; var layer = (this._layer ? this._layer : L.featureGroup()); layer._noMeasure = true; for (var y = startY; y <= endY; y += 8) { var mark = GSI.UTM.Utils.getUTMMark(y); if (y < 16) continue; if (y >= 57) break; var latlngs = []; for (var x = startX; x <= endX; x += 6) { if (!nolabel) { var zone = Math.floor(x / 6) + 31; var nextZone = Math.floor((x + 6) / 6) + 31; if (zone < 51) continue; if (zone > 57) break; if (y + 8 <= endY && y + 8 < 57 && x + 6 <= endX && nextZone <= 57) { if (this._zoneLabels.length <= labelIndex) { var label = new L.Label({ zoomAnimation: true, noHide: true, offset: [8, -24], className: this.options.labelClassName + " nomaptoimage" }); label.setContent(zone + mark); label.setLatLng({ 'lng': x, 'lat': y }); layer.addLayer(label); this._zoneLabels.push(label); } else { var label = this._zoneLabels[labelIndex]; label.setContent(zone + mark); label.setLatLng({ 'lng': x, 'lat': y }); } labelIndex++; } } latlngs.push(L.latLng(y, x)); } if (this._zoneLines.length <= lineIndex) { var polyline = L.polyline(latlngs, lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._zoneLines.push(polyline); } else { var polyline = this._zoneLines[lineIndex]; polyline.setStyle(lineStyle); polyline.setLatLngs(latlngs); } lineIndex++; } for (var x = startX; x <= endX; x += 6) { var zone = Math.floor(x / 6) + 31; if (zone < 51 || zone > 57) continue; var latlngs = []; for (var y = startY; y <= endY; y += 8) { if (y < 16 || y >= 57) continue; latlngs.push(L.latLng(y, x)); } if (this._zoneLines.length <= lineIndex) { var polyline = L.polyline(latlngs, lineStyle); polyline._noMeasure = true; layer.addLayer(polyline); this._zoneLines.push(polyline); } else { var polyline = this._zoneLines[lineIndex]; polyline.setStyle(lineStyle); polyline.setLatLngs(latlngs); } lineIndex++; } if (!this._layer) { this._layer = layer; this._map.addLayer(this._layer); } this._clearLayerArr(this._zoneLines, lineIndex); this._clearLayerArr(this._zoneLabels, labelIndex); }, _clearLayerArr: function (arr, idx) { if (this._layer) { for (var i = idx; i < arr.length; i++) { this._layer.removeLayer(arr[i]); } } if (arr.length > idx) { arr.splice(idx); } }, clear: function () { if (this._layer) { this._map.removeLayer(this._layer); this._layer = null; } this._lines = []; this._labels = []; this._zoneLines = []; this._zoneLabels = []; }, setVisible: function (visible) { if (visible) { this.show(); } else { this.hide(); } this.fire("change"); }, getVisible: function () { return this.options.visible; }, show: function () { if (!this.options.visible) { this.options.visible = true; this._map.on('moveend', this._onMoveEnd); this.refresh(); } }, hide: function () { if (this.options.visible) { this.options.visible = false; this._map.off('moveend', this._onMoveEnd); this.refresh(); } } }); GSI.CenterCross = L.Evented.extend({ marker: null, options: { visible: true }, initialize: function (map, options) { options = L.setOptions(this, options); this.map = map; this._refresh = L.bind(this.refresh, this); this.setVisible(this.options.visible); }, refresh: function () { if (this.options.visible) { var pos = this.map.getCenter(); if (!this.marker) { var icon = L.divIcon({ iconSize: [32, 32], iconAnchor: [16, 16], className: 'gsi_centercross', html: "" }); this.marker = new GSI.CenterCrossMarker(pos, { icon: icon, clickable: false, draggable: false, keyboard: false, opacity: 0.8, zIndexOffset: 0 }); this.marker.addTo(this.map); } else { this.marker.setLatLng(pos); } } else if (this.marker) { this.map.removeLayer(this.marker); this.marker = null; } }, setVisible: function (on) { this.options.visible = on; if (this.options.visible) { this.map.on('move', this._refresh); } else { this.map.off('move', this._refresh); } this.refresh(); this.fire("change", { visible: this.options.visible }); }, getVisible: function () { return this.options.visible; } }); GSI.ZoomGuide = L.Evented.extend({ options: { visible: true }, initialize: function (map, options) { options = L.setOptions(this, options); this.map = map; this.setVisible(this.options.visible); }, setVisible: function (on) { this.options.visible = on; }, getVisible: function () { return this.options.visible; } }); /************************************************************************ L.Class - GSI.COCOTileLayer ************************************************************************/ GSI.COCOTileLayer = L.Layer.extend({ visible: true, options: { minZoom: 0, maxZoom: 18, tileSize: 256, errorTileUrl: '', zoomOffset: 0, refreshInterval: 1000, unloadInvisibleTiles: L.Browser.mobile, updateWhenIdle: L.Browser.mobile }, initialize: function (map, url, options) { this.map = map; options = L.setOptions(this, options); this.visible = options.visible; // detecting retina displays, adjusting tileSize and zoom levels if (options.detectRetina && L.Browser.retina && options.maxZoom > 0) { options.tileSize = Math.floor(options.tileSize / 2); options.zoomOffset++; if (options.minZoom > 0) { options.minZoom--; } this.options.maxZoom--; } if (options.bounds) { options.bounds = L.latLngBounds(options.bounds); } this._url = url; if (options.visible) { this.addTo(this.map); } }, onAdd: function (map) { this._map = map; this._reset(); this._update(); map.on({ 'viewreset': this._reset, 'moveend': this._moveend, 'movestart': this._movestart }, this); }, addTo: function (map) { this.visible = true; map.addLayer(this); return this; }, getVisible: function () { return this.visible; }, setVisible: function (on) { if (on) { this.addTo(this.map); } else if (this._map) { this.visible = false; this.map.removeLayer(this); this.fire('hide', null); } }, refresh: function () { if (this.visible) { this._reset(); this._update(); } }, onRemove: function (map) { map.off({ 'viewreset': this._reset, 'moveend': this._update, 'movestart': this._movestart }, this); this._map = null; }, _reset: function (e) { if (this._tiles) { for (var id in this._tiles) { var tile = this._tiles[id]; if (tile.ajax) { tile.ajax.abort(); tile.ajax = null; } } } if (this.refreshTimerId) { clearTimeout(this.refreshTimerId); this.refreshTimerId = null; } this._haveTiles = {}; this._tiles = {}; this._tilesToLoad = 0; }, _moveend: function () { if (!this._map) { return; } this._reset(); this.refreshTimerId = setTimeout( L.Util.bind(this._timerRefresh, this), this.options.refreshInterval); }, _movestart: function () { this._reset(); }, _timerRefresh: function () { this._update(); }, _update: function () { if (this.refreshTimerId) { clearTimeout(this.refreshTimerId); this.refreshTimerId = null; } if (!this._map) { return; } var map = this._map, bounds = this.map.getPixelBounds(), zoom = this.map.getZoom(), tileSize = this._getTileSize(); if (zoom > this.options.maxZoom || zoom < this.options.minZoom) { return; } var tileBounds = L.bounds( bounds.min.divideBy(tileSize)._floor(), bounds.max.divideBy(tileSize)._floor()); this._addTilesFromCenterOut(tileBounds); }, _getTileSize: function () { var map = this._map, zoom = this.map.getZoom() + this.options.zoomOffset, zoomN = this.options.maxNativeZoom, tileSize = this.options.tileSize; if (zoomN && zoom > zoomN) { tileSize = Math.round(this.map.getZoomScale(zoom) / this.map.getZoomScale(zoomN) * tileSize); } return tileSize; }, _tileShouldBeLoaded: function (tilePoint) { if ((tilePoint.x + ':' + tilePoint.y) in this._tiles) { return false; // already loaded } var options = this.options; if (!options.continuousWorld) { var limit = this._getWrapTileNum(); // don't load if exceeds world bounds if ((options.noWrap && (tilePoint.x < 0 || tilePoint.x >= limit.x)) || tilePoint.y < 0 || tilePoint.y >= limit.y) { return false; } } if (options.bounds) { var tileSize = options.tileSize, nwPoint = tilePoint.multiplyBy(tileSize), sePoint = nwPoint.add([tileSize, tileSize]), nw = this._map.unproject(nwPoint), se = this._map.unproject(sePoint); // TODO temporary hack, will be removed after refactoring projections // https://github.com/Leaflet/Leaflet/issues/1618 if (!options.continuousWorld && !options.noWrap) { nw = nw.wrap(); se = se.wrap(); } if (!options.bounds.intersects([nw, se])) { return false; } } return true; }, _addTilesFromCenterOut: function (bounds) { var queue = [], center = bounds.getCenter(); var j, i, point; for (j = bounds.min.y; j <= bounds.max.y; j++) { for (i = bounds.min.x; i <= bounds.max.x; i++) { point = new L.Point(i, j); if (this._tileShouldBeLoaded(point)) { queue.push(point); } } } var tilesToLoad = queue.length; if (tilesToLoad === 0) { return; } queue.sort(function (a, b) { return a.distanceTo(center) - b.distanceTo(center); }); this._tilesToLoad += tilesToLoad; for (i = 0; i < tilesToLoad; i++) { this._addTile(queue[i]); } this.fire('loadstart', null); }, _getTilePos: function (tilePoint) { var origin = this._map.getPixelOrigin(), tileSize = this._getTileSize(); return tilePoint.multiplyBy(tileSize).subtract(origin); }, _addTile: function (tilePoint) { var tilePos = this._getTilePos(tilePoint); var tile = {}; this._tiles[tilePoint.x + ':' + tilePoint.y] = tile; this._loadTile(tile, tilePoint); }, _resetTile: function (/*tile*/) { }, _adjustTilePoint: function (tilePoint) { var limit = this._getWrapTileNum(); if (!this.options.continuousWorld && !this.options.noWrap) { tilePoint.x = ((tilePoint.x % limit.x) + limit.x) % limit.x; } if (this.options.tms) { tilePoint.y = limit.y - tilePoint.y - 1; } tilePoint.z = this._getZoomForUrl(); }, _getZoomForUrl: function () { var options = this.options, zoom = this._map.getZoom(); if (options.zoomReverse) { zoom = options.maxZoom - zoom; } zoom += options.zoomOffset; return options.maxNativeZoom ? Math.min(zoom, options.maxNativeZoom) : zoom; }, _getWrapTileNum: function () { var crs = this._map.options.crs; var s = crs.scale(this._map.getZoom()); var size = L.point(s, s); return size.divideBy(this._getTileSize())._floor(); }, getTileUrl: function (url, tilePoint) { return L.Util.template(url, L.extend({ z: tilePoint.z, x: tilePoint.x, y: tilePoint.y }, this.options)); }, _loadTile: function (tile, tilePoint) { this._adjustTilePoint(tilePoint); this._loadTileAjax(this._url.concat(), tile, tilePoint); }, _loadTileAjax: function (url, tile, tilePoint) { if (url.length != 0) { tile.src = this.getTileUrl(url[0], tilePoint); tile.ajax = $.ajax({ url: tile.src, cache: CONFIG.LOADCOCOTILECACHE, crossDomain: true, success: L.Util.bind(this._tileLoaded, this, url, tile, tilePoint), complete: L.Util.bind(this._tileLoaded_Complete, this, url, tile, tilePoint) }); } }, _tileLoaded: function (url, tile, tilePoint) { if (tile.ajax) { var lines = tile.ajax.responseText.split("\n"); if (lines.length > 0) { var line = lines[0]; var ids = line.split(','); for (var i = 0; i < ids.length; i++) { var tileId = ids[i]; this._haveTiles[tileId] = true; } } } }, _tileLoaded_Complete: function (url, tile, tilePoint) { if (tile.ajax) { var ret = false; if (url.length > 0) { url.shift(); if (url.length > 0) { this._loadTileAjax(url, tile, tilePoint); ret = true; } } if (!ret) { tile.ajax = null; } } tile.loaded = true; var n = 0; for (var id in this._tiles) { n++; var tile = this._tiles[id]; if (tile.ajax || !tile.loaded) { return; } } if (this.options.onLoad) this.options.onLoad(this._haveTiles); if (this.refreshTimerId_load) { clearTimeout(this.refreshTimerId_load); this.refreshTimerId_load = null; } if (n == 0) { return; } var that = this; this.refreshTimerId_load = setTimeout( function () { that.refreshTimerId_load = null; that.fire('load', { tileIds: that._haveTiles }); } , 100); } }); /************************************************************************ L.Class - GSI.Dialog ************************************************************************/ GSI.Dialog = L.Evented.extend({ options: { containerClass: 'gsi_dialog', headerClass: 'gsi_dialog_header', contentClass: 'gsi_dialog_content', effect: null, top: 0, left: 0, width: 300, resizable: "" }, _userResized: false, initialize: function (dialogManager, options) { options = L.setOptions(this, options); this._dialogManager = dialogManager; this._dialogManager.append(this); this.create(); if (options.visible) this.show(); }, getTitle: function () { return this.options.title; }, isMinimized: function () { return this._dialogManager.isMinimized(this); }, isResizable: function () { return (this.options.resizable && this.options.resizable != '' ? true : false); }, createHeader: function () { return $('').html('       '); }, createContent: function () { return $('
').html('       '); }, _cloceButtonClick: function () { this.hide(true); }, _minimizeButtonClick: function () { this.minimize(); }, _dragMove: function () { }, create: function () { if (this.container) return; this.container = $('
').addClass(this.options.containerClass); this.headerFrame = $('
').addClass(this.options.headerClass); this.contentFrame = $('
').addClass(this.options.contentClass); this.closeBtn = $('').html('×').attr({ 'href': 'javascript:void(0);' }).addClass('closebtn'); if (this.options.minimize) { this.minimizeBtn = $('').html('-').attr({ 'href': 'javascript:void(0);' }).addClass('minimizebtn'); } this.headerTitle = $('
').addClass('title'); this.headerFrame.append(this.headerTitle); if (this.minimizeBtn) this.headerFrame.append(this.minimizeBtn); this.headerFrame.append(this.closeBtn); this.headerTitle.append(this.createHeader()); this.contentFrame.append(this.createContent()); this.container.append(this.headerFrame); this.container.append(this.contentFrame); $(document.body).append(this.container); this.container.draggable({ delay: 100, scroll: false, handle: this.headerFrame, stop: L.bind(function () { this._dialogManager.adjust(this); this._dragEnd(); }, this), start: L.bind(function () { this.container.css({ "clip": "auto" }); }, this), drag: L.bind(function () { this._dragMove(); }, this) }) .on('mousedown', L.bind(this.onClick, this)) .on('touchstart', L.bind(this.onClick, this)); if (this.options.width) { this.container.css({ width: this.options.width }); } this.closeBtn.on('click',L.bind(this._cloceButtonClick, this)); if (this.minimizeBtn) this.minimizeBtn.on('click',L.bind(this._minimizeButtonClick, this)); this.container.hide(); var left = this.options.left; if (left == 'center') { var screenSize = this._dialogManager.getScreenSize(); left = Math.floor((screenSize.w / 2) - (parseInt(this.options.width) / 2)); left += screenSize.left; } else { var screenSize = this._dialogManager.getScreenSize(); if (left + this.options.width > screenSize.w) { left = screenSize.w - this.options.width - 8; } } this.container.css({ left: left + 'px', top: this.options.top + 'px', width: this.options.width + 'px', "min-width": "80px", height: 'auto' }); if (this.isResizable()) { this.container.resizable({ resize: L.bind(function (evt, ui) { this._onResize(ui); this._userResized = true; }, this), handles: this.options.resizable }); } if (this._createAfter) this._createAfter(); }, _dragEnd: function (e, ui) { var size = this._dialogManager.getScreenSize(); var w = this.container.outerWidth(); var h = this.container.outerHeight(); var left = this.container.position().left; var top = this.container.position().top; var right = w + left; if (size.w < right || size.left > left || top + h > size.h) { if (top + h > size.h) h = size.h - top; this.container.css({ "clip": "rect(" + (this._marginLeft ? this._marginLeft : 0) + "px," + (w - (right - (size.left + size.w))) + "px," + 9999 + "px," + (size.left - left) + "px)" }); } else this.container.css({ "clip": "auto" }); }, css: function (css) { if (this.container) this.container.css(css); }, _onResize: function () { }, addClass: function (className) { if (this.container) this.container.addClass(className); }, removeClass: function (className) { if (this.container) this.container.removeClass(className); }, show: function (noActivate) { if (this.container && this._dialogManager.isMinimized(this)) { this._dialogManager.removeMinimizeList(this); this.normalize(); return; } if (!this.container) this.create(); this._dialogManager.appendVisibleList(this, noActivate); var visible = this.container.is(":visible"); if (!visible) this.container.css({ "visibility": "hidden" }).show(); this._dragEnd(); if (!visible) this.container.css({ "visibility": "visible" }).hide(); if (!this.container.is(":visible")) { this.container.css({ "opacity": 0, "transform": "scale(0)" }).show(); } this.container.finish().animate( { "opacity": 1 }, { "duration": 200, "step": L.bind(function (now) { this.container.css({ "transform": "scale(" + now + ")" }); }, this), "complete": L.bind(function () { if (this.afterShow) this.afterShow(); }, this) } ); return; }, hide: function () { this._dialogManager.removeMinimizeList(this); this._dialogManager.removeVisibleList(this); this.container.finish().css({ "transform": "scale(1)" }).animate( { "opacity": 0 }, { "duration": 200, "step": L.bind(function (now) { this.container.css({ "transform": "scale(" + now + ")" }); }, this), "complete": L.bind(function () { this.container.hide().css({ "opacity": 1, "transform": "scale(1)" }); }, this) } ); return; }, normalize: function () { this._dialogManager.appendVisibleList(this); var visible = this.container.is(":visible"); if (!visible) this.container.css({ "visibility": "hidden" }).show(); this._dragEnd(); if (!visible) this.container.css({ "visibility": "visible" }).hide(); this.container.finish().css({ "opacity": 0, "transform": "scale(0)" }).show().animate( { "opacity": 1 }, { "duration": 200, "step": L.bind(function (now) { this.container.css({ "transform": "scale(" + now + ")" }); }, this), "complete": L.bind(function () { }, this) } ); return; }, minimize: function () { this._dialogManager.removeVisibleList(this); var pos = this.container.offset(); var screenSize = this._dialogManager.getScreenSize(); this.container.finish().css({ "transform": "scale(1)" }).animate( { "opacity": 0 }, { "duration": 300, "step": L.bind(function (to, now) { var x = (to.x - Math.floor(to.x * now)) / (now * 2); var y = (to.y - Math.floor(to.y * now)) / (now * 2); this.container.css({ "transform": "scale(" + now + ") translate(" + x + "px, " + y + "px)" }); }, this, { x: screenSize.w - pos.left, y: screenSize.h - pos.top }), "complete": L.bind(function () { this.container.hide().css({ "opacity": 1, "transform": "scale(1)" }); }, this) } ); this._dialogManager.appendMinimizeList(this); }, setMaxScrollHeight: function (maxHeight) { }, getVisible: function () { return (this.container && this.container.is(':visible') ? true : false); }, onClick: function () { this._dialogManager.activate(this); }, getLeft: function () { if (!this.container) return this.options.left; var visible = this.container.is(':visible'); if (!visible) { this.container.css({ "visibility": "hidden" }).show(); } var left = this.container.offset().left; if (!visible) { this.container.hide().css({ "visibility": "visible" }); } return left; }, setLeft: function (left) { if (!this.container) { this.options.left = left; return; } this.container.css({ "left": left + "px" }); this._dialogManager.adjust(this); } }); /************************************************************************ L.Class - GSI.Dialog - GSI.HelpDialog (ヘルプダイアログ管理) ************************************************************************/ GSI.HelpDialog = L.Class.extend({ options: { }, initialize: function (map, mapMouse, options) { this.map = map; this.mapMouse = mapMouse; this._blind = $("
") .on('click',L.bind(function () { this.hide(); }, this)) .addClass("help_window_blind"); this._frame = $("
").addClass("help_window_frame"); this._titleFrame = $("
").addClass("help_window_content_title"); this._contentFrame = $("
").addClass("help_window_content_frame"); this._contentFrame.on({ /* フリック開始時 */ 'touchstart': L.bind(function (e) { this._touchX = e.originalEvent.changedTouches[0].pageX; this._touchStartX = this._touchX; this._accel = 0; this._touchY = e.originalEvent.changedTouches[0].pageY; //←縦方向のタッチ位置も取得 }, this), /* フリック中 */ 'touchmove': L.bind(function (e) { var moveX = this.touchX - e.originalEvent.changedTouches[0].pageX, moveY = this.touchY - e.originalEvent.changedTouches[0].pageY, //←縦方向のタッチ位置も取得 moveRate = moveX / moveY; //←フリックした縦横の移動量の比率を計算 //↓垂直方向から15度以上の方向にフリックした場合のみ、ページのスクロールをキャンセル if (moveRate > Math.tan(15 * Math.PI / 180)) { e.preventDefault(); } this._accel = (e.originalEvent.changedTouches[0].pageX - this._touchX) * 5; this._touchX = e.originalEvent.changedTouches[0].pageX; this._touchEndX = this._touchX; }, this), /* フリック終了 */ 'touchend': L.bind(function (e) { if (Math.abs(this._touchEndX - this._touchStartX) > 50) { if (this._accel > 1) this.prev(); else if (this._accel < -1) this.next(); } }, this) }); this._closeButton = $("") .attr({ "href": "javascript:void(0);" }) .on('click',L.bind(function () { this.hide(); }, this)) .addClass("help_window_closebtn").html("×"); this._titleFrame.append($("")); this._titleFrame.append(this._closeButton); this._frame.append(this._titleFrame); this._frame.append(this._contentFrame); this._nextButton = $("") .attr({ "href": "javascript:void(0);" }) .addClass("help_window_frame_button") .addClass("help_window_frame_next_button") .html("") .on('click',L.bind(function () { this._nextButton.trigger('blur'); this.next(); }, this)); this._prevButton = $("") .attr({ "href": "javascript:void(0);" }) .addClass("help_window_frame_button") .addClass("help_window_frame_prev_button") .html("") .on('click',L.bind(function () { this._prevButton.trigger('blur'); this.prev(); }, this)); this._frame.append(this._prevButton); this._frame.append(this._nextButton); this._contentList = []; this._selectedIndex = -1; $("#help .help_content").each(L.bind(function (index, elem) { this._contentList.push({ content: $(elem).clone(), title: $(elem).attr("title") }); }, this)); this.select(0); $("body").append(this._blind); $("body").append(this._frame); }, next: function () { if (this._contentList.length > this._selectedIndex + 1) this.select(this._selectedIndex + 1); else this.select(0); }, prev: function () { if (0 <= this._selectedIndex - 1) this.select(this._selectedIndex - 1); else this.select(this._contentList.length - 1); }, select: function (index) { if (this._contentList && this._contentList.length > index && index >= 0) { if (this._selectedIndex >= 0) { this._contentFrame.fadeOut(100, L.bind(function () { this._titleFrame.find("span").empty().append(this._contentList[index].title); this._contentFrame.empty().append(this._contentList[index].content); this._contentFrame.fadeIn(100); }, this)); } else { this._titleFrame.find("span").empty().append(this._contentList[index].title); this._contentFrame.empty().append(this._contentList[index].content); } this._selectedIndex = index; } }, getVisible: function () { return (this._blind ? this._blind.is(":visible") : false); }, show: function () { this._blind.fadeIn(200); this._frame.fadeIn(200); }, hide: function () { this._blind.fadeOut(200); this._frame.fadeOut(200); }, create: function () { this.title = $('
').html(this.options.title); return $('
').append(this.title); } }); GSI.HelpDialog.hide = function () { if (GSI.GLOBALS.HelpDialog) GSI.GLOBALS.HelpDialog.hide(); }; /************************************************************************ L.Class - GSI.Dialog - GSI.SearchResultDialog ************************************************************************/ GSI.SearchResultDialog = GSI.Dialog.extend({ options: { title: '検索結果', maxMarkerNum: 30, minimize: true }, initialize: function (dialogManager, map, options) { this.map = map; GSI.Dialog.prototype.initialize.call(this, dialogManager, options); }, setTitle: function (title) { var subTitle = $('').html("協力:東大CSIS").addClass('searchresultdialog_subtitle') .css({ 'font-size': '7pt' }).attr('href', 'https://geocode.csis.u-tokyo.ac.jp/home/simple-geocoding/') .attr('target', '_blank'); this.title.html(title).append(subTitle); }, _onResize: function () { GSI.Dialog.prototype._onResize.call(this); var height = this.container.outerHeight(false) - this.headerFrame.outerHeight(true) - this.selectFrame.outerHeight(true) - 8; this.listFrame.css({ "max-height": 'none', height: height + 'px' }); }, createHeader: function () { this.title = $('
').html(this.options.title); return $('
').append(this.title); }, hide: function () { if (this.markerList) this.map.removeLayer(this.markerList); GSI.Dialog.prototype.hide.call(this); }, createContent: function () { this.frame = $('
'); var selectFrame = $('
').addClass("searchresultdialog_select_frame"); this.selectFrame = selectFrame; this.kenSelect = $('').css({ 'width': '48%', 'margin-left': '4px' }); this.typeSelect = $('