How to use the leaflet.latLng function in leaflet

To help you get started, we’ve selected a few leaflet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Esri / esri-leaflet / src / Layers / FeatureLayer / FeatureLayer.js View on Github external
_redraw: function (id) {
    var layer = this._layers[id];
    var geojson = layer.feature;

    // if this looks like a marker
    if (layer && layer.setIcon && this.options.pointToLayer) {
      // update custom symbology, if necessary
      if (this.options.pointToLayer) {
        var getIcon = this.options.pointToLayer(geojson, latLng(geojson.geometry.coordinates[1], geojson.geometry.coordinates[0]));
        var updatedIcon = getIcon.options.icon;
        layer.setIcon(updatedIcon);
      }
    }

    // looks like a vector marker (circleMarker)
    if (layer && layer.setStyle && this.options.pointToLayer) {
      var getStyle = this.options.pointToLayer(geojson, latLng(geojson.geometry.coordinates[1], geojson.geometry.coordinates[0]));
      var updatedStyle = getStyle.options;
      this.setFeatureStyle(geojson.id, updatedStyle);
    }

    // looks like a path (polygon/polyline)
    if (layer && layer.setStyle && this.options.style) {
      this.resetStyle(geojson.id);
    }
github Esri / esri-leaflet / src / Util.js View on Github external
export function extentToBounds (extent) {
  // "NaN" coordinates from ArcGIS Server indicate a null geometry
  if (extent.xmin !== 'NaN' && extent.ymin !== 'NaN' && extent.xmax !== 'NaN' && extent.ymax !== 'NaN') {
    var sw = latLng(extent.ymin, extent.xmin);
    var ne = latLng(extent.ymax, extent.xmax);
    return latLngBounds(sw, ne);
  } else {
    return null;
  }
}
github Asymmetrik / ngx-leaflet / src / demo / app / leaflet / leaflet-demo.component.ts View on Github external
12,
		46.879966, -121.726909,
		[ this.LAYER_OSM, this.LAYER_OCM ],
		this.LAYER_OSM.id
	);


	// Leaflet values
	leaflet: {
		layers: L.Layer[],
		zoom: number,
		center: L.LatLng
	} = {
		layers: [],
		zoom: 0,
		center: L.latLng([ 0, 0 ])
	};

	constructor() {
		this.onApply();

		setTimeout(() => {
			this.showDemo = true;
		}, 1000);
	}

	onApply() {

		// Get the active base layer
		let baseLayer = this.model.baseLayers.find((l) => { return l.id === this.model.baseLayer; });

		// Get all the active control layers
github rubenspgcavalcante / leaflet-ant-path / src / specs / leaflet-ant-path.unit.js View on Github external
it("Should be able to add new points to the path", () => {
      const coord = L.latLng(42, 42);
      antPath.addLatLng(coord);
      expect(antPath.getLatLngs()).toEqual([...samplePath, coord]);
    });
github wladich / nakarte / src / lib / leaflet.control.track-list / lib / geo_file_exporters.js View on Github external
let newLine = [wrappedLatLngs[0]];
    newLines.push(newLine);
    for (let i = 1; i < wrappedLatLngs.length; i++) {
        let latLng = wrappedLatLngs[i];
        let prevLatLng = wrappedLatLngs[i - 1];
        if (Math.abs(latLng.lng - prevLatLng.lng) <= 180) {
            newLine.push(latLng);
        } else {
            let positiveLng = L.Util.wrapNum(latLng.lng, [0, 360]);
            let positivePrevLng = L.Util.wrapNum(prevLatLng.lng, [0, 360]);
            let splitLng = 180 - 0.000001 * Math.sign(latLng.lng);
            let splitPrevLng = 180 - 0.000001 * Math.sign(prevLatLng.lng);
            let splitLat = getSegmentLatForLng(L.latLng(prevLatLng.lat, positivePrevLng), L.latLng(latLng.lat, positiveLng), splitLng);
            let splitPrevLat = getSegmentLatForLng(L.latLng(prevLatLng.lat, positivePrevLng), L.latLng(latLng.lat, positiveLng), splitPrevLng);
            newLine.push(L.latLng(splitPrevLat, splitPrevLng).wrap());
            newLine = [L.latLng(splitLat, splitLng).wrap(), latLng];
            newLines.push(newLine);
        }
    }
    return newLines;
}
github Vizzuality / trase / frontend / scripts / components / tool / map.component.js View on Github external
constructor() {
    this.canvasRender = !!document.createElement('canvas').getContext && USE_CANVAS_MAP;

    this.darkBasemap = false;

    const mapOptions = {
      zoomControl: false,
      minZoom: 2,
      preferCanvas: this.canvasRender
    };

    this.map = L.map('js-map', mapOptions);
    new L.Control.Zoom({ position: 'topleft' }).addTo(this.map);
    L.control.scale({ position: 'bottomleft', imperial: false }).addTo(this.map);

    const worldBounds = L.latLngBounds(L.latLng(-89, -180), L.latLng(89, 180));
    this.map.setMaxBounds(worldBounds);
    this.map.on('drag', () => {
      this.map.panInsideBounds(worldBounds, { animate: false });
    });

    this.map.on('layeradd', () => this._updateAttribution());
    this.map.on('dragend zoomend', () =>
      this.callbacks.onMoveEnd(this.map.getCenter(), this.map.getZoom())
    );
    this.map.on('zoomend', () => {
      this._recalculatePointVolumeShadowRadius();
    });

    this._setMapViewDebounced = debounce(this._setMapViewDebounced, 500);

    Object.keys(MAP_PANES).forEach(paneKey => {
github HSLdevcom / jore-map-ui / src / components / map / Map.tsx View on Github external
private centerMap = () => {
        const mapStore = this.props.mapStore;
        const map = this.getMap();
        if (map) {
            try {
                const mapCoordinates = map.getCenter();
                if (!L.latLng(mapStore!.coordinates!).equals(L.latLng(mapCoordinates))) {
                    map.setView(mapStore!.coordinates!, map.getZoom());
                }
            } catch {
                map.setView(mapStore!.coordinates!, mapStore!.zoom);
            }
        }
    };
github OpenGov / react-leaflet-heatmap-layer / src / HeatmapLayer.js View on Github external
fitBounds(): void {
    const points = this.props.points;
    const lngs = map(points, this.props.longitudeExtractor);
    const lats = map(points, this.props.latitudeExtractor);
    const ne = { lng: max(lngs), lat: max(lats) };
    const sw = { lng: min(lngs), lat: min(lats) };

    if (shouldIgnoreLocation(ne) || shouldIgnoreLocation(sw)) {
      return;
    }

    this.context.map.fitBounds(L.latLngBounds(L.latLng(sw), L.latLng(ne)));
  }
github kdwink / supercharge.info / src / main / primary_entry / script / page / map / MapView.js View on Github external
handleViewportChange() {

        const latLngBounds = this.mapApi.getBounds();
        const northEast = latLngBounds.getNorthEast();
        const southWest = latLngBounds.getSouthWest();
        const newNorthEast = L.latLng(northEast.lat + 1, northEast.lng + 2);
        const newSouthWest = L.latLng(southWest.lat - 1, southWest.lng - 2);
        const expandedBounds = L.latLngBounds(newSouthWest, newNorthEast);

        new SiteIterator()
            .withPredicate(SitePredicates.HAS_NO_MARKER)
            .withPredicate(SitePredicates.buildInViewPredicate(expandedBounds))
            .iterate((supercharger) => this.markerFactory.createMarker(supercharger));
        EventBus.dispatch("map-viewport-change-event", latLngBounds);

        const mapCenter = this.getCenter();
        userConfig.setLatLngZoom(mapCenter.lat, mapCenter.lng, this.mapApi.getZoom());
    };
github Asymmetrik / ngx-leaflet / src / demo / app / leaflet / core / core-demo.component.ts View on Github external
doApply() {
		this.center = latLng(this.lat, this.lng);
		this.zoom = this.formZoom;
	}
}