Giter Site home page Giter Site logo

smithmicro / mapbox-gl-circle Goto Github PK

View Code? Open in Web Editor NEW
53.0 53.0 27.0 929 KB

A *google.maps.Circle* replacement for Mapbox GL JS

Home Page: https://smithmicro.github.io/mapbox-gl-circle/

License: ISC License

JavaScript 88.11% HTML 10.30% Dockerfile 0.66% Shell 0.93%
google-maps mapbox-gl turfjs

mapbox-gl-circle's People

Contributors

actions-user avatar carlba avatar dsperling avatar eddydg avatar mblomdahl avatar mdartic avatar ryanhamley avatar vtepliuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-gl-circle's Issues

optionalDependencies?

Is there a need to have optionalDependencies? Our installation procedure always tries to install them regardless of no-optional flag in npm, but I was wondering is there any particular reason you ship package.json with that property? Could it be removed or transferred to devDependencies since it’s mostly build stuff like Yarn?

Cancel drag op on blur

Sometimes the drag operation does not end in a "mouseup", e.g. when drag ends outside the document or cmd-shifting to another application during drag. Circle logic should handle this as a dragend.

Add `click` and `contextmenu` events

  • When clicking on a circle, it should fire a click event with target circle as first callback argument.
  • When right-clicking on a circle, it should fire a contextmenu event with target circle as first callback argument.
  • When doing the funky ctrl + left-click combo that some old Mac users might use as means of right-clicking, it should also fire a contextmenu event (and suppress the "normal" click)

Getting weird lines within circle at various zoom levels

I get some strange lines that span the circle at various points that shift based on zoom level. However, they seem to disappear above zoom level 16 or there abouts.

const areaCircle = new MapboxCircle({ lat: 42.2446, lng: -70.9623 }, 804, { strokeColor: '#ffffff', strokeWeight: 5, fillOpacity: 0, }).addTo(map);

Screen Shot 2020-12-08 at 9 11 14 PM

Conflict with other map elements

Hey guys,

I've noticed that there is an issue while moving with circle while there are also some other elements placed on the map, like markers. When you move across these elements it will stop dragging the circle, I've prepared codepen example so you can check it out. I think that issue exists there from version 1.4.0, I'm using version 1.3.0 for now as it's working fine there.

Example

Mismatch with Google Circle behavior when editing radius

When hovering over a radius handle, before dragging:

  • mapbox-gl-circle: all handles are highlighted
  • google.maps.Circle: only the radius handle under mouse cursor is highlighted

When dragging a handle to adjust radius:

  • mapbox-gl-circle
    1. all radius handles moves
    2. extra circle stroke follows radius handles
  • google.maps.Circle:
    1. only the handle that user interact with moves
    2. extra circle stroke follows radius handle

react build issue

hey guys,
we are using your library in 1 project,
however we faced an issue when trying to deploy to production,
in create-react-app project we are not able to build it,
it's saying it's app.js line 43, but I cannot figure out what's wrong there,
would be great if you can fix it,
thanks,
Greg

Circles appear behind other layers

Hi, I started implementing mapbox-gl-circle into a program that has several other layers on the map and noticed that the circle always appeared behind one of my other layers, regardless of what order they were added in.

I tracked it down to these lines in the code where waterway-label is hardcoded as the second argument to addLayer causing the circle to always be added just before this layer.

You can see the issue in action here:
screen shot 2017-10-10 at 11 20 58 am

It's pretty straightforward to expose the before argument to the user so that users can control where a circle is added in the layer stack. I implemented a fix as you can see in this image.

screen shot 2017-10-10 at 11 16 46 am

Here's my pull request for the proposed fix https://github.com/mblomdahl/mapbox-gl-circle/pull/51

Thanks!

Improve example usage docs

Add usage instructions when not relying on require(...) (standalone script load) + test that it actually works as NPM dependency for third-party libraries.

