diff --git a/.editorconfig b/.editorconfig index 1d1c76e..17ddf75 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ charset = utf-8 indent_style = space indent_size = 4 -[{package.json,package-lock.json,.travis.yml}] +[{package.json,package-lock.json}] indent_style = space indent_size = 2 diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 3ffb0b0..0000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -# /node_modules/* and /bower_components/* ignored by default - -# Ignore built files -build/* - -# Ignore dist files -dist/* diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 49939b4..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": ["eslint:recommended", "google"], - "env": { - "browser": true, - "commonjs": true - }, - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module" - }, - "rules": { - "max-len": ["error", {"code": 120, "ignoreStrings": true}], - "comma-dangle": ["error", "never"], - "space-before-function-paren": ["warn", {"anonymous": "always", "named": "never"}] - } -} diff --git a/.gitignore b/.gitignore index 6df3e26..ce6733b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .idea -node_modules/ -dist/ +/node_modules/ +/dist/ +/example/*.js +bundle.js *.tgz diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..4ddba9a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "printWidth": 120, + "trailingComma": "all", + "singleQuote": true +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 24a8ab9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: node_js -node_js: - - "5" diff --git a/Dockerfile b/Dockerfile index 34d3c80..25b868e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,11 @@ FROM node:8-alpine WORKDIR /opt/mapbox-gl-circle COPY package.json /opt/mapbox-gl-circle/ +COPY index.html /opt/mapbox-gl-circle/ +COPY lib/main.ts /opt/mapbox-gl-circle/lib/ +COPY example/index.ts /opt/mapbox-gl-circle/example/ -RUN npm install && mkdir -p example/ lib/ - -COPY lib/main.js /opt/mapbox-gl-circle/lib/ -COPY example/index.js /opt/mapbox-gl-circle/example/ +RUN npm install EXPOSE 9966 35729 diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100755 index cef185e..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env groovy - -//noinspection GroovyAssignabilityCheck -pipeline { - agent any - stages { - stage('Set Build Variables') { - steps { - script { - - def getProjectVersion = { -> - return sh( - returnStdout: true, - script: 'echo $(node -e "console.log(require(\'./package.json\').version)")' - ).replace('\n', '') - } - - def getBranchTypeAndName = { String fullBranchName -> - - if (fullBranchName in ['develop', 'master']) { - return [fullBranchName, fullBranchName] - } - - if (fullBranchName.matches(/(feature|bugfix)\/[.\d\-\w]+$/)) { - return [fullBranchName.split('/')[0], - fullBranchName.split('/')[1].toLowerCase().replaceAll(/[^.\da-z]/, '.')] - } - - if (fullBranchName.matches(/hotfix\/\d+(\.\d+){1,2}p\d+$/)) { - return fullBranchName.split('/') as List - } - - if (fullBranchName.matches(/release\/\d+(\.\d+){1,2}([ab]\d+)?$/)) { - return fullBranchName.split('/') as List - } - - if (fullBranchName.matches(/PR-\d+$/)) { - return fullBranchName.split('-') as List - } - - error "Enforcing Gitflow Workflow and SemVer on '${fullBranchName}'. Ha!" - } - - def getBuildVersion = { String fullBranchName, buildNumber -> - String projectVersion = getProjectVersion() - def branchTypeAndName = getBranchTypeAndName(fullBranchName) - - switch (branchTypeAndName[0]) { - case 'master': - return projectVersion - case 'hotfix': - return "${branchTypeAndName[1]}-rc.${buildNumber}" - case 'develop': - return "${projectVersion}+develop.dev${buildNumber}" - case 'feature': - return "${projectVersion}+feature.${branchTypeAndName[1]}.dev${buildNumber}" - case 'bugfix': - return "${projectVersion}+bugfix.${branchTypeAndName[1]}.dev${buildNumber}" - case 'release': - assert branchTypeAndName[1] == projectVersion - return "${projectVersion}-rc.${buildNumber}" - case 'PR': - return "${projectVersion}+PR.${branchTypeAndName[1]}.${buildNumber}" - default: - error "Oops, we messed up! :(" - } - } - - def getNpmTag = { String fullBranchName -> - switch (getBranchTypeAndName(fullBranchName)[0]) { - case 'master': - return 'latest' - case 'release': - return 'next' - default: - return '' - } - } - - env.BUILD_VERSION = getBuildVersion(BRANCH_NAME as String, BUILD_NUMBER) - env.NPM_TAG = getNpmTag(BRANCH_NAME as String) - env.BUILD_TYPE = env.NPM_TAG ? env.NPM_TAG : 'develop' // latest, next or develop - - if (env.BUILD_TYPE == 'next') { - sh 'npm version $BUILD_VERSION' - } - } - } - } - stage('Install Dependencies') { - steps { - stash 'pre_install_git_checkout' - sh 'npm install' - } - } - stage('Run ESLint') { - steps { - sh 'npm run lint' - } - } - stage('Build Artifacts') { - steps { - //noinspection GroovyAssignabilityCheck - parallel( - 'Development Bundle': { - sh 'npm run browserify' - archiveArtifacts "dist/mapbox-gl-circle-${BUILD_VERSION}.js" - }, - 'Production Bundle': { - script { - if (env.BUILD_TYPE in ['next', 'latest']) { - sh 'npm pack' - archiveArtifacts "mapbox-gl-circle-${BUILD_VERSION}.tgz" - } else { - sh 'npm run prepare' - archiveArtifacts "dist/mapbox-gl-circle-${BUILD_VERSION}.min.js" - } - } - }, - 'API Docs': { - sh 'npm run docs' - } - ) - } - } - stage('Publish') { - when { - expression { env.BUILD_TYPE in ['next', 'latest'] } - } - environment { - NPM_TOKEN = credentials('mblomdahl_npm') - } - steps { - //noinspection GroovyAssignabilityCheck - parallel( - 'NPM Package': { - sh 'echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc' - sh 'npm publish --tag $NPM_TAG .' - } - ) - } - } - } - post { - always { - deleteDir() - } - success { - echo 'Build succeeded!' - } - unstable { - echo 'Build unstable :/' - } - failure { - echo 'Build failed :(' - } - changed { - echo 'Things are different...' - } - } -} diff --git a/LICENSE b/LICENSE index 104a365..240fcad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017, Smith Micro Software, Inc. +Copyright (c) 2020, Smith Micro Software, Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/README.md b/README.md index 4211dac..c102533 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,16 @@ const MapboxCircle = require('mapbox-gl-circle'); -### MapboxCircle +#### Table of Contents -A `google.maps.Circle` replacement for Mapbox GL JS, rendering a "spherical cap" on top of the world. +- [MapboxCircle](#mapboxcircle) + - [Examples](#examples) -**Parameters** +### MapboxCircle -- `center` -- `radius` -- `options` +A `google.maps.Circle` replacement for Mapbox GL JS, rendering a "spherical cap" on top of the world. -**Examples** +#### Examples ```javascript var myCircle = new MapboxCircle({lat: 39.984, lng: -75.343}, 25000, { @@ -64,104 +63,6 @@ myCircle.on('contextmenu', function (mapMouseEvent) { }); ``` -#### constructor - -**Parameters** - -- `center` **({lat: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), lng: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)} | \[[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)])** Circle center as an object or `[lng, lat]` coordinates -- `radius` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Meter radius -- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** - - `options.editable` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Enable handles for changing center and radius (optional, default `false`) - - `options.minRadius` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Minimum radius on user interaction (optional, default `10`) - - `options.maxRadius` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Maximum radius on user interaction (optional, default `1100000`) - - `options.strokeColor` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Stroke color (optional, default `'#000000'`) - - `options.strokeWeight` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Stroke weight (optional, default `0.5`) - - `options.strokeOpacity` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Stroke opacity (optional, default `0.75`) - - `options.fillColor` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Fill color (optional, default `'#FB6A4A'`) - - `options.fillOpacity` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Fill opacity (optional, default `0.25`) - - `options.refineStroke` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Adjust circle polygon precision based on radius and zoom - (i.e. prettier circles at the expense of performance) (optional, default `false`) - - `options.properties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Property metadata for Mapbox GL JS circle object (optional, default `{}`) - -#### on - -Subscribe to circle event. - -**Parameters** - -- `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Event name; `click`, `contextmenu`, `centerchanged` or `radiuschanged` -- `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Event handler, invoked with the target circle as first argument on - _'centerchanged'_ and _'radiuschanged'_, or a _MapMouseEvent_ on _'click'_ and _'contextmenu'_ events -- `onlyOnce` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Remove handler after first call (optional, default `false`) - -Returns **[MapboxCircle](#mapboxcircle)** - -#### once - -Alias for registering event listener with _onlyOnce=true_, see [#on](#on). - -**Parameters** - -- `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Event name -- `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Event handler - -Returns **[MapboxCircle](#mapboxcircle)** - -#### off - -Unsubscribe to circle event. - -**Parameters** - -- `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Event name -- `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler to be removed - -Returns **[MapboxCircle](#mapboxcircle)** - -#### addTo - -**Parameters** - -- `map` **mapboxgl.Map** Target map for adding and initializing circle Mapbox GL layers/data/listeners. -- `before` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Layer ID to insert the circle layers before; explicitly pass `null` to - get the circle assets appended at the end of map-layers array (optional, default `'waterway-label'`) - -Returns **[MapboxCircle](#mapboxcircle)** - -#### remove - -Remove source data, layers and listeners from map. - -Returns **[MapboxCircle](#mapboxcircle)** - -#### getCenter - -Returns **{lat: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), lng: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Circle center position - -#### setCenter - -**Parameters** - -- `position` **{lat: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), lng: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}** - -Returns **[MapboxCircle](#mapboxcircle)** - -#### getRadius - -Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Current radius, in meters - -#### setRadius - -**Parameters** - -- `newRadius` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Meter radius - -Returns **[MapboxCircle](#mapboxcircle)** - -#### getBounds - -Returns **{sw: {lat: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), lng: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}, ne: {lat: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), lng: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}}** Southwestern/northeastern bounds - ## Development ### Install Dependencies @@ -186,6 +87,12 @@ Returns **{sw: {lat: [number](https://developer.mozilla.org/docs/Web/JavaScript/ ## Changelog +### v. 2.0.0 + +- Upgrades Mapbox GL JS from `v.0.44.1 -> v.1.6.1` +- Upgrades Turf `v.4.7.3 -> v.5.1.6` +- Converts mapbox-gl-circle to typescript + ### v. 1.6.5 - Bug fix for layer switching in `mapbox-gl>0.40.1` ([#73](https://github.com/smithmicro/mapbox-gl-circle/issues/73)) diff --git a/example/index.js b/example/index.js deleted file mode 100644 index 4795961..0000000 --- a/example/index.js +++ /dev/null @@ -1,172 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const mapboxgl = require('mapbox-gl'); -const MapboxCircle = require('../lib/main.js'); - -// eslint-disable-next-line -console.log("Loaded MapboxCircle from 'mapbox-gl-circle-" + MapboxCircle.VERSION + "'"); - -const mapDiv = document.body.appendChild(document.createElement('div')); -mapDiv.style.position = 'absolute'; -mapDiv.style.top = '32px'; -mapDiv.style.right = 0; -mapDiv.style.left = 0; -mapDiv.style.bottom = 0; - -const defaultStyle = 'streets'; - -const styleMenuDiv = document.body.appendChild(document.createElement('div')); -styleMenuDiv.id = 'menu'; -styleMenuDiv.style.position = 'absolute'; -styleMenuDiv.style.left = 0; -styleMenuDiv.style.bottom = 0; -styleMenuDiv.style.backgroundColor = 'rgba(255, 255, 255, 0.5)'; - -for (let styleOption of ['basic', 'streets', 'bright', 'light', 'dark', 'satellite', 'satellite-streets']) { - let inputEl = styleMenuDiv.appendChild(document.createElement('input')); - inputEl.type = 'radio'; - inputEl.name = 'styleSwitcher'; - inputEl.id = inputEl.value = styleOption; - if (styleOption === defaultStyle) { - inputEl.checked = true; - } - - inputEl.onclick = function setStyle(clickEvent) { - map.setStyle('mapbox://styles/mapbox/' + clickEvent.target.id + '-v9'); - }; - - let labelEl = styleMenuDiv.appendChild(document.createElement('label')); - labelEl.for = labelEl.textContent = styleOption; - labelEl.style.paddingRight = '10px'; -} - -// noinspection SpellCheckingInspection -mapboxgl.accessToken = 'pk.eyJ1IjoicnNiYXVtYW5uIiwiYSI6IjdiOWEzZGIyMGNkOGY3NWQ4ZTBhN2Y5ZGU2Mzg2NDY2In0.jycgv7qwF8MMIWt4cT0RaQ'; - -const center = {lat: 39.984, lng: -75.343}; -const map = new mapboxgl.Map({ - container: mapDiv, - style: 'mapbox://styles/mapbox/' + defaultStyle + '-v9', - center: [center.lng, center.lat], - zoom: 14 -}); - -window.map = map; - -const markerElement = document.createElement('div'); -markerElement.style.backgroundImage = 'url(https://placekitten.com/g/50/)'; -markerElement.style.width = '50px'; -markerElement.style.height = '50px'; -markerElement.style.borderRadius = '50%'; -window.marker1 = new mapboxgl.Marker(markerElement) - .setLngLat([center.lng, center.lat]) - .addTo(map); - -// MapboxCircle Setup - -const editableOpts = { - editable: true, - strokeColor: '#29AB87', - strokeWeight: 1, - strokeOpacity: 0.85, - fillColor: '#29AB87', - fillOpacity: 0.2, - minRadius: 100, - maxRadius: 500000, - debugEl: document.body.appendChild(document.createElement('div')) -}; - -const extraPrettyEditableOpts = _.extend({refineStroke: true}, editableOpts); - -const nonEditableOpts = { - strokeWeight: 0, - fillColor: '#000000', - fillOpacity: 0.2 -}; - -window.editableCircle0 = new MapboxCircle({lat: 39.986, lng: -75.341}, 350, editableOpts).addTo(map); - -window.plainCircle0 = new MapboxCircle({lat: 39.982, lng: -75.345}, 250, nonEditableOpts).addTo(map); - -window.plainCircle1 = new MapboxCircle({lat: 39.983, lng: -75.344}, 300, nonEditableOpts).addTo(map); - -window.editableCircle1 = new MapboxCircle({lat: 39.984, lng: -75.349}, 300, editableOpts).addTo(map) - .setCenter({lat: 39.989, lng: -75.348}).setRadius(50); - -window.editableCircle2 = new MapboxCircle({lat: 39.974377, lng: -75.639449}, 25000, extraPrettyEditableOpts).addTo(map); -window.editableCircle3 = new MapboxCircle({lat: 39.980, lng: -75.340}, 225, editableOpts).addTo(map); - -window.plainCircle2 = new MapboxCircle({lat: 39.983, lng: -75.345}, 150, nonEditableOpts).addTo(map); -window.plainCircle3 = new MapboxCircle([-75.352, 39.983], 200, nonEditableOpts).addTo(map); - -window.setTimeout(function () { - window.editableCircle1.remove(); - window.editableCircle3.remove(); - window.setTimeout(function () { - window.editableCircle1.addTo(map).setCenter({lat: 39.984, lng: -75.349}).setRadius(300); - window.editableCircle3.addTo(map); - }, 1250); -}, 2500); - - -window.editableCircle2 - .on('radiuschanged', function (circleObj) { - const newRadius = circleObj.getRadius(); - // eslint-disable-next-line - console.log('editableCircle2/radiuschanged', circleObj.getBounds()); - window.setTimeout(function () { - if (newRadius === circleObj.getRadius()) { - circleObj.setRadius(newRadius * .99); - } - }, 1500); - }) - .on('centerchanged', function (circleObj) { - // eslint-disable-next-line - console.log('editableCircle2/centerchanged', circleObj.getCenter()); - }) - .on('radiuschanged', function (circleObj) { - // eslint-disable-next-line - console.log('editableCircle2/radiuschanged', circleObj.getRadius()); - }) - .on('click', function (mouseEvent) { - // eslint-disable-next-line - console.log('editableCircle2/click', mouseEvent); - }) - .on('contextmenu', function (mouseEvent) { - // eslint-disable-next-line - console.log('editableCircle2/contextmenu', mouseEvent); - }) - .on('click', function (mouseEvent) { - // eslint-disable-next-line - console.log('editableCircle2/click', mouseEvent); - }) - .on('contextmenu', function (mouseEvent) { - // eslint-disable-next-line - console.log('editableCircle2/contextmenu', mouseEvent); - }); - -window.editableCircle3 - .on('radiuschanged', function (circleObj) { - const newRadius = circleObj.getRadius(); - // eslint-disable-next-line - console.log('editableCircle3/radiuschanged', circleObj.getBounds()); - window.setTimeout(function () { - if (newRadius === circleObj.getRadius()) { - circleObj.setRadius(newRadius * 1.01); - } - }, 1750); - }) - .on('centerchanged', function (circleObj) { - // eslint-disable-next-line - console.log('editableCircle3/centerchanged', circleObj.getCenter()); - }) - .on('click', function (mouseEvent) { - // eslint-disable-next-line - console.log('editableCircle3/click', mouseEvent); - }) - .on('contextmenu', function (mouseEvent) { - // eslint-disable-next-line - console.log('editableCircle3/contextmenu', mouseEvent); - }); - diff --git a/example/index.ts b/example/index.ts new file mode 100644 index 0000000..36c5d02 --- /dev/null +++ b/example/index.ts @@ -0,0 +1,84 @@ +import { MapboxCircle } from './../dist/mapbox-gl-circle'; +import * as mapboxgl from 'mapbox-gl'; +import * as turf from '@turf/turf'; + +document.getElementById('version').textContent = 'mapbox-gl-circle-' + MapboxCircle.VERSION; + +function boundsTo5percentRadius(bounds) { + return Math.round( + turf.distance(bounds.getSouthWest().toArray(), bounds.getNorthEast().toArray(), { units: 'meters' }) * 0.05, + ); +} + +var map = new mapboxgl.Map({ + container: 'map', + style: 'mapbox://styles/mapbox/streets-v9', + center: [18.059678, 59.322465], + zoom: 12.30543, + accessToken: 'pk.eyJ1IjoiYW5hbmR0aGFra2VyIiwiYSI6ImNqNWptdjU1YjJheWszM256ZWN0MXNrejMifQ.TXnoKtnlam-KBmRSjXQgEw', +}).addControl(new mapboxgl.ScaleControl({ maxWidth: 300 }), 'top-right'); + +var layerList = document.getElementById('menu'); +var inputs = layerList.getElementsByTagName('input'); + +function switchLayer(clickEvent) { + var layerId = clickEvent.target.id; + map.setStyle('mapbox://styles/mapbox/' + layerId + '-v9'); +} + +for (var i = 0; i < inputs.length; i++) { + inputs[i].onclick = switchLayer; +} + +// Non-editable circles. +var lidingoMunicipality = { position: { lat: 59.379278, lng: 18.17814 }, radius: 4846 }; + +new MapboxCircle(lidingoMunicipality.position, lidingoMunicipality.radius, { + strokeColor: '#0000ff', + strokeOpacity: 0.25, + strokeWeight: 2, + refineStroke: true, + fillColor: '#000000', + fillOpacity: 0.05, +}).addTo(map); + +// Editable circles. +var northPole = { position: { lat: 84.928218, lng: -38.074812 }, radius: 1100000 }; +var irelandAndUK = { position: { lat: 54.431637, lng: -4.223538 }, radius: 547293 }; +var oldTown = { position: { lat: 59.325017, lng: 18.069263 }, radius: 508 }; +var smsiStockholm = { position: { lat: 59.346978, lng: 18.03912 }, radius: 142 }; +var kvadratSthlm = { position: { lat: 59.34131, lng: 18.058817 }, radius: 122 }; +var stormforsOffice = { position: { lat: 59.337678, lng: 18.083402 }, radius: 85 }; +var midsommarkransenSubway = { position: { lat: 59.301857, lng: 18.012292 }, radius: 131 }; + +var editableCircleOpts = { + editable: true, + minRadius: 50, + debugEl: document.getElementById('debug'), +}; + +var baseDelay = 500; +[northPole, irelandAndUK, oldTown, smsiStockholm, kvadratSthlm, stormforsOffice, midsommarkransenSubway].forEach( + function(item) { + window.setTimeout(function() { + var newEditable = new MapboxCircle(item.position, item.radius, editableCircleOpts) + .addTo(map) + .once('click', function(mapMouseEvent) { + // Left-click on circle to remove. + console.log('remove circle / mapMouseEvent:', mapMouseEvent); + newEditable.remove(); + }); + }, (baseDelay += 500)); + }, +); + +map.on('contextmenu', function(event) { + // Right-click on map to add new circle. + console.log('Add editable circle at ' + event.lngLat); + var newEditable = new MapboxCircle(event.lngLat, boundsTo5percentRadius(map.getBounds()), editableCircleOpts) + .once('click', function(mapMouseEvent) { + console.log('remove circle / mapMouseEvent:', mapMouseEvent); + newEditable.remove(); + }) + .addTo(map); +}); diff --git a/index.html b/index.html index 11bb06f..ffb8523 100644 --- a/index.html +++ b/index.html @@ -4,11 +4,7 @@