Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

OR Markers

robindekkersb54ff72ddb4b
diff --git a/ui/component/or-map-marker/.npmignore b/ui/component/or-map-marker/.npmignore
new file mode 100644
index 000000000..ca658009d
--- /dev/null
+++ b/ui/component/or-map-marker/.npmignore
@@ -0,0 +1,3 @@
+build/
+build.gradle
+test/
\ No newline at end of file
diff --git a/ui/component/or-map-marker/README.md b/ui/component/or-map-marker/README.md
new file mode 100644
index 000000000..db087e0eb
--- /dev/null
+++ b/ui/component/or-map-marker/README.md
@@ -0,0 +1,21 @@
+# \<or-asset-tree\>
+
+Displays assets in a tree
+
+## Install the Polymer-CLI
+
+First, make sure you have the [Polymer CLI](https://www.npmjs.com/package/polymer-cli) and npm (packaged with [Node.js](https://nodejs.org)) installed. Run `npm install` to install your element's dependencies, then run `polymer serve` to serve your element locally.
+
+## Viewing Your Element
+
+```
+$ polymer serve
+```
+
+## Running Tests
+
+```
+$ polymer test
+```
+
+Your application is already set up to be tested via [web-component-tester](https://github.com/Polymer/web-component-tester). Run `polymer test` to run your application's test suite locally.
diff --git a/ui/component/or-map-marker/build.gradle b/ui/component/or-map-marker/build.gradle
new file mode 100644
index 000000000..012bdf2b6
--- /dev/null
+++ b/ui/component/or-map-marker/build.gradle
@@ -0,0 +1,11 @@
+task clean() {
+ doLast {
+ delete "dist"
+ }
+}
+
+task build() {
+ dependsOn npmBuild
+}
+
+npmBuild.dependsOn(resolveTask(":ui:component:rest:build"))
\ No newline at end of file
diff --git a/ui/component/or-map-marker/package.json b/ui/component/or-map-marker/package.json
new file mode 100644
index 000000000..ee4dca0dc
--- /dev/null
+++ b/ui/component/or-map-marker/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "@openremote/or-map-marker",
+ "version": "1.0.0",
+ "description": "Displays or map marker",
+ "main": "build/or-map-marker.js",
+ "types": "src/or-map-marker.ts",
+ "scripts": {
+ "build": "npx tsc",
+ "test": "echo \"No tests\" && exit 0"
+ },
+ "author": "OpenRemote",
+ "license": "AGPL-3.0-or-later",
+ "dependencies": {
+ "@polymer/polymer": "^3.0.0",
+ "@openremote/or-map": "^1.0.0",
+ "@openremote/rest": "^1.0.0"
+ },
+ "devDependencies": {
+ "typescript": "^3.1.6",
+ "tslint": "^5.11.0",
+ "@polymer/iron-demo-helpers": "^3.0.0-pre.19",
+ "@webcomponents/webcomponentsjs": "^2.0.0",
+ "wct-browser-legacy": "^1.0.0"
+ }
+}
diff --git a/ui/component/or-map-marker/src/or-map-marker-basic.ts b/ui/component/or-map-marker/src/or-map-marker-basic.ts
new file mode 100644
index 000000000..038b20986
--- /dev/null
+++ b/ui/component/or-map-marker/src/or-map-marker-basic.ts
@@ -0,0 +1,44 @@
+import {html} from "@polymer/polymer";
+import {customElement, property} from "@polymer/decorators";
+import {OrMapMarker} from "./or-map-marker";
+
+
+/**
+ * `or-map-marker`
+ * Displays marker on OpenRemote Map
+ *
+ * @customElement
+ * @polymer
+ * @demo demo/index.html
+ */
+
+@customElement('or-map-marker-basic')
+export class OrMapMarkerBasic extends OrMapMarker {
+ @property({type: Number})
+ lat: number = 0;
+
+ @property({type: Number})
+ lng: number = 0;
+
+ @property({type: String})
+ icon: string = '';
+
+ ready() {
+ super.ready();
+ this._lat = this.lat;
+ this._lng = this.lng;
+ const div = document.createElement('div');
+ div.innerHTML = `<style>
+ .marker {
+ position: absolute;
+ width: 32px;
+ height: 32px;
+ background-size: 32px;
+ }
+ </style>
+ <div style="background-image: url('${this.icon}');" class="marker"></div>`;
+ this._html = div;
+ }
+
+}
+
diff --git a/ui/component/or-map-marker/src/or-map-marker.ts b/ui/component/or-map-marker/src/or-map-marker.ts
new file mode 100644
index 000000000..9bb51041f
--- /dev/null
+++ b/ui/component/or-map-marker/src/or-map-marker.ts
@@ -0,0 +1,27 @@
+import {html, PolymerElement} from "@polymer/polymer";
+
+/**
+ * `or-map-marker`
+ * Displays marker on OpenRemote Map
+ *
+ * @customElement
+ * @polymer
+ * @demo demo/index.html
+ */
+export abstract class OrMapMarker extends PolymerElement {
+ protected _lat: number = 0;
+ protected _lng: number = 0;
+ protected _html?: HTMLElement = undefined;
+
+ get latitude(): number {
+ return this._lat;
+ }
+
+ get longitude(): number {
+ return this._lng;
+ }
+
+ get html(): HTMLElement | undefined {
+ return this._html;
+ }
+}
\ No newline at end of file
diff --git a/ui/component/or-map-marker/tsconfig.json b/ui/component/or-map-marker/tsconfig.json
new file mode 100644
index 000000000..2a929565b
--- /dev/null
+++ b/ui/component/or-map-marker/tsconfig.json
@@ -0,0 +1,12 @@
+{
+ "compilerOptions": {
+ "outDir": "./dist/",
+ "strict": true,
+ "module": "es6",
+ "target": "es2015",
+ "declaration": true,
+ "sourceMap": true,
+ "moduleResolution": "node",
+ "experimentalDecorators": true
+ }
+}
\ No newline at end of file
diff --git a/ui/component/or-map-marker/tslint.json b/ui/component/or-map-marker/tslint.json
new file mode 100644
index 000000000..846fa2dfc
--- /dev/null
+++ b/ui/component/or-map-marker/tslint.json
@@ -0,0 +1,11 @@
+{
+ "defaultSeverity": "error",
+ "extends": "tslint:recommended",
+ "rules": {
+ "interface-name" : [true, "never-prefix"],
+ "variable-name": [false],
+ "trailing-comma": [false],
+ "no-trailing-whitespace": [false],
+ "no-console": [false]
+ }
+}
\ No newline at end of file
diff --git a/ui/component/or-map/src/or-map.ts b/ui/component/or-map/src/or-map.ts
index d3ec6b763..f854e8052 100644
--- a/ui/component/or-map/src/or-map.ts
+++ b/ui/component/or-map/src/or-map.ts
@@ -1,7 +1,9 @@
import openremote, {EventCallback, OREvent} from "@openremote/core";
import {html, PolymerElement} from "@polymer/polymer";
+import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
import {customElement, property} from '@polymer/decorators';
import rest from "@openremote/rest";
+import {OrMapMarker} from "@openremote/or-map-marker";
import {Map, MapboxOptions, Style as MapboxStyle} from "mapbox-gl";
import L from "mapbox.js";
@@ -21,6 +23,7 @@ export class OrMap extends PolymerElement {
protected _map?: Map;
protected static _mapboxGlStyle?: any;
protected static _mapboxJsStyle?: any;
+ protected _observer?: FlattenedNodesObserver;
protected _loaded: boolean;
static get template() {
@@ -35,8 +38,12 @@ export class OrMap extends PolymerElement {
width: 100%;
height: 100%;
}
+ slot {
+ display: none;
+ }
</style>
<div id="map"></div>
+ <slot id="markers-slot"></slot>
`;
}
@@ -47,6 +54,26 @@ export class OrMap extends PolymerElement {
super();
}
+ _processNewMarkers(nodes) {
+ nodes.forEach(function (node) {
+ // node tagName should include marker to pass this check
+ if(node instanceof OrMapMarker) {
+ const marker = <OrMapMarker>node;
+ let leafletMarket = L.divIcon({className: 'map-marker', html: marker.html.innerHTML});
+ L.marker([marker.latitude, marker.longitude], {icon:leafletMarket}).addTo(this._map);
+ }
+ }.bind(this));
+ }
+
+ _processRemovedMarkers(nodes) {
+
+ }
+
+ disconnectedCallback() {
+ super.disconnectedCallback();
+ this._observer.disconnect();
+ }
+
ready() {
super.ready();
@@ -102,6 +129,7 @@ export class OrMap extends PolymerElement {
}
const m: L.mapbox.map = new L.mapbox.map(mapElement, settings, options);
+ this._map = m;
} else {
if (!OrMap._mapboxGlStyle) {
@@ -137,8 +165,17 @@ export class OrMap extends PolymerElement {
this._map = new map.Map(options);
}
+
+ // Get markers from slot
+ let slotElement = this.shadowRoot.getElementById('markers-slot');
+ this._observer = new FlattenedNodesObserver(slotElement, (info) => {
+ this._processNewMarkers(info.addedNodes);
+ this._processRemovedMarkers(info.removedNodes);
+ });
}
+
+
this._loaded = true;
}
}
diff --git a/ui/demo/demo-or-map/index.html b/ui/demo/demo-or-map/index.html
index ec74f262e..7df7c750e 100644
--- a/ui/demo/demo-or-map/index.html
+++ b/ui/demo/demo-or-map/index.html
@@ -16,8 +16,10 @@
<h3>Demo</h3>
<demo-snippet>
<template>
+ <or-map type="RASTER" style="height: 500px; width: 100%;">
+ <or-map-marker-basic lat="51.4403423" lng="5.4679712" click-action="showCard" icon="http://pngimg.com/uploads/smiley/smiley_PNG36233.png"></or-map-marker-basic>
+ </or-map>
<or-map style="height: 500px; width: 100%;"></or-map>
- <or-map type="RASTER" style="height: 500px; width: 100%;"></or-map>
</template>
</demo-snippet>
</div>
diff --git a/ui/demo/demo-or-map/src/index.ts b/ui/demo/demo-or-map/src/index.ts
index 8ea3a118f..ab218a93f 100644
--- a/ui/demo/demo-or-map/src/index.ts
+++ b/ui/demo/demo-or-map/src/index.ts
@@ -1,6 +1,7 @@
import '@polymer/iron-demo-helpers/demo-pages-shared-styles';
import '@polymer/iron-demo-helpers/demo-snippet';
import "@openremote/or-map";
+import "@openremote/or-map-marker/src/or-map-marker-basic";
import openremote, {Auth} from "@openremote/core";
openremote.init({