Replace Jenkins CI/CD with GitHub Actions CI/CD

Initially brought up during review of PR #86, the current CI/CD via Jenkins is broken and needs a replacement to continue structured and robust maintenance of this repository.

Draft acceptance criterion:

  • Document how to add the necessary NPM credentials to the repo, replacing the current NPM_TOKEN = credentials('mblomdahl_npm') secret in Jenkinsfile L#131
  • Evaluate and propose alternative to the current code for generating unique build identifiers, Jenkinsfile L#11-L#67
  • Building from the release/x.y.z branch should push a release candidate to NPM
  • Building from the master branch should push a release to NPM

Ping @gleite-smsi FYI!

Style switcher no longer working with GL JS 0.44.1

When attempting to update GL JS version from 0.40.1 to 0.44.1, we found that the style-layer switching no longer works.

How it was (successfully) handled in the latest mapbox-gl-circle version:

  1. a circle listens to styledataloading upon being added to a map
  2. when switching style layer, the circle would remove itself from the map and wait for styledata firing
  3. on styledata firing, the circle would add itself back to the map

Was working really well.

Here's the code that does it:

class MapboxCircle {

    /* snip */

    /**
     * When map style is changed, remove circle assets from map and add it back on next MapboxGL 'styledata' event.
     * @param {MapDataEvent} event
     * @private
     */
    _onMapStyleDataLoading(event) {
        if (this.map) {
            this.map.once('styledata', () => {
                // noinspection JSUnresolvedVariable
                this.addTo(event.target);
            });
            this.remove();
        }
    }

    /* snip */

    addTo(map, before) {
        const addCircleAssetsOnMap = () => {
            /* snip */
            map.on('styledataloading', this._onMapStyleDataLoading);
            /* snip */
    }

    /* snip */

    /**
     * Remove source data, layers and listeners from map.
     * @return {MapboxCircle}
     * @public
     */
    remove() {
        this.map.off('styledataloading', this._onMapStyleDataLoading);

        this.observer.disconnect();

        if (this.options.editable) {
            this._unbindBroadcastListeners();
            MapboxCircle._removeActiveEditableCircle(this);

            this.off('radiuschanged', this._onRadiusChanged).off('centerchanged', this._onCenterChanged);

            this._unbindRadiusHandlesListeners();
            this.map.removeLayer(this._circleRadiusHandlesId);

            this._unbindCenterHandleListeners();
            this.map.removeLayer(this._circleCenterHandleId);

            this.map.removeSource(this._circleRadiusHandlesSourceId);
            this.map.removeSource(this._circleCenterHandleSourceId);
        }

        this.map.off('zoomend', this._onZoomEnd);
        this._unbindCircleFillListeners();
        this.map.removeLayer(this._circleFillId);
        this.map.removeLayer(this._circleStrokeId);

        this.map.removeSource(this._circleSourceId);

        this.map = null;

        return this;
    }

    /* snip */

}

What happens with the latest version is that remove() call fails because, apparently, the circle assets already does not exist.

Question: @ryanbaumann is there some earlier event we should listen to in order to detect-and-handle a style layer change?

Cannot minify repo during Webpack build

Import repo:
import MapboxCircle from 'mapbox-gl-circle';

Summary:
Run Webpack to build the codebase with Webpack's UglifyJsPlugin on. Webpack is attempting to minify all the files in the codebase, but cannot handle ES6 code, resulting in an error.

Error:
ERROR in <file>.js from UglifyJs Unexpected token: name (MapboxCircle)

Workaround:
import MapboxCircle from 'mapbox-gl-circle/dist/mapbox-gl-circle.min.js'

Importing the minified file seems to be an acceptable workaround for the time being.

Solution:
I don't believe this is limited to Webpack. I'm guessing any minification would result in this error. ES6 code could still cause errors in older browsers as well if not transpiled to ES5. It would be nice if the main file for importing was transpiled to ES5 so that it could be imported as mapbox-gl-circle; building and minifying would work well and unbuilt/unminified code could be assumed to work in older browsers.

Publish normal release builds to NPM registry

When building a normal release, the build should be automatically published to NPM after "Build Artifacts" stage steps have completed successfully, tagged as @latest.

Depends upon:

