해당 특성을 기반으로 기능 레이어를 선택하는 데 문제가 있습니다. 나는 아래의 코드를 가지고 있지만 말한다 :Openlayer에서 내부 함수를 호출하는 방법은 무엇입니까?
는Uncaught TypeError: Cannot read property 'features' of undefined
여기 내 코드입니다 :
var init = function() { // A function that will initialize and execute all the declared variables
var geographic = new OpenLayers.Projection("EPSG:4326"); // Setting the standard geographic projection
var mercator = new OpenLayers.Projection("EPSG:3857"); // Setting the universal geographic projection
map = new OpenLayers.Map('map'); // Creating & initializing map constructor
var base_osm = new OpenLayers.Layer.OSM("OpenStreetMap"); // Setting OpenStreetMap as a BaseMap
map.addControl(
new OpenLayers.Control.MousePosition({
prefix: '<small style="color:blue">',
suffix: '</small>',
numDigits: 2,
emptyString: '<small style="color:red">' + 'Mouse is not over map.' +'</small>'
})
);
var layer_agao = new OpenLayers.Layer.Vector("Agao");
map.addLayers([layer_agao, base_osm]); // Adding the vector layer to the map
map.addControl(new OpenLayers.Control.LayerSwitcher());
selectControl = new OpenLayers.Control.SelectFeature(layer_agao, {
onSelect: onFeatureSelect, onUnselect: onFeatureUnselect
});
map.addControl(selectControl);
selectControl.activate();
map.setCenter(new OpenLayers.LonLat(13975400.3513, 999830.692078),16);
var format_agao = new OpenLayers.Format.GeoJSON(); //initializing and calling the rendered GeoJSON Layer from views.py
var feat_agao = format_agao.read({{agao_transform|safe}});
layer_agao.addFeatures(feat_agao);
layer_agao.events.on({
featureselected: function(event) {
var feature = event.feature;
var area = feature.geometry.getArea();
var id = feature.attributes.newpin;
var output = "Land Pin: " + id + "<br/>" + "Area: " + area.toFixed(12);
document.getElementById("status").innerHTML = output;
}
});
init.showparcel();
}
init.showparcel = function (getpin){
for(var f=0;f<layer_agao.features.length;f++) {
if(layer_agao.features[f].attributes.newpin == getpin) {
selectControl.select(layer_agao.features[f]);
break;
}
}
}
나는 또한 getfeaturesbyattribute에 대해 읽어,하지만 난 어떤 예를 찾을 수 없습니다. 그렇다면 클릭 (이벤트)시 특정 기능 레이어를 호출하는 다른 방법이 있습니까? 이것은 내 검색을위한 것입니다 ...
showparcel 또는 실제 마우스 이벤트로 선택 하시겠습니까? –
어느 쪽이든 .. 나는 속성에 따라 소포를 보여주고 싶습니다. '지도에서 소포 표시'버튼을 클릭하면 해당 PIN이있는 구획/지형지 물이 선택됩니다. –
우리는 이것을 gis 섹션으로 검토해야합니다. –