Skip to content

Commit

Permalink
Bump leaflet version for tests to 1.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Apr 22, 2016
1 parent c20061c commit 7779c2e
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 214 deletions.
23 changes: 15 additions & 8 deletions .eslintrc
Expand Up @@ -2,28 +2,35 @@
"rules": {
"camelcase": 2,
"quotes": [2, "single", "avoid-escape"],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"space-after-function-name": 2,
"indent": "error",
"space-before-function-paren": 2,
"space-in-parens": 2,
"space-in-brackets": 2,
"object-curly-spacing": 2,
"space-before-blocks": 2,
"space-after-keywords": 2,
"keyword-spacing": 2,
"no-lonely-if": 2,
"comma-style": 2,
"no-underscore-dangle": 0,
"no-constant-condition": 0,
"no-multi-spaces": 0,
"strict": 0,
"key-spacing": 0,
"no-shadow": 0
"no-shadow": 0,
"no-console": 0
},
"globals": {
"L": true,
"module": false,
"define": false
"module": true,
"define": true
},
"plugins": [
"html"
],
"settings": {
"html/report-bad-indent": 2,
"html/indent": "space"
},
"env": {
"browser": true,
"amd": true
}
}
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -3,6 +3,9 @@
Leaflet layer instances cannot be added to different maps in one javascript runtime.
`leaflet-clonelayer` clones layers to allow reuse.

- Works with leaflet 0.7.7 and 1.0.0-rc.1
- Used in jieter/Leaflet.layerscontrol-minimap

## Example

```JavaScript
Expand All @@ -19,6 +22,3 @@ console.log(L.stamp(cloned)); // 2
// Different _leaflet_id, so now we can safely add it to another map
cloned.addTo(map2);
```