  • #6 Pre-release publishing to NPM
  • #7 Normal release identifier

First handle interaction always fail

When attempting to drag a center or radius handle, it consistently pans the map instead of triggering the intended handle. Once this has failed once, both center and radius handles work as intended.

Doesn't work on mobile device

Hi,

When adding the circle library to my mapbox app, it works fine on the desktop but I can't seem to interact with the circle at all on a mobile device.

Is there any way to get this working?

Thanks in advance

Emit a 'radiuschanging' event

For a more advanced styling I'd need to keep track of a circle whose radius is being dragged.
Currently we only have 'radiuschanged' which is emitted once the drag has ended. So a 'radiuschanging' could come in handy.

To be consistent, a 'centerchanging' could also be added.

What do you think? would you accept a PR with this feature?

Unable to resize and drag circle

I am using react-map-gl + mapbox-gl-circle. I displayed a circle but I cannot resize it and drag it.

But if I use mapbox-gl + mapbox-gl-circle = all is good.

import React from "react";
import MapboxCircle from "mapbox-gl-circle";
import MapGL from "react-map-gl";

const MAPBOX_ACCESS_TOKEN =
  "pk.eyJ1IjoiYWxlcGhyaSIsImEiOiJjamdwbHpycjIyZm45Mndud3AzamRibHpqIn0.ejAHwSGT6dcGxiDOrPCFLg";

export default function App() {
  const [viewport, setViewport] = React.useState({
    latitude: 6,
    longitude: 22,
    zoom: 12,
    bearing: 0,
    pitch: 0
  });

  const [mapRef, setMapRef] = React.useState(null);

  const myCircle = new MapboxCircle({ lat: 6, lng: 22 }, 2200, {
    editable: true,
    minRadius: 120,
    fillColor: "#29AB87"
  });

  if (mapRef !== null) {
    myCircle.addTo(mapRef.getMap());

    myCircle.on("centerchanged", function(circleObj) {
      console.log("New center:", circleObj.getCenter());
    });
    myCircle.once("radiuschanged", function(circleObj) {
      console.log("New radius (once!):", circleObj.getRadius());
    });
    myCircle.on("click", function(mapMouseEvent) {
      console.log("Click:", mapMouseEvent.point);
    });
    myCircle.on("contextmenu", function(mapMouseEvent) {
      console.log("Right-click:", mapMouseEvent.lngLat);
    });
  }

  return (
      <MapGL
        ref={e => setMapRef(e)}
        width="100%"
        height="100vh"
        mapStyle="mapbox://styles/mapbox/light-v9"
        mapboxApiAccessToken={MAPBOX_ACCESS_TOKEN}
        latitude={viewport.latitude}
        longitude={viewport.longitude}
        zoom={viewport.zoom}
        bearing={viewport.bearing}
        pitch={viewport.pitch}
        onViewportChange={viewport => setViewport(viewport)}
      />
  );
}

Codesandbox react-map-gl example:
https://codesandbox.io/s/competent-feather-geo7c

Codesandbox mapbox-gl example:
https://codesandbox.io/s/react-and-mapbox-gl-2tnnx

Result is oval

i use it in EPSG:4326 or EPSG:3857. The result is an oval.
image

Rotate circle and create half/quarter of the circle

Hi I am using mapbox-gl-circle library to create circle on mapbox-gl map in my Angular application providing center of the circle and radius in metres.

Two simple questions:

