OpenMap.Layer.FlowPopLayer = OpenLayers.Class(OpenLayers.Layer.Vector, { isBaseLayer: false, drawn: false, operator: null, pre: null, success: null, error: null, isServerSide : false, // projection:"EPSG:4326", // displayProjection:"EPSG:900913", CLASS_NAME: "OpenMap.Layer.FlowPopLayer", initialize: function(options) { this.layerProperty = options.layerProperty; arguments = [].slice.call(arguments); arguments.unshift(this.layerProperty.LAYER_NM); OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments); var age = this.layerProperty.PROPERTY_JSON.age var time = this.layerProperty.PROPERTY_JSON.time; // var age = this.layerProperty.age // var time = this.layerProperty.time; // this.layerProperty.PROPERTY_JSON = {}; // this.layerProperty.PROPERTY_JSON.age = age; // this.layerProperty.PROPERTY_JSON.time = time; this.layerProperty.minpop = '0'; this.layerProperty.maxpop = '0'; //var colors = ['#1D96D5','#1DD545','#FBF008','#FF9200','#FF331E']; var colors = ['#FFCCCC','#FF9999','#FF6666','#FF3333','#FF0000']; var strokeWidthes = [2, 4, 6, 8, 10]; var context = { getColor: function(feature) { //console.log(colors[feature.attributes["type"]]); return colors[feature.attributes["type"]]; }, getStrokeWidth: function(feature) { return strokeWidthes [feature.attributes["type"]]; } }; var template = { strokeColor: "${getColor}", // using context.getColor(feature) strokeWidth: "${getStrokeWidth}" // using context.getColor(feature) }; var style = new OpenLayers.Style(template, {context: context}); this.styleMap = new OpenLayers.StyleMap(style) }, getName : function() { return this.layerProperty.LAYER_NM; }, getLayerId : function() { return this.layerProperty.LAYER_ID; }, setMap: function(map) { OpenLayers.Layer.Vector.prototype.setMap.call(this,map); this.map.events.register("moveend", this, this.update); this.update(); }, removeMap: function(map) { OpenLayers.Layer.Vector.prototype.removeMap.call(this,map); this.map.events.unregister("moveend", this, this.update); }, setCallback: function(pre,success,error) { this.pre = pre; this.success = success; this.error = error; }, setAge: function(age) { this.layerProperty.PROPERTY_JSON.age = age; this.events.triggerEvent('propertychanged', {layer:this}); }, setTime: function(time) { this.layerProperty.PROPERTY_JSON.time = time; this.events.triggerEvent('propertychanged', {layer:this}); }, setProperty: function(property) { this.property = property; this.events.triggerEvent('propertychanged', {layer:this}); }, update: function() { if(this.pre != null) this.pre(); if(this.operator != null) { this.operator.cancel(); this.operator = null; } if(this.map.getZoom() < 8) { this.removeAllFeatures(); if(this.error != null) this.error('현재 줌 레벨에서는 유동인구를 보실 수 없습니다.'); return; } // var mbr = this.getExtent().transform(this.map.getProjectionObject(),new OpenLayers.Projection('OPENMATE')); var mbr = this.getExtent().transform(this.map.projection, this.map.dataProjection); var params = { // 's_i_d' : 'flow', // 'LF' : 'geoCluster.common', // 'LID' : 'rFlowPopList', 'columns' : 'pop_' + this.layerProperty.PROPERTY_JSON.age + '_' + this.layerProperty.PROPERTY_JSON.time, 'age' : this.layerProperty.PROPERTY_JSON.age.substring(0,2), 'time' : this.layerProperty.PROPERTY_JSON.time, minx : mbr.left, miny : mbr.bottom, maxx : mbr.right, maxy : mbr.top }; this.operator = new FlowPopOperator(this); this.operator.run(params); }, omprint : function(zoom, minX, minY, maxX, maxY) { var features = []; var bounds = new OpenLayers.Bounds(minX,minY,maxX,maxY); var ret = []; // 레이어 숨김 속성.. if(this.visibility == false) return []; // 모든 Feature에 대해 for(var i=0; i< this.features.length; i++) { var m = this.features[i]; if(!m.getVisibility()) continue; var feature = {}; feature['fill'] = feature['color'] = this.styleMap.styles["default"].context.getColor(m);// '0xee9900'; feature['thick'] = this.styleMap.styles["default"].context.getStrokeWidth(m); // feature['fill'] = '0xee9900'; feature['opacity'] = 0.4; feature['type'] = 'polyline'; feature.points = []; for(var j = 0 ; j < m.geometry.components.length; j++) { var c = m.geometry.components[j]; feature.points.push(c.x,c.y); } ret.push(feature); } return ret; } }); function FlowPopOperator(owner) { this.isCancelled = false; //this.isRun = false; this.run = function(params) { if(this.isCancelled) { //console.log('cancel1') return; } setTimeout($.proxy(function() { if(this.isCancelled) { //console.log('cancel2') return; } $.ajax({ context: this, url: OpenMap.Config.flowPopUrl, cache: false, type: "GET", //timeout:3000, data: params, layer: owner, success: function(flowpopList) { if(this.isCancelled) { //console.log('cancel3') return; } // todo: add features.. var list = flowpopList.rFlowPopList; var features = new Array(list.length); if(this.isCancelled) { //console.log('cancel4') return; } for (var i=0; i