Comparing version 4.0.4 to 4.0.5
@@ -12,2 +12,4 @@ /* Copyright (c) 2016 Jean-Marc VIGLINO, | ||
* @constructor | ||
* @fires control:active | ||
* @fires control:add | ||
* @extends ol_control_Control | ||
@@ -183,2 +185,7 @@ * @param {Object=} options Control options. | ||
} | ||
if (e.type) { | ||
this.dispatchEvent({ type: 'control:active', control: ctrl, active: e.active }) | ||
} else { | ||
this.dispatchEvent({ type: 'control:add', control: ctrl, active: e.active }) | ||
} | ||
} | ||
@@ -185,0 +192,0 @@ /** |
@@ -272,10 +272,9 @@ import {unByKey as ol_Observable_unByKey} from 'ol/Observable.js' | ||
if (!this._moving) { | ||
this.dispatchEvent({ type: 'select', feature: f }); | ||
this._scrolldiv.scrollLeft = img.offsetLeft | ||
+ ol_ext_element.getStyle(img, 'width') / 2 | ||
- ol_ext_element.getStyle(this.element, 'width') / 2; | ||
if (this._select) | ||
this._select.elt.classList.remove('select'); | ||
+ ol_ext_element.getStyle(img, 'width') / 2 | ||
- ol_ext_element.getStyle(this.element, 'width') / 2; | ||
if (this._select) this._select.elt.classList.remove('select'); | ||
this._select = sel; | ||
this._select.elt.classList.add('select'); | ||
if (this._select) this._select.elt.classList.add('select'); | ||
this.dispatchEvent({ type: 'select', feature: f }); | ||
} | ||
@@ -282,0 +281,0 @@ }.bind(this)); |
@@ -265,3 +265,3 @@ /* Copyright (c) 2015 Jean-Marc VIGLINO, | ||
ol_ext_element.setStyle(this.element, { height: '100%' }) | ||
var li = this.panel_.querySelectorAll('li.visible .li-content')[0] | ||
var li = this.panel_.querySelectorAll('li.ol-visible .li-content')[0] | ||
var lh = li ? 2 * ol_ext_element.getStyle(li, 'height') : 0 | ||
@@ -340,4 +340,5 @@ switch (dir) { | ||
var i = li.querySelector('.layerswitcher-opacity-cursor') | ||
if (i) | ||
if (i){ | ||
i.style.left = (layer.getOpacity() * 100) + "%" | ||
} | ||
this.dispatchEvent({ type: 'layer:opacity', layer: layer }) | ||
@@ -352,8 +353,10 @@ } | ||
var i = li.querySelector('.ol-visibility') | ||
if (i) | ||
if (i) { | ||
i.checked = layer.getVisible() | ||
if (layer.getVisible()) | ||
} | ||
if (layer.getVisible()){ | ||
li.classList.add('ol-visible') | ||
else | ||
} else{ | ||
li.classList.remove('ol-visible') | ||
} | ||
this.dispatchEvent({ type: 'layer:visible', layer: layer }) | ||
@@ -379,4 +382,5 @@ } | ||
for (var i = 0, l; l = this._layers[i]; i++) { | ||
if (l.li === li) | ||
if (l.li === li) { | ||
return l.layer | ||
} | ||
} | ||
@@ -393,6 +397,7 @@ return null | ||
if (l) { | ||
if (this.testLayerVisibility(l)) | ||
if (this.testLayerVisibility(l)) { | ||
li.classList.remove('ol-layer-hidden') | ||
else | ||
} else { | ||
li.classList.add('ol-layer-hidden') | ||
} | ||
} | ||
@@ -422,4 +427,5 @@ }.bind(this)) | ||
drawPanel_() { | ||
if (--this.dcount || this.dragging_) | ||
if (--this.dcount || this.dragging_) { | ||
return | ||
} | ||
var scrollTop = this.panelContainer_.scrollTop | ||
@@ -434,7 +440,7 @@ | ||
// Draw list | ||
if (this._layerGroup) | ||
if (this._layerGroup) { | ||
this.drawList(this.panel_, this._layerGroup.getLayers()) | ||
else if (this.getMap()) | ||
} else if (this.getMap()) { | ||
this.drawList(this.panel_, this.getMap().getLayers()) | ||
} | ||
// Reset scrolltop | ||
@@ -452,7 +458,9 @@ this.panelContainer_.scrollTop = scrollTop | ||
} else { | ||
if (!l.getVisible()) | ||
if (!l.getVisible()) { | ||
l.setVisible(true) | ||
} | ||
layers.forEach(function (li) { | ||
if (l !== li && li.get('baseLayer') && li.getVisible()) | ||
if (l !== li && li.get('baseLayer') && li.getVisible()) { | ||
li.setVisible(false) | ||
} | ||
}) | ||
@@ -721,6 +729,7 @@ } | ||
var l = self._getLayerForLI(this.parentNode.parentNode) | ||
if (self.onextent) | ||
if (self.onextent) { | ||
self.onextent(l) | ||
else | ||
} else { | ||
self.getMap().getView().fit(l.getExtent(), self.getMap().getSize()) | ||
} | ||
self.dispatchEvent({ type: "extent", layer: l }) | ||
@@ -755,3 +764,3 @@ } | ||
var li = ol_ext_element.create('LI', { | ||
className: (layer.getVisible() ? "visible " : " ") + (layer.get('baseLayer') ? "baselayer" : ""), | ||
className: (layer.getVisible() ? "ol-visible " : " ") + (layer.get('baseLayer') ? "baselayer" : ""), | ||
parent: ul | ||
@@ -758,0 +767,0 @@ }) |
@@ -5,3 +5,2 @@ import {asString as ol_color_asString} from 'ol/color.js' | ||
import ol_legend_Legend from '../legend/Legend.js' | ||
import ol_ext_element from '../util/element.js'; | ||
@@ -8,0 +7,0 @@ /** Create a legend for styles |
@@ -162,3 +162,2 @@ /* | ||
/** Print the map | ||
* @param {function} cback a callback function that take a string containing the requested data URI. | ||
* @param {Object} options | ||
@@ -165,0 +164,0 @@ * @param {string} options.imageType A string indicating the image format, default the control one |
@@ -26,2 +26,3 @@ /* Copyright (c) 2017 Jean-Marc VIGLINO, | ||
* @param {function | undefined} options.getSearchString a function that take a feature and return a text to be used as search string, default geTitle() is used as search string | ||
* @param {function | undefined} options.sort a function to sort autocomplete list. Takes 2 features and return 0, -1 or 1. | ||
*/ | ||
@@ -41,2 +42,3 @@ var ol_control_SearchFeature = class olcontrolSearchFeature extends ol_control_Search { | ||
this.source_ = options.source; | ||
this._sort = options.sort; | ||
} | ||
@@ -72,5 +74,5 @@ /** No history avaliable on features | ||
/** Get the source | ||
* @return {ol.source.Vector} | ||
* @api | ||
*/ | ||
* @return {ol.source.Vector} | ||
* @api | ||
*/ | ||
getSource() { | ||
@@ -80,15 +82,21 @@ return this.source_; | ||
/** Get the source | ||
* @param {ol.source.Vector} source | ||
* @api | ||
*/ | ||
* @param {ol.source.Vector} source | ||
* @api | ||
*/ | ||
setSource(source) { | ||
this.source_ = source; | ||
} | ||
/** Set function to sort autocomplete results | ||
* @param {function} sort a sort function that takes 2 features and returns 0, -1 or 1 | ||
*/ | ||
setSortFunction(sort) { | ||
this._sort = sort | ||
} | ||
/** Autocomplete function | ||
* @param {string} s search string | ||
* @param {int} max max | ||
* @param {function} cback a callback function that takes an array to display in the autocomplete field (for asynchronous search) | ||
* @return {Array<any>|false} an array of search solutions or false if the array is send with the cback argument (asnchronous) | ||
* @api | ||
*/ | ||
* @param {string} s search string | ||
* @param {int} max max | ||
* @param {function} cback a callback function that takes an array to display in the autocomplete field (for asynchronous search) | ||
* @return {Array<any>|false} an array of search solutions or false if the array is send with the cback argument (asnchronous) | ||
* @api | ||
*/ | ||
autocomplete(s) { | ||
@@ -112,2 +120,5 @@ var result = []; | ||
} | ||
if (typeof(this._sort) === 'function') { | ||
result = result.sort(this._sort) | ||
} | ||
return result; | ||
@@ -114,0 +125,0 @@ } |
@@ -18,2 +18,3 @@ /* Copyright (c) 2017 Jean-Marc VIGLINO, | ||
* @param {string | undefined} [options.apiKey] the service api key. | ||
* @param {string | undefined} [options.version] API version '2' to use geocodage-beta-2, default v1 | ||
* @param {string | undefined} options.authentication: basic authentication for the service API as btoa("login:pwd") | ||
@@ -30,2 +31,3 @@ * @param {Element | string | undefined} options.target Specify a target if you want the control to be rendered outside of the map's viewport. | ||
* @see {@link https://geoservices.ign.fr/documentation/geoservices/geocodage.html} | ||
* @see {@link https://geoservices.ign.fr/documentation/services/api-et-services-ogc/geocodage-beta-20/documentation-technique-de-lapi} | ||
*/ | ||
@@ -37,3 +39,7 @@ var ol_control_SearchGeoportail = class olcontrolSearchGeoportail extends ol_control_SearchJSON { | ||
options.typing = options.typing || 500; | ||
options.url = 'https://wxs.ign.fr/' + (options.apiKey || 'essentiels') + '/ols/apis/completion'; | ||
if (options.version == 2) { | ||
options.url = 'https://wxs.ign.fr/' + (options.apiKey || 'essentiels') + '/geoportail/geocodage/rest/0.1/completion'; | ||
} else { | ||
options.url = 'https://wxs.ign.fr/' + (options.apiKey || 'essentiels') + '/ols/apis/completion'; | ||
} | ||
options.copy = '<a href="https://www.geoportail.gouv.fr/" target="new">© IGN-Géoportail</a>'; | ||
@@ -61,61 +67,104 @@ super(options); | ||
var type = this.get('type') === 'Commune' ? 'PositionOfInterest' : this.get('type') || 'StreetAddress'; | ||
if (/,/.test(type)) | ||
type = 'StreetAddress'; | ||
// request | ||
var request = '<?xml version="1.0" encoding="UTF-8"?>' | ||
+ '<XLS xmlns:xls="http://www.opengis.net/xls" xmlns:gml="http://www.opengis.net/gml" xmlns="http://www.opengis.net/xls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="http://www.opengis.net/xls http://schemas.opengis.net/ols/1.2/olsAll.xsd">' | ||
+ ' <Request requestID="1" version="1.2" methodName="ReverseGeocodeRequest" maximumResponses="1" >' | ||
+ ' <ReverseGeocodeRequest>' | ||
+ ' <ReverseGeocodePreference>' + type + '</ReverseGeocodePreference>' | ||
+ ' <Position>' | ||
+ ' <gml:Point><gml:pos>' + lonlat[1] + ' ' + lonlat[0] + '</gml:pos></gml:Point>' | ||
+ ' </Position>' | ||
+ ' </ReverseGeocodeRequest>' | ||
+ ' </Request>' | ||
+ '</XLS>'; | ||
if (/,/.test(type)) type = 'StreetAddress'; | ||
this.ajax(this.get('url').replace('ols/apis/completion', 'geoportail/ols'), | ||
{ xls: request }, | ||
function (xml) { | ||
var f = {}; | ||
if (!xml) { | ||
f = { x: lonlat[0], y: lonlat[1], fulltext: lonlat[0].toFixed(6) + ',' + lonlat[1].toFixed(6) }; | ||
} else { | ||
xml = xml.replace(/\n|\r/g, ''); | ||
var p = (xml.replace(/.*<gml:pos>(.*)<\/gml:pos>.*/, "$1")).split(' '); | ||
if (!Number(p[1]) && !Number(p[0])) { | ||
// Search url | ||
var url = this.get('url').replace('ols/apis/completion', 'geoportail/ols').replace('completion', 'reverse'); | ||
if (/ols/.test(url)) { | ||
// request | ||
var request = '<?xml version="1.0" encoding="UTF-8"?>' | ||
+ '<XLS xmlns:xls="http://www.opengis.net/xls" xmlns:gml="http://www.opengis.net/gml" xmlns="http://www.opengis.net/xls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="http://www.opengis.net/xls http://schemas.opengis.net/ols/1.2/olsAll.xsd">' | ||
+ ' <Request requestID="1" version="1.2" methodName="ReverseGeocodeRequest" maximumResponses="1" >' | ||
+ ' <ReverseGeocodeRequest>' | ||
+ ' <ReverseGeocodePreference>' + type + '</ReverseGeocodePreference>' | ||
+ ' <Position>' | ||
+ ' <gml:Point><gml:pos>' + lonlat[1] + ' ' + lonlat[0] + '</gml:pos></gml:Point>' | ||
+ ' </Position>' | ||
+ ' </ReverseGeocodeRequest>' | ||
+ ' </Request>' | ||
+ '</XLS>'; | ||
this.ajax(url, | ||
{ xls: request }, | ||
function (xml) { | ||
var f = {}; | ||
if (!xml) { | ||
f = { x: lonlat[0], y: lonlat[1], fulltext: lonlat[0].toFixed(6) + ',' + lonlat[1].toFixed(6) }; | ||
} else { | ||
f.x = lonlat[0]; | ||
f.y = lonlat[1]; | ||
f.city = (xml.replace(/.*<Place type="Municipality">([^<]*)<\/Place>.*/, "$1")); | ||
f.insee = (xml.replace(/.*<Place type="INSEE">([^<]*)<\/Place>.*/, "$1")); | ||
f.zipcode = (xml.replace(/.*<PostalCode>([^<]*)<\/PostalCode>.*/, "$1")); | ||
if (/<Street>/.test(xml)) { | ||
f.kind = ''; | ||
f.country = 'StreetAddress'; | ||
f.street = (xml.replace(/.*<Street>([^<]*)<\/Street>.*/, "$1")); | ||
var number = (xml.replace(/.*<Building number="([^"]*).*/, "$1")); | ||
f.fulltext = number + ' ' + f.street + ', ' + f.zipcode + ' ' + f.city; | ||
xml = xml.replace(/\n|\r/g, ''); | ||
var p = (xml.replace(/.*<gml:pos>(.*)<\/gml:pos>.*/, "$1")).split(' '); | ||
if (!Number(p[1]) && !Number(p[0])) { | ||
f = { x: lonlat[0], y: lonlat[1], fulltext: lonlat[0].toFixed(6) + ',' + lonlat[1].toFixed(6) }; | ||
} else { | ||
f.kind = (xml.replace(/.*<Place type="Nature">([^<]*)<\/Place>.*/, "$1")); | ||
f.country = 'PositionOfInterest'; | ||
f.street = ''; | ||
f.fulltext = f.zipcode + ' ' + f.city; | ||
f.x = lonlat[0]; | ||
f.y = lonlat[1]; | ||
f.city = (xml.replace(/.*<Place type="Municipality">([^<]*)<\/Place>.*/, "$1")); | ||
f.insee = (xml.replace(/.*<Place type="INSEE">([^<]*)<\/Place>.*/, "$1")); | ||
f.zipcode = (xml.replace(/.*<PostalCode>([^<]*)<\/PostalCode>.*/, "$1")); | ||
if (/<Street>/.test(xml)) { | ||
f.kind = ''; | ||
f.country = 'StreetAddress'; | ||
f.street = (xml.replace(/.*<Street>([^<]*)<\/Street>.*/, "$1")); | ||
var number = (xml.replace(/.*<Building number="([^"]*).*/, "$1")); | ||
f.fulltext = number + ' ' + f.street + ', ' + f.zipcode + ' ' + f.city; | ||
} else { | ||
f.kind = (xml.replace(/.*<Place type="Nature">([^<]*)<\/Place>.*/, "$1")); | ||
f.country = 'PositionOfInterest'; | ||
f.street = ''; | ||
f.fulltext = f.zipcode + ' ' + f.city; | ||
} | ||
} | ||
} | ||
if (typeof (options) === 'function') { | ||
options.call(this, [f]); | ||
} else { | ||
this.getHistory().shift(); | ||
this._handleSelect(f, true, options); | ||
// this.setInput('', true); | ||
// this.drawList_(); | ||
} | ||
}.bind(this), { | ||
timeout: this.get('timeout'), | ||
dataType: 'XML' | ||
}); | ||
} else { | ||
this.ajax(url + '?lon='+lonlat[0] + '&lat=' + lonlat[1], | ||
{}, | ||
function(resp) { | ||
var f; | ||
try { | ||
resp = JSON.parse(resp).features[0]; | ||
f = resp.properties; | ||
// lonlat | ||
f.x = resp.geometry.coordinates[0]; | ||
f.y = resp.geometry.coordinates[1]; | ||
f.click = lonlat; | ||
// Fulltext | ||
if (f.name) { | ||
f.fulltext = f.name + ', ' + f.postcode + ' ' + f.city; | ||
} else { | ||
f.fulltext = f.postcode + ' ' + f.city; | ||
} | ||
} catch(e) { | ||
f = { | ||
x: lonlat[0], | ||
y: lonlat[1], | ||
lonlat: lonlat, | ||
fulltext: lonlat[0].toFixed(6) + ',' + lonlat[1].toFixed(6) | ||
}; | ||
} | ||
if (typeof (options) === 'function') { | ||
options.call(this, [f]); | ||
} else { | ||
this.getHistory().shift(); | ||
this._handleSelect(f, true, options); | ||
// this.setInput('', true); | ||
// this.drawList_(); | ||
} | ||
}.bind(this), { | ||
timeout: this.get('timeout'), | ||
dataType: 'XML' | ||
} | ||
if (typeof (options) === 'function') { | ||
options.call(this, [f]); | ||
} else { | ||
this.getHistory().shift(); | ||
this._handleSelect(f, true, options); | ||
// this.setInput('', true); | ||
// this.drawList_(); | ||
} | ||
}.bind(this), { | ||
timeout: this.get('timeout'), | ||
dataType: 'XML' | ||
); | ||
} | ||
); | ||
} | ||
@@ -122,0 +171,0 @@ /** Returns the text to be displayed in the menu |
@@ -14,3 +14,3 @@ import ol_control_Control from 'ol/control/Control.js' | ||
* @param {Object=} options Control options. | ||
* @param {String} options.className class of the control | ||
* @param {String} options.className class of the control (scrollLine, scrollBox or any) | ||
* @param {Element | string | undefined} [options.html] The storymap content | ||
@@ -17,0 +17,0 @@ * @param {Element | string | undefined} [options.target] The target element to place the story. If no html is provided the content of the target will be used. |
@@ -114,5 +114,6 @@ import ol_control_WMSCapabilities from './WMSCapabilities.js'; | ||
return tm.TileMatrixSet === 'PM' | ||
|| tm.TileMatrixSet === '3857' | ||
|| tm.TileMatrixSet === 'EPSG:3857' | ||
|| tm.TileMatrixSet === 'webmercator' | ||
|| tm.TileMatrixSet === '3857' | ||
|| tm.TileMatrixSet === 'EPSG:3857' | ||
|| tm.TileMatrixSet === 'webmercator' | ||
|| tm.TileMatrixSet === 'GoogleMapsCompatible' | ||
} | ||
@@ -119,0 +120,0 @@ /** Return a WMTS options for the given capabilities |
@@ -70,3 +70,3 @@ /* Copyright (c) 2017 Jean-Marc VIGLINO, | ||
for (var x = 0; x < w2; x++) | ||
for (var y = 0; y < h2; y++) { | ||
for (var y = 0; y < h2; y++) if (data[x * 4 + 3 + y * w2 * 4]) { | ||
var pix; | ||
@@ -73,0 +73,0 @@ switch (this.get('channel')) { |
@@ -134,135 +134,2 @@ /* Copyright (c) 2016 Jean-Marc VIGLINO, | ||
/* Copyright (c) 2016 Jean-Marc VIGLINO, | ||
released under the CeCILL-B license (French BSD license) | ||
(http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt). | ||
Usefull function to handle geometric operations | ||
*/ | ||
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/ | ||
import ol_geom_MultiLineString from 'ol/geom/MultiLineString.js' | ||
import ol_geom_Polygon from 'ol/geom/Polygon.js' | ||
import ol_geom_MultiPolygon from 'ol/geom/Multipolygon.js' | ||
import '../render/Cspline.js' | ||
import { ol_coordinate_splitH } from "./GeomUtils.js"; | ||
/** | ||
* Calculate a MultiPolyline to fill a Polygon with a scribble effect that appears hand-made | ||
* @param {} options | ||
* @param {Number} options.interval interval beetween lines | ||
* @param {Number} options.angle hatch angle in radian, default PI/2 | ||
* @return {ol_geom_MultiLineString|null} the resulting MultiLineString geometry or null if none | ||
*/ | ||
ol_geom_MultiPolygon.prototype.scribbleFill = function (options) { | ||
var scribbles = []; | ||
var poly = this.getPolygons(); | ||
var i, p, s; | ||
for (i=0; p=poly[i]; i++) { | ||
var mls = p.scribbleFill(options); | ||
if (mls) scribbles.push(mls); | ||
} | ||
if (!scribbles.length) return null; | ||
// Merge scribbles | ||
var scribble = scribbles[0]; | ||
var ls; | ||
for (i = 0; s = scribbles[i]; i++) { | ||
ls = s.getLineStrings(); | ||
for (var k = 0; k < ls.length; k++) { | ||
scribble.appendLineString(ls[k]); | ||
} | ||
} | ||
return scribble; | ||
}; | ||
/** | ||
* Calculate a MultiPolyline to fill a Polygon with a scribble effect that appears hand-made | ||
* @param {} options | ||
* @param {Number} options.interval interval beetween lines | ||
* @param {Number} options.angle hatch angle in radian, default PI/2 | ||
* @return {ol_geom_MultiLineString|null} the resulting MultiLineString geometry or null if none | ||
*/ | ||
ol_geom_Polygon.prototype.scribbleFill = function (options) { | ||
var step = options.interval; | ||
var angle = options.angle || Math.PI/2; | ||
var i, k,l; | ||
// Geometry + rotate | ||
var geom = this.clone(); | ||
geom.rotate(angle, [0,0]); | ||
var coords = geom.getCoordinates(); | ||
// Merge holes | ||
var coord = coords[0]; | ||
for (i=1; i<coords.length; i++) { | ||
// Add a separator | ||
coord.push([]); | ||
// Add the hole | ||
coord = coord.concat(coords[i]); | ||
} | ||
// Extent | ||
var ext = geom.getExtent(); | ||
// Split polygon with horizontal lines | ||
var lines = []; | ||
for (var y = (Math.floor(ext[1]/step)+1)*step; y<ext[3]; y += step) { | ||
l = ol_coordinate_splitH(coord, y, i); | ||
lines = lines.concat(l); | ||
} | ||
if (!lines.length) return null; | ||
// Order lines on segment index | ||
var mod = coord.length-1; | ||
var first = lines[0][0].index; | ||
for (k=0; l=lines[k]; k++) { | ||
lines[k][0].index = (lines[k][0].index-first+mod) % mod; | ||
lines[k][1].index = (lines[k][1].index-first+mod) % mod; | ||
} | ||
var scribble = []; | ||
while (true) { | ||
for (k=0; l=lines[k]; k++) { | ||
if (!l[0].done) break; | ||
} | ||
if (!l) break; | ||
var scrib = []; | ||
while (l) { | ||
l[0].done = true; | ||
scrib.push(l[0].pt); | ||
scrib.push(l[1].pt); | ||
var nexty = l[0].pt[1] + step; | ||
var d0 = Infinity; | ||
var l2 = null; | ||
while (lines[k]) { | ||
if (lines[k][0].pt[1] > nexty) break; | ||
if (lines[k][0].pt[1] === nexty) { | ||
var d = Math.min( | ||
(lines[k][0].index - l[0].index + mod) % mod, | ||
(l[0].index - lines[k][0].index + mod) % mod | ||
); | ||
var d2 = Math.min( | ||
(l[1].index - l[0].index + mod) % mod, | ||
(l[0].index - l[1].index + mod) % mod | ||
); | ||
if (d<d0 && d<d2) { | ||
d0 = d; | ||
if (!lines[k][0].done) l2 = lines[k]; | ||
else l2 = null; | ||
} | ||
} | ||
k++; | ||
} | ||
l = l2; | ||
} | ||
if (scrib.length) { | ||
scribble.push(scrib); | ||
} | ||
} | ||
// Return the scribble as MultiLineString | ||
if (!scribble.length) return null; | ||
var mline = new ol_geom_MultiLineString(scribble); | ||
mline.rotate(-angle,[0,0]); | ||
return mline.cspline({ pointsPerSeg:8, tension:.9 }); | ||
}; | ||
/** Calculate a MultiPolyline to fill a geomatry (Polygon or MultiPolygon) with a scribble effect that appears hand-made | ||
@@ -269,0 +136,0 @@ * @param {ol_geom_Geometry} geom the geometry to scribble |
@@ -36,6 +36,5 @@ import ol_interaction_Interaction from 'ol/interaction/Interaction.js' | ||
var self = this | ||
zone.addEventListener('drop', function (e) { | ||
return self.ondrop(e) | ||
}) | ||
return this.ondrop(e) | ||
}.bind(this)) | ||
} | ||
@@ -59,3 +58,2 @@ /** Set the map | ||
if (e.dataTransfer && e.dataTransfer.files.length) { | ||
var self = this | ||
var projection = this.projection_ || (this.getMap() ? this.getMap().getView().getProjection() : null) | ||
@@ -66,41 +64,39 @@ // fetch FileList object | ||
// process all File objects | ||
var file | ||
var pat = /\.([0-9a-z]+)(?=[?#])|(\.)(?:[\w]+)$/ | ||
for (var i = 0; file = files[i]; i++) { | ||
Array.prototype.forEach.call(files, function(file) { | ||
var ex = file.name.match(pat)[0] | ||
var isok = (this.accept_.indexOf(ex.toLocaleLowerCase()) >= 0) | ||
self.dispatchEvent({ type: 'loadstart', file: file, filesize: file.size, filetype: file.type, fileextension: ex, projection: projection, isok: isok }) | ||
this.dispatchEvent({ type: 'loadstart', file: file, filesize: file.size, filetype: file.type, fileextension: ex, projection: projection, isok: isok }) | ||
// Don't load file | ||
if (!this.formatConstructors_.length) | ||
continue | ||
if (this.formatConstructors_.length) { | ||
// Load file | ||
var reader = new FileReader() | ||
var formatConstructors = this.formatConstructors_ | ||
// Load file | ||
var reader = new FileReader() | ||
var formatConstructors = this.formatConstructors_ | ||
var theFile = file | ||
reader.onload = function (e) { | ||
var result = e.target.result | ||
var theFile = file | ||
reader.onload = function (e) { | ||
var result = e.target.result | ||
var features = [] | ||
var i, ii | ||
for (i = 0, ii = formatConstructors.length; i < ii; ++i) { | ||
var formatConstructor = formatConstructors[i] | ||
try { | ||
var format = new formatConstructor() | ||
features = format.readFeatures(result, { featureProjection: projection }) | ||
if (features && features.length > 0) { | ||
self.dispatchEvent({ type: 'addfeatures', features: features, file: theFile, projection: projection }) | ||
self.dispatchEvent({ type: 'loadend', features: features, file: theFile, projection: projection }) | ||
return | ||
} | ||
} catch (e) { /* ok */ } | ||
} | ||
// Nothing match, try to load by yourself | ||
self.dispatchEvent({ type: 'loadend', file: theFile, result: result }) | ||
var features = [] | ||
var i, ii | ||
for (i = 0, ii = formatConstructors.length; i < ii; ++i) { | ||
var formatConstructor = formatConstructors[i] | ||
try { | ||
var format = new formatConstructor() | ||
features = format.readFeatures(result, { featureProjection: projection }) | ||
if (features && features.length > 0) { | ||
this.dispatchEvent({ type: 'addfeatures', features: features, file: theFile, projection: projection }) | ||
this.dispatchEvent({ type: 'loadend', features: features, file: theFile, projection: projection }) | ||
return | ||
} | ||
} catch (e) { /* ok */ } | ||
} | ||
// Nothing match, try to load by yourself | ||
this.dispatchEvent({ type: 'loadend', file: theFile, result: result }) | ||
}.bind(this) | ||
// Start loading | ||
reader.readAsText(file) | ||
} | ||
// Start loading | ||
reader.readAsText(file) | ||
} | ||
}.bind(this)) | ||
} | ||
@@ -107,0 +103,0 @@ return false |
{ | ||
"name": "ol-ext", | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"description": "A set of cool extensions for OpenLayers (ol) in node modules structure", | ||
@@ -5,0 +5,0 @@ "main": "dist/ol-ext.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6316674
496
102044