## Used in
- https://github.com/jieter/Leaflet.layerscontrol-minimap
100 changes: 50 additions & 50 deletions index.js
@@ -1,59 +1,59 @@
function cloneLayer(layer) {
var options = layer.options;
function cloneLayer (layer) {
var options = layer.options;

// Tile layers
if (layer instanceof L.TileLayer) {
return L.tileLayer(layer._url, options);
}
if (layer instanceof L.ImageOverlay) {
return L.imageOverlay(layer._url, layer._bounds, options);
}
// Tile layers
if (layer instanceof L.TileLayer) {
return L.tileLayer(layer._url, options);
}
if (layer instanceof L.ImageOverlay) {
return L.imageOverlay(layer._url, layer._bounds, options);
}

// Marker layers
if (layer instanceof L.Marker) {
return L.marker(layer.getLatLng(), options);
}
if (layer instanceof L.circleMarker) {
return L.circleMarker(layer.getLatLng(), options);
}
// Marker layers
if (layer instanceof L.Marker) {
return L.marker(layer.getLatLng(), options);
}
if (layer instanceof L.circleMarker) {
return L.circleMarker(layer.getLatLng(), options);
}

// Vector layers
if (layer instanceof L.Rectangle) {
return L.rectangle(layer.getBounds(), options);
}
if (layer instanceof L.Polygon) {
return L.polygon(layer.getLatLngs(), options);
}
if (layer instanceof L.Polyline) {
return L.polyline(layer.getLatLngs(), options);
}
// MultiPolyline is removed in leaflet 0.8-dev
if (L.MultiPolyline && layer instanceof L.MultiPolyline) {
return L.polyline(layer.getLatLngs(), options);
}
// MultiPolygon is removed in leaflet 0.8-dev
if (L.MultiPolygon && layer instanceof L.MultiPolygon) {
return L.multiPolygon(layer.getLatLngs(), options);
}
if (layer instanceof L.Circle) {
return L.circle(layer.getLatLng(), layer.getRadius(), options);
}
if (layer instanceof L.GeoJSON) {
return L.geoJson(layer.toGeoJSON(), options);
}
// Vector layers
if (layer instanceof L.Rectangle) {
return L.rectangle(layer.getBounds(), options);
}
if (layer instanceof L.Polygon) {
return L.polygon(layer.getLatLngs(), options);
}
if (layer instanceof L.Polyline) {
return L.polyline(layer.getLatLngs(), options);
}
// MultiPolyline is removed in leaflet 1.0.0
if (L.MultiPolyline && layer instanceof L.MultiPolyline) {
return L.polyline(layer.getLatLngs(), options);
}
// MultiPolygon is removed in leaflet 1.0.0
if (L.MultiPolygon && layer instanceof L.MultiPolygon) {
return L.multiPolygon(layer.getLatLngs(), options);
}
if (layer instanceof L.Circle) {
return L.circle(layer.getLatLng(), layer.getRadius(), options);
}
if (layer instanceof L.GeoJSON) {
return L.geoJson(layer.toGeoJSON(), options);
}

// layer/feature groups
if (layer instanceof L.LayerGroup || layer instanceof L.FeatureGroup) {
var layergroup = L.layerGroup();
layer.eachLayer(function (inner) {
layergroup.addLayer(cloneLayer(inner));
});
return layergroup;
}
// layer/feature groups
if (layer instanceof L.LayerGroup || layer instanceof L.FeatureGroup) {
var layergroup = L.layerGroup();
layer.eachLayer(function (inner) {
layergroup.addLayer(cloneLayer(inner));
});
return layergroup;
}

throw 'Unknown layer, cannot clone this layer';
throw 'Unknown layer, cannot clone this layer';
}

if (typeof exports === 'object') {
module.exports = cloneLayer;
module.exports = cloneLayer;
}
21 changes: 12 additions & 9 deletions package.json
Expand Up @@ -4,9 +4,10 @@
"description": "Clone leaflet layers",
"main": "index.js",
"scripts": {
"lint": "eslint index.js test/spec.js",
"test": "npm run lint && npm run test-browser",
"test-browser": "mocha-phantomjs test/index.html",
"lint": "eslint index.js test/spec.js test/index.html",
"test": "npm run lint && npm run test-node && npm run test-browser",
"test-browser": "phantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html",
"test-node": "mocha test/spec.js",
"release": "mversion patch -m"
},
"repository": {
Expand All @@ -25,12 +26,14 @@
},
"homepage": "https://github.com/jieter/leaflet-clonelayer",
"devDependencies": {
"chai": "^2.1.2",
"chai-leaflet": "0.0.10",
"eslint": "^0.16.2",
"mocha": "^2.2.1",
"mocha-phantomjs": "^3.5.3",
"chai": "^3.5.0",
"chai-leaflet": "0.0.11",
"eslint": "^2.7.0",
"eslint-plugin-html": "^1.4.0",
"leaflet-headless": "^0.1.1",
"mocha": "^2.4.5",
"mocha-phantomjs-core": "^2.0.1",
"mversion": "^1.10.0",
"phantomjs": "^1.9.16"
"phantomjs-prebuilt": "^2.1.4"
}
}
37 changes: 19 additions & 18 deletions test/index.html
@@ -1,31 +1,32 @@
<html>
<head>
<meta charset="utf-8">
<title>leaflet-clonelayer Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<meta charset="utf-8">
<title>leaflet-clonelayer Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.0-rc.1/leaflet.css" />
</head>
<body>
<div id="mocha"></div>
<div id="mocha"></div>

<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="http://cdn.leafletjs.com/leaflet/v1.0.0-rc.1/leaflet.js"></script>

<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai-leaflet/chai-leaflet.js"></script>

<script src="../index.js"></script>

<script>
mocha.setup('bdd');
</script>
<script src="../index.js"></script>

<script src="spec.js"></script>
<script>
window.initMochaPhantomJS();
mocha.setup('bdd');
</script>

<script>
mocha.globals(['L']);
(window.mochaPhantomJS || mocha).run();
</script>
<script src="spec.js"></script>

<script>
mocha.globals(['L']);
(window.mochaPhantomJS || mocha).run();
</script>
</body>
</html>

0 comments on commit 7779c2e

Please sign in to comment.