123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- define(["https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.0/mapbox-gl.js", "https://api.mapbox.com/mapbox.js/plugins/turf/v3.0.11/turf.min.js", "https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"], function(mapboxgl, turf) {
- map = '';
- mapboxgl_gbl = mapboxgl;
- turf_gbl = turf;
- dots = '';
- svg = '';
- curLon = '0';
- curLat = '0';
- bounds = '';
- geojsonFeature = {}
- geoBusFeature = {}
- function mapControl() {};
-
- mapControl.prototype.initialize = function(oControlHost, fnDoneInitializing, oDataStore) {
- console.log('1.Initialize')
-
- $("head link[rel='stylesheet']").last().after("<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.0/mapbox-gl.css' rel='stylesheet' />");
- $("head link[rel='stylesheet']").last().after("<link href='https://endor-bsln.analytics-devlab-nonprod.w3cloud.ibm.com/samples/images/Team10_generic.css' rel='stylesheet' />");
- var mapContainer = oControlHost.container.id;
-
- geojsonFeature = {
- "type": "FeatureCollection",
- "features": []
- }
-
- mapboxgl.accessToken = 'pk.eyJ1IjoibWNpbnRvc2hkZXJlayIsImEiOiJjajh6M3h5eTMya3lkMzNtYmV2aWwycWZ2In0.jMqt3uXdINkigqeV8skBqA';
- map = new mapboxgl.Map({
- container: mapContainer,
- style: 'mapbox://styles/mapbox/streets-v11',
- center: [-96, 37.8],
- zoom: 3,
- interactive: true
- });
- bounds = new mapboxgl.LngLatBounds();
- fnDoneInitializing();
- };
-
- mapControl.prototype.draw = function(oControlHost) {
- console.log("3. Draw ---");
- console.log(geojsonFeature);
- var oPage = oControlHost.page;
- var box = oControlHost.container.id;
- $('#' + box).parent().prepend('<button id="reset" onclick ="reset()">Reset</button>');
-
- map.on("load", function() {
-
- map.addSource("points", {
- "type": "geojson",
- "data": geojsonFeature
- });
- map.addLayer({
- "id": "points",
- "type": "circle",
- "source": "points",
- "paint": {
- 'circle-radius': {
- base: 10,
- stops: [
- [10, 10],
- [13, 10]
- ]
- },
- "circle-color": ["get", "color"]
- },
- "filter": ["==", "$type", "Point"],
- });
-
- map.addLayer({
- 'id': '3d-buildings',
- 'source': 'composite',
- 'source-layer': 'building',
- 'filter': ['==', 'extrude', 'true'],
- 'type': 'fill-extrusion',
- 'minzoom': 15,
- 'paint': {
- 'fill-extrusion-color': '#aaa',
-
-
- 'fill-extrusion-height': [
- "interpolate", ["linear"],
- ["zoom"],
- 15, 0,
- 15.05, ["get", "height"]
- ],
- 'fill-extrusion-base': [
- "interpolate", ["linear"],
- ["zoom"],
- 15, 0,
- 15.05, ["get", "min_height"]
- ],
- 'fill-extrusion-opacity': .6
- }
- });
- });
-
- geojsonFeature.features.forEach(function(feature) {
- bounds.extend(feature.geometry.coordinates);
- });
- map.fitBounds(bounds, {
- padding: 40
- });
-
- map.on('click', 'points', function(e) {
- var coordinates = e.features[0].geometry.coordinates.slice();
- var description = e.features[0].properties.tooltip;
- var chart = e.features[0].properties.chart;
- var clr = e.features[0].properties.color;
- var id = e.features[0].properties.id;
-
- while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
- coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
- }
-
- new mapboxgl.Popup()
- .setLngLat(coordinates)
- .setHTML(description)
- .addTo(map);
-
-
- });
-
- map.on('mouseenter', 'points', function() {
- map.getCanvas().style.cursor = 'pointer';
- });
-
- map.on('mouseleave', 'points', function() {
- map.getCanvas().style.cursor = '';
- });
-
-
-
- $("[lid='List1']").css("background-color", "#ffffff");
- var numCols = $('[lid="List1"] tr:nth-child(1) td').length;
- $("[lid='List1'] tr").each(function(i) {
- var $tds = $(this).find('td'),
- msg = $tds.eq(2).text(),
- lon = $tds.eq(numCols - 1).text(),
- lat = $tds.eq(numCols - 2).text();
- $tds.eq(numCols - 1).hide();
- $tds.eq(numCols - 2).hide();
-
- var MapClickIcon = '<td class="lc" style="padding: 2px 5px 2px 5px; vertical-align: top; text-align:center; ">  <a class="flyMe" href="#" onclick ="flyToStore(' + parseFloat(lon) + ',' + parseFloat(lat) + ',' + parseFloat(lat) + ',\'' + msg + '\');"> <img height="20px" width="15px" src="https://dedicated-bsln.analytics-devlab-nonprod.w3cloud.ibm.com/bi/samples/images/Team10_map-pin-02.png"></img></a> </td>'
- var resetIcon = '<td bgcolor="#EEEEEE" style="padding: 2px 5px 2px 5px; vertical-align: middle; text-align:center; " ><a href="#" onclick ="reset()"> <img height="20px" width="20px" src="https://dedicated-bsln.analytics-devlab-nonprod.w3cloud.ibm.com/bi/samples/images/Team10_refresh.png"></img></a> </td>'
- if (i == 0) {
- $(this).prepend(resetIcon);
- } else {
- $(this).prepend(MapClickIcon);
- }
- });
-
- $("[lid='List1'] tr").not(':first').hover(
- function() {
- var $tds = $(this).find('td');
- if ($tds.eq(4).text().indexOf("-") >= 0) {
- var lat = $tds.eq(4).text().split('-')
- var did = $tds.eq(5).text() + ',' + lat[1];
- } else {
- var did = $tds.eq(5).text() + ',' + $tds.eq(4).text();
- }
- },
- function() {
- $(this).css("background", "");
- }
- );
-
-
-
-
-
-
-
-
-
- };
- mapControl.prototype.setData = function(oControlHost, oDataStore) {
- this.m_oDataStore = oDataStore;
-
-
-
-
-
-
-
- var iRowCount = oDataStore.rowCount;
- for (var iRow = 0; iRow < iRowCount; iRow++) {
- var feature = {}
- feature['type'] = 'Feature'
- feature['geometry'] = {
- 'type': 'Point',
- 'coordinates': [parseFloat(oDataStore.getCellValue(iRow, 1)), parseFloat(oDataStore.getCellValue(iRow, 2)) * 1],
- }
- feature['properties'] = { 'id': oDataStore.getCellValue(iRow, 0), 'tooltip': oDataStore.getCellValue(iRow, 3), 'color': oDataStore.getCellValue(iRow, 4) }
- geojsonFeature['features'].push(feature)
- }
- };
- return mapControl;
- });
- function flyToStore(lng, lat, msg) {
- $('.proximityData').hide("fade", '', 500);
- $('.curLocation').text('View Center on: (' + lat + ',' + lng + ')');
- $('.reset').show();
- $('[lid="legendLive"]').hide()
- $('[lid="legendCognos"]').hide()
- curLon = lng;
- curLat = lat;
- if (lat < 0) {
- lat = -lat
- }
- map.flyTo({ center: [lng, lat], zoom: 14 });
- try {
- map.removeLayer("buff");
- map.removeSource("buffer");
- } catch (err) {
- console.log("Error!");
- }
- var nullIsland = {
- type: 'Feature',
- geometry: {
- type: 'Point',
- coordinates: [lng, lat]
- },
- properties: {
- name: 'Null Island'
- }
- };
-
- var oneMileOut = createGeoJSONCircle([lng, lat], .125).data
-
- map.addSource("buffer", {
- "type": "geojson",
- "data": oneMileOut
- });
- map.addLayer({
- "id": "buff",
- "type": "fill",
- "source": "buffer",
- "paint": {
- "fill-color": "#ffffff",
- "fill-opacity": 0.2
- },
- "filter": ["==", "$type", "Polygon"]
- }, "points");
- }
- function resetBounds() {
- map.fitBounds(bounds, {
- padding: 40
- });
- }
- var createGeoJSONCircle = function(center, radiusInKm, points) {
- var geoFeatures = [];
- var counts = [];
- var statCounts = [];
- for (var k = 0; k < 4; k++) {
- if (!points) points = 64;
- var coords = {
- latitude: center[1],
- longitude: center[0]
- };
- var km = radiusInKm * (k + 1);
- var ret = [];
- var distanceX = km / (111.320 * Math.cos(coords.latitude * Math.PI / 180));
- var distanceY = km / 110.574;
- var theta, x, y;
- for (var i = 0; i < points; i++) {
- theta = (i / points) * (2 * Math.PI);
- x = distanceX * Math.cos(theta);
- y = distanceY * Math.sin(theta);
- ret.push([coords.longitude + x, coords.latitude + y]);
- }
- ret.push(ret[0]);
- var feature = {}
- feature['type'] = 'Feature'
- feature['geometry'] = {
- 'type': 'Polygon',
- 'coordinates': [ret],
- }
- feature['properties'] = { 'circle': k }
- geoFeatures.push(feature)
- }
- return {
- "type": "geojson",
- "data": {
- "type": "FeatureCollection",
- "features": geoFeatures
- }
- };
- };
- function reset() {
- resetBounds();
- curLat = 0;
- $('.curLocation').text('View: All');
- $('.proximityData').hide("fade", '', 500);
- $('.reset').hide();
- $('[lid="legendLive"]').show()
- $('[lid="legendCognos"]').show()
-
- $("[lid='List1'] tr").removeClass('trBlock');
- $("[lid='List1'] td").removeClass('tdBlock');
- $("[lid='List1'] tr").show();
- }
- function layerToggle(clickedLayer) {
- var visibility = map.getLayoutProperty(clickedLayer, 'visibility');
- if (visibility === 'visible') {
- map.setLayoutProperty(clickedLayer, 'visibility', 'none');
- } else {
- map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
- }
- };
|