  1. Can I create half or quarter the circle (something looking like pizza slice) with center coordinates of the circle. So I need exactly the same functionality like creating circle with center coordinates just I don't want full circle, rather than this it would be awesome if I can create half or quarter of the circle?
  2. Can I somehow rotate circle after it is created?

Best regards.

Warnings in Docker build

Running Docker build:

docker build -t circle .

produces warnings on Step 4/8:

...
Step 4/8 : RUN npm install && mkdir -p example/ lib/
 ---> Running in 88bdb9b71fdb
npm WARN deprecated [email protected]: πŸ™Œ  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
npm WARN deprecated [email protected]: It is recommended to install Yarn using the native installation method for your environment. See https://yarnpkg.com/en/docs/install
npm WARN deprecated [email protected]: This package has been moved to @mapbox/mapbox-gl-supported
npm WARN deprecated [email protected]: This module is now under the @mapbox namespace: install @mapbox/geojson-area instead
npm WARN lifecycle [email protected]~prepare: cannot run in wd %s %s (wd=%s) [email protected] mkdir -p dist && browserify --standalone MapboxCircle -t [ babelify --presets [ es2015 ] ] lib/main.js | uglifyjs -c -m > dist/mapbox-gl-circle-${BUILD_VERSION:-dev}.min.js && cp -f dist/mapbox-gl-circle-${BUILD_VERSION:-dev}.min.js dist/mapbox-gl-circle.min.js /opt/mapbox-gl-circle
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
...

We should get these cleaned up to produce a clean Docker image.

Prevent overlapping mouse down events

Currently, when the circle is small enough, radius and center edit handlers will overlap.
Dragging one of those handlers will trigger both events _onCenterHandleMouseDown and _onRadiusHandlesMouseDown which provoke weird behaviours after mouseup/mouseout: the circle sticks to the cursor and you have to refresh the page to reset it:

v1.6.5
pre

I would expect only one of the events to be triggered: the one corresponding to the cursor style.

  • move -> center handler mouse down event
  • ns-resize , ew-resize -> radius handler mouse down event

bugfix/overlapping-events
post

Pull request: #79

Users are wondering if the repo is maintained or not

πŸ› Describe the bug

There are a bunch of issues #100, #92, #91, #90, #89, #87, #83, #76, #72, #61, #60, #56, #49, and #25 they are left unanswered for years. Now @AbhishekD15 is wondering in #101, is it maintained or should it be marked as archived?

⚠️ Current behavior

Someone files a bug or a feature request, and maintainers do not reply for multiple years.

βœ… Expected behavior

I would expect maintainers to read their notifications and react in some way when filing a issue in their open source project.

πŸ’£ Steps to reproduce

N/A

πŸ“· Screenshots

image

πŸ“± Tech info

N/A

Unable to drag and resize sometimes

πŸ› Describe the bug

Dragging and resizing doesnt work after zooming in to a certain level

⚠️ Current behavior

βœ… Expected behavior

It should allow to drag and resize at any zoom level

πŸ’£ Steps to reproduce

  1. add the circle to map
  2. slowly zoom in one step at a time and keep hovering on sides
  3. at some point the resize arrow will become normal hand arrow
  4. then resizing doesnt work

πŸ“· Screenshots

πŸ“± Tech info

  • Device: Chrome Browser
  • OS: Linux
  • Library/App version: 1.6.7

Expose minRadius

minRadius and maxRadius are hardcoded in v. 1.4.2; lines 161-162.

It would be better to expose these as constructor options, alongside fillColor, strokeOpacity and friends.

Publish pre-release builds to NPM registry

When the current branch is of type release/, the build should be automatically published to NPM after "Build Artifacts" stage steps have completed successfully, tagged as @next.

Depends upon:

  • #6 Pre-release identifier

Need dynamic options

Its good if support dynamic options like fillcolor / editable will change dynamically.
#feature_request

Angular CLI production build issue

Hey we built a map using mapbox-gl-circle. Works fine on local but when uglifies/minifies for production, the map that uses mapbox-gl-circle eats up CPU and browsers freezes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.